1 /*
2 Copyright © 2011-2012 kitano
3 Copyright © 2013 Kurt Rinnert
4 Copyright © 2014 Henrik Andersson
5 Copyright © 2012-2016 Justin Jacobs
6 
7 This file is part of FLARE.
8 
9 FLARE is free software: you can redistribute it and/or modify it under the terms
10 of the GNU General Public License as published by the Free Software Foundation,
11 either version 3 of the License, or (at your option) any later version.
12 
13 FLARE is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
15 PARTICULAR PURPOSE.  See the GNU General Public License for more details.
16 
17 You should have received a copy of the GNU General Public License along with
18 FLARE.  If not, see http://www.gnu.org/licenses/
19 */
20 
21 /**
22  * class WidgetInput
23  *
24  * A simple text box with a label above it.
25  * It has two images - one for focused and one for unfocused.
26  */
27 
28 #ifndef WIDGETINPUT_H
29 #define WIDGETINPUT_H
30 
31 #include "CommonIncludes.h"
32 #include "Utils.h"
33 #include "Widget.h"
34 #include "WidgetTooltip.h"
35 
36 class WidgetInput : public Widget {
37 
38 protected:
39 
40 	void loadGraphics(const std::string& filename);
41 	void trimText();
42 	bool checkClick(const Point& mouse);
43 
44 	Sprite *background;
45 
46 	bool enabled;
47 	bool pressed;
48 
49 	std::string text; // the text that has been typed into the box
50 	std::string trimmed_text; // a trimmed version of text that is rendered
51 	std::string trimmed_text_cursor; // same as trimmed_text, but with a '|' inserted to represent the cursor
52 	size_t cursor_pos;
53 
54 	Point font_pos;
55 
56 	// on-screen keyboard tooltip
57 	TooltipData osk_buf;
58 	WidgetTooltip osk_tip;
59 
60 public:
61 	static const std::string DEFAULT_FILE;
62 
63 	explicit WidgetInput(const std::string& filename);
64 	~WidgetInput();
65 	void setPos(int offset_x, int offset_y);
66 
67 	void activate();
68 	void logic();
69 	bool logicAt(int x, int y);
70 	void render();
getText()71 	std::string getText() {
72 		return text;
73 	}
setText(const std::string & _text)74 	void setText(const std::string& _text) {
75 		text = _text;
76 		cursor_pos = text.length();
77 		trimText();
78 	}
79 
80 	bool edit_mode;
81 	unsigned int max_length;
82 	bool only_numbers;
83 	bool accept_to_defocus;
84 };
85 
86 #endif
87