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