34#include <guichan/font.hpp>
40 , mLoseFocusOnTab(loseFocusOnTab)
43 setFrameSize(skin.frameSize);
46 setWidth(getFont()->getWidth(mText) + 2 *
mPadding);
47 setHeight(getFont()->getHeight() + 2 *
mPadding);
53 if (getFrameSize() == 0)
57 g->
pushClipRect(gcn::Rectangle(0, 0, getWidth(), getHeight()));
62 getFont()->getWidth(mText.substr(0, mCaretPosition)) - mXScroll);
74 const int bs = getFrameSize();
77 state.
width += bs * 2;
89 const char *text = mText.c_str();
90 for (
const char *textPtr = text; *textPtr; ++textPtr)
92 if (*textPtr <
'0' || *textPtr >
'9')
94 setText(mText.substr(0, textPtr - text));
105 int value = atoi(mText.c_str());
123 switch (keyEvent.getKey().getValue())
127 while (mCaretPosition > 0)
130 if ((mText[mCaretPosition] & 192) != 128)
137 unsigned sz = mText.size();
138 while (mCaretPosition < sz)
141 if (mCaretPosition == sz ||
142 (mText[mCaretPosition] & 192) != 128)
154 setCaretPosition(getText().length());
168 setCaretPosition(getText().length());
172 setText(std::string());
176 else if (!getText().empty())
179 setText(std::string());
185 unsigned sz = mText.size();
186 while (mCaretPosition < sz)
189 mText.erase(mCaretPosition, 1);
190 if (mCaretPosition == sz ||
191 (mText[mCaretPosition] & 192) != 128)
198 while (mCaretPosition > 0)
201 int v = mText[mCaretPosition];
202 mText.erase(mCaretPosition, 1);
203 if ((v & 192) != 128)
break;
220 distributeActionEvent();
228 mCaretPosition = mText.size();
238 if (keyEvent.isControlPressed())
249 mText.insert(mCaretPosition,
textInput.getText());
250 mCaretPosition +=
textInput.getText().length();
257 const int caretPos = getCaretPosition();
259 const std::string inputText = getText();
260 std::string name = inputText.substr(0, caretPos);
263 for (
int f = caretPos - 1; f > -1; f--)
268 name = inputText.substr(f + 1, caretPos - startName);
273 if (caretPos == startName)
277 std::vector<std::string> nameList;
285 std::vector<std::string> nameList;
289 std::string line = *i;
295 line = line.substr(0, f);
298 nameList.push_back(line);
306 if (!newName.empty())
308 if(inputText[0] ==
'@' || inputText[0] ==
'/')
309 newName =
"\"" + newName +
"\"";
311 setText(inputText.substr(0, startName) + newName
312 + inputText.substr(caretPos, inputText.length()
315 setCaretPosition(caretPos - name.length() + newName.length());
322 std::string text = getText();
323 std::string::size_type caretPos = getCaretPosition();
327 setCaretPosition(caretPos);
virtual void getAutoCompleteList(std::vector< std::string > &) const
A central point of control for graphics.
void drawText(const std::string &text, int x, int y, gcn::Graphics::Alignment alignment, const gcn::Color &color, gcn::Font *font, bool outline=false, bool shadow=false, const std::optional< gcn::Color > &outlineColor={}, const std::optional< gcn::Color > &shadowColor={})
void setColor(const gcn::Color &color) override
void pushClipRect(const gcn::Rectangle &rect)
Theme * getTheme() const
The global GUI theme.
void textInput(const TextInput &textInput)
Handle text input (should possibly be new event in Guichan).
void keyPressed(gcn::KeyEvent &keyEvent) override
Processes one keypress.
TextHistory * mHistory
Text history.
void drawFrame(gcn::Graphics *graphics) override
Draws the background and border.
int getValue() const
Return the value for a numeric field.
void drawCaret(gcn::Graphics *graphics, int x) override
void draw(gcn::Graphics *graphics) override
Draws the text field.
AutoCompleteLister * mAutoComplete
TextField(const std::string &text=std::string(), bool loseFocusOnTab=true)
Constructor, initializes the text field with the given string.
void setNumeric(bool numeric)
Determine whether the field should be numeric or not.
const Skin & getSkin(SkinType skinType) const
static const gcn::Color & getThemeColor(int type)
Gets the color associated with the type in the default palette (0).
void drawSkin(Graphics *graphics, SkinType type, const WidgetState &state) const
bool insertFromClipboard(std::string &text, std::string::size_type &pos)
Attempts to retrieve text from the clipboard buffer and inserts it in text at position \pos.
bool isWordSeparator(char chr)
Tells wether the character is a word separator.
std::string autocomplete(const std::vector< std::string > &candidates, std::string base)
Returns the most approaching string of base from candidates.
bool matchesLastEntry(const std::string &text)
std::list< std::string > history
Command history.
std::list< std::string >::iterator current
History iterator.
void addEntry(const std::string &text)