Neo  0.5.0
Developer Documentation
InputField.h
Go to the documentation of this file.
1 /*
2  * Copyright 2014 (C) Yannick Pflanzer <neo-engine.de>
3  *
4  * This file is part of Neo2D.
5  *
6  * Neo2D is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * Neo2D is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with Neo2D. If not, see <http://www.gnu.org/licenses/>.
18  *
19  * Diese Datei ist Teil von Neo2D.
20  *
21  * Neo2D ist Freie Software: Sie können es unter den Bedingungen
22  * der GNU Lesser General Public License, wie von der Free Software Foundation,
23  * Version 3 der Lizenz oder (nach Ihrer Wahl) jeder späteren
24  * veröffentlichten Version, weiterverbreiten und/oder modifizieren.
25  *
26  * Neo2D wird in der Hoffnung, dass es nützlich sein wird, aber
27  * OHNE JEDE GEWÄHRLEISTUNG, bereitgestellt; sogar ohne die implizite
28  * Gewährleistung der MARKTFÄHIGKEIT oder EIGNUNG FÜR EINEN BESTIMMTEN ZWECK.
29  * Siehe die GNU Lesser General Public License für weitere Details.
30  *
31  * Sie sollten eine Kopie der GNU Lesser General Public License zusammen mit
32  *diesem
33  * Programm erhalten haben. Wenn nicht, siehe <http://www.gnu.org/licenses/>.
34  */
35 
36 #ifndef __INPUT_H__
37 #define __INPUT_H__
38 
39 #include <Widget.h>
40 #include <NeoEngine.h>
41 #include <string>
42 
43 namespace Neo2D
44 {
45 namespace Gui
46 {
47 
48 using namespace Neo;
49 
51 {
58 };
59 
61 {
65 };
66 
73 class NEO2D_EXPORT InputField : public Widget
74 {
75 protected:
78  unsigned int m_cursorpos;
79 
82 
83  void updateLabel(string s);
84 
90  Vector2 calculateCursorPos(OText* text, int pos = -1);
91  void addChar(unsigned int c);
92 
93 public:
94  InputField(unsigned int x, unsigned int y, unsigned int width,
95  unsigned int height, const char* label);
96 
97  void draw(Vector2 offset);
98  void update();
99 
100  void setState(INPUT_STATE state) { m_state = state; }
101  const char* getStaticName() { return "InputField"; }
102 
103  void setLabel(const char* str) { m_cursorpos = 0; Widget::setLabel(str); }
104 
105  INPUT_TYPE getType() { return m_inputType; }
106  void setType(INPUT_TYPE t) { m_inputType = t; }
107 
108  bool isMultiline() { return m_multiline; }
109  void setMultiline(bool b) { m_multiline = b; }
110 };
111 }
112 }
113 
114 #endif
The input field is hovered by the mouse cursor.
Definition: InputField.h:55
INPUT_TYPE m_inputType
Definition: InputField.h:80
Definition: InputField.h:62
Definition: OText.h:40
The input field is neither hovered over nor selected.
Definition: InputField.h:53
The Widget class contains all information that is common to all GUI widgets.
Definition: Widget.h:72
INPUT_STATE
Definition: InputField.h:50
void setLabel(const char *l)
Changes the current label of the widget.
Definition: Widget.h:228
OText * m_labelText
Definition: InputField.h:76
INPUT_STATE m_state
Definition: InputField.h:77
Definition: InputField.h:64
const char * getStaticName()
Definition: InputField.h:101
bool isMultiline()
Definition: InputField.h:108
Implements a basic input field that takes keyboard input and delivers it to the program.
Definition: InputField.h:73
Definition: Vector2.h:31
Definition: Button.h:42
Definition: InputField.h:63
void setLabel(const char *str)
Definition: InputField.h:103
INPUT_TYPE
Definition: InputField.h:60
INPUT_TYPE getType()
Definition: InputField.h:105
The input field currently has focus.
Definition: InputField.h:57
unsigned int m_cursorpos
Definition: InputField.h:78
void setState(INPUT_STATE state)
Definition: InputField.h:100
void setType(INPUT_TYPE t)
Definition: InputField.h:106
bool m_multiline
Definition: InputField.h:81
Definition: Color.h:29
void setMultiline(bool b)
Definition: InputField.h:109