1 /*------------------------------------------------------------------------- 2 This source file is a part of OGRE 3 (Object-oriented Graphics Rendering Engine) 4 5 For the latest info, see http://www.ogre3d.org/ 6 7 Copyright (c) 2000-2014 Torus Knot Software Ltd 8 Permission is hereby granted, free of charge, to any person obtaining a copy 9 of this software and associated documentation files (the "Software"), to deal 10 in the Software without restriction, including without limitation the rights 11 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 copies of the Software, and to permit persons to whom the Software is 13 furnished to do so, subject to the following conditions: 14 15 The above copyright notice and this permission notice shall be included in 16 all copies or substantial portions of the Software. 17 18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 THE SOFTWARE 25 -------------------------------------------------------------------------*/ 26 27 #ifndef _TextAreaOverlayElement_H__ 28 #define _TextAreaOverlayElement_H__ 29 30 #include "OgreOverlayElement.h" 31 #include "OgreRenderOperation.h" 32 #include "OgreFont.h" 33 34 namespace Ogre 35 { 36 /** \addtogroup Optional 37 * @{ 38 */ 39 /** \addtogroup Overlays 40 * @{ 41 */ 42 /** This class implements an overlay element which contains simple unformatted text. 43 */ 44 class _OgreOverlayExport TextAreaOverlayElement : public OverlayElement 45 { 46 public: 47 enum Alignment 48 { 49 Left, 50 Right, 51 Center 52 }; 53 54 public: 55 /** Constructor. */ 56 TextAreaOverlayElement(const String& name); 57 virtual ~TextAreaOverlayElement(); 58 59 virtual void initialise(void); 60 61 /** @copydoc OverlayElement::_releaseManualHardwareResources */ 62 virtual void _releaseManualHardwareResources(); 63 /** @copydoc OverlayElement::_restoreManualHardwareResources */ 64 virtual void _restoreManualHardwareResources(); 65 66 virtual void setCaption(const DisplayString& text); 67 68 void setCharHeight( Real height ); 69 Real getCharHeight() const; 70 71 void setSpaceWidth( Real width ); 72 Real getSpaceWidth() const; 73 74 void setFontName( const String& font, const String& group = DEFAULT_RESOURCE_GROUP ); 75 /// @deprecated use getFont() 76 OGRE_DEPRECATED const String& getFontName() const; 77 getFont()78 const FontPtr& getFont() const { 79 return mFont; 80 } 81 82 /** See OverlayElement. */ 83 virtual const String& getTypeName(void) const; 84 /** See Renderable. */ 85 const MaterialPtr& getMaterial(void) const; 86 /** See Renderable. */ 87 void getRenderOperation(RenderOperation& op); 88 89 /** Sets the colour of the text. 90 @remarks 91 This method establishes a constant colour for 92 the entire text. Also see setColourBottom and 93 setColourTop which allow you to set a colour gradient. 94 */ 95 void setColour(const ColourValue& col); 96 97 /** Gets the colour of the text. */ 98 const ColourValue& getColour(void) const; 99 /** Sets the colour of the bottom of the letters. 100 @remarks 101 By setting a separate top and bottom colour, you 102 can create a text area which has a graduated colour 103 effect to it. 104 */ 105 void setColourBottom(const ColourValue& col); 106 /** Gets the colour of the bottom of the letters. */ 107 const ColourValue& getColourBottom(void) const; 108 /** Sets the colour of the top of the letters. 109 @remarks 110 By setting a separate top and bottom colour, you 111 can create a text area which has a graduated colour 112 effect to it. 113 */ 114 void setColourTop(const ColourValue& col); 115 /** Gets the colour of the top of the letters. */ 116 const ColourValue& getColourTop(void) const; 117 setAlignment(Alignment a)118 inline void setAlignment( Alignment a ) 119 { 120 mAlignment = a; 121 mGeomPositionsOutOfDate = true; 122 } getAlignment()123 inline Alignment getAlignment() const 124 { 125 return mAlignment; 126 } 127 128 /** Overridden from OverlayElement */ 129 void setMetricsMode(GuiMetricsMode gmm); 130 131 /** Overridden from OverlayElement */ 132 void _update(void); 133 134 //----------------------------------------------------------------------------------------- 135 /** Command object for setting the caption. 136 @see ParamCommand 137 */ 138 class _OgrePrivate CmdCaption : public ParamCommand 139 { 140 public: 141 String doGet( const void* target ) const; 142 void doSet( void* target, const String& val ); 143 }; 144 //----------------------------------------------------------------------------------------- 145 /** Command object for setting the char height. 146 @see ParamCommand 147 */ 148 class _OgrePrivate CmdCharHeight : public ParamCommand 149 { 150 public: 151 String doGet( const void* target ) const; 152 void doSet( void* target, const String& val ); 153 }; 154 //----------------------------------------------------------------------------------------- 155 /** Command object for setting the width of a space. 156 @see ParamCommand 157 */ 158 class _OgrePrivate CmdSpaceWidth : public ParamCommand 159 { 160 public: 161 String doGet( const void* target ) const; 162 void doSet( void* target, const String& val ); 163 }; 164 //----------------------------------------------------------------------------------------- 165 /** Command object for setting the caption. 166 @see ParamCommand 167 */ 168 class _OgrePrivate CmdFontName : public ParamCommand 169 { 170 public: 171 String doGet( const void* target ) const; 172 void doSet( void* target, const String& val ); 173 }; 174 //----------------------------------------------------------------------------------------- 175 /** Command object for setting the top colour. 176 @see ParamCommand 177 */ 178 class _OgrePrivate CmdColourTop : public ParamCommand 179 { 180 public: 181 String doGet( const void* target ) const; 182 void doSet( void* target, const String& val ); 183 }; 184 //----------------------------------------------------------------------------------------- 185 /** Command object for setting the bottom colour. 186 @see ParamCommand 187 */ 188 class _OgrePrivate CmdColourBottom : public ParamCommand 189 { 190 public: 191 String doGet( const void* target ) const; 192 void doSet( void* target, const String& val ); 193 }; 194 //----------------------------------------------------------------------------------------- 195 /** Command object for setting the constant colour. 196 @see ParamCommand 197 */ 198 class _OgrePrivate CmdColour : public ParamCommand 199 { 200 public: 201 String doGet( const void* target ) const; 202 void doSet( void* target, const String& val ); 203 }; 204 //----------------------------------------------------------------------------------------- 205 /** Command object for setting the alignment. 206 @see ParamCommand 207 */ 208 class _OgrePrivate CmdAlignment : public ParamCommand 209 { 210 public: 211 String doGet( const void* target ) const; 212 void doSet( void* target, const String& val ); 213 }; 214 215 protected: 216 /// The text alignment 217 Alignment mAlignment; 218 219 /// Flag indicating if this panel should be visual or just group things 220 bool mTransparent; 221 222 /// Render operation 223 RenderOperation mRenderOp; 224 225 /// Method for setting up base parameters for this class 226 void addBaseParameters(void); 227 228 static String msTypeName; 229 230 // Command objects 231 static CmdCharHeight msCmdCharHeight; 232 static CmdSpaceWidth msCmdSpaceWidth; 233 static CmdFontName msCmdFontName; 234 static CmdColour msCmdColour; 235 static CmdColourTop msCmdColourTop; 236 static CmdColourBottom msCmdColourBottom; 237 static CmdAlignment msCmdAlignment; 238 239 240 FontPtr mFont; 241 Real mCharHeight; 242 ushort mPixelCharHeight; 243 bool mSpaceWidthOverridden; 244 Real mSpaceWidth; 245 ushort mPixelSpaceWidth; 246 size_t mAllocSize; 247 Real mViewportAspectCoef; 248 249 /// Colours to use for the vertices 250 ColourValue mColourBottom; 251 ColourValue mColourTop; 252 bool mColoursChanged; 253 254 255 /// Internal method to allocate memory, only reallocates when necessary 256 void checkMemoryAllocation( size_t numChars ); 257 /// Inherited function 258 virtual void updatePositionGeometry(); 259 /// Inherited function 260 virtual void updateTextureGeometry(); 261 /// Updates vertex colours 262 virtual void updateColours(void); 263 }; 264 /** @} */ 265 /** @} */ 266 } 267 268 #endif 269 270