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 "IGUIEditBox.h"
\r
9 #include "irrArray.h"
\r
10 #include "IOSOperator.h"
\r
16 class CGUIEditBox : public IGUIEditBox
\r
21 CGUIEditBox(const wchar_t* text, bool border, IGUIEnvironment* environment,
\r
22 IGUIElement* parent, s32 id, const core::rect<s32>& rectangle);
\r
25 virtual ~CGUIEditBox();
\r
27 //! Sets another skin independent font.
\r
28 void setOverrideFont(IGUIFont* font=0) override;
\r
30 //! Gets the override font (if any)
\r
31 /** \return The override font (may be 0) */
\r
32 IGUIFont* getOverrideFont() const override;
\r
34 //! Get the font which is used right now for drawing
\r
35 /** Currently this is the override font when one is set and the
\r
36 font of the active skin otherwise */
\r
37 IGUIFont* getActiveFont() const override;
\r
39 //! Sets another color for the text.
\r
40 void setOverrideColor(video::SColor color) override;
\r
42 //! Gets the override color
\r
43 video::SColor getOverrideColor() const override;
\r
45 //! Sets if the text should use the override color or the
\r
46 //! color in the gui skin.
\r
47 void enableOverrideColor(bool enable) override;
\r
49 //! Checks if an override color is enabled
\r
50 /** \return true if the override color is enabled, false otherwise */
\r
51 bool isOverrideColorEnabled(void) const override;
\r
53 //! Sets whether to draw the background
\r
54 void setDrawBackground(bool draw) override;
\r
56 //! Checks if background drawing is enabled
\r
57 bool isDrawBackgroundEnabled() const override;
\r
59 //! Turns the border on or off
\r
60 void setDrawBorder(bool border) override;
\r
62 //! Checks if border drawing is enabled
\r
63 bool isDrawBorderEnabled() const override;
\r
65 //! Enables or disables word wrap for using the edit box as multiline text editor.
\r
66 void setWordWrap(bool enable) override;
\r
68 //! Checks if word wrap is enabled
\r
69 //! \return true if word wrap is enabled, false otherwise
\r
70 bool isWordWrapEnabled() const override;
\r
72 //! Enables or disables newlines.
\r
73 /** \param enable: If set to true, the EGET_EDITBOX_ENTER event will not be fired,
\r
74 instead a newline character will be inserted. */
\r
75 void setMultiLine(bool enable) override;
\r
77 //! Checks if multi line editing is enabled
\r
78 //! \return true if mult-line is enabled, false otherwise
\r
79 bool isMultiLineEnabled() const override;
\r
81 //! Enables or disables automatic scrolling with cursor position
\r
82 //! \param enable: If set to true, the text will move around with the cursor position
\r
83 void setAutoScroll(bool enable) override;
\r
85 //! Checks to see if automatic scrolling is enabled
\r
86 //! \return true if automatic scrolling is enabled, false if not
\r
87 bool isAutoScrollEnabled() const override;
\r
89 //! Gets the size area of the text in the edit box
\r
90 //! \return Returns the size in pixels of the text
\r
91 core::dimension2du getTextDimension() override;
\r
93 //! Sets text justification
\r
94 void setTextAlignment(EGUI_ALIGNMENT horizontal, EGUI_ALIGNMENT vertical) override;
\r
96 //! called if an event happened.
\r
97 bool OnEvent(const SEvent& event) override;
\r
99 //! draws the element and its children
\r
100 void draw() override;
\r
102 //! Sets the new caption of this element.
\r
103 void setText(const wchar_t* text) override;
\r
105 //! Sets the maximum amount of characters which may be entered in the box.
\r
106 //! \param max: Maximum amount of characters. If 0, the character amount is
\r
108 void setMax(u32 max) override;
\r
110 //! Returns maximum amount of characters, previously set by setMax();
\r
111 u32 getMax() const override;
\r
113 //! Set the character used for the cursor.
\r
114 /** By default it's "_" */
\r
115 void setCursorChar(const wchar_t cursorChar) override;
\r
117 //! Get the character used for the cursor.
\r
118 wchar_t getCursorChar() const override;
\r
120 //! Set the blinktime for the cursor. 2x blinktime is one full cycle.
\r
121 //** \param timeMs Blinktime in milliseconds. When set to 0 the cursor is constantly on without blinking */
\r
122 void setCursorBlinkTime(irr::u32 timeMs) override;
\r
124 //! Get the cursor blinktime
\r
125 irr::u32 getCursorBlinkTime() const override;
\r
127 //! Sets whether the edit box is a password box. Setting this to true will
\r
128 /** disable MultiLine, WordWrap and the ability to copy with ctrl+c or ctrl+x
\r
129 \param passwordBox: true to enable password, false to disable
\r
130 \param passwordChar: the character that is displayed instead of letters */
\r
131 void setPasswordBox(bool passwordBox, wchar_t passwordChar = L'*') override;
\r
133 //! Returns true if the edit box is currently a password box.
\r
134 bool isPasswordBox() const override;
\r
136 //! Updates the absolute position, splits text if required
\r
137 void updateAbsolutePosition() override;
\r
139 //! Returns whether the element takes input from the IME
\r
140 bool acceptsIME() override;
\r
143 //! Breaks the single text line.
\r
145 //! sets the area of the given line
\r
146 void setTextRect(s32 line);
\r
147 //! returns the line number that the cursor is on
\r
148 s32 getLineFromPos(s32 pos);
\r
149 //! adds a letter to the edit box
\r
150 void inputChar(wchar_t c);
\r
151 //! adds a string to the edit box
\r
152 void inputString(const core::stringw &str);
\r
153 //! calculates the current scroll position
\r
154 void calculateScrollPos();
\r
155 //! calculated the FrameRect
\r
156 void calculateFrameRect();
\r
157 //! send some gui event to parent
\r
158 void sendGuiEvent(EGUI_EVENT_TYPE type);
\r
159 //! set text markers
\r
160 void setTextMarkers(s32 begin, s32 end);
\r
161 //! delete current selection or next char
\r
164 bool processKey(const SEvent& event);
\r
165 bool processMouse(const SEvent& event);
\r
166 s32 getCursorPos(s32 x, s32 y);
\r
168 bool OverwriteMode;
\r
172 bool OverrideColorEnabled;
\r
176 video::SColor OverrideColor;
\r
177 gui::IGUIFont *OverrideFont, *LastBreakFont;
\r
178 IOSOperator* Operator;
\r
180 u32 BlinkStartTime;
\r
181 irr::u32 CursorBlinkTime;
\r
182 core::stringw CursorChar; // IGUIFont::draw needs stringw instead of wchar_t
\r
184 s32 HScrollPos, VScrollPos; // scroll position in characters
\r
187 bool WordWrap, MultiLine, AutoScroll, PasswordBox;
\r
188 wchar_t PasswordChar;
\r
189 EGUI_ALIGNMENT HAlign, VAlign;
\r
191 core::array< core::stringw > BrokenText;
\r
192 core::array< s32 > BrokenTextPositions;
\r
194 core::rect<s32> CurrentTextRect, FrameRect; // temporary values
\r
198 } // end namespace gui
\r
199 } // end namespace irr
\r
201 #endif // __C_GUI_EDIT_BOX_H_INCLUDED__
\r