1 // Copyright (C) 2002-2012 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_GUI_EDIT_BOX_H_INCLUDED__ 6 #define __C_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 CGUIEditBox : public IGUIEditBox 20 { 21 public: 22 23 //! constructor 24 CGUIEditBox(const wchar_t* text, bool border, IGUIEnvironment* environment, 25 IGUIElement* parent, s32 id, const core::rect<s32>& rectangle); 26 27 //! destructor 28 virtual ~CGUIEditBox(); 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 core::stringw& 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); setComposingText(const std::u32string & ct)127 virtual void setComposingText(const std::u32string& ct) {} clearComposingText()128 virtual void clearComposingText() {} getICPos()129 virtual const core::position2di& getICPos() const 130 { 131 static core::position2di unused; 132 return unused; 133 } 134 protected: 135 //! Breaks the single text line. 136 void breakText(); 137 //! sets the area of the given line 138 void setTextRect(s32 line); 139 //! returns the line number that the cursor is on 140 s32 getLineFromPos(s32 pos); 141 //! adds a letter to the edit box 142 void inputChar(wchar_t c); 143 //! calculates the current scroll position 144 void calculateScrollPos(); 145 //! calculated the FrameRect 146 void calculateFrameRect(); 147 //! send some gui event to parent 148 void sendGuiEvent(EGUI_EVENT_TYPE type); 149 //! set text markers 150 void setTextMarkers(s32 begin, s32 end); 151 152 bool processKey(const SEvent& event); 153 bool processMouse(const SEvent& event); 154 s32 getCursorPos(s32 x, s32 y); 155 156 bool MouseMarking; 157 bool Border; 158 bool Background; 159 bool OverrideColorEnabled; 160 s32 MarkBegin; 161 s32 MarkEnd; 162 163 video::SColor OverrideColor; 164 gui::IGUIFont *OverrideFont, *LastBreakFont; 165 IOSOperator* Operator; 166 167 u32 BlinkStartTime; 168 s32 CursorPos; 169 s32 HScrollPos, VScrollPos; // scroll position in characters 170 u32 Max; 171 172 bool WordWrap, MultiLine, AutoScroll, PasswordBox; 173 wchar_t PasswordChar; 174 EGUI_ALIGNMENT HAlign, VAlign; 175 176 core::array< core::stringw > BrokenText; 177 core::array< s32 > BrokenTextPositions; 178 179 core::rect<s32> CurrentTextRect, FrameRect; // temporary values 180 }; 181 182 183 } // end namespace gui 184 } // end namespace irr 185 186 #endif // _IRR_COMPILE_WITH_GUI_ 187 #endif // __C_GUI_EDIT_BOX_H_INCLUDED__ 188 189