[1] | 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-2006 Torus Knot Software Ltd |
---|
| 8 | Also see acknowledgements in Readme.html |
---|
| 9 | |
---|
| 10 | This library is free software; you can redistribute it and/or modify it |
---|
| 11 | under the terms of the GNU Lesser General Public License (LGPL) as |
---|
| 12 | published by the Free Software Foundation; either version 2.1 of the |
---|
| 13 | License, or (at your option) any later version. |
---|
| 14 | |
---|
| 15 | This library is distributed in the hope that it will be useful, but |
---|
| 16 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
---|
| 17 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public |
---|
| 18 | License for more details. |
---|
| 19 | |
---|
| 20 | You should have received a copy of the GNU Lesser General Public License |
---|
| 21 | along with this library; if not, write to the Free Software Foundation, |
---|
| 22 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA or go to |
---|
| 23 | http://www.gnu.org/copyleft/lesser.txt |
---|
| 24 | -------------------------------------------------------------------------*/ |
---|
| 25 | |
---|
| 26 | #ifndef _TextAreaOverlayElement_H__ |
---|
| 27 | #define _TextAreaOverlayElement_H__ |
---|
| 28 | |
---|
| 29 | #include "OgreOverlayElement.h" |
---|
| 30 | #include "OgreFont.h" |
---|
| 31 | |
---|
| 32 | namespace Ogre |
---|
| 33 | { |
---|
| 34 | /** This class implements an overlay element which contains simple unformatted text. |
---|
| 35 | */ |
---|
| 36 | class _OgreExport TextAreaOverlayElement : public OverlayElement |
---|
| 37 | { |
---|
| 38 | public: |
---|
| 39 | enum Alignment |
---|
| 40 | { |
---|
| 41 | Left, |
---|
| 42 | Right, |
---|
| 43 | Center |
---|
| 44 | }; |
---|
| 45 | |
---|
| 46 | public: |
---|
| 47 | /** Constructor. */ |
---|
| 48 | TextAreaOverlayElement(const String& name); |
---|
| 49 | virtual ~TextAreaOverlayElement(); |
---|
| 50 | |
---|
| 51 | virtual void initialise(void); |
---|
| 52 | virtual void setCaption(const DisplayString& text); |
---|
| 53 | |
---|
| 54 | void setCharHeight( Real height ); |
---|
| 55 | Real getCharHeight() const; |
---|
| 56 | |
---|
| 57 | void setSpaceWidth( Real width ); |
---|
| 58 | Real getSpaceWidth() const; |
---|
| 59 | |
---|
| 60 | void setFontName( const String& font ); |
---|
| 61 | const String& getFontName() const; |
---|
| 62 | |
---|
| 63 | /** See OverlayElement. */ |
---|
| 64 | virtual const String& getTypeName(void) const; |
---|
| 65 | /** See Renderable. */ |
---|
| 66 | void getRenderOperation(RenderOperation& op); |
---|
| 67 | /** Overridden from OverlayElement */ |
---|
| 68 | void setMaterialName(const String& matName); |
---|
| 69 | |
---|
| 70 | /** Sets the colour of the text. |
---|
| 71 | @remarks |
---|
| 72 | This method establishes a constant colour for |
---|
| 73 | the entire text. Also see setColourBottom and |
---|
| 74 | setColourTop which allow you to set a colour gradient. |
---|
| 75 | */ |
---|
| 76 | void setColour(const ColourValue& col); |
---|
| 77 | |
---|
| 78 | /** Gets the colour of the text. */ |
---|
| 79 | const ColourValue& getColour(void) const; |
---|
| 80 | /** Sets the colour of the bottom of the letters. |
---|
| 81 | @remarks |
---|
| 82 | By setting a separate top and bottom colour, you |
---|
| 83 | can create a text area which has a graduated colour |
---|
| 84 | effect to it. |
---|
| 85 | */ |
---|
| 86 | void setColourBottom(const ColourValue& col); |
---|
| 87 | /** Gets the colour of the bottom of the letters. */ |
---|
| 88 | const ColourValue& getColourBottom(void) const; |
---|
| 89 | /** Sets the colour of the top of the letters. |
---|
| 90 | @remarks |
---|
| 91 | By setting a separate top and bottom colour, you |
---|
| 92 | can create a text area which has a graduated colour |
---|
| 93 | effect to it. |
---|
| 94 | */ |
---|
| 95 | void setColourTop(const ColourValue& col); |
---|
| 96 | /** Gets the colour of the top of the letters. */ |
---|
| 97 | const ColourValue& getColourTop(void) const; |
---|
| 98 | |
---|
| 99 | inline void setAlignment( Alignment a ) |
---|
| 100 | { |
---|
| 101 | mAlignment = a; |
---|
| 102 | mGeomPositionsOutOfDate = true; |
---|
| 103 | } |
---|
| 104 | inline Alignment getAlignment() const |
---|
| 105 | { |
---|
| 106 | return mAlignment; |
---|
| 107 | } |
---|
| 108 | |
---|
| 109 | /** Overridden from OverlayElement */ |
---|
| 110 | void setMetricsMode(GuiMetricsMode gmm); |
---|
| 111 | |
---|
| 112 | /** Overridden from OverlayElement */ |
---|
| 113 | void _update(void); |
---|
| 114 | |
---|
| 115 | //----------------------------------------------------------------------------------------- |
---|
| 116 | /** Command object for setting the caption. |
---|
| 117 | @see ParamCommand |
---|
| 118 | */ |
---|
| 119 | class _OgrePrivate CmdCaption : public ParamCommand |
---|
| 120 | { |
---|
| 121 | public: |
---|
| 122 | String doGet( const void* target ) const; |
---|
| 123 | void doSet( void* target, const String& val ); |
---|
| 124 | }; |
---|
| 125 | //----------------------------------------------------------------------------------------- |
---|
| 126 | /** Command object for setting the char height. |
---|
| 127 | @see ParamCommand |
---|
| 128 | */ |
---|
| 129 | class _OgrePrivate CmdCharHeight : public ParamCommand |
---|
| 130 | { |
---|
| 131 | public: |
---|
| 132 | String doGet( const void* target ) const; |
---|
| 133 | void doSet( void* target, const String& val ); |
---|
| 134 | }; |
---|
| 135 | //----------------------------------------------------------------------------------------- |
---|
| 136 | /** Command object for setting the width of a space. |
---|
| 137 | @see ParamCommand |
---|
| 138 | */ |
---|
| 139 | class _OgrePrivate CmdSpaceWidth : public ParamCommand |
---|
| 140 | { |
---|
| 141 | public: |
---|
| 142 | String doGet( const void* target ) const; |
---|
| 143 | void doSet( void* target, const String& val ); |
---|
| 144 | }; |
---|
| 145 | //----------------------------------------------------------------------------------------- |
---|
| 146 | /** Command object for setting the caption. |
---|
| 147 | @see ParamCommand |
---|
| 148 | */ |
---|
| 149 | class _OgrePrivate CmdFontName : public ParamCommand |
---|
| 150 | { |
---|
| 151 | public: |
---|
| 152 | String doGet( const void* target ) const; |
---|
| 153 | void doSet( void* target, const String& val ); |
---|
| 154 | }; |
---|
| 155 | //----------------------------------------------------------------------------------------- |
---|
| 156 | /** Command object for setting the top colour. |
---|
| 157 | @see ParamCommand |
---|
| 158 | */ |
---|
| 159 | class _OgrePrivate CmdColourTop : public ParamCommand |
---|
| 160 | { |
---|
| 161 | public: |
---|
| 162 | String doGet( const void* target ) const; |
---|
| 163 | void doSet( void* target, const String& val ); |
---|
| 164 | }; |
---|
| 165 | //----------------------------------------------------------------------------------------- |
---|
| 166 | /** Command object for setting the bottom colour. |
---|
| 167 | @see ParamCommand |
---|
| 168 | */ |
---|
| 169 | class _OgrePrivate CmdColourBottom : public ParamCommand |
---|
| 170 | { |
---|
| 171 | public: |
---|
| 172 | String doGet( const void* target ) const; |
---|
| 173 | void doSet( void* target, const String& val ); |
---|
| 174 | }; |
---|
| 175 | //----------------------------------------------------------------------------------------- |
---|
| 176 | /** Command object for setting the constant colour. |
---|
| 177 | @see ParamCommand |
---|
| 178 | */ |
---|
| 179 | class _OgrePrivate CmdColour : public ParamCommand |
---|
| 180 | { |
---|
| 181 | public: |
---|
| 182 | String doGet( const void* target ) const; |
---|
| 183 | void doSet( void* target, const String& val ); |
---|
| 184 | }; |
---|
| 185 | //----------------------------------------------------------------------------------------- |
---|
| 186 | /** Command object for setting the alignment. |
---|
| 187 | @see ParamCommand |
---|
| 188 | */ |
---|
| 189 | class _OgrePrivate CmdAlignment : public ParamCommand |
---|
| 190 | { |
---|
| 191 | public: |
---|
| 192 | String doGet( const void* target ) const; |
---|
| 193 | void doSet( void* target, const String& val ); |
---|
| 194 | }; |
---|
| 195 | |
---|
| 196 | protected: |
---|
| 197 | /// The text alignment |
---|
| 198 | Alignment mAlignment; |
---|
| 199 | |
---|
| 200 | /// Flag indicating if this panel should be visual or just group things |
---|
| 201 | bool mTransparent; |
---|
| 202 | |
---|
| 203 | /// Render operation |
---|
| 204 | RenderOperation mRenderOp; |
---|
| 205 | |
---|
| 206 | /// Method for setting up base parameters for this class |
---|
| 207 | void addBaseParameters(void); |
---|
| 208 | |
---|
| 209 | static String msTypeName; |
---|
| 210 | |
---|
| 211 | // Command objects |
---|
| 212 | static CmdCharHeight msCmdCharHeight; |
---|
| 213 | static CmdSpaceWidth msCmdSpaceWidth; |
---|
| 214 | static CmdFontName msCmdFontName; |
---|
| 215 | static CmdColour msCmdColour; |
---|
| 216 | static CmdColourTop msCmdColourTop; |
---|
| 217 | static CmdColourBottom msCmdColourBottom; |
---|
| 218 | static CmdAlignment msCmdAlignment; |
---|
| 219 | |
---|
| 220 | |
---|
| 221 | FontPtr mpFont; |
---|
| 222 | Real mCharHeight; |
---|
| 223 | ushort mPixelCharHeight; |
---|
| 224 | Real mSpaceWidth; |
---|
| 225 | ushort mPixelSpaceWidth; |
---|
| 226 | size_t mAllocSize; |
---|
| 227 | Real mViewportAspectCoef; |
---|
| 228 | |
---|
| 229 | /// Colours to use for the vertices |
---|
| 230 | ColourValue mColourBottom; |
---|
| 231 | ColourValue mColourTop; |
---|
| 232 | bool mColoursChanged; |
---|
| 233 | |
---|
| 234 | |
---|
| 235 | /// Internal method to allocate memory, only reallocates when necessary |
---|
| 236 | void checkMemoryAllocation( size_t numChars ); |
---|
| 237 | /// Inherited function |
---|
| 238 | virtual void updatePositionGeometry(); |
---|
| 239 | /// Inherited function |
---|
| 240 | virtual void updateTextureGeometry(); |
---|
| 241 | /// Updates vertex colours |
---|
| 242 | virtual void updateColours(void); |
---|
| 243 | }; |
---|
| 244 | } |
---|
| 245 | |
---|
| 246 | #endif |
---|
| 247 | |
---|