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-2013 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 "OgreFont.h" |
---|
32 | |
---|
33 | namespace Ogre |
---|
34 | { |
---|
35 | /** \addtogroup Core |
---|
36 | * @{ |
---|
37 | */ |
---|
38 | /** \addtogroup Overlays |
---|
39 | * @{ |
---|
40 | */ |
---|
41 | /** This class implements an overlay element which contains simple unformatted text. |
---|
42 | */ |
---|
43 | class _OgreOverlayExport TextAreaOverlayElement : public OverlayElement |
---|
44 | { |
---|
45 | public: |
---|
46 | enum Alignment |
---|
47 | { |
---|
48 | Left, |
---|
49 | Right, |
---|
50 | Center |
---|
51 | }; |
---|
52 | |
---|
53 | public: |
---|
54 | /** Constructor. */ |
---|
55 | TextAreaOverlayElement(const String& name); |
---|
56 | virtual ~TextAreaOverlayElement(); |
---|
57 | |
---|
58 | virtual void initialise(void); |
---|
59 | virtual void setCaption(const DisplayString& text); |
---|
60 | |
---|
61 | void setCharHeight( Real height ); |
---|
62 | Real getCharHeight() const; |
---|
63 | |
---|
64 | void setSpaceWidth( Real width ); |
---|
65 | Real getSpaceWidth() const; |
---|
66 | |
---|
67 | void setFontName( const String& font ); |
---|
68 | const String& getFontName() const; |
---|
69 | |
---|
70 | /** See OverlayElement. */ |
---|
71 | virtual const String& getTypeName(void) const; |
---|
72 | /** See Renderable. */ |
---|
73 | const MaterialPtr& getMaterial(void) const; |
---|
74 | /** See Renderable. */ |
---|
75 | void getRenderOperation(RenderOperation& op); |
---|
76 | /** Overridden from OverlayElement */ |
---|
77 | void setMaterialName(const String& matName); |
---|
78 | |
---|
79 | /** Sets the colour of the text. |
---|
80 | @remarks |
---|
81 | This method establishes a constant colour for |
---|
82 | the entire text. Also see setColourBottom and |
---|
83 | setColourTop which allow you to set a colour gradient. |
---|
84 | */ |
---|
85 | void setColour(const ColourValue& col); |
---|
86 | |
---|
87 | /** Gets the colour of the text. */ |
---|
88 | const ColourValue& getColour(void) const; |
---|
89 | /** Sets the colour of the bottom 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 setColourBottom(const ColourValue& col); |
---|
96 | /** Gets the colour of the bottom of the letters. */ |
---|
97 | const ColourValue& getColourBottom(void) const; |
---|
98 | /** Sets the colour of the top of the letters. |
---|
99 | @remarks |
---|
100 | By setting a separate top and bottom colour, you |
---|
101 | can create a text area which has a graduated colour |
---|
102 | effect to it. |
---|
103 | */ |
---|
104 | void setColourTop(const ColourValue& col); |
---|
105 | /** Gets the colour of the top of the letters. */ |
---|
106 | const ColourValue& getColourTop(void) const; |
---|
107 | |
---|
108 | inline void setAlignment( Alignment a ) |
---|
109 | { |
---|
110 | mAlignment = a; |
---|
111 | mGeomPositionsOutOfDate = true; |
---|
112 | } |
---|
113 | inline Alignment getAlignment() const |
---|
114 | { |
---|
115 | return mAlignment; |
---|
116 | } |
---|
117 | |
---|
118 | /** Overridden from OverlayElement */ |
---|
119 | void setMetricsMode(GuiMetricsMode gmm); |
---|
120 | |
---|
121 | /** Overridden from OverlayElement */ |
---|
122 | void _update(void); |
---|
123 | |
---|
124 | //----------------------------------------------------------------------------------------- |
---|
125 | /** Command object for setting the caption. |
---|
126 | @see ParamCommand |
---|
127 | */ |
---|
128 | class _OgrePrivate CmdCaption : public ParamCommand |
---|
129 | { |
---|
130 | public: |
---|
131 | String doGet( const void* target ) const; |
---|
132 | void doSet( void* target, const String& val ); |
---|
133 | }; |
---|
134 | //----------------------------------------------------------------------------------------- |
---|
135 | /** Command object for setting the char height. |
---|
136 | @see ParamCommand |
---|
137 | */ |
---|
138 | class _OgrePrivate CmdCharHeight : 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 width of a space. |
---|
146 | @see ParamCommand |
---|
147 | */ |
---|
148 | class _OgrePrivate CmdSpaceWidth : 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 caption. |
---|
156 | @see ParamCommand |
---|
157 | */ |
---|
158 | class _OgrePrivate CmdFontName : 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 top colour. |
---|
166 | @see ParamCommand |
---|
167 | */ |
---|
168 | class _OgrePrivate CmdColourTop : 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 bottom colour. |
---|
176 | @see ParamCommand |
---|
177 | */ |
---|
178 | class _OgrePrivate CmdColourBottom : 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 constant colour. |
---|
186 | @see ParamCommand |
---|
187 | */ |
---|
188 | class _OgrePrivate CmdColour : 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 alignment. |
---|
196 | @see ParamCommand |
---|
197 | */ |
---|
198 | class _OgrePrivate CmdAlignment : public ParamCommand |
---|
199 | { |
---|
200 | public: |
---|
201 | String doGet( const void* target ) const; |
---|
202 | void doSet( void* target, const String& val ); |
---|
203 | }; |
---|
204 | |
---|
205 | protected: |
---|
206 | /// The text alignment |
---|
207 | Alignment mAlignment; |
---|
208 | |
---|
209 | /// Flag indicating if this panel should be visual or just group things |
---|
210 | bool mTransparent; |
---|
211 | |
---|
212 | /// Render operation |
---|
213 | RenderOperation mRenderOp; |
---|
214 | |
---|
215 | /// Method for setting up base parameters for this class |
---|
216 | void addBaseParameters(void); |
---|
217 | |
---|
218 | static String msTypeName; |
---|
219 | |
---|
220 | // Command objects |
---|
221 | static CmdCharHeight msCmdCharHeight; |
---|
222 | static CmdSpaceWidth msCmdSpaceWidth; |
---|
223 | static CmdFontName msCmdFontName; |
---|
224 | static CmdColour msCmdColour; |
---|
225 | static CmdColourTop msCmdColourTop; |
---|
226 | static CmdColourBottom msCmdColourBottom; |
---|
227 | static CmdAlignment msCmdAlignment; |
---|
228 | |
---|
229 | |
---|
230 | FontPtr mFont; |
---|
231 | Real mCharHeight; |
---|
232 | ushort mPixelCharHeight; |
---|
233 | Real mSpaceWidth; |
---|
234 | ushort mPixelSpaceWidth; |
---|
235 | size_t mAllocSize; |
---|
236 | Real mViewportAspectCoef; |
---|
237 | |
---|
238 | /// Colours to use for the vertices |
---|
239 | ColourValue mColourBottom; |
---|
240 | ColourValue mColourTop; |
---|
241 | bool mColoursChanged; |
---|
242 | |
---|
243 | |
---|
244 | /// Internal method to allocate memory, only reallocates when necessary |
---|
245 | void checkMemoryAllocation( size_t numChars ); |
---|
246 | /// Inherited function |
---|
247 | virtual void updatePositionGeometry(); |
---|
248 | /// Inherited function |
---|
249 | virtual void updateTextureGeometry(); |
---|
250 | /// Updates vertex colours |
---|
251 | virtual void updateColours(void); |
---|
252 | }; |
---|
253 | /** @} */ |
---|
254 | /** @} */ |
---|
255 | } |
---|
256 | |
---|
257 | #endif |
---|
258 | |
---|