SuperTuxKart
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 <cstdint>
17 #include <string>
18 #include <vector>
19 
20 #if !defined(SERVER_ONLY) && defined(_IRR_COMPILE_WITH_SDL_DEVICE_)
21 #include "SDL_events.h"
22 #endif
23 
24 using namespace irr;
25 using namespace gui;
26 
27 namespace GUIEngine
28 {
29  enum TextBoxType: int;
30 }
31 
32  class CGUIEditBox : public IGUIEditBox
33  {
34  public:
35 
36  LEAK_CHECK()
37 
38 
39  CGUIEditBox(const wchar_t* text, bool border, IGUIEnvironment* environment,
40  IGUIElement* parent, s32 id, const core::rect<s32>& rectangle);
41 
43  virtual ~CGUIEditBox();
44 
46  virtual void setOverrideFont(IGUIFont* font=0);
47 
49  virtual void setOverrideColor(video::SColor color);
50 
52  virtual video::SColor getOverrideColor() const;
53 
56  virtual void enableOverrideColor(bool enable);
57 
59 
60  virtual bool isOverrideColorEnabled(void) const;
61 
63  virtual void setDrawBorder(bool border);
64 
66  virtual void setWordWrap(bool enable) {}
67 
70  virtual bool isWordWrapEnabled() const { return false; }
71 
73 
75  virtual void setMultiLine(bool enable) {}
76 
79  virtual bool isMultiLineEnabled() const { return false; }
80 
83  virtual void setAutoScroll(bool enable);
84 
87  virtual bool isAutoScrollEnabled() const;
88 
91  virtual core::dimension2du getTextDimension();
92 
94  virtual void setTextAlignment(EGUI_ALIGNMENT horizontal, EGUI_ALIGNMENT vertical);
95 
97  virtual bool OnEvent(const SEvent& event);
98 
100  virtual void draw();
101 
103  virtual void setText(const core::stringw& text);
104 
108  virtual void setMax(u32 max);
109 
111  virtual u32 getMax() const;
112 
114 
117  virtual void setPasswordBox(bool passwordBox, wchar_t passwordChar = L'*');
118 
120  virtual bool isPasswordBox() const;
121 
123  virtual void updateAbsolutePosition();
124 
126  virtual void serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const;
127 
129  virtual void deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options);
130 
131  virtual irr::gui::IGUIFont* getOverrideFont() const { return NULL; }
132  virtual irr::gui::IGUIFont* getActiveFont() const { return NULL; }
133  virtual void setDrawBackground(bool) { }
134 
135  void fromAndroidEditText(const std::u32string& text, int start, int end,
136  int composing_start, int composing_end);
137  void openScreenKeyboard();
138  s32 getCursorPosInBox() const { return m_cursor_pos; }
139  s32 getTextCount() const { return (s32)m_edit_text.size(); }
140  void setTextBoxType(GUIEngine::TextBoxType t) { m_type = t; }
141  virtual void setComposingText(const std::u32string& ct) { m_composing_text = ct; }
142  virtual void clearComposingText() { m_composing_text.clear(); }
143  virtual const core::position2di& getICPos() const { return m_ic_pos; }
144  void sendGuiEvent(EGUI_EVENT_TYPE type);
145  protected:
147  void setTextRect(s32 line);
149  virtual void inputChar(char32_t c);
151  void calculateScrollPos();
154  void setTextMarkers(s32 begin, s32 end);
155  void updateCursorDistance();
156  bool processKey(const SEvent& event);
157  bool processMouse(const SEvent& event);
158  s32 getCursorPos(s32 x, s32 y);
159  void updateGlyphLayouts();
160 
161  bool MouseMarking;
162  bool Border;
163  bool OverrideColorEnabled;
164  s32 m_mark_begin;
165  s32 m_mark_end;
166 
167  GUIEngine::TextBoxType m_type;
168 
169  video::SColor OverrideColor;
170  gui::IGUIFont *OverrideFont, *LastBreakFont;
171  IOSOperator* Operator;
172 
173  uint64_t m_force_show_cursor_time;
174  s32 m_cursor_pos;
175  s32 m_scroll_pos;
176  s32 m_cursor_distance;
177  u32 m_max_chars;
178 
179  bool AutoScroll, PasswordBox;
180  char32_t PasswordChar;
181  EGUI_ALIGNMENT HAlign, VAlign;
182 
183  core::rect<s32> CurrentTextRect, FrameRect; // temporary values
184 
185  s32 m_composing_start;
186  s32 m_composing_end;
187 
188  /* UTF32 string for shaping and editing to avoid wchar_t issue in
189  * windows */
190  std::u32string m_edit_text;
191  /* Used in windows api for native composing text handling. */
192  std::u32string m_composing_text;
193  std::vector<GlyphLayout> m_glyph_layouts;
194  // Pre-edit surrogate chars
195  std::vector<wchar_t> m_surrogate_chars;
196  // Position to show composition box in native window (linux / windows)
197  core::position2di m_ic_pos;
198  void correctCursor(s32& cursor_pos, bool left);
199  void updateSurrogatePairText();
200  };
201 
202 
203 
204 #endif // __C_GUI_EDIT_BOX_H_INCLUDED__
205 
Definition: CGUIEditBox.hpp:33
virtual bool isMultiLineEnabled() const
Checks if multi line editing is enabled.
Definition: CGUIEditBox.hpp:79
virtual void setWordWrap(bool enable)
Enables or disables word wrap for using the edit box as multiline text editor.
Definition: CGUIEditBox.hpp:66
virtual bool isWordWrapEnabled() const
Checks if word wrap is enabled.
Definition: CGUIEditBox.hpp:70
virtual void setMultiLine(bool enable)
Enables or disables newlines.
Definition: CGUIEditBox.hpp:75
Contains all GUI engine related classes and functions.
Definition: abstract_state_manager.hpp:33