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
5 #ifndef __C_INTL_GUI_EDIT_BOX_H_INCLUDED__
6 #define __C_INTL_GUI_EDIT_BOX_H_INCLUDED__
8 #include "IrrCompileConfig.h"
9 //#ifdef _IRR_COMPILE_WITH_GUI_
11 #include "IGUIEditBox.h"
13 #include "IOSOperator.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);
28 virtual ~intlGUIEditBox();
30 //! Sets another skin independent font.
31 virtual void setOverrideFont(IGUIFont* font=0);
33 //! Gets the override font (if any)
34 /** \return The override font (may be 0) */
35 virtual IGUIFont* getOverrideFont() const;
37 //! Get the font which is used right now for drawing
38 /** Currently this is the override font when one is set and the
39 font of the active skin otherwise */
40 virtual IGUIFont* getActiveFont() const;
42 //! Sets another color for the text.
43 virtual void setOverrideColor(video::SColor color);
45 //! Gets the override color
46 virtual video::SColor getOverrideColor() const;
48 //! Sets if the text should use the overide color or the
49 //! color in the gui skin.
50 virtual void enableOverrideColor(bool enable);
52 //! Checks if an override color is enabled
53 /** \return true if the override color is enabled, false otherwise */
54 virtual bool isOverrideColorEnabled(void) const;
56 //! Sets whether to draw the background
57 virtual void setDrawBackground(bool draw);
59 //! Turns the border on or off
60 virtual void setDrawBorder(bool border);
62 //! Enables or disables word wrap for using the edit box as multiline text editor.
63 virtual void setWordWrap(bool enable);
65 //! Checks if word wrap is enabled
66 //! \return true if word wrap is enabled, false otherwise
67 virtual bool isWordWrapEnabled() const;
69 //! Enables or disables newlines.
70 /** \param enable: If set to true, the EGET_EDITBOX_ENTER event will not be fired,
71 instead a newline character will be inserted. */
72 virtual void setMultiLine(bool enable);
74 //! Checks if multi line editing is enabled
75 //! \return true if mult-line is enabled, false otherwise
76 virtual bool isMultiLineEnabled() const;
78 //! Enables or disables automatic scrolling with cursor position
79 //! \param enable: If set to true, the text will move around with the cursor position
80 virtual void setAutoScroll(bool enable);
82 //! Checks to see if automatic scrolling is enabled
83 //! \return true if automatic scrolling is enabled, false if not
84 virtual bool isAutoScrollEnabled() const;
86 //! Gets the size area of the text in the edit box
87 //! \return Returns the size in pixels of the text
88 virtual core::dimension2du getTextDimension();
90 //! Sets text justification
91 virtual void setTextAlignment(EGUI_ALIGNMENT horizontal, EGUI_ALIGNMENT vertical);
93 //! called if an event happened.
94 virtual bool OnEvent(const SEvent& event);
96 //! draws the element and its children
99 //! Sets the new caption of this element.
100 virtual void setText(const wchar_t* text);
102 //! Sets the maximum amount of characters which may be entered in the box.
103 //! \param max: Maximum amount of characters. If 0, the character amount is
105 virtual void setMax(u32 max);
107 //! Returns maximum amount of characters, previously set by setMax();
108 virtual u32 getMax() const;
110 //! Sets whether the edit box is a password box. Setting this to true will
111 /** disable MultiLine, WordWrap and the ability to copy with ctrl+c or ctrl+x
112 \param passwordBox: true to enable password, false to disable
113 \param passwordChar: the character that is displayed instead of letters */
114 virtual void setPasswordBox(bool passwordBox, wchar_t passwordChar = L'*');
116 //! Returns true if the edit box is currently a password box.
117 virtual bool isPasswordBox() const;
119 //! Updates the absolute position, splits text if required
120 virtual void updateAbsolutePosition();
122 //! Writes attributes of the element.
123 virtual void serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const;
125 //! Reads attributes of the element
126 virtual void deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options);
129 //! Breaks the single text line.
131 //! sets the area of the given line
132 void setTextRect(s32 line);
133 //! returns the line number that the cursor is on
134 s32 getLineFromPos(s32 pos);
135 //! adds a letter to the edit box
136 void inputChar(wchar_t c);
137 //! calculates the current scroll position
138 void calculateScrollPos();
139 //! send some gui event to parent
140 void sendGuiEvent(EGUI_EVENT_TYPE type);
142 void setTextMarkers(s32 begin, s32 end);
144 bool processKey(const SEvent& event);
145 bool processMouse(const SEvent& event);
146 s32 getCursorPos(s32 x, s32 y);
148 bool MouseMarking = false;
150 bool OverrideColorEnabled = false;
154 video::SColor OverrideColor = video::SColor(101,255,255,255);
155 gui::IGUIFont *OverrideFont = nullptr;
156 gui::IGUIFont *LastBreakFont = nullptr;
157 IOSOperator *Operator = nullptr;
159 u64 BlinkStartTime = 0;
162 s32 VScrollPos = 0; // scroll position in characters
165 bool WordWrap = false;
166 bool MultiLine = false;
167 bool AutoScroll = true;
168 bool PasswordBox = false;
169 wchar_t PasswordChar = L'*';
170 EGUI_ALIGNMENT HAlign = EGUIA_UPPERLEFT;
171 EGUI_ALIGNMENT VAlign = EGUIA_CENTER;
173 core::array<core::stringw> BrokenText;
174 core::array<s32> BrokenTextPositions;
176 core::rect<s32> CurrentTextRect = core::rect<s32>(0,0,1,1);
177 core::rect<s32> FrameRect; // temporary values
181 } // end namespace gui
182 } // end namespace irr
184 //#endif // _IRR_COMPILE_WITH_GUI_
185 #endif // __C_GUI_EDIT_BOX_H_INCLUDED__