1 | /************************************************************************
|
---|
2 | filename: CEGUIStaticText.h
|
---|
3 | created: 4/6/2004
|
---|
4 | author: Paul D Turner
|
---|
5 |
|
---|
6 | purpose: Defines interface for a static text widget
|
---|
7 | *************************************************************************/
|
---|
8 | /*************************************************************************
|
---|
9 | Crazy Eddie's GUI System (http://www.cegui.org.uk)
|
---|
10 | Copyright (C)2004 - 2005 Paul D Turner (paul@cegui.org.uk)
|
---|
11 |
|
---|
12 | This library is free software; you can redistribute it and/or
|
---|
13 | modify it under the terms of the GNU Lesser General Public
|
---|
14 | License as published by the Free Software Foundation; either
|
---|
15 | version 2.1 of the License, or (at your option) any later version.
|
---|
16 |
|
---|
17 | This library is distributed in the hope that it will be useful,
|
---|
18 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | Lesser General Public License for more details.
|
---|
21 |
|
---|
22 | You should have received a copy of the GNU Lesser General Public
|
---|
23 | License along with this library; if not, write to the Free Software
|
---|
24 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
---|
25 | *************************************************************************/
|
---|
26 | #ifndef _CEGUIStaticText_h_
|
---|
27 | #define _CEGUIStaticText_h_
|
---|
28 |
|
---|
29 | #include "elements/CEGUIStatic.h"
|
---|
30 | #include "elements/CEGUIStaticTextProperties.h"
|
---|
31 |
|
---|
32 |
|
---|
33 | #if defined(_MSC_VER)
|
---|
34 | # pragma warning(push)
|
---|
35 | # pragma warning(disable : 4251)
|
---|
36 | #endif
|
---|
37 |
|
---|
38 |
|
---|
39 | // Start of CEGUI namespace section
|
---|
40 | namespace CEGUI
|
---|
41 | {
|
---|
42 | /*!
|
---|
43 | \brief
|
---|
44 | Base class for a static text widget.
|
---|
45 | */
|
---|
46 | class CEGUIEXPORT StaticText : public Static
|
---|
47 | {
|
---|
48 | public:
|
---|
49 | static const String EventNamespace; //!< Namespace for global events
|
---|
50 |
|
---|
51 |
|
---|
52 | /*************************************************************************
|
---|
53 | Formatting Enumerations
|
---|
54 | *************************************************************************/
|
---|
55 | /*!
|
---|
56 | \brief
|
---|
57 | Enumeration of horizontal formatting options for static text widgets
|
---|
58 | */
|
---|
59 | enum HorzFormatting
|
---|
60 | {
|
---|
61 | LeftAligned, //!< Text is output as a single line of text with the first character aligned with the left edge of the widget.
|
---|
62 | RightAligned, //!< Text is output as a single line of text with the last character aligned with the right edge of the widget.
|
---|
63 | HorzCentred, //!< Text is output as a single line of text horizontally centred within the widget.
|
---|
64 | HorzJustified, //!< Text is output as a single line of text with the first and last characters aligned with the edges of the widget.
|
---|
65 | WordWrapLeftAligned, //!< Text is output as multiple word-wrapped lines of text with the first character of each line aligned with the left edge of the widget.
|
---|
66 | WordWrapRightAligned, //!< Text is output as multiple word-wrapped lines of text with the last character of each line aligned with the right edge of the widget.
|
---|
67 | WordWrapCentred, //!< Text is output as multiple word-wrapped lines of text with each line horizontally centered within the widget.
|
---|
68 | WordWrapJustified //!< Text is output as multiple word-wrapped lines of text with the first and last characters of each line aligned with the edges of the widget.
|
---|
69 | };
|
---|
70 |
|
---|
71 |
|
---|
72 | /*!
|
---|
73 | \brief
|
---|
74 | Enumeration of vertical formatting options for a static text widgets
|
---|
75 | */
|
---|
76 | enum VertFormatting
|
---|
77 | {
|
---|
78 | TopAligned, //!< Text is output with the top of first line of text aligned with the top edge of the widget.
|
---|
79 | BottomAligned, //!< Text is output with the bottom of last line of text aligned with the bottom edge of the widget.
|
---|
80 | VertCentred //!< Text is output vertically centred within the widget.
|
---|
81 | };
|
---|
82 |
|
---|
83 |
|
---|
84 | /*************************************************************************
|
---|
85 | Construction and Destruction
|
---|
86 | *************************************************************************/
|
---|
87 | /*!
|
---|
88 | \brief
|
---|
89 | Constructor for static text widgets.
|
---|
90 | */
|
---|
91 | StaticText(const String& type, const String& name);
|
---|
92 |
|
---|
93 |
|
---|
94 | /*!
|
---|
95 | \brief
|
---|
96 | Destructor for static text widgets.
|
---|
97 | */
|
---|
98 | virtual ~StaticText(void);
|
---|
99 |
|
---|
100 |
|
---|
101 | /*************************************************************************
|
---|
102 | Accessors
|
---|
103 | *************************************************************************/
|
---|
104 | /*!
|
---|
105 | \brief
|
---|
106 | Return a ColourRect object containing the colours used when rendering this widget.
|
---|
107 |
|
---|
108 | \return
|
---|
109 | ColourRect object initialised with the colours used when rendering the text for this widget.
|
---|
110 | */
|
---|
111 | ColourRect getTextColours(void) const {return d_textCols;}
|
---|
112 |
|
---|
113 |
|
---|
114 | /*!
|
---|
115 | \brief
|
---|
116 | Return the current horizontal formatting option set for this widget.
|
---|
117 |
|
---|
118 | \return
|
---|
119 | One of the StaticText::HorzFormatting enumerated values specifying the horizontal formatting currently set.
|
---|
120 | */
|
---|
121 | HorzFormatting getHorizontalFormatting(void) const {return d_horzFormatting;}
|
---|
122 |
|
---|
123 |
|
---|
124 | /*!
|
---|
125 | \brief
|
---|
126 | Return the current vertical formatting option set for this widget.
|
---|
127 |
|
---|
128 | \return
|
---|
129 | One of the StaticText::VertFormatting enumerated values specifying the vertical formatting currently set.
|
---|
130 | */
|
---|
131 | VertFormatting getVerticalFormatting(void) const {return d_vertFormatting;}
|
---|
132 |
|
---|
133 |
|
---|
134 | /*!
|
---|
135 | \brief
|
---|
136 | Return whether the vertical scroll bar is set to be shown if needed.
|
---|
137 |
|
---|
138 | \return
|
---|
139 | - true if the vertical scroll bar will be shown if needed (top or bottom aligned formatting only).
|
---|
140 | - false if the vertical scroll bar will never be shown (default behaviour).
|
---|
141 | */
|
---|
142 | bool isVerticalScrollbarEnabled(void) const;
|
---|
143 |
|
---|
144 |
|
---|
145 | /*!
|
---|
146 | \brief
|
---|
147 | Return whether the horizontal scroll bar is set to be shown if needed.
|
---|
148 |
|
---|
149 | \return
|
---|
150 | - true if the horizontal scroll bar will be shown if needed (non-word wrapped, left or right aligned formatting only).
|
---|
151 | - false if the horizontal scroll bar will never be shown (default behaviour).
|
---|
152 | */
|
---|
153 | bool isHorizontalScrollbarEnabled(void) const;
|
---|
154 |
|
---|
155 |
|
---|
156 | // overridden (again) so scroll bars are not clipped when they are active
|
---|
157 | virtual Rect getUnclippedInnerRect(void) const;
|
---|
158 |
|
---|
159 |
|
---|
160 | /*************************************************************************
|
---|
161 | Manipulators
|
---|
162 | *************************************************************************/
|
---|
163 | /*!
|
---|
164 | \brief
|
---|
165 | Initialise the Window based object ready for use.
|
---|
166 |
|
---|
167 | \note
|
---|
168 | This must be called for every window created. Normally this is handled automatically by the WindowFactory for each Window type.
|
---|
169 |
|
---|
170 | \return
|
---|
171 | Nothing
|
---|
172 | */
|
---|
173 | virtual void initialise(void);
|
---|
174 |
|
---|
175 |
|
---|
176 | /*!
|
---|
177 | \brief
|
---|
178 | Sets the colours to be applied when rendering the text.
|
---|
179 |
|
---|
180 | \param colours
|
---|
181 | ColourRect object describing the colours to be used for each text glyph rendered.
|
---|
182 |
|
---|
183 | \return
|
---|
184 | Nothing.
|
---|
185 | */
|
---|
186 | void setTextColours(const ColourRect& colours);
|
---|
187 |
|
---|
188 |
|
---|
189 | /*!
|
---|
190 | \brief
|
---|
191 | Sets the colours to be applied when rendering the text.
|
---|
192 |
|
---|
193 | \param top_left_colour
|
---|
194 | Colour to be applied to the top-left corner of each text glyph rendered.
|
---|
195 |
|
---|
196 | \param top_right_colour
|
---|
197 | Colour to be applied to the top-right corner of each text glyph rendered.
|
---|
198 |
|
---|
199 | \param bottom_left_colour
|
---|
200 | Colour to be applied to the bottom-left corner of each text glyph rendered.
|
---|
201 |
|
---|
202 | \param bottom_right_colour
|
---|
203 | Colour to be applied to the bottom-right corner of each text glyph rendered.
|
---|
204 |
|
---|
205 | \return
|
---|
206 | Nothing.
|
---|
207 | */
|
---|
208 | void setTextColours(const colour& top_left_colour, const colour& top_right_colour, const colour& bottom_left_colour, const colour& bottom_right_colour);
|
---|
209 |
|
---|
210 |
|
---|
211 | /*!
|
---|
212 | \brief
|
---|
213 | Sets the colour to be applied when rendering the text.
|
---|
214 |
|
---|
215 | \param col
|
---|
216 | colour value to be used when rendering.
|
---|
217 |
|
---|
218 | \return
|
---|
219 | Nothing.
|
---|
220 | */
|
---|
221 | void setTextColours(const colour& col) {setTextColours(col, col, col, col);}
|
---|
222 |
|
---|
223 |
|
---|
224 | /*!
|
---|
225 | \brief
|
---|
226 | Set the formatting required for the text.
|
---|
227 |
|
---|
228 | \param h_fmt
|
---|
229 | One of the HorzFormatting enumerated values specifying the formatting required.
|
---|
230 |
|
---|
231 | \param v_fmt
|
---|
232 | One of the VertFormatting enumerated values specifying the formatting required.
|
---|
233 |
|
---|
234 | \return
|
---|
235 | Nothing
|
---|
236 | */
|
---|
237 | void setFormatting(HorzFormatting h_fmt, VertFormatting v_fmt);
|
---|
238 |
|
---|
239 |
|
---|
240 | /*!
|
---|
241 | \brief
|
---|
242 | Set the formatting required for the text.
|
---|
243 |
|
---|
244 | \param v_fmt
|
---|
245 | One of the VertFormatting enumerated values specifying the formatting required.
|
---|
246 |
|
---|
247 | \return
|
---|
248 | Nothing
|
---|
249 | */
|
---|
250 | void setVerticalFormatting(VertFormatting v_fmt);
|
---|
251 |
|
---|
252 |
|
---|
253 | /*!
|
---|
254 | \brief
|
---|
255 | Set the formatting required for the text.
|
---|
256 |
|
---|
257 | \param h_fmt
|
---|
258 | One of the HorzFormatting enumerated values specifying the formatting required.
|
---|
259 |
|
---|
260 | \return
|
---|
261 | Nothing
|
---|
262 | */
|
---|
263 | void setHorizontalFormatting(HorzFormatting h_fmt);
|
---|
264 |
|
---|
265 |
|
---|
266 | /*!
|
---|
267 | \brief
|
---|
268 | Set whether the vertical scroll bar will be shown if needed.
|
---|
269 |
|
---|
270 | \param setting
|
---|
271 | - true if the vertical scroll bar should be shown if needed (top or bottom aligned formatting only).
|
---|
272 | - false if the vertical scroll bar should never be shown (default behaviour).
|
---|
273 | */
|
---|
274 | void setVerticalScrollbarEnabled(bool setting);
|
---|
275 |
|
---|
276 |
|
---|
277 | /*!
|
---|
278 | \brief
|
---|
279 | Set whether the horizontal scroll bar will be shown if needed.
|
---|
280 |
|
---|
281 | \param setting
|
---|
282 | - true if the horizontal scroll bar should be shown if needed (non-word wrapped, left or right aligned formatting only).
|
---|
283 | - false if the horizontal scroll bar should never be shown (default behaviour).
|
---|
284 | */
|
---|
285 | void setHorizontalScrollbarEnabled(bool setting);
|
---|
286 |
|
---|
287 |
|
---|
288 | protected:
|
---|
289 | /*************************************************************************
|
---|
290 | Overridden from base class
|
---|
291 | *************************************************************************/
|
---|
292 | /*!
|
---|
293 | \brief
|
---|
294 | Perform the actual rendering for this Window.
|
---|
295 |
|
---|
296 | \param z
|
---|
297 | float value specifying the base Z co-ordinate that should be used when rendering
|
---|
298 |
|
---|
299 | \return
|
---|
300 | Nothing
|
---|
301 | */
|
---|
302 | virtual void drawSelf(float z);
|
---|
303 |
|
---|
304 |
|
---|
305 | /*************************************************************************
|
---|
306 | Overridden events
|
---|
307 | *************************************************************************/
|
---|
308 | virtual void onTextChanged(WindowEventArgs& e);
|
---|
309 | virtual void onSized(WindowEventArgs& e);
|
---|
310 | virtual void onFontChanged(WindowEventArgs& e);
|
---|
311 | virtual void onMouseWheel(MouseEventArgs& e);
|
---|
312 |
|
---|
313 |
|
---|
314 | /*************************************************************************
|
---|
315 | Implementation methods
|
---|
316 | *************************************************************************/
|
---|
317 | /*!
|
---|
318 | \brief
|
---|
319 | Return a Rect object describing, in un-clipped pixels, the window relative area
|
---|
320 | that the text should be rendered in to.
|
---|
321 |
|
---|
322 | \return
|
---|
323 | Rect object describing the area of the Window to be used for rendering text.
|
---|
324 | */
|
---|
325 | virtual Rect getTextRenderArea(void) const;
|
---|
326 |
|
---|
327 |
|
---|
328 | /*!
|
---|
329 | \brief
|
---|
330 | Setup size and position for the component widgets attached to this StaticText
|
---|
331 |
|
---|
332 | \return
|
---|
333 | Nothing.
|
---|
334 | */
|
---|
335 | virtual void layoutComponentWidgets();
|
---|
336 |
|
---|
337 |
|
---|
338 | /*!
|
---|
339 | \brief
|
---|
340 | display required integrated scroll bars according to current state of the edit box and update their values.
|
---|
341 | */
|
---|
342 | void configureScrollbars(void);
|
---|
343 |
|
---|
344 |
|
---|
345 | /*!
|
---|
346 | \brief
|
---|
347 | Return whether this window was inherited from the given class name at some point in the inheritance heirarchy.
|
---|
348 |
|
---|
349 | \param class_name
|
---|
350 | The class name that is to be checked.
|
---|
351 |
|
---|
352 | \return
|
---|
353 | true if this window was inherited from \a class_name. false if not.
|
---|
354 | */
|
---|
355 | virtual bool testClassName_impl(const String& class_name) const
|
---|
356 | {
|
---|
357 | if (class_name==(const utf8*)"StaticText") return true;
|
---|
358 | return Static::testClassName_impl(class_name);
|
---|
359 | }
|
---|
360 |
|
---|
361 |
|
---|
362 | /*************************************************************************
|
---|
363 | Implementation Methods (abstract)
|
---|
364 | *************************************************************************/
|
---|
365 | /*!
|
---|
366 | \brief
|
---|
367 | create and return a pointer to a Scrollbar widget for use as vertical scroll bar
|
---|
368 |
|
---|
369 | \return
|
---|
370 | Pointer to a Scrollbar to be used for scrolling vertically.
|
---|
371 | */
|
---|
372 | virtual Scrollbar* createVertScrollbar(void) const = 0;
|
---|
373 |
|
---|
374 |
|
---|
375 | /*!
|
---|
376 | \brief
|
---|
377 | create and return a pointer to a Scrollbar widget for use as horizontal scroll bar
|
---|
378 |
|
---|
379 | \return
|
---|
380 | Pointer to a Scrollbar to be used for scrolling horizontally.
|
---|
381 | */
|
---|
382 | virtual Scrollbar* createHorzScrollbar(void) const = 0;
|
---|
383 |
|
---|
384 |
|
---|
385 | /*************************************************************************
|
---|
386 | Event subscribers
|
---|
387 | *************************************************************************/
|
---|
388 | bool handleScrollbarChange(const EventArgs& e);
|
---|
389 |
|
---|
390 |
|
---|
391 | /*************************************************************************
|
---|
392 | Implementation Data
|
---|
393 | *************************************************************************/
|
---|
394 | HorzFormatting d_horzFormatting; //!< Horizontal formatting to be applied to the text.
|
---|
395 | VertFormatting d_vertFormatting; //!< Vertical formatting to be applied to the text.
|
---|
396 | ColourRect d_textCols; //!< Colours used when rendering the text.
|
---|
397 | Scrollbar* d_vertScrollbar; //!< Widget used as vertical scrollbar;
|
---|
398 | Scrollbar* d_horzScrollbar; //!< Widget used as horizontal scrollbar;
|
---|
399 | bool d_enableVertScrollbar; //!< true if vertical scroll bar is enabled.
|
---|
400 | bool d_enableHorzScrollbar; //!< true if horizontal scroll bar is enabled.
|
---|
401 |
|
---|
402 | private:
|
---|
403 | /*************************************************************************
|
---|
404 | Static Properties for this class
|
---|
405 | *************************************************************************/
|
---|
406 | static StaticTextProperties::TextColours d_textColoursProperty;
|
---|
407 | static StaticTextProperties::VertFormatting d_vertFormattingProperty;
|
---|
408 | static StaticTextProperties::HorzFormatting d_horzFormattingProperty;
|
---|
409 | static StaticTextProperties::VertScrollbar d_vertScrollbarProperty;
|
---|
410 | static StaticTextProperties::HorzScrollbar d_horzScrollbarProperty;
|
---|
411 |
|
---|
412 |
|
---|
413 | /*************************************************************************
|
---|
414 | Private methods
|
---|
415 | *************************************************************************/
|
---|
416 | void addStaticTextProperties(void);
|
---|
417 | };
|
---|
418 |
|
---|
419 | } // End of CEGUI namespace section
|
---|
420 |
|
---|
421 | #if defined(_MSC_VER)
|
---|
422 | # pragma warning(pop)
|
---|
423 | #endif
|
---|
424 |
|
---|
425 | #endif // end of guard _CEGUIStaticText_h_
|
---|