Luanti 5.10.0-dev
 
Loading...
Searching...
No Matches
guiEditBox.h
Go to the documentation of this file.
1// Luanti
2// SPDX-License-Identifier: LGPL-2.1-or-later
3// Copyright (C) 2021 Minetest
4
5#pragma once
6
7#include "irrlichttypes.h"
8#include "IGUIEditBox.h"
9#include "IOSOperator.h"
10#include "guiScrollBar.h"
11#include <vector>
12
13using namespace irr;
14using namespace irr::gui;
15
16class GUIEditBox : public IGUIEditBox
17{
18public:
19 GUIEditBox(IGUIEnvironment *environment, IGUIElement *parent, s32 id,
20 core::rect<s32> rectangle, bool border, bool writable) :
21 IGUIEditBox(environment, parent, id, rectangle),
22 m_border(border), m_writable(writable), m_frame_rect(rectangle)
23 {
24 }
25
26 virtual ~GUIEditBox();
27
29 virtual void setOverrideFont(IGUIFont *font = 0);
30
31 virtual IGUIFont *getOverrideFont() const { return m_override_font; }
32
34
36 virtual IGUIFont *getActiveFont() const;
37
39 virtual void setOverrideColor(video::SColor color);
40
42 virtual video::SColor getOverrideColor() const;
43
46 virtual void enableOverrideColor(bool enable);
47
49
50 virtual bool isOverrideColorEnabled(void) const
51 {
53 }
54
56 virtual void setWordWrap(bool enable);
57
60 virtual bool isWordWrapEnabled() const { return m_word_wrap; }
61
63 virtual void setDrawBorder(bool border);
64
65 virtual bool isDrawBorderEnabled() const { return m_border; }
66
68
70 virtual void setMultiLine(bool enable);
71
74 virtual bool isMultiLineEnabled() const { return m_multiline; }
75
79 virtual void setAutoScroll(bool enable);
80
83 virtual bool isAutoScrollEnabled() const { return m_autoscroll; }
84
86
89 virtual void setPasswordBox(bool passwordBox, wchar_t passwordChar = L'*');
90
92 virtual bool isPasswordBox() const { return m_passwordbox; }
93
95 virtual void setTextAlignment(EGUI_ALIGNMENT horizontal, EGUI_ALIGNMENT vertical);
96
98 virtual void setText(const wchar_t *text);
99
103 virtual void setMax(u32 max);
104
106 virtual u32 getMax() const { return m_max; }
107
110 virtual core::dimension2du getTextDimension();
111
113 virtual void setWritable(bool can_write_text);
114
116 virtual bool OnEvent(const SEvent &event);
117
118 virtual bool acceptsIME() { return isEnabled() && m_writable; };
119
120protected:
121 virtual void breakText() = 0;
122
124 virtual void setTextRect(s32 line) = 0;
125
127 void setTextMarkers(s32 begin, s32 end);
128
130 void sendGuiEvent(EGUI_EVENT_TYPE type);
131
133 virtual void calculateScrollPos() = 0;
134
135 virtual s32 getCursorPos(s32 x, s32 y) = 0;
136
137 bool processKey(const SEvent &event);
138 virtual void inputString(const core::stringw &str);
139 virtual void inputChar(wchar_t c);
140
142 s32 getLineFromPos(s32 pos);
143
145 void updateVScrollBar();
146
147 gui::IGUIFont *m_override_font = nullptr;
148
150 bool m_word_wrap = false;
151 bool m_multiline = false;
152 bool m_autoscroll = true;
153
155
156 bool m_passwordbox = false;
157 wchar_t m_passwordchar = L'*';
158
159 std::vector<core::stringw> m_broken_text;
160 std::vector<s32> m_broken_text_positions;
161
162 EGUI_ALIGNMENT m_halign = EGUIA_UPPERLEFT;
163 EGUI_ALIGNMENT m_valign = EGUIA_CENTER;
164
168 s32 m_vscroll_pos = 0; // scroll position in characters
169 u32 m_max = 0;
170
171 video::SColor m_override_color = video::SColor(101, 255, 255, 255);
172
173 core::rect<s32> m_current_text_rect = core::rect<s32>(0, 0, 1, 1);
174
176
177 bool m_mouse_marking = false;
178
180 s32 m_mark_end = 0;
181
182 gui::IGUIFont *m_last_break_font = nullptr;
183 IOSOperator *m_operator = nullptr;
184
185 core::rect<s32> m_frame_rect; // temporary values
186
189
190private:
191 bool processMouse(const SEvent &event);
192
193 bool onKeyUp(const SEvent &event, s32 &mark_begin, s32 &mark_end);
194 bool onKeyDown(const SEvent &event, s32 &mark_begin, s32 &mark_end);
195 void onKeyControlC(const SEvent &event);
196 bool onKeyControlX(const SEvent &event, s32 &mark_begin, s32 &mark_end);
197 bool onKeyControlV(const SEvent &event, s32 &mark_begin, s32 &mark_end);
198 bool onKeyBack(const SEvent &event, s32 &mark_begin, s32 &mark_end);
199 bool onKeyDelete(const SEvent &event, s32 &mark_begin, s32 &mark_end);
200};
Definition guiEditBox.h:17
bool m_passwordbox
Definition guiEditBox.h:156
virtual void setText(const wchar_t *text)
Sets the new caption of this element.
Definition guiEditBox.cpp:110
virtual void calculateScrollPos()=0
calculates the current scroll position
virtual u32 getMax() const
Returns maximum amount of characters, previously set by setMax();.
Definition guiEditBox.h:106
IOSOperator * m_operator
Definition guiEditBox.h:183
bool onKeyDelete(const SEvent &event, s32 &mark_begin, s32 &mark_end)
Definition guiEditBox.cpp:626
virtual void setMultiLine(bool enable)
Enables or disables newlines.
Definition guiEditBox.cpp:79
s32 m_hscroll_pos
Definition guiEditBox.h:167
s32 m_vscroll_pos
Definition guiEditBox.h:168
core::rect< s32 > m_current_text_rect
Definition guiEditBox.h:173
bool m_border
Definition guiEditBox.h:154
virtual void setOverrideFont(IGUIFont *font=0)
Sets another skin independent font.
Definition guiEditBox.cpp:26
virtual ~GUIEditBox()
Definition guiEditBox.cpp:14
bool onKeyUp(const SEvent &event, s32 &mark_begin, s32 &mark_end)
Definition guiEditBox.cpp:439
virtual bool isMultiLineEnabled() const
Checks if multi line editing is enabled.
Definition guiEditBox.h:74
bool m_mouse_marking
Definition guiEditBox.h:177
u32 m_scrollbar_width
Definition guiEditBox.h:187
bool m_multiline
Definition guiEditBox.h:151
video::SColor m_override_color
Definition guiEditBox.h:171
virtual void setMax(u32 max)
Sets the maximum amount of characters which may be entered in the box.
Definition guiEditBox.cpp:122
wchar_t m_passwordchar
Definition guiEditBox.h:157
virtual void enableOverrideColor(bool enable)
Sets if the text should use the overide color or the color in the gui skin.
Definition guiEditBox.cpp:66
gui::IGUIFont * m_last_break_font
Definition guiEditBox.h:182
bool onKeyControlX(const SEvent &event, s32 &mark_begin, s32 &mark_end)
Definition guiEditBox.cpp:512
bool m_writable
Definition guiEditBox.h:175
virtual void setWordWrap(bool enable)
Enables or disables word wrap for using the edit box as multiline text editor.
Definition guiEditBox.cpp:72
virtual void inputChar(wchar_t c)
Definition guiEditBox.cpp:662
bool processKey(const SEvent &event)
Definition guiEditBox.cpp:225
virtual s32 getCursorPos(s32 x, s32 y)=0
void setTextMarkers(s32 begin, s32 end)
set text markers
Definition guiEditBox.cpp:160
core::rect< s32 > m_frame_rect
Definition guiEditBox.h:185
virtual bool isDrawBorderEnabled() const
Definition guiEditBox.h:65
virtual bool isAutoScrollEnabled() const
Checks to see if automatic scrolling is enabled.
Definition guiEditBox.h:83
bool processMouse(const SEvent &event)
Definition guiEditBox.cpp:707
std::vector< core::stringw > m_broken_text
Definition guiEditBox.h:159
u32 m_max
Definition guiEditBox.h:169
virtual bool isPasswordBox() const
Returns true if the edit box is currently a password box.
Definition guiEditBox.h:92
virtual bool OnEvent(const SEvent &event)
called if an event happened.
Definition guiEditBox.cpp:194
bool m_autoscroll
Definition guiEditBox.h:152
virtual core::dimension2du getTextDimension()
Gets the size area of the text in the edit box.
Definition guiEditBox.cpp:132
virtual void setDrawBorder(bool border)
Turns the border on or off.
Definition guiEditBox.cpp:149
u32 m_blink_start_time
Definition guiEditBox.h:165
virtual void setWritable(bool can_write_text)
set true if this EditBox is writable
Definition guiEditBox.cpp:154
virtual void setAutoScroll(bool enable)
Enables or disables automatic scrolling with cursor position.
Definition guiEditBox.cpp:86
virtual IGUIFont * getActiveFont() const
Get the font which is used right now for drawing.
Definition guiEditBox.cpp:43
virtual void setPasswordBox(bool passwordBox, wchar_t passwordChar=L' *')
Sets whether the edit box is a password box. Setting this to true will.
Definition guiEditBox.cpp:91
s32 getLineFromPos(s32 pos)
returns the line number that the cursor is on
Definition guiEditBox.cpp:801
virtual void breakText()=0
virtual void setTextAlignment(EGUI_ALIGNMENT horizontal, EGUI_ALIGNMENT vertical)
Sets text justification.
Definition guiEditBox.cpp:103
virtual void inputString(const core::stringw &str)
Definition guiEditBox.cpp:670
bool onKeyControlV(const SEvent &event, s32 &mark_begin, s32 &mark_end)
Definition guiEditBox.cpp:543
s32 m_mark_end
Definition guiEditBox.h:180
EGUI_ALIGNMENT m_valign
Definition guiEditBox.h:163
virtual bool acceptsIME()
Definition guiEditBox.h:118
GUIEditBox(IGUIEnvironment *environment, IGUIElement *parent, s32 id, core::rect< s32 > rectangle, bool border, bool writable)
Definition guiEditBox.h:19
bool onKeyDown(const SEvent &event, s32 &mark_begin, s32 &mark_end)
Definition guiEditBox.cpp:469
s32 m_cursor_pos
Definition guiEditBox.h:166
GUIScrollBar * m_vscrollbar
Definition guiEditBox.h:188
gui::IGUIFont * m_override_font
Definition guiEditBox.h:147
virtual bool isWordWrapEnabled() const
Checks if word wrap is enabled.
Definition guiEditBox.h:60
void updateVScrollBar()
update the vertical scrollBar (visibilty & position)
Definition guiEditBox.cpp:815
virtual void setOverrideColor(video::SColor color)
Sets another color for the text.
Definition guiEditBox.cpp:54
s32 m_mark_begin
Definition guiEditBox.h:179
bool m_override_color_enabled
Definition guiEditBox.h:149
void onKeyControlC(const SEvent &event)
Definition guiEditBox.cpp:499
bool m_word_wrap
Definition guiEditBox.h:150
virtual video::SColor getOverrideColor() const
Gets the override color.
Definition guiEditBox.cpp:60
std::vector< s32 > m_broken_text_positions
Definition guiEditBox.h:160
void sendGuiEvent(EGUI_EVENT_TYPE type)
send some gui event to parent
Definition guiEditBox.cpp:180
virtual bool isOverrideColorEnabled(void) const
Checks if an override color is enabled.
Definition guiEditBox.h:50
bool onKeyBack(const SEvent &event, s32 &mark_begin, s32 &mark_end)
Definition guiEditBox.cpp:588
virtual IGUIFont * getOverrideFont() const
Definition guiEditBox.h:31
virtual void setTextRect(s32 line)=0
sets the area of the given line
EGUI_ALIGNMENT m_halign
Definition guiEditBox.h:162
Definition guiScrollBar.h:24
Definition fontengine.h:14
Definition clientmap.h:30