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"
13 #include "IGUIScrollBar.h"
19 class intlGUIEditBox : public IGUIEditBox
24 intlGUIEditBox(const wchar_t* text, bool border, IGUIEnvironment* environment,
25 IGUIElement* parent, s32 id, const core::rect<s32>& rectangle,
26 bool writable = true, bool has_vscrollbar = false);
29 virtual ~intlGUIEditBox();
31 //! Sets another skin independent font.
32 virtual void setOverrideFont(IGUIFont* font=0);
34 //! Gets the override font (if any)
35 /** \return The override font (may be 0) */
36 virtual IGUIFont* getOverrideFont() const;
38 //! Get the font which is used right now for drawing
39 /** Currently this is the override font when one is set and the
40 font of the active skin otherwise */
41 virtual IGUIFont* getActiveFont() const;
43 //! Sets another color for the text.
44 virtual void setOverrideColor(video::SColor color);
46 //! Gets the override color
47 virtual video::SColor getOverrideColor() const;
49 //! Sets if the text should use the overide color or the
50 //! color in the gui skin.
51 virtual void enableOverrideColor(bool enable);
53 //! Checks if an override color is enabled
54 /** \return true if the override color is enabled, false otherwise */
55 virtual bool isOverrideColorEnabled(void) const;
57 //! Sets whether to draw the background
58 virtual void setDrawBackground(bool draw);
60 //! Turns the border on or off
61 virtual void setDrawBorder(bool border);
63 //! Enables or disables word wrap for using the edit box as multiline text editor.
64 virtual void setWordWrap(bool enable);
66 //! Checks if word wrap is enabled
67 //! \return true if word wrap is enabled, false otherwise
68 virtual bool isWordWrapEnabled() const;
70 //! Enables or disables newlines.
71 /** \param enable: If set to true, the EGET_EDITBOX_ENTER event will not be fired,
72 instead a newline character will be inserted. */
73 virtual void setMultiLine(bool enable);
75 //! Checks if multi line editing is enabled
76 //! \return true if mult-line is enabled, false otherwise
77 virtual bool isMultiLineEnabled() const;
79 //! Enables or disables automatic scrolling with cursor position
80 //! \param enable: If set to true, the text will move around with the cursor position
81 virtual void setAutoScroll(bool enable);
83 //! Checks to see if automatic scrolling is enabled
84 //! \return true if automatic scrolling is enabled, false if not
85 virtual bool isAutoScrollEnabled() const;
87 //! Gets the size area of the text in the edit box
88 //! \return Returns the size in pixels of the text
89 virtual core::dimension2du getTextDimension();
91 //! Sets text justification
92 virtual void setTextAlignment(EGUI_ALIGNMENT horizontal, EGUI_ALIGNMENT vertical);
94 //! called if an event happened.
95 virtual bool OnEvent(const SEvent& event);
97 //! draws the element and its children
100 //! Sets the new caption of this element.
101 virtual void setText(const wchar_t* text);
103 //! Sets the maximum amount of characters which may be entered in the box.
104 //! \param max: Maximum amount of characters. If 0, the character amount is
106 virtual void setMax(u32 max);
108 //! Returns maximum amount of characters, previously set by setMax();
109 virtual u32 getMax() const;
111 //! Sets whether the edit box is a password box. Setting this to true will
112 /** disable MultiLine, WordWrap and the ability to copy with ctrl+c or ctrl+x
113 \param passwordBox: true to enable password, false to disable
114 \param passwordChar: the character that is displayed instead of letters */
115 virtual void setPasswordBox(bool passwordBox, wchar_t passwordChar = L'*');
117 //! Returns true if the edit box is currently a password box.
118 virtual bool isPasswordBox() const;
120 //! Updates the absolute position, splits text if required
121 virtual void updateAbsolutePosition();
123 //! set true if this EditBox is writable
124 virtual void setWritable(bool can_write_text);
126 //! Writes attributes of the element.
127 virtual void serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const;
129 //! Reads attributes of the element
130 virtual void deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options);
133 //! Breaks the single text line.
135 //! sets the area of the given line
136 void setTextRect(s32 line);
137 //! returns the line number that the cursor is on
138 s32 getLineFromPos(s32 pos);
139 //! adds a letter to the edit box
140 void inputChar(wchar_t c);
141 //! calculates the current scroll position
142 void calculateScrollPos();
143 //! send some gui event to parent
144 void sendGuiEvent(EGUI_EVENT_TYPE type);
146 void setTextMarkers(s32 begin, s32 end);
148 bool processKey(const SEvent& event);
149 bool processMouse(const SEvent& event);
150 s32 getCursorPos(s32 x, s32 y);
152 //! Create a vertical scrollbar
153 void createVScrollBar();
155 //! Update the vertical scrollbar (visibilty & scroll position)
156 void updateVScrollBar();
158 bool MouseMarking = false;
160 bool OverrideColorEnabled = false;
164 video::SColor OverrideColor = video::SColor(101,255,255,255);
165 gui::IGUIFont *OverrideFont = nullptr;
166 gui::IGUIFont *LastBreakFont = nullptr;
167 IOSOperator *Operator = nullptr;
169 u64 BlinkStartTime = 0;
172 s32 VScrollPos = 0; // scroll position in characters
175 bool WordWrap = false;
176 bool MultiLine = false;
177 bool AutoScroll = true;
178 bool PasswordBox = false;
179 wchar_t PasswordChar = L'*';
180 EGUI_ALIGNMENT HAlign = EGUIA_UPPERLEFT;
181 EGUI_ALIGNMENT VAlign = EGUIA_CENTER;
183 core::array<core::stringw> BrokenText;
184 core::array<s32> BrokenTextPositions;
186 core::rect<s32> CurrentTextRect = core::rect<s32>(0,0,1,1);
187 core::rect<s32> FrameRect; // temporary values
188 u32 m_scrollbar_width;
189 IGUIScrollBar *m_vscrollbar;
195 } // end namespace gui
196 } // end namespace irr
198 //#endif // _IRR_COMPILE_WITH_GUI_