]> git.lizzy.rs Git - irrlicht.git/blob - source/Irrlicht/CGUIEditBox.h
b0b5070643e22c5be641c51156bcf160573ced8f
[irrlicht.git] / source / Irrlicht / CGUIEditBox.h
1 // Copyright (C) 2002-2012 Nikolaus Gebhardt\r
2 // This file is part of the "Irrlicht Engine".\r
3 // For conditions of distribution and use, see copyright notice in irrlicht.h\r
4 \r
5 #ifndef __C_GUI_EDIT_BOX_H_INCLUDED__\r
6 #define __C_GUI_EDIT_BOX_H_INCLUDED__\r
7 \r
8 #include "IrrCompileConfig.h"\r
9 #ifdef _IRR_COMPILE_WITH_GUI_\r
10 \r
11 #include "IGUIEditBox.h"\r
12 #include "irrArray.h"\r
13 #include "IOSOperator.h"\r
14 \r
15 namespace irr\r
16 {\r
17 namespace gui\r
18 {\r
19         class CGUIEditBox : public IGUIEditBox\r
20         {\r
21         public:\r
22 \r
23                 //! constructor\r
24                 CGUIEditBox(const wchar_t* text, bool border, IGUIEnvironment* environment,\r
25                         IGUIElement* parent, s32 id, const core::rect<s32>& rectangle);\r
26 \r
27                 //! destructor\r
28                 virtual ~CGUIEditBox();\r
29 \r
30                 //! Sets another skin independent font.\r
31                 void setOverrideFont(IGUIFont* font=0) override;\r
32 \r
33                 //! Gets the override font (if any)\r
34                 /** \return The override font (may be 0) */\r
35                 IGUIFont* getOverrideFont() const override;\r
36 \r
37                 //! Get the font which is used right now for drawing\r
38                 /** Currently this is the override font when one is set and the\r
39                 font of the active skin otherwise */\r
40                 IGUIFont* getActiveFont() const override;\r
41 \r
42                 //! Sets another color for the text.\r
43                 void setOverrideColor(video::SColor color) override;\r
44 \r
45                 //! Gets the override color\r
46                 video::SColor getOverrideColor() const override;\r
47 \r
48                 //! Sets if the text should use the override color or the\r
49                 //! color in the gui skin.\r
50                 void enableOverrideColor(bool enable) override;\r
51 \r
52                 //! Checks if an override color is enabled\r
53                 /** \return true if the override color is enabled, false otherwise */\r
54                 bool isOverrideColorEnabled(void) const override;\r
55 \r
56                 //! Sets whether to draw the background\r
57                 void setDrawBackground(bool draw) override;\r
58 \r
59                 //! Checks if background drawing is enabled\r
60                 bool isDrawBackgroundEnabled() const override;\r
61 \r
62                 //! Turns the border on or off\r
63                 void setDrawBorder(bool border) override;\r
64 \r
65                 //! Checks if border drawing is enabled\r
66                 bool isDrawBorderEnabled() const override;\r
67 \r
68                 //! Enables or disables word wrap for using the edit box as multiline text editor.\r
69                 void setWordWrap(bool enable) override;\r
70 \r
71                 //! Checks if word wrap is enabled\r
72                 //! \return true if word wrap is enabled, false otherwise\r
73                 bool isWordWrapEnabled() const override;\r
74 \r
75                 //! Enables or disables newlines.\r
76                 /** \param enable: If set to true, the EGET_EDITBOX_ENTER event will not be fired,\r
77                 instead a newline character will be inserted. */\r
78                 void setMultiLine(bool enable) override;\r
79 \r
80                 //! Checks if multi line editing is enabled\r
81                 //! \return true if mult-line is enabled, false otherwise\r
82                 bool isMultiLineEnabled() const override;\r
83 \r
84                 //! Enables or disables automatic scrolling with cursor position\r
85                 //! \param enable: If set to true, the text will move around with the cursor position\r
86                 void setAutoScroll(bool enable) override;\r
87 \r
88                 //! Checks to see if automatic scrolling is enabled\r
89                 //! \return true if automatic scrolling is enabled, false if not\r
90                 bool isAutoScrollEnabled() const override;\r
91 \r
92                 //! Gets the size area of the text in the edit box\r
93                 //! \return Returns the size in pixels of the text\r
94                 core::dimension2du getTextDimension() override;\r
95 \r
96                 //! Sets text justification\r
97                 void setTextAlignment(EGUI_ALIGNMENT horizontal, EGUI_ALIGNMENT vertical) override;\r
98 \r
99                 //! called if an event happened.\r
100                 bool OnEvent(const SEvent& event) override;\r
101 \r
102                 //! draws the element and its children\r
103                 void draw() override;\r
104 \r
105                 //! Sets the new caption of this element.\r
106                 void setText(const wchar_t* text) override;\r
107 \r
108                 //! Sets the maximum amount of characters which may be entered in the box.\r
109                 //! \param max: Maximum amount of characters. If 0, the character amount is\r
110                 //! infinity.\r
111                 void setMax(u32 max) override;\r
112 \r
113                 //! Returns maximum amount of characters, previously set by setMax();\r
114                 u32 getMax() const override;\r
115 \r
116                 //! Set the character used for the cursor.\r
117                 /** By default it's "_" */\r
118                 void setCursorChar(const wchar_t cursorChar) override;\r
119 \r
120                 //! Get the character used for the cursor.\r
121                 wchar_t getCursorChar() const override;\r
122 \r
123                 //! Set the blinktime for the cursor. 2x blinktime is one full cycle.\r
124                 //** \param timeMs Blinktime in milliseconds. When set to 0 the cursor is constantly on without blinking */\r
125                 void setCursorBlinkTime(irr::u32 timeMs) override;\r
126 \r
127                 //! Get the cursor blinktime\r
128                 irr::u32 getCursorBlinkTime() const override;\r
129 \r
130                 //! Sets whether the edit box is a password box. Setting this to true will\r
131                 /** disable MultiLine, WordWrap and the ability to copy with ctrl+c or ctrl+x\r
132                 \param passwordBox: true to enable password, false to disable\r
133                 \param passwordChar: the character that is displayed instead of letters */\r
134                 void setPasswordBox(bool passwordBox, wchar_t passwordChar = L'*') override;\r
135 \r
136                 //! Returns true if the edit box is currently a password box.\r
137                 bool isPasswordBox() const override;\r
138 \r
139                 //! Updates the absolute position, splits text if required\r
140                 void updateAbsolutePosition() override;\r
141 \r
142                 //! Returns whether the element takes input from the IME\r
143                 bool acceptsIME() override;\r
144 \r
145         protected:\r
146                 //! Breaks the single text line.\r
147                 void breakText();\r
148                 //! sets the area of the given line\r
149                 void setTextRect(s32 line);\r
150                 //! returns the line number that the cursor is on\r
151                 s32 getLineFromPos(s32 pos);\r
152                 //! adds a letter to the edit box\r
153                 void inputChar(wchar_t c);\r
154                 //! adds a string to the edit box\r
155                 void inputString(const core::stringw &str);\r
156                 //! calculates the current scroll position\r
157                 void calculateScrollPos();\r
158                 //! calculated the FrameRect\r
159                 void calculateFrameRect();\r
160                 //! send some gui event to parent\r
161                 void sendGuiEvent(EGUI_EVENT_TYPE type);\r
162                 //! set text markers\r
163                 void setTextMarkers(s32 begin, s32 end);\r
164                 //! delete current selection or next char\r
165                 bool keyDelete();\r
166 \r
167                 bool processKey(const SEvent& event);\r
168                 bool processMouse(const SEvent& event);\r
169                 s32 getCursorPos(s32 x, s32 y);\r
170 \r
171                 bool OverwriteMode;\r
172                 bool MouseMarking;\r
173                 bool Border;\r
174                 bool Background;\r
175                 bool OverrideColorEnabled;\r
176                 s32 MarkBegin;\r
177                 s32 MarkEnd;\r
178 \r
179                 video::SColor OverrideColor;\r
180                 gui::IGUIFont *OverrideFont, *LastBreakFont;\r
181                 IOSOperator* Operator;\r
182 \r
183                 u32 BlinkStartTime;\r
184                 irr::u32 CursorBlinkTime;\r
185                 core::stringw CursorChar; // IGUIFont::draw needs stringw instead of wchar_t\r
186                 s32 CursorPos;\r
187                 s32 HScrollPos, VScrollPos; // scroll position in characters\r
188                 u32 Max;\r
189 \r
190                 bool WordWrap, MultiLine, AutoScroll, PasswordBox;\r
191                 wchar_t PasswordChar;\r
192                 EGUI_ALIGNMENT HAlign, VAlign;\r
193 \r
194                 core::array< core::stringw > BrokenText;\r
195                 core::array< s32 > BrokenTextPositions;\r
196 \r
197                 core::rect<s32> CurrentTextRect, FrameRect; // temporary values\r
198         };\r
199 \r
200 \r
201 } // end namespace gui\r
202 } // end namespace irr\r
203 \r
204 #endif // _IRR_COMPILE_WITH_GUI_\r
205 #endif // __C_GUI_EDIT_BOX_H_INCLUDED__\r
206 \r