1 // Copyright (C) 2002-2012 Nikolaus Gebhardt, Modified by Mustapha Tachouct
2 // This file is part of the "Irrlicht Engine".
3 // For conditions of distribution and use, see copyright notice in irrlicht.h
5 #ifndef GUIEDITBOXWITHSCROLLBAR_HEADER
6 #define GUIEDITBOXWITHSCROLLBAR_HEADER
8 #include "IGUIEditBox.h"
9 #include "IOSOperator.h"
10 #include "IGUIScrollBar.h"
14 using namespace irr::gui;
16 class GUIEditBoxWithScrollBar : public IGUIEditBox
21 GUIEditBoxWithScrollBar(const wchar_t* text, bool border, IGUIEnvironment* environment,
22 IGUIElement* parent, s32 id, const core::rect<s32>& rectangle,
23 bool writable = true, bool has_vscrollbar = true);
26 virtual ~GUIEditBoxWithScrollBar();
28 //! Sets another skin independent font.
29 virtual void setOverrideFont(IGUIFont* font = 0);
31 //! Gets the override font (if any)
32 /** \return The override font (may be 0) */
33 virtual IGUIFont* getOverrideFont() const;
35 //! Get the font which is used right now for drawing
36 /** Currently this is the override font when one is set and the
37 font of the active skin otherwise */
38 virtual IGUIFont* getActiveFont() const;
40 //! Sets another color for the text.
41 virtual void setOverrideColor(video::SColor color);
43 //! Gets the override color
44 virtual video::SColor getOverrideColor() const;
46 //! Sets if the text should use the overide color or the
47 //! color in the gui skin.
48 virtual void enableOverrideColor(bool enable);
50 //! Checks if an override color is enabled
51 /** \return true if the override color is enabled, false otherwise */
52 virtual bool isOverrideColorEnabled(void) const;
54 //! Sets whether to draw the background
55 virtual void setDrawBackground(bool draw);
57 //! Turns the border on or off
58 virtual void setDrawBorder(bool border);
60 //! Enables or disables word wrap for using the edit box as multiline text editor.
61 virtual void setWordWrap(bool enable);
63 //! Checks if word wrap is enabled
64 //! \return true if word wrap is enabled, false otherwise
65 virtual bool isWordWrapEnabled() const;
67 //! Enables or disables newlines.
68 /** \param enable: If set to true, the EGET_EDITBOX_ENTER event will not be fired,
69 instead a newline character will be inserted. */
70 virtual void setMultiLine(bool enable);
72 //! Checks if multi line editing is enabled
73 //! \return true if mult-line is enabled, false otherwise
74 virtual bool isMultiLineEnabled() const;
76 //! Enables or disables automatic scrolling with cursor position
77 //! \param enable: If set to true, the text will move around with the cursor position
78 virtual void setAutoScroll(bool enable);
80 //! Checks to see if automatic scrolling is enabled
81 //! \return true if automatic scrolling is enabled, false if not
82 virtual bool isAutoScrollEnabled() const;
84 //! Gets the size area of the text in the edit box
85 //! \return Returns the size in pixels of the text
86 virtual core::dimension2du getTextDimension();
88 //! Sets text justification
89 virtual void setTextAlignment(EGUI_ALIGNMENT horizontal, EGUI_ALIGNMENT vertical);
91 //! called if an event happened.
92 virtual bool OnEvent(const SEvent& event);
94 //! draws the element and its children
97 //! Sets the new caption of this element.
98 virtual void setText(const wchar_t* text);
100 //! Sets the maximum amount of characters which may be entered in the box.
101 //! \param max: Maximum amount of characters. If 0, the character amount is
103 virtual void setMax(u32 max);
105 //! Returns maximum amount of characters, previously set by setMax();
106 virtual u32 getMax() const;
108 //! Sets whether the edit box is a password box. Setting this to true will
109 /** disable MultiLine, WordWrap and the ability to copy with ctrl+c or ctrl+x
110 \param passwordBox: true to enable password, false to disable
111 \param passwordChar: the character that is displayed instead of letters */
112 virtual void setPasswordBox(bool passwordBox, wchar_t passwordChar = L'*');
114 //! Returns true if the edit box is currently a password box.
115 virtual bool isPasswordBox() const;
117 //! Updates the absolute position, splits text if required
118 virtual void updateAbsolutePosition();
120 virtual void setWritable(bool writable);
122 //! Change the background color
123 virtual void setBackgroundColor(const video::SColor &bg_color);
125 //! Writes attributes of the element.
126 virtual void serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const;
128 //! Reads attributes of the element
129 virtual void deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options);
131 virtual bool isDrawBackgroundEnabled() const;
132 virtual bool isDrawBorderEnabled() const;
133 virtual void setCursorChar(const wchar_t cursorChar);
134 virtual wchar_t getCursorChar() const;
135 virtual void setCursorBlinkTime(irr::u32 timeMs);
136 virtual irr::u32 getCursorBlinkTime() const;
139 //! Breaks the single text line.
141 //! sets the area of the given line
142 void setTextRect(s32 line);
143 //! returns the line number that the cursor is on
144 s32 getLineFromPos(s32 pos);
145 //! adds a letter to the edit box
146 void inputChar(wchar_t c);
147 //! calculates the current scroll position
148 void calculateScrollPos();
149 //! calculated the FrameRect
150 void calculateFrameRect();
151 //! send some gui event to parent
152 void sendGuiEvent(EGUI_EVENT_TYPE type);
154 void setTextMarkers(s32 begin, s32 end);
155 //! create a Vertical ScrollBar
156 void createVScrollBar();
157 //! update the vertical scrollBar (visibilty & position)
158 void updateVScrollBar();
160 bool processKey(const SEvent& event);
161 bool processMouse(const SEvent& event);
162 s32 getCursorPos(s32 x, s32 y);
164 bool m_mouse_marking;
167 bool m_override_color_enabled;
171 video::SColor m_override_color;
172 gui::IGUIFont *m_override_font, *m_last_break_font;
173 IOSOperator* m_operator;
175 u32 m_blink_start_time;
177 s32 m_hscroll_pos, m_vscroll_pos; // scroll position in characters
180 bool m_word_wrap, m_multiline, m_autoscroll, m_passwordbox;
181 wchar_t m_passwordchar;
182 EGUI_ALIGNMENT m_halign, m_valign;
184 std::vector<core::stringw> m_broken_text;
185 std::vector<s32> m_broken_text_positions;
187 core::rect<s32> m_current_text_rect, m_frame_rect; // temporary values
189 u32 m_scrollbar_width;
190 IGUIScrollBar *m_vscrollbar;
193 bool m_bg_color_used;
194 video::SColor m_bg_color;
198 #endif // GUIEDITBOXWITHSCROLLBAR_HEADER