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
7 #include "IrrCompileConfig.h"
8 //#ifdef _IRR_COMPILE_WITH_GUI_
10 #include "IGUIEditBox.h"
12 #include "IOSOperator.h"
18 class intlGUIEditBox : public IGUIEditBox
23 intlGUIEditBox(const wchar_t* text, bool border, IGUIEnvironment* environment,
24 IGUIElement* parent, s32 id, const core::rect<s32>& rectangle);
27 virtual ~intlGUIEditBox();
29 //! Sets another skin independent font.
30 virtual void setOverrideFont(IGUIFont* font=0);
32 //! Gets the override font (if any)
33 /** \return The override font (may be 0) */
34 virtual IGUIFont* getOverrideFont() const;
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;
41 //! Sets another color for the text.
42 virtual void setOverrideColor(video::SColor color);
44 //! Gets the override color
45 virtual video::SColor getOverrideColor() const;
47 //! Sets if the text should use the overide color or the
48 //! color in the gui skin.
49 virtual void enableOverrideColor(bool enable);
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;
55 //! Sets whether to draw the background
56 virtual void setDrawBackground(bool draw);
58 //! Turns the border on or off
59 virtual void setDrawBorder(bool border);
61 //! Enables or disables word wrap for using the edit box as multiline text editor.
62 virtual void setWordWrap(bool enable);
64 //! Checks if word wrap is enabled
65 //! \return true if word wrap is enabled, false otherwise
66 virtual bool isWordWrapEnabled() const;
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);
73 //! Checks if multi line editing is enabled
74 //! \return true if mult-line is enabled, false otherwise
75 virtual bool isMultiLineEnabled() const;
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);
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;
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();
89 //! Sets text justification
90 virtual void setTextAlignment(EGUI_ALIGNMENT horizontal, EGUI_ALIGNMENT vertical);
92 //! called if an event happened.
93 virtual bool OnEvent(const SEvent& event);
95 //! draws the element and its children
98 //! Sets the new caption of this element.
99 virtual void setText(const wchar_t* text);
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
104 virtual void setMax(u32 max);
106 //! Returns maximum amount of characters, previously set by setMax();
107 virtual u32 getMax() const;
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'*');
115 //! Returns true if the edit box is currently a password box.
116 virtual bool isPasswordBox() const;
118 //! Updates the absolute position, splits text if required
119 virtual void updateAbsolutePosition();
121 //! Writes attributes of the element.
122 virtual void serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const;
124 //! Reads attributes of the element
125 virtual void deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options);
128 //! Breaks the single text line.
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);
141 void setTextMarkers(s32 begin, s32 end);
143 bool processKey(const SEvent& event);
144 bool processMouse(const SEvent& event);
145 s32 getCursorPos(s32 x, s32 y);
147 bool MouseMarking = false;
149 bool OverrideColorEnabled = false;
153 video::SColor OverrideColor = video::SColor(101,255,255,255);
154 gui::IGUIFont *OverrideFont = nullptr;
155 gui::IGUIFont *LastBreakFont = nullptr;
156 IOSOperator *Operator = nullptr;
158 u64 BlinkStartTime = 0;
161 s32 VScrollPos = 0; // scroll position in characters
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;
172 core::array<core::stringw> BrokenText;
173 core::array<s32> BrokenTextPositions;
175 core::rect<s32> CurrentTextRect = core::rect<s32>(0,0,1,1);
176 core::rect<s32> FrameRect; // temporary values
180 } // end namespace gui
181 } // end namespace irr
183 //#endif // _IRR_COMPILE_WITH_GUI_