|
| 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 |
| 4 | + |
| 5 | +#ifndef __C_INTL_GUI_EDIT_BOX_H_INCLUDED__ |
| 6 | +#define __C_INTL_GUI_EDIT_BOX_H_INCLUDED__ |
| 7 | + |
| 8 | +#include "IrrCompileConfig.h" |
| 9 | +//#ifdef _IRR_COMPILE_WITH_GUI_ |
| 10 | + |
| 11 | +#include "IGUIEditBox.h" |
| 12 | +#include "irrArray.h" |
| 13 | +#include "IOSOperator.h" |
| 14 | + |
| 15 | +namespace irr |
| 16 | +{ |
| 17 | +namespace gui |
| 18 | +{ |
| 19 | + class intlGUIEditBox : public IGUIEditBox |
| 20 | + { |
| 21 | + public: |
| 22 | + |
| 23 | + //! constructor |
| 24 | + intlGUIEditBox(const wchar_t* text, bool border, IGUIEnvironment* environment, |
| 25 | + IGUIElement* parent, s32 id, const core::rect<s32>& rectangle); |
| 26 | + |
| 27 | + //! destructor |
| 28 | + virtual ~intlGUIEditBox(); |
| 29 | + |
| 30 | + //! Sets another skin independent font. |
| 31 | + virtual void setOverrideFont(IGUIFont* font=0); |
| 32 | + |
| 33 | + //! Gets the override font (if any) |
| 34 | + /** \return The override font (may be 0) */ |
| 35 | + virtual IGUIFont* getOverrideFont() const; |
| 36 | + |
| 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; |
| 41 | + |
| 42 | + //! Sets another color for the text. |
| 43 | + virtual void setOverrideColor(video::SColor color); |
| 44 | + |
| 45 | + //! Gets the override color |
| 46 | + virtual video::SColor getOverrideColor() const; |
| 47 | + |
| 48 | + //! Sets if the text should use the overide color or the |
| 49 | + //! color in the gui skin. |
| 50 | + virtual void enableOverrideColor(bool enable); |
| 51 | + |
| 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; |
| 55 | + |
| 56 | + //! Sets whether to draw the background |
| 57 | + virtual void setDrawBackground(bool draw); |
| 58 | + |
| 59 | + //! Turns the border on or off |
| 60 | + virtual void setDrawBorder(bool border); |
| 61 | + |
| 62 | + //! Enables or disables word wrap for using the edit box as multiline text editor. |
| 63 | + virtual void setWordWrap(bool enable); |
| 64 | + |
| 65 | + //! Checks if word wrap is enabled |
| 66 | + //! \return true if word wrap is enabled, false otherwise |
| 67 | + virtual bool isWordWrapEnabled() const; |
| 68 | + |
| 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); |
| 73 | + |
| 74 | + //! Checks if multi line editing is enabled |
| 75 | + //! \return true if mult-line is enabled, false otherwise |
| 76 | + virtual bool isMultiLineEnabled() const; |
| 77 | + |
| 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); |
| 81 | + |
| 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; |
| 85 | + |
| 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(); |
| 89 | + |
| 90 | + //! Sets text justification |
| 91 | + virtual void setTextAlignment(EGUI_ALIGNMENT horizontal, EGUI_ALIGNMENT vertical); |
| 92 | + |
| 93 | + //! called if an event happened. |
| 94 | + virtual bool OnEvent(const SEvent& event); |
| 95 | + |
| 96 | + //! draws the element and its children |
| 97 | + virtual void draw(); |
| 98 | + |
| 99 | + //! Sets the new caption of this element. |
| 100 | + virtual void setText(const wchar_t* text); |
| 101 | + |
| 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 |
| 104 | + //! infinity. |
| 105 | + virtual void setMax(u32 max); |
| 106 | + |
| 107 | + //! Returns maximum amount of characters, previously set by setMax(); |
| 108 | + virtual u32 getMax() const; |
| 109 | + |
| 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'*'); |
| 115 | + |
| 116 | + //! Returns true if the edit box is currently a password box. |
| 117 | + virtual bool isPasswordBox() const; |
| 118 | + |
| 119 | + //! Updates the absolute position, splits text if required |
| 120 | + virtual void updateAbsolutePosition(); |
| 121 | + |
| 122 | + //! Writes attributes of the element. |
| 123 | + virtual void serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const; |
| 124 | + |
| 125 | + //! Reads attributes of the element |
| 126 | + virtual void deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options); |
| 127 | + |
| 128 | + protected: |
| 129 | + //! Breaks the single text line. |
| 130 | + void breakText(); |
| 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); |
| 141 | + //! set text markers |
| 142 | + void setTextMarkers(s32 begin, s32 end); |
| 143 | + |
| 144 | + bool processKey(const SEvent& event); |
| 145 | + bool processMouse(const SEvent& event); |
| 146 | + s32 getCursorPos(s32 x, s32 y); |
| 147 | + |
| 148 | + bool MouseMarking; |
| 149 | + bool Border; |
| 150 | + bool OverrideColorEnabled; |
| 151 | + s32 MarkBegin; |
| 152 | + s32 MarkEnd; |
| 153 | + |
| 154 | + video::SColor OverrideColor; |
| 155 | + gui::IGUIFont *OverrideFont, *LastBreakFont; |
| 156 | + IOSOperator* Operator; |
| 157 | + |
| 158 | + u32 BlinkStartTime; |
| 159 | + s32 CursorPos; |
| 160 | + s32 HScrollPos, VScrollPos; // scroll position in characters |
| 161 | + u32 Max; |
| 162 | + |
| 163 | + bool WordWrap, MultiLine, AutoScroll, PasswordBox; |
| 164 | + wchar_t PasswordChar; |
| 165 | + EGUI_ALIGNMENT HAlign, VAlign; |
| 166 | + |
| 167 | + core::array< core::stringw > BrokenText; |
| 168 | + core::array< s32 > BrokenTextPositions; |
| 169 | + |
| 170 | + core::rect<s32> CurrentTextRect, FrameRect; // temporary values |
| 171 | + }; |
| 172 | + |
| 173 | + |
| 174 | +} // end namespace gui |
| 175 | +} // end namespace irr |
| 176 | + |
| 177 | +//#endif // _IRR_COMPILE_WITH_GUI_ |
| 178 | +#endif // __C_GUI_EDIT_BOX_H_INCLUDED__ |
0 commit comments