1 // Copyright (C) 2002-2012 Nikolaus Gebhardt
\r
2 // This file is part of the "Irrlicht Engine".
\r
3 // For conditions of distribution and use, see copyright notice in irrlicht.h
\r
5 #ifndef __C_GUI_EDIT_BOX_H_INCLUDED__
\r
6 #define __C_GUI_EDIT_BOX_H_INCLUDED__
\r
8 #include "IrrCompileConfig.h"
\r
9 #include "IGUIEditBox.h"
\r
10 #include "irrArray.h"
\r
11 #include "IOSOperator.h"
\r
17 class CGUIEditBox : public IGUIEditBox
\r
22 CGUIEditBox(const wchar_t* text, bool border, IGUIEnvironment* environment,
\r
23 IGUIElement* parent, s32 id, const core::rect<s32>& rectangle);
\r
26 virtual ~CGUIEditBox();
\r
28 //! Sets another skin independent font.
\r
29 void setOverrideFont(IGUIFont* font=0) override;
\r
31 //! Gets the override font (if any)
\r
32 /** \return The override font (may be 0) */
\r
33 IGUIFont* getOverrideFont() const override;
\r
35 //! Get the font which is used right now for drawing
\r
36 /** Currently this is the override font when one is set and the
\r
37 font of the active skin otherwise */
\r
38 IGUIFont* getActiveFont() const override;
\r
40 //! Sets another color for the text.
\r
41 void setOverrideColor(video::SColor color) override;
\r
43 //! Gets the override color
\r
44 video::SColor getOverrideColor() const override;
\r
46 //! Sets if the text should use the override color or the
\r
47 //! color in the gui skin.
\r
48 void enableOverrideColor(bool enable) override;
\r
50 //! Checks if an override color is enabled
\r
51 /** \return true if the override color is enabled, false otherwise */
\r
52 bool isOverrideColorEnabled(void) const override;
\r
54 //! Sets whether to draw the background
\r
55 void setDrawBackground(bool draw) override;
\r
57 //! Checks if background drawing is enabled
\r
58 bool isDrawBackgroundEnabled() const override;
\r
60 //! Turns the border on or off
\r
61 void setDrawBorder(bool border) override;
\r
63 //! Checks if border drawing is enabled
\r
64 bool isDrawBorderEnabled() const override;
\r
66 //! Enables or disables word wrap for using the edit box as multiline text editor.
\r
67 void setWordWrap(bool enable) override;
\r
69 //! Checks if word wrap is enabled
\r
70 //! \return true if word wrap is enabled, false otherwise
\r
71 bool isWordWrapEnabled() const override;
\r
73 //! Enables or disables newlines.
\r
74 /** \param enable: If set to true, the EGET_EDITBOX_ENTER event will not be fired,
\r
75 instead a newline character will be inserted. */
\r
76 void setMultiLine(bool enable) override;
\r
78 //! Checks if multi line editing is enabled
\r
79 //! \return true if mult-line is enabled, false otherwise
\r
80 bool isMultiLineEnabled() const override;
\r
82 //! Enables or disables automatic scrolling with cursor position
\r
83 //! \param enable: If set to true, the text will move around with the cursor position
\r
84 void setAutoScroll(bool enable) override;
\r
86 //! Checks to see if automatic scrolling is enabled
\r
87 //! \return true if automatic scrolling is enabled, false if not
\r
88 bool isAutoScrollEnabled() const override;
\r
90 //! Gets the size area of the text in the edit box
\r
91 //! \return Returns the size in pixels of the text
\r
92 core::dimension2du getTextDimension() override;
\r
94 //! Sets text justification
\r
95 void setTextAlignment(EGUI_ALIGNMENT horizontal, EGUI_ALIGNMENT vertical) override;
\r
97 //! called if an event happened.
\r
98 bool OnEvent(const SEvent& event) override;
\r
100 //! draws the element and its children
\r
101 void draw() override;
\r
103 //! Sets the new caption of this element.
\r
104 void setText(const wchar_t* text) override;
\r
106 //! Sets the maximum amount of characters which may be entered in the box.
\r
107 //! \param max: Maximum amount of characters. If 0, the character amount is
\r
109 void setMax(u32 max) override;
\r
111 //! Returns maximum amount of characters, previously set by setMax();
\r
112 u32 getMax() const override;
\r
114 //! Set the character used for the cursor.
\r
115 /** By default it's "_" */
\r
116 void setCursorChar(const wchar_t cursorChar) override;
\r
118 //! Get the character used for the cursor.
\r
119 wchar_t getCursorChar() const override;
\r
121 //! Set the blinktime for the cursor. 2x blinktime is one full cycle.
\r
122 //** \param timeMs Blinktime in milliseconds. When set to 0 the cursor is constantly on without blinking */
\r
123 void setCursorBlinkTime(irr::u32 timeMs) override;
\r
125 //! Get the cursor blinktime
\r
126 irr::u32 getCursorBlinkTime() const override;
\r
128 //! Sets whether the edit box is a password box. Setting this to true will
\r
129 /** disable MultiLine, WordWrap and the ability to copy with ctrl+c or ctrl+x
\r
130 \param passwordBox: true to enable password, false to disable
\r
131 \param passwordChar: the character that is displayed instead of letters */
\r
132 void setPasswordBox(bool passwordBox, wchar_t passwordChar = L'*') override;
\r
134 //! Returns true if the edit box is currently a password box.
\r
135 bool isPasswordBox() const override;
\r
137 //! Updates the absolute position, splits text if required
\r
138 void updateAbsolutePosition() override;
\r
140 //! Returns whether the element takes input from the IME
\r
141 bool acceptsIME() override;
\r
144 //! Breaks the single text line.
\r
146 //! sets the area of the given line
\r
147 void setTextRect(s32 line);
\r
148 //! returns the line number that the cursor is on
\r
149 s32 getLineFromPos(s32 pos);
\r
150 //! adds a letter to the edit box
\r
151 void inputChar(wchar_t c);
\r
152 //! adds a string to the edit box
\r
153 void inputString(const core::stringw &str);
\r
154 //! calculates the current scroll position
\r
155 void calculateScrollPos();
\r
156 //! calculated the FrameRect
\r
157 void calculateFrameRect();
\r
158 //! send some gui event to parent
\r
159 void sendGuiEvent(EGUI_EVENT_TYPE type);
\r
160 //! set text markers
\r
161 void setTextMarkers(s32 begin, s32 end);
\r
162 //! delete current selection or next char
\r
165 bool processKey(const SEvent& event);
\r
166 bool processMouse(const SEvent& event);
\r
167 s32 getCursorPos(s32 x, s32 y);
\r
169 bool OverwriteMode;
\r
173 bool OverrideColorEnabled;
\r
177 video::SColor OverrideColor;
\r
178 gui::IGUIFont *OverrideFont, *LastBreakFont;
\r
179 IOSOperator* Operator;
\r
181 u32 BlinkStartTime;
\r
182 irr::u32 CursorBlinkTime;
\r
183 core::stringw CursorChar; // IGUIFont::draw needs stringw instead of wchar_t
\r
185 s32 HScrollPos, VScrollPos; // scroll position in characters
\r
188 bool WordWrap, MultiLine, AutoScroll, PasswordBox;
\r
189 wchar_t PasswordChar;
\r
190 EGUI_ALIGNMENT HAlign, VAlign;
\r
192 core::array< core::stringw > BrokenText;
\r
193 core::array< s32 > BrokenTextPositions;
\r
195 core::rect<s32> CurrentTextRect, FrameRect; // temporary values
\r
199 } // end namespace gui
\r
200 } // end namespace irr
\r
202 #endif // __C_GUI_EDIT_BOX_H_INCLUDED__
\r