SuperTuxKart
Loading...
Searching...
No Matches
CGUIEditBox.hpp
1// Copyright (C) 2002-2015 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#ifndef __C_GUI_EDIT_BOX_H_INCLUDED__
6#define __C_GUI_EDIT_BOX_H_INCLUDED__
7
8#include "IrrCompileConfig.h"
9#include "IGUIEditBox.h"
10#include "irrArray.h"
11#include "IOSOperator.h"
12#include "utils/leak_check.hpp"
13
14#include "GlyphLayout.h"
15
16#include <string>
17#include <vector>
18
19#if !defined(SERVER_ONLY) && defined(_IRR_COMPILE_WITH_SDL_DEVICE_)
20#include "SDL_events.h"
21#endif
22
23using namespace irr;
24using namespace gui;
25
26namespace GUIEngine
27{
28 enum TextBoxType: int;
29}
30
31 class CGUIEditBox : public IGUIEditBox
32 {
33 public:
34
35 LEAK_CHECK()
36
37
38 CGUIEditBox(const wchar_t* text, bool border, IGUIEnvironment* environment,
39 IGUIElement* parent, s32 id, const core::rect<s32>& rectangle);
40
42 virtual ~CGUIEditBox();
43
45 virtual void setOverrideFont(IGUIFont* font=0);
46
48 virtual void setOverrideColor(video::SColor color);
49
51 virtual video::SColor getOverrideColor() const;
52
55 virtual void enableOverrideColor(bool enable);
56
58
59 virtual bool isOverrideColorEnabled(void) const;
60
62 virtual void setDrawBorder(bool border);
63
65 virtual void setWordWrap(bool enable) {}
66
69 virtual bool isWordWrapEnabled() const { return false; }
70
72
74 virtual void setMultiLine(bool enable) {}
75
78 virtual bool isMultiLineEnabled() const { return false; }
79
82 virtual void setAutoScroll(bool enable);
83
86 virtual bool isAutoScrollEnabled() const;
87
90 virtual core::dimension2du getTextDimension();
91
93 virtual void setTextAlignment(EGUI_ALIGNMENT horizontal, EGUI_ALIGNMENT vertical);
94
96 virtual bool OnEvent(const SEvent& event);
97
99 virtual void draw();
100
102 virtual void setText(const core::stringw& text);
103
107 virtual void setMax(u32 max);
108
110 virtual u32 getMax() const;
111
113
116 virtual void setPasswordBox(bool passwordBox, wchar_t passwordChar = L'*');
117
119 virtual bool isPasswordBox() const;
120
122 virtual void updateAbsolutePosition();
123
125 virtual void serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const;
126
128 virtual void deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options);
129
130 virtual irr::gui::IGUIFont* getOverrideFont() const { return NULL; }
131 virtual irr::gui::IGUIFont* getActiveFont() const { return NULL; }
132 virtual void setDrawBackground(bool) { }
133
134 void fromAndroidEditText(const std::u32string& text, int start, int end,
135 int composing_start, int composing_end);
136 void openScreenKeyboard();
137 s32 getCursorPosInBox() const { return m_cursor_pos; }
138 s32 getTextCount() const { return (s32)m_edit_text.size(); }
139 void setTextBoxType(GUIEngine::TextBoxType t) { m_type = t; }
140 virtual void setComposingText(const std::u32string& ct) { m_composing_text = ct; }
141 virtual void clearComposingText() { m_composing_text.clear(); }
142 virtual const core::position2di& getICPos() const { return m_ic_pos; }
143 void sendGuiEvent(EGUI_EVENT_TYPE type);
144 protected:
146 void setTextRect(s32 line);
148 virtual void inputChar(char32_t c);
150 void calculateScrollPos();
153 void setTextMarkers(s32 begin, s32 end);
154 void updateCursorDistance();
155 bool processKey(const SEvent& event);
156 bool processMouse(const SEvent& event);
157 s32 getCursorPos(s32 x, s32 y);
158 void updateGlyphLayouts();
159
160 bool MouseMarking;
161 bool Border;
162 bool OverrideColorEnabled;
163 s32 m_mark_begin;
164 s32 m_mark_end;
165
166 GUIEngine::TextBoxType m_type;
167
168 video::SColor OverrideColor;
169 gui::IGUIFont *OverrideFont, *LastBreakFont;
170 IOSOperator* Operator;
171
172 uint64_t m_force_show_cursor_time;
173 s32 m_cursor_pos;
174 s32 m_scroll_pos;
175 s32 m_cursor_distance;
176 u32 m_max_chars;
177
178 bool AutoScroll, PasswordBox;
179 char32_t PasswordChar;
180 EGUI_ALIGNMENT HAlign, VAlign;
181
182 core::rect<s32> CurrentTextRect, FrameRect; // temporary values
183
184 s32 m_composing_start;
185 s32 m_composing_end;
186
187 /* UTF32 string for shaping and editing to avoid wchar_t issue in
188 * windows */
189 std::u32string m_edit_text;
190 /* Used in windows api for native composing text handling. */
191 std::u32string m_composing_text;
192 std::vector<GlyphLayout> m_glyph_layouts;
193 // Pre-edit surrogate chars
194 std::vector<wchar_t> m_surrogate_chars;
195 // Position to show composition box in native window (linux / windows)
196 core::position2di m_ic_pos;
197 void correctCursor(s32& cursor_pos, bool left);
198 void updateSurrogatePairText();
199 };
200
201
202
203#endif // __C_GUI_EDIT_BOX_H_INCLUDED__
204
Definition: CGUIEditBox.hpp:32
virtual bool isMultiLineEnabled() const
Checks if multi line editing is enabled.
Definition: CGUIEditBox.hpp:78
virtual void setWordWrap(bool enable)
Enables or disables word wrap for using the edit box as multiline text editor.
Definition: CGUIEditBox.hpp:65
virtual void deserializeAttributes(io::IAttributes *in, io::SAttributeReadWriteOptions *options)
Reads attributes of the element.
Definition: CGUIEditBox.cpp:1464
virtual bool isWordWrapEnabled() const
Checks if word wrap is enabled.
Definition: CGUIEditBox.hpp:69
virtual void setTextAlignment(EGUI_ALIGNMENT horizontal, EGUI_ALIGNMENT vertical)
Sets text justification.
Definition: CGUIEditBox.cpp:331
virtual bool isPasswordBox() const
Returns true if the edit box is currently a password box.
Definition: CGUIEditBox.cpp:323
virtual void inputChar(char32_t c)
adds a letter to the edit box
Definition: CGUIEditBox.cpp:1272
virtual void setMultiLine(bool enable)
Enables or disables newlines.
Definition: CGUIEditBox.hpp:74
virtual bool isAutoScrollEnabled() const
Checks to see if automatic scrolling is enabled.
Definition: CGUIEditBox.cpp:1061
virtual video::SColor getOverrideColor() const
Gets the override color.
Definition: CGUIEditBox.cpp:281
virtual void setDrawBorder(bool border)
Turns the border on or off.
Definition: CGUIEditBox.cpp:288
virtual void setAutoScroll(bool enable)
Enables or disables automatic scrolling with cursor position.
Definition: CGUIEditBox.cpp:1053
virtual void serializeAttributes(io::IAttributes *out, io::SAttributeReadWriteOptions *options) const
Writes attributes of the element.
Definition: CGUIEditBox.cpp:1443
virtual void draw()
draws the element and its children
Definition: CGUIEditBox.cpp:889
void calculateScrollPos()
calculates the current scroll position
Definition: CGUIEditBox.cpp:1353
virtual ~CGUIEditBox()
destructor
Definition: CGUIEditBox.cpp:236
virtual void setPasswordBox(bool passwordBox, wchar_t passwordChar=L' *')
Sets whether the edit box is a password box. Setting this to true will.
Definition: CGUIEditBox.cpp:313
virtual void enableOverrideColor(bool enable)
Sets if the text should use the overide color or the color in the gui skin.
Definition: CGUIEditBox.cpp:295
virtual void setText(const core::stringw &text)
Sets the new caption of this element.
Definition: CGUIEditBox.cpp:1034
virtual void setOverrideFont(IGUIFont *font=0)
Sets another skin independent font.
Definition: CGUIEditBox.cpp:257
virtual void updateAbsolutePosition()
Updates the absolute position, splits text if required.
Definition: CGUIEditBox.cpp:307
void setTextMarkers(s32 begin, s32 end)
send some gui event to parent set text markers
Definition: CGUIEditBox.cpp:1404
virtual void setMax(u32 max)
Sets the maximum amount of characters which may be entered in the box.
Definition: CGUIEditBox.cpp:1091
virtual bool OnEvent(const SEvent &event)
called if an event happened.
Definition: CGUIEditBox.cpp:339
virtual void setOverrideColor(video::SColor color)
Sets another color for the text.
Definition: CGUIEditBox.cpp:274
void sendGuiEvent(EGUI_EVENT_TYPE type)
send some gui event to parent
Definition: CGUIEditBox.cpp:1428
virtual bool isOverrideColorEnabled(void) const
Checks if an override color is enabled.
Definition: CGUIEditBox.cpp:300
void setTextRect(s32 line)
sets the area of the given line
Definition: CGUIEditBox.cpp:1209
virtual u32 getMax() const
Returns maximum amount of characters, previously set by setMax();.
Definition: CGUIEditBox.cpp:1100
virtual core::dimension2du getTextDimension()
Gets the size area of the text in the edit box.
Definition: CGUIEditBox.cpp:1070
Contains all GUI engine related classes and functions.
Definition: abstract_state_manager.hpp:33