1 /*********************************************************************** 2 created: Sat Jun 25 2005 3 author: Paul D Turner <paul@cegui.org.uk> 4 *************************************************************************/ 5 /*************************************************************************** 6 * Copyright (C) 2004 - 2009 Paul D Turner & The CEGUI Development Team 7 * 8 * Permission is hereby granted, free of charge, to any person obtaining 9 * a copy of this software and associated documentation files (the 10 * "Software"), to deal in the Software without restriction, including 11 * without limitation the rights to use, copy, modify, merge, publish, 12 * distribute, sublicense, and/or sell copies of the Software, and to 13 * permit persons to whom the Software is furnished to do so, subject to 14 * the following conditions: 15 * 16 * The above copyright notice and this permission notice shall be 17 * included in all copies or substantial portions of the Software. 18 * 19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 20 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 22 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 23 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 24 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 25 * OTHER DEALINGS IN THE SOFTWARE. 26 ***************************************************************************/ 27 #ifndef _FalEditbox_h_ 28 #define _FalEditbox_h_ 29 30 #include "CEGUI/WindowRendererSets/Core/Module.h" 31 #include "CEGUI/widgets/Editbox.h" 32 33 #if defined(_MSC_VER) 34 # pragma warning(push) 35 # pragma warning(disable : 4251) 36 #endif 37 38 // Start of CEGUI namespace section 39 namespace CEGUI 40 { 41 /*! 42 \brief 43 Editbox class for the FalagardBase module. 44 45 This class requires LookNFeel to be assigned. The LookNFeel should provide 46 the following: 47 48 States: 49 - Enabled: Rendering for when the editbox is in enabled and is in 50 read-write mode. 51 - ReadOnly: Rendering for when the editbox is in enabled and is in 52 read-only mode. 53 - Disabled: Rendering for when the editbox is disabled. 54 - ActiveSelection: additional state rendered for text selection 55 (the imagery in this section is rendered within the 56 selection area.) 57 - InactiveSelection: additional state rendered for text selection 58 (the imagery in this section is rendered within the 59 selection area.) 60 61 NamedAreas: 62 - TextArea: area where text, selection, and caret imagery will appear. 63 64 PropertyDefinitions (optional) 65 - NormalTextColour: property that accesses a colour value to be used to 66 render normal unselected text. If this property is 67 not defined, the colour defaults to black. 68 - SelectedTextColour: property that accesses a colour value to be used 69 to render selected text. If this property is 70 not defined, the colour defaults to black. 71 72 Imagery Sections: 73 - Caret 74 */ 75 class COREWRSET_API FalagardEditbox : public EditboxWindowRenderer 76 { 77 public: 78 //! type name for this widget. 79 static const String TypeName; 80 81 //! Name of the optional property to access for the unselected text colour. 82 static const String UnselectedTextColourPropertyName; 83 //! Name of the optional property to access for the selected text colour. 84 static const String SelectedTextColourPropertyName; 85 //! Name of the optional property to access to obtain active selection rendering colour. 86 static const String ActiveSelectionColourPropertyName; 87 //! Name of the optional property to access to obtain inactive selection rendering colour. 88 static const String InactiveSelectionColourPropertyName; 89 //! The default timeout (in seconds) used when blinking the caret. 90 static const float DefaultCaretBlinkTimeout; 91 92 /*! 93 \brief 94 Constructor 95 */ 96 FalagardEditbox(const String& type); 97 98 /*! 99 \brief 100 Set the given ColourRect to the colour to be used for rendering Editbox 101 text oustside of the selected region. 102 */ 103 void setColourRectToUnselectedTextColour(ColourRect& colour_rect) const; 104 105 /*! 106 \brief 107 Set the given ColourRect to the colour to be used for rendering Editbox 108 text falling within the selected region. 109 */ 110 void setColourRectToSelectedTextColour(ColourRect& colour_rect) const; 111 112 /*! 113 \brief 114 Set the given ColourRect to the colour(s) fetched from the named 115 property if it exists, else the default colour of black. 116 117 \param propertyName 118 String object holding the name of the property to be accessed if it 119 exists. 120 121 \param colour_rect 122 Reference to a ColourRect that will be set. 123 */ 124 void setColourRectToOptionalPropertyColour(const String& propertyName, 125 ColourRect& colour_rect) const; 126 127 //! return whether the blinking caret is enabled. 128 bool isCaretBlinkEnabled() const; 129 //! return the caret blink timeout period (only used if blink is enabled). 130 float getCaretBlinkTimeout() const; 131 //! set whether the blinking caret is enabled. 132 void setCaretBlinkEnabled(bool enable); 133 //! set the caret blink timeout period (only used if blink is enabled). 134 void setCaretBlinkTimeout(float seconds); 135 136 /*! 137 \brief 138 Sets the horizontal text formatting to be used from now onwards. 139 140 \param format 141 Specifies the formatting to use. Currently can only be one of the 142 following HorizontalTextFormatting values: 143 - HTF_LEFT_ALIGNED (default) 144 - HTF_RIGHT_ALIGNED 145 - HTF_CENTRE_ALIGNED 146 */ 147 void setTextFormatting(const HorizontalTextFormatting format); 148 HorizontalTextFormatting getTextFormatting() const; 149 150 void render(); 151 152 // overridden from EditboxWindowRenderer base class. 153 size_t getTextIndexFromPosition(const Vector2f& pt) const; 154 // overridden from WindowRenderer class 155 void update(float elapsed); 156 bool handleFontRenderSizeChange(const Font* const font); 157 158 protected: 159 //! helper to draw the base imagery (container and what have you) 160 void renderBaseImagery(const WidgetLookFeel& wlf) const; 161 //! helper to set 'visual' to the string we will render (part of) 162 void setupVisualString(String& visual) const; 163 size_t getCaretIndex(const String& visual_text) const; 164 float calculateTextOffset(const Rectf& text_area, 165 const float text_extent, 166 const float caret_width, 167 const float extent_to_caret); 168 void renderTextNoBidi(const WidgetLookFeel& wlf, 169 const String& text, 170 const Rectf& text_area, 171 float text_offset); 172 void renderTextBidi(const WidgetLookFeel& wlf, 173 const String& text, 174 const Rectf& text_area, 175 float text_offset); 176 bool editboxIsFocussed() const; 177 bool editboxIsReadOnly() const; 178 void renderCaret(const ImagerySection& imagery, 179 const Rectf& text_area, 180 const float text_offset, 181 const float extent_to_caret) const; 182 183 bool isUnsupportedFormat(const HorizontalTextFormatting format); 184 185 //! x rendering offset used last time we drew the widget. 186 float d_lastTextOffset; 187 //! true if the caret imagery should blink. 188 bool d_blinkCaret; 189 //! time-out in seconds used for blinking the caret. 190 float d_caretBlinkTimeout; 191 //! current time elapsed since last caret blink state change. 192 float d_caretBlinkElapsed; 193 //! true if caret should be shown. 194 bool d_showCaret; 195 //! horizontal formatting. Only supports left, right, and centred. 196 HorizontalTextFormatting d_textFormatting; 197 }; 198 199 } // End of CEGUI namespace section 200 201 #if defined(_MSC_VER) 202 # pragma warning(pop) 203 #endif 204 205 #endif // end of guard _FalEditbox_h_ 206