Mana
Loading...
Searching...
No Matches
textfield.h
Go to the documentation of this file.
1/*
2 * The Mana Client
3 * Copyright (C) 2004-2009 The Mana World Development Team
4 * Copyright (C) 2009-2012 The Mana Developers
5 *
6 * This file is part of The Mana Client.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#pragma once
23
24#include <guichan/widgets/textfield.hpp>
25
26#include <vector>
27
28class TextInput;
29
31{
32 std::list<std::string> history;
33 std::list<std::string>::iterator current;
36 { current = history.end(); }
37
38 bool empty() const
39 { return history.empty(); }
40
41 bool atBegining() const
42 { return current == history.begin(); }
43
44 bool atEnd() const
45 { return current == history.end(); }
46
48 { current = history.begin(); }
49
50 void toEnd()
51 { current = history.end(); }
52
53 void addEntry(const std::string &text)
54 { history.push_back(text); }
55
56 bool matchesLastEntry(const std::string &text)
57 { return history.back() == text; }
58};
59
61public:
62 virtual ~AutoCompleteLister() = default;
63 virtual void getAutoCompleteList(std::vector<std::string>&) const {}
64};
65
71class TextField : public gcn::TextField
72{
73 public:
77 TextField(const std::string &text = std::string(),
78 bool loseFocusOnTab = true);
79
83 void draw(gcn::Graphics *graphics) override;
84
88 void drawFrame(gcn::Graphics *graphics) override;
89
93 void setNumeric(bool numeric);
94
98 void setRange(int min, int max)
99 {
100 mMinimum = min;
101 mMaximum = max;
102 }
103
107 void keyPressed(gcn::KeyEvent &keyEvent) override;
108
112 void textInput(const TextInput &textInput);
113
117 void setMinimum(int min) { mMinimum = min; }
118
122 void setMaximum(int max) { mMaximum = max; }
123
127 int getValue() const;
128
134 { mAutoComplete = lister; }
135
141
145 void setHistory(TextHistory *history)
146 { mHistory = history; }
147
152 { return mHistory; }
153
154 protected:
155 void drawCaret(gcn::Graphics *graphics, int x) override;
156
157 private:
158 void autoComplete();
159 void handlePaste();
160
161 bool mNumeric = false;
162 int mMinimum = 0;
163 int mMaximum = 0;
165 int mPadding = 1;
166
168
170};
virtual void getAutoCompleteList(std::vector< std::string > &) const
Definition textfield.h:63
virtual ~AutoCompleteLister()=default
A text field.
Definition textfield.h:72
void setMinimum(int min)
Set the minimum value for a range.
Definition textfield.h:117
int mMinimum
Definition textfield.h:162
void textInput(const TextInput &textInput)
Handle text input (should possibly be new event in Guichan).
int mPadding
Definition textfield.h:165
void keyPressed(gcn::KeyEvent &keyEvent) override
Processes one keypress.
void setAutoComplete(AutoCompleteLister *lister)
Sets the TextField's source of autocomplete.
Definition textfield.h:133
AutoCompleteLister * getAutoComplete() const
Returns the TextField's source of autocomplete.
Definition textfield.h:139
bool mNumeric
Definition textfield.h:161
TextHistory * mHistory
Text history.
Definition textfield.h:169
void setMaximum(int max)
Set the maximum value for a range.
Definition textfield.h:122
void drawFrame(gcn::Graphics *graphics) override
Draws the background and border.
Definition textfield.cpp:72
void handlePaste()
void setHistory(TextHistory *history)
Sets the TextField's source of input history.
Definition textfield.h:145
void autoComplete()
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.
Definition textfield.cpp:51
AutoCompleteLister * mAutoComplete
Definition textfield.h:167
bool mLoseFocusOnTab
Definition textfield.h:164
void setRange(int min, int max)
Set the range on the field if it is numeric.
Definition textfield.h:98
TextHistory * getHistory() const
Returns the TextField's source of input history.
Definition textfield.h:151
int mMaximum
Definition textfield.h:163
void setNumeric(bool numeric)
Determine whether the field should be numeric or not.
Definition textfield.cpp:83
Graphics * graphics
Definition client.cpp:104
bool atBegining() const
Definition textfield.h:41
bool atEnd() const
Definition textfield.h:44
void toEnd()
Definition textfield.h:50
bool matchesLastEntry(const std::string &text)
Definition textfield.h:56
std::list< std::string > history
Command history.
Definition textfield.h:32
bool empty() const
Definition textfield.h:38
std::list< std::string >::iterator current
History iterator.
Definition textfield.h:33
void toBegining()
Definition textfield.h:47
void addEntry(const std::string &text)
Definition textfield.h:53