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