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 virtual bool isDrawBackgroundEnabled() const { return true; }
62 //! Turns the border on or off
63 virtual void setDrawBorder(bool border);
65 virtual bool isDrawBorderEnabled() const { return Border; }
67 //! Enables or disables word wrap for using the edit box as multiline text editor.
68 virtual void setWordWrap(bool enable);
70 //! Checks if word wrap is enabled
71 //! \return true if word wrap is enabled, false otherwise
72 virtual bool isWordWrapEnabled() const;
74 //! Enables or disables newlines.
75 /** \param enable: If set to true, the EGET_EDITBOX_ENTER event will not be fired,
76 instead a newline character will be inserted. */
77 virtual void setMultiLine(bool enable);
79 //! Checks if multi line editing is enabled
80 //! \return true if mult-line is enabled, false otherwise
81 virtual bool isMultiLineEnabled() const;
83 //! Enables or disables automatic scrolling with cursor position
84 //! \param enable: If set to true, the text will move around with the cursor position
85 virtual void setAutoScroll(bool enable);
87 //! Checks to see if automatic scrolling is enabled
88 //! \return true if automatic scrolling is enabled, false if not
89 virtual bool isAutoScrollEnabled() const;
91 //! Gets the size area of the text in the edit box
92 //! \return Returns the size in pixels of the text
93 virtual core::dimension2du getTextDimension();
95 //! Sets text justification
96 virtual void setTextAlignment(EGUI_ALIGNMENT horizontal, EGUI_ALIGNMENT vertical);
98 //! called if an event happened.
99 virtual bool OnEvent(const SEvent& event);
101 //! draws the element and its children
104 //! Sets the new caption of this element.
105 virtual void setText(const wchar_t* text);
107 //! Sets the maximum amount of characters which may be entered in the box.
108 //! \param max: Maximum amount of characters. If 0, the character amount is
110 virtual void setMax(u32 max);
112 //! Returns maximum amount of characters, previously set by setMax();
113 virtual u32 getMax() const;
115 //! Sets whether the edit box is a password box. Setting this to true will
116 /** disable MultiLine, WordWrap and the ability to copy with ctrl+c or ctrl+x
117 \param passwordBox: true to enable password, false to disable
118 \param passwordChar: the character that is displayed instead of letters */
119 virtual void setPasswordBox(bool passwordBox, wchar_t passwordChar = L'*');
121 //! Returns true if the edit box is currently a password box.
122 virtual bool isPasswordBox() const;
124 //! Updates the absolute position, splits text if required
125 virtual void updateAbsolutePosition();
127 //! set true if this EditBox is writable
128 virtual void setWritable(bool can_write_text);
130 //! Writes attributes of the element.
131 virtual void serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const;
133 //! Reads attributes of the element
134 virtual void deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options);
136 virtual void setCursorChar(const wchar_t cursorChar) {}
138 virtual wchar_t getCursorChar() const { return L'|'; }
140 virtual void setCursorBlinkTime(u32 timeMs) {}
142 virtual u32 getCursorBlinkTime() const { return 500; }
145 //! Breaks the single text line.
147 //! sets the area of the given line
148 void setTextRect(s32 line);
149 //! returns the line number that the cursor is on
150 s32 getLineFromPos(s32 pos);
151 //! adds a letter to the edit box
152 void inputChar(wchar_t c);
153 //! calculates the current scroll position
154 void calculateScrollPos();
155 //! send some gui event to parent
156 void sendGuiEvent(EGUI_EVENT_TYPE type);
158 void setTextMarkers(s32 begin, s32 end);
160 bool processKey(const SEvent& event);
161 bool processMouse(const SEvent& event);
162 s32 getCursorPos(s32 x, s32 y);
164 //! Create a vertical scrollbar
165 void createVScrollBar();
167 //! Update the vertical scrollbar (visibilty & scroll position)
168 void updateVScrollBar();
170 bool MouseMarking = false;
172 bool OverrideColorEnabled = false;
176 video::SColor OverrideColor = video::SColor(101,255,255,255);
177 gui::IGUIFont *OverrideFont = nullptr;
178 gui::IGUIFont *LastBreakFont = nullptr;
179 IOSOperator *Operator = nullptr;
181 u64 BlinkStartTime = 0;
184 s32 VScrollPos = 0; // scroll position in characters
187 bool WordWrap = false;
188 bool MultiLine = false;
189 bool AutoScroll = true;
190 bool PasswordBox = false;
191 wchar_t PasswordChar = L'*';
192 EGUI_ALIGNMENT HAlign = EGUIA_UPPERLEFT;
193 EGUI_ALIGNMENT VAlign = EGUIA_CENTER;
195 core::array<core::stringw> BrokenText;
196 core::array<s32> BrokenTextPositions;
198 core::rect<s32> CurrentTextRect = core::rect<s32>(0,0,1,1);
199 core::rect<s32> FrameRect; // temporary values
200 u32 m_scrollbar_width;
201 IGUIScrollBar *m_vscrollbar;
207 } // end namespace gui
208 } // end namespace irr
210 //#endif // _IRR_COMPILE_WITH_GUI_