| GL Studio C++ Runtime API

gls_text.h
Go to the documentation of this file.
1/*! \file
2 \brief The disti::GlsText class.
3
4 \par Copyright Information
5
6 Copyright (c) 2017 by The DiSTI Corporation.<br>
7 11301 Corporate Blvd; Suite 100<br>
8 Orlando, Florida 32817<br>
9 USA<br>
10 <br>
11 All rights reserved.<br>
12
13 This Software contains proprietary trade secrets of DiSTI and may not be
14 reproduced, in whole or part, in any form, or by any means of electronic,
15 mechanical, or otherwise, without the written permission of DiSTI. Said
16 permission may be derived through the purchase of applicable DiSTI product
17 licenses which detail the distribution rights of this content and any
18 Derivative Works based on this or other copyrighted DiSTI Software.
19
20 NO WARRANTY. THE SOFTWARE IS PROVIDED "AS-IS," WITHOUT WARRANTY OF ANY KIND,
21 AND ANY USE OF THIS SOFTWARE PRODUCT IS AT YOUR OWN RISK. TO THE MAXIMUM EXTENT
22 PERMITTED BY APPLICABLE LAW, DISTI AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES
23 AND CONDITIONS, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
24 IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY AND/OR FITNESS FOR A
25 PARTICULAR PURPOSE, TITLE, AND NON-INFRINGEMENT, WITH REGARD TO THE SOFTWARE.
26
27 LIMITATION OF LIABILITY. TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW,
28 IN NO EVENT SHALL DISTI OR ITS SUPPLIERS BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
29 INDIRECT, OR CONSEQUENTIAL DAMAGES WHATSOEVER (INCLUDING, WITHOUT LIMITATION,
30 DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS
31 INFORMATION, OR ANY OTHER PECUNIARY LOSS) ARISING OUT OF THE USE OF OR
32 INABILITY TO USE THE SOFTWARE, EVEN IF DISTI HAS BEEN ADVISED OF THE POSSIBILITY
33 OF SUCH DAMAGES. DISTI'S ENTIRE LIABILITY AND YOUR EXCLUSIVE REMEDY SHALL NOT
34 EXCEED FIVE DOLLARS (US$5.00).
35
36 The aforementioned terms and restrictions are governed by the laws of the
37 State of Florida and the United States of America.
38
39*/
40
41#ifndef _GLS_TEXT_H
42#define _GLS_TEXT_H
43
44#include "unhide_globals.h"
45
46#include "gls_gl.h"
47#include <string>
48
49#include "glpolygon.h"
50#include "gls_color.h"
51#include "gls_cpp_lang_support.h"
52#include "gls_font_base.h"
53#include "gls_font_man.h"
54#include "gls_metadata_attributes.h"
55#include "gls_runtime_font_base.h"
56#include "gls_unicode_font_base.h"
57#include "scoped_ptr.h"
58
59//===========================================================================
60// MACROS
61//===========================================================================
62/// Macro to refresh geometry in ES, that does nothing on Desktop.
63#ifdef GLES
64# define GLS_TEXT_SET_GEOMETRY_REFRESH GeometryRefresh();
65#else
66# define GLS_TEXT_SET_GEOMETRY_REFRESH
67#endif
68
69/// Macro to set a given attribute on all characters with the given value.
70#define SET_ALL_CHARS( attribute, value ) \
71 { \
72 for( CharAttrCont_t::iterator i = _chars.begin(); i != _chars.end(); ++i ) \
73 { \
74 i->attribute = value; \
75 } \
76 GLS_TEXT_SET_GEOMETRY_REFRESH \
77 }
78
79//===========================================================================
80// BEGIN NAMESPACE
81//===========================================================================
82 namespace disti
83{
84#ifdef GLES
85// Forward Declaration
86 class GlsGloFileAttribute;
87#endif
88
89// Forward Declaration
90 class RuntimeGlyphGenerationText;
91
92/// Initializers for text
93 typedef enum
94{
95 GLS_TEXT_BORDER = GLS_LAST_INITIALIZER + 1,
96 GLS_TEXT_CELL_HEIGHT,
97 GLS_TEXT_CELL_WIDTH,
98 GLS_TEXT_CONSTRAIN_CELL_RATIO,
99 GLS_TEXT_CONTROL_CELL_SIZE,
100 GLS_TEXT_FONT,
101 GLS_TEXT_HALO,
102 GLS_TEXT_LINESPACING,
103 GLS_TEXT_LOCK_CELL_SIZE,
104 GLS_TEXT_JUSTIFY,
105 GLS_TEXT_SHADOW,
106 GLS_TEXT_STRING,
107 GLS_TEXT_UPPERCASE,
108 GLS_TEXT_WRAP,
109 GLS_LAST_TEXT_INITIALIZER = GLS_TEXT_WRAP
110} GlsTextInitializers_t;
111
112/** helper method for safely getting a runtime font base from a font base (if possible)
113 * \param font font in question
114 * \return runtime font else NULL
115 */
116 inline GlsRuntimeFontBase* GetGlsRuntimeFontBase( const GlsFontBase* font )
117{
118 GlsRuntimeFontBase* rtf = NULL;
119 if( font )
120 {
121 // determine if font can be safely cast to a runtime font by inspecting the family name
122 if( 0 == font->Family().find( GLS_RUNTIME_FONT_NAME_PREFIX ) )
123 {
124 rtf = static_cast<GlsRuntimeFontBase*>( (GlsFontBase*)font );
125 }
126 }
127 return ( rtf );
128}
129
130/** helper method for safely getting a unicode font base from a font base (if possible)
131 * \param font font in question
132 * \return unicode font else NULL
133 */
134 inline const GlsUnicodeFontBase* GetGlsUnicodeFontBase( const GlsFontBase* font )
135{
136 const GlsUnicodeFontBase* unf = NULL;
137 if( font )
138 {
139 // determine if font can be safely cast to a unicode font by inspecting the family name
140 if( 0 == font->Family().find( GLS_UNICODE_FONT_NAME_PREFIX ) )
141 {
142 unf = static_cast<const GlsUnicodeFontBase*>( font );
143 }
144 }
145 return ( unf );
146}
147
148//===========================================================================
149/**
150* The GlsText class provides a base class for all GLStudio text components.
151*/
152//===========================================================================
153 class GlsText : public GLPolygon
154{
155 public:
156 DISTI_DEPRECATED( "This identifier is forbidden by the C++ standard. Use BaseClass instead." )
157 typedef GLPolygon _BaseClass; ///< Deprecated typedef for the base class.
158 typedef GLPolygon BaseClass; ///< Typedef for the base class.
159
160 typedef GlsFontBase::Char_t Char_t; ///< Typedef shorthand for GlsFontBase::Char_t.
161
162 static GLS_EXPORT const Char_t EOL; ///< Carriage return (end of line) character
163
164 enum
165 {
166 NUM_VERTICES = 4
167 };
168
169 /// Different text justifications.
170 enum Justify_t
171 {
172 LEFT,
173 CENTER,
174 RIGHT
175 };
176
177 /// Attributes for each character position in the grid.
178 struct CharAttr_t
179 {
180 Char_t code; ///< The code point for this character.
181 float baselineShift; ///< The base line shift in pixels.
182 GlsColor bgColor; ///< The background color.
183 GlsColor fgColor; ///< The foreground (glyph itself) color.
184 bool fauxBold; ///< Whether or not faux bold is enabled.
185 bool inverse; ///< Whether or not inverse is enabled.
186 float scale; ///< Scaled size of this character.
187 float spacing; ///< Scale of spacing between this character.
188 bool strikeThru; ///< Whether or not strike through is enabled.
189 bool underline; ///< Whether or not underline is enabled.
190
191 GLS_EXPORT CharAttr_t();
192
193 /// Copy constructor
194 /// \param r The object to copy from.
195 GLS_EXPORT CharAttr_t( const CharAttr_t& r );
196
197 /// Reset values to their defaults.
198 GLS_EXPORT void Clear();
199
200 /// Assignment operator
201 /// \param r The object to copy from.
202 /// \return The resulting object (this).
203 GLS_EXPORT CharAttr_t& operator=( const CharAttr_t& r );
204 };
205
206 /** Class Constructor. */
207 GLS_EXPORT GlsText();
208
209 /// Copy constructor
210 /// \param that The object to copy from.
211 /// \param generateNames Whether or not to generate an instance name for this object.
212 GLS_EXPORT GlsText( const GlsText& that, const bool generateNames );
213
214 /** Class Constructor. */
215 GLS_EXPORT virtual ~GlsText();
216
217 virtual GLS_EXPORT void SetAvailableAttributes( unsigned int value ) DISTI_METHOD_OVERRIDE;
218
219 /** Sets the baseline shift for all characters.
220 * \param baselineShift multiplier used to shift the baseline. This will
221 * be multiplied by the character height to
222 * determine how much to shift. A value of 0 does
223 * not shift at all, a value of 1 will shift up
224 * by the height of 1 character.
225 */
226 GLS_EXPORT void Baseline( const float& baselineShift );
227
228 /// \return The baseline shift for the first character.
229 GLS_EXPORT float Baseline();
230
231 /** Sets the background color for all characters
232 * \param color The background color to set
233 */
234 GLS_EXPORT void BgColor( const GlsColor& color );
235
236 /// \return The background color for the first character.
237 GLS_EXPORT GlsColor BgColor();
238
239 /** Sets the spacing between the box outline and the text in logical units.
240 * \param units Border offset value in logical units
241 */
242 GLS_EXPORT void Border( const float& units );
243
244 /// \return The spacing between the box outline and the text in logical units.
245 float Border() const
246 {
247 return _border;
248 }
249
250 /** Sets the height of a character cell of the grid in logical units
251 * when stretch to fit mode is in effect. When stretch to fit mode
252 * is not in effect, this call will not affect the grid since the
253 * font determines the cell size.
254 * \param height the new character cell height.
255 */
256 GLS_EXPORT void CellHeight( float height );
257
258 /** \return the height of a char cell of the grid in logical units.
259 */
260 float CellHeight() const
261 {
262 return _cellHeight;
263 }
264
265 /** Sets the width of a character cell of the grid in logical units
266 * when stretch to fit mode is in effect. When stretch to fit mode
267 * is not in effect, this call will not affect the grid since the
268 * font determines the cell size.
269 * \param width the new character cell width.
270 */
271 GLS_EXPORT void CellWidth( float width );
272
273 /** \return the width of a char cell of the grid in logical units. */
274 float CellWidth() const
275 {
276 return _cellWidth;
277 }
278
279 /** Sets the character code for all cell positions in the text grid
280 * \param code The Unicode character code to set
281 */
282 GLS_EXPORT void Char( Char_t code );
283
284 /** Accessor method used by metadata to read and write the character attributes
285 * for this object. Currently only allows you to load and save attributes for the
286 * entire object, not on a per character basis.
287 * \return The character attribute for the first character in the object and therefore
288 * for every character in the object
289 */
290 CharAttr_t CharAttribs() const
291 {
292 return _chars[ 0 ];
293 }
294
295 /// \return A particular cell's character attributes.
296 /// \param index The index whose attributes are to be returned.
297 CharAttr_t CharAttr( unsigned int index ) const
298 {
299 return _chars[ index < _chars.size() ? index : 0 ];
300 }
301
302 /** Sets the scale factor of all characters NOTE: This is the size of the character in its
303 * cell not the overall scale of the entire object
304 * \param newScale The new scale factor of the characters (0.0 < newScale <= 1.0)
305 */
306 GLS_EXPORT void CharScaling( const float& newScale );
307
308 /// \return The scale factor of the first character.
309 GLS_EXPORT float CharScaling();
310
311 /** Sets the horizontal character spacing for all characters (spacing
312 * from the start of one character to the start of the next character.
313 * 1.0 is the default spacing 2.0 would be twice the normal spacing
314 * \param horizontalSpacing The horizontalSpacing value
315 */
316 GLS_EXPORT void CharSpacing( const float& horizontalSpacing );
317
318 /// \return The horizontal character spacing for the first character.
319 GLS_EXPORT float CharSpacing();
320
321 /** Sets whether to constrain cell width and height proportions when
322 * in stretch to fit mode and changing the size of character cells.
323 * \param constrain true to constrain proportions.
324 */
325 GLS_EXPORT void ConstrainCellRatio( bool constrain );
326
327 /** \return whether to constrain cell width and height proportions when
328 * in stretch to fit mode and changing the size of character cells.
329 */
330 bool ConstrainCellRatio() const
331 {
332 return _constrainRatio;
333 }
334
335 /** Sets whether or not the character cell size will stretch to fit
336 * this object's bounding box or if it is based on its font and font.
337 * \param control True if stretch to fit will be enabled
338 */
339 GLS_EXPORT void ControlCellSize( bool control );
340
341 /** \return whether or not the character cell size will stretch to fit
342 * this object's bounding box or if it is based on its font and font
343 */
344 bool ControlCellSize() const
345 {
346 return _controlCellSize;
347 }
348
349 GLS_EXPORT virtual void CopyGeometry( DisplayObject* src ) DISTI_METHOD_OVERRIDE;
350 GLS_EXPORT virtual void CopyProperties( DisplayObject* src ) DISTI_METHOD_OVERRIDE;
351
352 /** Erase all characters. */
353 GLS_EXPORT void Erase();
354
355 /** Set the bold state on or off for all characters
356 * \param bold Bold state
357 */
358 GLS_EXPORT void FauxBold( const bool& bold );
359
360 /// \return The bold state on or off for the first character.
361 GLS_EXPORT bool FauxBold();
362
363 /** \return The font currently being used to render this text.
364 */
365 GlsFontBase* Font() const
366 {
367 return _font;
368 }
369
370 /** Set the font used to render this text.
371 * \param font Pointer to a font instance to set
372 */
373 GLS_EXPORT void Font( GlsFontBase* font );
374
375#ifndef GLES
376 virtual GLS_EXPORT InterfaceListType* GetCppInterfaceDescription( InterfaceListType* addToThisList = NULL ) DISTI_METHOD_OVERRIDE;
377 virtual GLS_EXPORT void GetCppInterfaceDescriptionFree( InterfaceListType* array ) DISTI_METHOD_OVERRIDE;
378#endif
379
380 /** Set the halo state to on or off for the text
381 * \param halo halo state
382 */
383 GLS_EXPORT void Halo( bool halo );
384
385 /// \return Whether or not the halo is visible.
386 bool Halo() const
387 {
388 return _halo;
389 }
390
391 /** Set the color of the halo around the text
392 * \param color halo color
393 */
394 GLS_EXPORT void HaloColor( const GlsColor& color );
395
396 /// \return The current halo color.
397 GlsColor HaloColor() const
398 {
399 return _haloColor;
400 }
401
402 /** Invalidates the font for this object. If the font is invalidated, this object will
403 * draw using the default font. This is used in the editor and should not need to
404 * be called by any user code at run-time.
405 */
406 GLS_EXPORT void InvalidateFont();
407
408 /** Set the inverse video state on or off for all characters
409 * \param inverse inverse video state
410 */
411 GLS_EXPORT void Inverse( const bool& inverse );
412
413 /// \return The inverse video state on or off for the first character.
414 GLS_EXPORT bool Inverse();
415
416 /** Set the justification mode for this text object
417 * \param justification The justification mode (LEFT, RIGHT, CENTER)
418 */
419 GLS_EXPORT void Justify( Justify_t justification );
420
421 /** \return the justification mode (LEFT, RIGHT, CENTER)*/
422 Justify_t Justify() const
423 {
424 return _justify;
425 }
426
427 /** Sets the linespacing for the text object. A line spacing of 1.0 indicates normal
428 * "single spaced" text. 2.0 would be double spaced, etc.
429 * \param spacing The new linespacing value
430 */
431 GLS_EXPORT void LineSpacing( float spacing );
432
433 /** \return the linespacing for the text object. */
434 float LineSpacing() const
435 {
436 return _lineSpacing;
437 }
438
439 /** Sets whether or not the cell size is locked while in stretch to fit
440 * mode. If locked, changing other attributes will not affect the
441 * cell size, but the box size instead. If not locked, changing
442 * certain attributes, eg. border, will affect the cell size.
443 * \param lock true to lock cell size, false otherwise
444 */
445 GLS_EXPORT void LockCellSize( bool lock );
446
447 /** \return the setting of lock cell size. */
448 bool LockCellSize() const
449 {
450 return _lockCellSize;
451 }
452
453#if !defined( GCC_2_95 )
454 /* Unhides base class implementation. */
455 using BaseClass::Rotate;
456#endif
457 virtual GLS_EXPORT void Rotate( const Vector& orig, float angle, const Vector& axis ) DISTI_METHOD_OVERRIDE;
458
459 virtual GLS_EXPORT void SetValue( int spec, va_list& args ) DISTI_METHOD_OVERRIDE;
460
461#ifdef GLES
462 /** Set a single attribute from the GLO file.
463 * \param data The attribute to set and its associated data.
464 */
465 virtual GLS_EXPORT void SetFromGloData( GlsGloFileAttribute& data ) DISTI_METHOD_OVERRIDE;
466#endif
467
468 /** Set the shadow state to on or off for the text
469 * \param shadow shadow state
470 */
471 GLS_EXPORT void Shadow( bool shadow );
472
473 /// \return Whether or not text shadow is visible.
474 bool Shadow() const
475 {
476 return _shadow;
477 }
478
479 /** Set the color of the shadow behind the text
480 * \param color shadow color
481 */
482 GLS_EXPORT void ShadowColor( const GlsColor& color );
483
484 /// \return The current shadow color.
485 GlsColor ShadowColor() const
486 {
487 return _shadowColor;
488 }
489
490 /** Set the distance of the shadow from the text. Distance represent a percentage of the character
491 * width. Negative values are up and to the left. Positive values are down and to the right. Note that the
492 * corresponding getter was removed because ShadowDistance is deprecated in favor of ShadowOffset.
493 * \param dist shadow distance
494 */
495 void ShadowDistance( const float& dist )
496 {
497 ShadowOffset( Vector( dist, -dist, 0.0f ) );
498 }
499
500 /** Set the Cartesian offset of the shadow from the text. Offset represent a percentage of the character
501 * width. Negative values are down and to the left. Positive values are up and to the right.
502 * Z component is ignored.
503 * \param offset shadow offset
504 */
505 GLS_EXPORT void ShadowOffset( const Vector& offset );
506
507 /// \return The current shadow offset.
508 Vector ShadowOffset()
509 {
510 return _shadowOffset;
511 }
512
513 /** Sets the strikethru state for all characters
514 * \param strike Whether or not set strikethru
515 */
516 GLS_EXPORT void StrikeThru( const bool& strike );
517
518 /// \return The strikethru state for the first character.
519 GLS_EXPORT bool StrikeThru();
520
521 /** Sets the Unicode string to be displayed for this object
522 * \param s STD Template Library String
523 */
524 virtual GLS_EXPORT void String( const std::string& s );
525
526 /** Sets the Unicode string to be displayed for this object
527 * \param s C Style string
528 */
529 virtual void String( const char* s )
530 {
531 String( std::string( s ) );
532 }
533
534 /** \return The string currently stored in this object.
535 * NOTE: This can contain extra characters not being displayed
536 * in the grid if the string size is greater than will
537 * fit within the grid.
538 */
539 std::string String() const
540 {
541 return _text;
542 }
543
544 /** Sets the foreground color for all characters in the text grid.
545 * \param color The foreground color to set
546 */
547 GLS_EXPORT void TextColor( const GlsColor& color );
548
549 /// \return The foreground color for the first character in the text grid.
550 GLS_EXPORT GlsColor TextColor();
551
552 /** Turns on/off underlines for all characters
553 * \param underline Whether or not to enable underline
554 */
555 GLS_EXPORT void Underline( const bool& underline );
556
557 /// \return The on/off state of underline for the first character.
558 GLS_EXPORT bool Underline();
559
560 /** Makes all characters uppercase when rendered.
561 * \param uppercase Whether or not to enable uppercase
562 */
563 GLS_EXPORT void Uppercase( bool uppercase );
564
565 /// \return The current uppercase state.
566 bool Uppercase() const
567 {
568 return _uppercase;
569 }
570
571 /** Enable/disable word wrap behavior for this object
572 * \param wrap Whether or not to enable word wrap
573 */
574 GLS_EXPORT void WrapText( bool wrap );
575
576 /** \return current word wrap behavior for this object */
577 bool WrapText() const
578 {
579 return _wrapText;
580 }
581
582 /** Sets the rebuild flag, which forces the text object to rebuild itself on the next call to Calculate, PreDraw, or Draw. */
583 void SetRebuild()
584 {
585 _needToRebuild = true;
586 InvalidatePainter();
587 }
588
589 /// \return Whether or not this text object requires a font file to work..
590 /// If this returns true, the text object may not work with the generated ASCII / UNICODE font types.
591 virtual bool RequiresFontFile() const
592 {
593 return false;
594 }
595
596 public: // protected is prefered, but VC 7.0 has issues with it.
597 /** Line Segment_t */
598 class LineSegment_t
599 {
600 public:
601 float x1; ///< Left side of the segment.
602 float x2; ///< Right side of the segment.
603 float y; ///< Vertical position of the segment.
604 float thickness; ///< Thickness of the segment in logical units.
605 float shadowOffsetX; ///< X offset of the shadow in logical units.
606 float shadowOffsetY; ///< Y offset of the shadow in logical units.
607 GlsColor color; ///< Color the segment is to be drawn.
608
609 LineSegment_t()
610 : x1( 0.0f )
611 , x2( 0.0f )
612 , y( 0.0f )
613 , thickness( 0.0f )
614 , shadowOffsetX( 0.0f )
615 , shadowOffsetY( 0.0f )
616 {
617 }
618
619 /// Constructor
620 /// \param segmentX1 Left side of the segment.
621 /// \param segmentX2 Right side of the segment.
622 /// \param segmentY Vertical position of the segment.
623 /// \param segmentThickness Thickness of the segment in logical units.
624 /// \param segmentShadowOffsetX X offset of the shadow in logical units.
625 /// \param segmentShadowOffsetY Y offset of the shadow in logical units.
626 /// \param segmentColor Color the segment is to be drawn.
627 LineSegment_t(
628 const float segmentX1,
629 const float segmentX2,
630 const float segmentY,
631 const float segmentThickness,
632 const float segmentShadowOffsetX,
633 const float segmentShadowOffsetY,
634 const GlsColor& segmentColor )
635 : x1( segmentX1 )
636 , x2( segmentX2 )
637 , y( segmentY )
638 , thickness( segmentThickness )
639 , shadowOffsetX( segmentShadowOffsetX )
640 , shadowOffsetY( segmentShadowOffsetY )
641 , color( segmentColor )
642 {
643 }
644 };
645
646 protected:
647 typedef std::vector<CharAttr_t> CharAttrCont_t; ///< Typedef for a list of character attributes.
648
649 static GLS_EXPORT const Vector XAXIS; ///< Vector for the global X axis.
650 static GLS_EXPORT const Vector YAXIS; ///< Vector for the global Y axis.
651
652 static GLS_EXPORT Vertex INITIAL_VERTICES[ NUM_VERTICES ]; ///< Default corners for new text objects.
653
654 /** The border offset in logical units for this object.
655 * Defines the size of the empty space between the outline of the box
656 * and its text
657 */
658 float _border;
659
660 /** Container of character attributes */
661 CharAttrCont_t _chars;
662
663 Vertex _currentVertices[ NUM_VERTICES ]; ///< The corners of the text object.
664
665 /** Height of each character cell in the grid in logical units */
666 float _cellHeight;
667
668 /** Width of each character cell in the grid in logical units */
669 float _cellWidth;
670
671 /** Only effective when _controlCellSize is true. Whether or not to
672 * constrain cell size ratio when changing cell height or width.
673 */
674 bool _constrainRatio;
675
676 /** If true, font size does not control cell size */
677 bool _controlCellSize;
678
679 /** Current font being used for the text */
680 GlsFontBase* _font;
681
682 bool _halo; ///< Whether or not the halo effect is on.
683
684 /** Color of the halo effect behind the characters */
685 GlsColor _haloColor;
686
687 /** Justification setting (LEFT, RIGHT, CENTER) */
688 Justify_t _justify;
689
690 /** Line spacing between grid rows as a percentage */
691 float _lineSpacing;
692
693 /** Only effective when _controlCellSize is true. If true, changes to
694 * rows, columns, border, line spacing, column spacing, etc. will
695 * not change the cell size. Normally, when _controlCellSize is true
696 * these attributes affect the cell size.
697 */
698 bool _lockCellSize;
699
700 /** This is set to true whenever an attribute changes that will affect
701 * the size of the grid or its cells.
702 */
703 bool _needToRebuild;
704
705 bool _shadow; ///< Whether or not the shadow effect is on.
706
707 /** Color of the shadow effect behind the characters */
708 GlsColor _shadowColor;
709
710 /** Offset of the shadow effect from the characters. Z component is ignored. */
711 Vector _shadowOffset;
712
713 /** String of text to be displayed. */
714 std::string _text;
715
716 /** If true, all characters will be displayed in uppercase */
717 bool _uppercase;
718
719 /** Direction vector indicating direction of horizontal travel for rendering */
720 Vector _vX;
721
722 /** Direction vector indicating direction of vertical travel for rendering */
723 Vector _vY;
724
725 /** Normal to the Vx Vy plane */
726 Vector _vZ;
727
728 /** Whether or not to word wrap text */
729 bool _wrapText;
730
731 public: // protected is preferred, but VC 7.0 has issues with it.
732#ifndef GLES
733
734 /// Draw a line by rendering a filled polygon with a line around it so that
735 /// the thickness scales and anti-aliasing will work if enabled.
736 /// \param x1 The left point.
737 /// \param y1 The top point.
738 /// \param x2 The right point.
739 /// \param y2 The bottom point.
740 static void DrawScalableLine( GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2 )
741 {
742 // APR: The Text Objects send x1,y1 as TOP-RIGHT. Rewrote glVertex calls to support CCW drawing.
743 glBegin( GL_POLYGON );
744 glVertex2f( x1, y1 );
745 glVertex2f( x1, y2 );
746 glVertex2f( x2, y2 );
747 glVertex2f( x2, y1 );
748 glEnd();
749 }
750#endif
751 protected:
752 /**
753 * Allocate a text buffer of the appropriate size for this grid and output snprintf style format
754 * into the buffer
755 * \param format snprintf style format spec
756 * \param args arguments for sprintf style formatting
757 * \param initialBufferLength the length of the initial character buffer
758 * \return formatted textbuffer ( must be deleted by caller )
759 */
760 GLS_EXPORT char* FormatVarArgList( const int initialBufferLength, const char* format, va_list args );
761
762 /// Calculates direction vectors based on the orientation of its vertices.
763 /// \note Not normally called by users.
764 GLS_EXPORT void RecalcDirectionVectors();
765
766 /** Pointer to the internal data needed for runtime glyph generation. */
767 ScopedPtr<RuntimeGlyphGenerationText> _runtimeGlyphGenerationText;
768
769 private:
770 // Allow derived classes to perform a custom action when cell height/width changes.
771 virtual GLS_EXPORT void OnCellDimensionChanged()
772 {}
773
774 // Disable copying.
775 GlsText( const GlsText& ) DISTI_SPECIAL_MEM_FUN_DELETE;
776 void operator=( const GlsText& ) DISTI_SPECIAL_MEM_FUN_DELETE;
777};
778
779/// Stream in operator
780/// \param instr The stream to read from.
781/// \param j The returned value read from the stream.
782/// \return The stream in its current state.
783 inline std::istream& operator>>( std::istream& instr, disti::GlsText::Justify_t& j )
784{
785 std::string str;
786 instr >> str;
787
788 if( str == "LEFT" )
789 {
790 j = disti::GlsText::LEFT;
791 }
792 else if( str == "CENTER" )
793 {
794 j = disti::GlsText::CENTER;
795 }
796 else if( str == "RIGHT" )
797 {
798 j = disti::GlsText::RIGHT;
799 }
800 return instr;
801}
802
803/// Stream out operator
804/// \param outstr The stream to write to.
805/// \param j The value to write to the stream.
806/// \return The stream in its current state.
807 inline std::ostream& operator<<( std::ostream& outstr, disti::GlsText::Justify_t j )
808{
809 switch( j )
810 {
811 case disti::GlsText::LEFT:
812 outstr << "LEFT";
813 break;
814 case disti::GlsText::CENTER:
815 outstr << "CENTER";
816 break;
817 case disti::GlsText::RIGHT:
818 outstr << "RIGHT";
819 break;
820 }
821 return outstr;
822}
823
824//===========================================================================
825/**
826* Attributes of a text character.
827* NOTE: Use of this attribute is deprecated.
828* Instead use individual top-level attributes such as ("FauxBold" and "TextColor").
829*/
830//===========================================================================
831 class GlsTextCharAttr : public DistiAttributeDictionaryAttribute
832{
833 public:
834 DISTI_DEPRECATED( "This identifier is forbidden by the C++ standard. Use BaseClass instead." )
835 typedef DistiAttributeDictionaryAttribute _BaseClass; ///< Deprecated typedef for the base class.
836 typedef DistiAttributeDictionaryAttribute BaseClass; ///< Typedef for the base class.
837
838 /// Constructor
839 /// \param name The name to use for this attribute.
840 /// \param text The text object associated with this attribute.
841 GlsTextCharAttr( const AttributeName& name, GlsText* text );
842
843 virtual ~GlsTextCharAttr()
844 {
845 delete _dict;
846 }
847
848 // Do not write out, because this interface is only for backward compatability.
849 virtual bool OkToWrite() const DISTI_METHOD_OVERRIDE
850 {
851 return false;
852 }
853
854 virtual std::ostream& WriteValue( std::ostream& outstr ) DISTI_METHOD_OVERRIDE
855 {
856 _charAttr = _text->CharAttr( 0 );
857 return BaseClass::WriteValue( outstr );
858 }
859
860 virtual std::istream& ReadValue( std::istream& instr ) DISTI_METHOD_OVERRIDE
861 {
862 // First get _charAttr to the current value.
863 // This is because the instr may not contain
864 // new values for all the attributes.
865 _charAttr = _text->CharAttr( 0 );
866
867 BaseClass::ReadValue( instr );
868
869 _text->Baseline( _charAttr.baselineShift );
870 _text->BgColor( _charAttr.bgColor );
871 _text->CharSpacing( _charAttr.spacing );
872 _text->TextColor( _charAttr.fgColor );
873 _text->FauxBold( _charAttr.fauxBold );
874 _text->Inverse( _charAttr.inverse );
875 _text->CharScaling( _charAttr.scale );
876 _text->StrikeThru( _charAttr.strikeThru );
877 _text->Underline( _charAttr.underline );
878
879 return instr;
880 }
881
882 protected:
883 GlsText* _text; ///< Observing pointer to the text object holding the attributes.
884 GlsText::CharAttr_t _charAttr; ///< Character attribute structure to apply to text.
885};
886
887} // namespace disti
888
889/// Stream out operator
890/// \param outstr The stream to write to.
891/// \param c The value to write to the stream.
892/// \return The stream in its current state.
893 DISTI_EXPORT std::ostream& operator<<( std::ostream& outstr, const disti::GlsText::CharAttr_t& c );
894
895/// Stream in operator
896/// \param instr The stream to read from.
897/// \param c The returned value read from the stream.
898/// \return The stream in its current state.
899 DISTI_EXPORT std::istream& operator>>( std::istream& instr, disti::GlsText::CharAttr_t& c );
900
901#endif
disti::AttributeName
Definition: disti_metadata.h:87
disti::DisplayObject
Definition: display.h:96
disti::DisplayObject::InvalidatePainter
void InvalidatePainter()
disti::DisplayObject::Rotate
virtual void Rotate(float angle, int axis=Z_AXIS)
disti::DistiAttributeDictionaryAttribute
Definition: gls_metadata_attributes.h:779
disti::DistiAttributeDictionaryAttribute::_dict
DistiAttribDict * _dict
An observing pointer to a dictionary of attributes.
Definition: gls_metadata_attributes.h:781
disti::DistiAttributeDictionaryAttribute::ReadValue
virtual std::istream & ReadValue(std::istream &instr) override
disti::DistiAttributeDictionaryAttribute::WriteValue
virtual std::ostream & WriteValue(std::ostream &outstr) override
disti::DynamicArray
Definition: dynamic_array.h:79
disti::GLPolygon
The Polygon class. Implements Polygons.
Definition: glpolygon.h:56
disti::GlsColor
Definition: gls_color.h:54
disti::GlsFontBase
Definition: gls_font_base.h:87
disti::GlsFontBase::Family
std::string Family() const
Definition: gls_font_base.h:275
disti::GlsGloFileAttribute
Definition: gls_glo_file.h:1243
disti::GlsRuntimeFontBase
Definition: gls_runtime_font_base.h:67
disti::GlsTextCharAttr
Definition: gls_text.h:832
disti::GlsTextCharAttr::_charAttr
GlsText::CharAttr_t _charAttr
Character attribute structure to apply to text.
Definition: gls_text.h:884
disti::GlsTextCharAttr::ReadValue
virtual std::istream & ReadValue(std::istream &instr) override
Definition: gls_text.h:860
disti::GlsTextCharAttr::_text
GlsText * _text
Observing pointer to the text object holding the attributes.
Definition: gls_text.h:883
disti::GlsTextCharAttr::OkToWrite
virtual bool OkToWrite() const override
Definition: gls_text.h:849
disti::GlsTextCharAttr::WriteValue
virtual std::ostream & WriteValue(std::ostream &outstr) override
Definition: gls_text.h:854
disti::GlsText::LineSegment_t
Definition: gls_text.h:599
disti::GlsText::LineSegment_t::x2
float x2
Right side of the segment.
Definition: gls_text.h:602
disti::GlsText::LineSegment_t::x1
float x1
Left side of the segment.
Definition: gls_text.h:601
disti::GlsText::LineSegment_t::shadowOffsetY
float shadowOffsetY
Y offset of the shadow in logical units.
Definition: gls_text.h:606
disti::GlsText::LineSegment_t::LineSegment_t
LineSegment_t(const float segmentX1, const float segmentX2, const float segmentY, const float segmentThickness, const float segmentShadowOffsetX, const float segmentShadowOffsetY, const GlsColor &segmentColor)
Definition: gls_text.h:627
disti::GlsText::LineSegment_t::thickness
float thickness
Thickness of the segment in logical units.
Definition: gls_text.h:604
disti::GlsText::LineSegment_t::color
GlsColor color
Color the segment is to be drawn.
Definition: gls_text.h:607
disti::GlsText::LineSegment_t::y
float y
Vertical position of the segment.
Definition: gls_text.h:603
disti::GlsText::LineSegment_t::shadowOffsetX
float shadowOffsetX
X offset of the shadow in logical units.
Definition: gls_text.h:605
disti::GlsText
Definition: gls_text.h:154
disti::GlsText::CharScaling
void CharScaling(const float &newScale)
disti::GlsText::XAXIS
static const Vector XAXIS
Vector for the global X axis.
Definition: gls_text.h:649
disti::GlsText::_cellWidth
float _cellWidth
Definition: gls_text.h:669
disti::GlsText::Underline
bool Underline()
disti::GlsText::Halo
void Halo(bool halo)
disti::GlsText::BgColor
void BgColor(const GlsColor &color)
disti::GlsText::String
virtual void String(const std::string &s)
disti::GlsText::_haloColor
GlsColor _haloColor
Definition: gls_text.h:685
disti::GlsText::Baseline
void Baseline(const float &baselineShift)
disti::GlsText::Shadow
bool Shadow() const
Definition: gls_text.h:474
disti::GlsText::Justify_t
Justify_t
Different text justifications.
Definition: gls_text.h:171
disti::GlsText::FormatVarArgList
char * FormatVarArgList(const int initialBufferLength, const char *format, va_list args)
disti::GlsText::SetFromGloData
virtual void SetFromGloData(GlsGloFileAttribute &data) override
disti::GlsText::CellHeight
float CellHeight() const
Definition: gls_text.h:260
disti::GlsText::CharAttrCont_t
std::vector< CharAttr_t > CharAttrCont_t
Typedef for a list of character attributes.
Definition: gls_text.h:647
disti::GlsText::RequiresFontFile
virtual bool RequiresFontFile() const
Definition: gls_text.h:591
disti::GlsText::CharAttr
CharAttr_t CharAttr(unsigned int index) const
Definition: gls_text.h:297
disti::GlsText::ConstrainCellRatio
void ConstrainCellRatio(bool constrain)
disti::GlsText::_lineSpacing
float _lineSpacing
Definition: gls_text.h:691
disti::GlsText::CellHeight
void CellHeight(float height)
disti::GlsText::ControlCellSize
void ControlCellSize(bool control)
disti::GlsText::Rotate
virtual void Rotate(const Vector &orig, float angle, const Vector &axis) override
disti::GlsText::Font
void Font(GlsFontBase *font)
disti::GlsText::_shadowOffset
Vector _shadowOffset
Definition: gls_text.h:711
disti::GlsText::SetAvailableAttributes
virtual void SetAvailableAttributes(unsigned int value) override
disti::GlsText::Border
void Border(const float &units)
disti::GlsText::GlsText
GlsText(const GlsText &that, const bool generateNames)
disti::GlsText::~GlsText
virtual ~GlsText()
disti::GlsText::Baseline
float Baseline()
disti::GlsText::Shadow
void Shadow(bool shadow)
disti::GlsText::FauxBold
bool FauxBold()
disti::GlsText::ShadowColor
GlsColor ShadowColor() const
Definition: gls_text.h:485
disti::GlsText::CharSpacing
void CharSpacing(const float &horizontalSpacing)
disti::GlsText::Border
float Border() const
Definition: gls_text.h:245
disti::GlsText::CharScaling
float CharScaling()
disti::GlsText::_border
float _border
Definition: gls_text.h:658
disti::GlsText::SetValue
virtual void SetValue(int spec, va_list &args) override
disti::GlsText::CellWidth
float CellWidth() const
Definition: gls_text.h:274
disti::GlsText::_uppercase
bool _uppercase
Definition: gls_text.h:717
disti::GlsText::String
virtual void String(const char *s)
Definition: gls_text.h:529
disti::GlsText::_runtimeGlyphGenerationText
ScopedPtr< RuntimeGlyphGenerationText > _runtimeGlyphGenerationText
Definition: gls_text.h:767
disti::GlsText::Inverse
void Inverse(const bool &inverse)
disti::GlsText::Halo
bool Halo() const
Definition: gls_text.h:386
disti::GlsText::_needToRebuild
bool _needToRebuild
Definition: gls_text.h:703
disti::GlsText::Font
GlsFontBase * Font() const
Definition: gls_text.h:365
disti::GlsText::StrikeThru
bool StrikeThru()
disti::GlsText::ConstrainCellRatio
bool ConstrainCellRatio() const
Definition: gls_text.h:330
disti::GlsText::Char
void Char(Char_t code)
disti::GlsText::Justify
void Justify(Justify_t justification)
disti::GlsText::Underline
void Underline(const bool &underline)
disti::GlsText::InvalidateFont
void InvalidateFont()
disti::GlsText::_cellHeight
float _cellHeight
Definition: gls_text.h:666
disti::GlsText::Uppercase
void Uppercase(bool uppercase)
disti::GlsText::LineSpacing
float LineSpacing() const
Definition: gls_text.h:434
disti::GlsText::SetRebuild
void SetRebuild()
Definition: gls_text.h:583
disti::GlsText::EOL
static const Char_t EOL
Carriage return (end of line) character.
Definition: gls_text.h:162
disti::GlsText::StrikeThru
void StrikeThru(const bool &strike)
disti::GlsText::CharSpacing
float CharSpacing()
disti::GlsText::_currentVertices
Vertex _currentVertices[NUM_VERTICES]
The corners of the text object.
Definition: gls_text.h:663
disti::GlsText::BgColor
GlsColor BgColor()
disti::GlsText::LineSpacing
void LineSpacing(float spacing)
disti::GlsText::YAXIS
static const Vector YAXIS
Vector for the global Y axis.
Definition: gls_text.h:650
disti::GlsText::RecalcDirectionVectors
void RecalcDirectionVectors()
disti::GlsText::_chars
CharAttrCont_t _chars
Definition: gls_text.h:661
disti::GlsText::ControlCellSize
bool ControlCellSize() const
Definition: gls_text.h:344
disti::GlsText::Erase
void Erase()
disti::GlsText::CopyProperties
virtual void CopyProperties(DisplayObject *src) override
disti::GlsText::WrapText
bool WrapText() const
Definition: gls_text.h:577
disti::GlsText::_halo
bool _halo
Whether or not the halo effect is on.
Definition: gls_text.h:682
disti::GlsText::LockCellSize
bool LockCellSize() const
Definition: gls_text.h:448
disti::GlsText::_shadow
bool _shadow
Whether or not the shadow effect is on.
Definition: gls_text.h:705
disti::GlsText::LockCellSize
void LockCellSize(bool lock)
disti::GlsText::CharAttribs
CharAttr_t CharAttribs() const
Definition: gls_text.h:290
disti::GlsText::HaloColor
GlsColor HaloColor() const
Definition: gls_text.h:397
disti::GlsText::INITIAL_VERTICES
static Vertex INITIAL_VERTICES[NUM_VERTICES]
Default corners for new text objects.
Definition: gls_text.h:652
disti::GlsText::_lockCellSize
bool _lockCellSize
Definition: gls_text.h:698
disti::GlsText::_wrapText
bool _wrapText
Definition: gls_text.h:729
disti::GlsText::_constrainRatio
bool _constrainRatio
Definition: gls_text.h:674
disti::GlsText::Char_t
GlsFontBase::Char_t Char_t
Typedef shorthand for GlsFontBase::Char_t.
Definition: gls_text.h:160
disti::GlsText::_shadowColor
GlsColor _shadowColor
Definition: gls_text.h:708
disti::GlsText::CellWidth
void CellWidth(float width)
disti::GlsText::Inverse
bool Inverse()
disti::GlsText::ShadowColor
void ShadowColor(const GlsColor &color)
disti::GlsText::TextColor
void TextColor(const GlsColor &color)
disti::GlsText::FauxBold
void FauxBold(const bool &bold)
disti::GlsText::_vZ
Vector _vZ
Definition: gls_text.h:726
disti::GlsText::ShadowOffset
Vector ShadowOffset()
Definition: gls_text.h:508
disti::GlsText::_font
GlsFontBase * _font
Definition: gls_text.h:680
disti::GlsText::ShadowDistance
void ShadowDistance(const float &dist)
Definition: gls_text.h:495
disti::GlsText::GlsText
GlsText()
disti::GlsText::Justify
Justify_t Justify() const
Definition: gls_text.h:422
disti::GlsText::WrapText
void WrapText(bool wrap)
disti::GlsText::CopyGeometry
virtual void CopyGeometry(DisplayObject *src) override
disti::GlsText::HaloColor
void HaloColor(const GlsColor &color)
disti::GlsText::Uppercase
bool Uppercase() const
Definition: gls_text.h:566
disti::GlsText::String
std::string String() const
Definition: gls_text.h:539
disti::GlsText::_controlCellSize
bool _controlCellSize
Definition: gls_text.h:677
disti::GlsText::_justify
Justify_t _justify
Definition: gls_text.h:688
disti::GlsText::ShadowOffset
void ShadowOffset(const Vector &offset)
disti::GlsText::_text
std::string _text
Definition: gls_text.h:714
disti::GlsText::_vX
Vector _vX
Definition: gls_text.h:720
disti::GlsText::_vY
Vector _vY
Definition: gls_text.h:723
disti::GlsText::TextColor
GlsColor TextColor()
disti::GlsUnicodeFontBase
Definition: gls_unicode_font_base.h:66
disti::ScopedPtr< RuntimeGlyphGenerationText >
disti::VertexNoColor
Definition: vertex.h:85
disti::Vertex
Definition: vertex.h:420
glpolygon.h
The disti::GLPolygon class. Implements Polygons.
gls_color.h
The Color class: Implements a 4 component RGBA color.
gls_cpp_lang_support.h
Macros and helper code to determine what subset of C++11/14/17 is available.
DISTI_SPECIAL_MEM_FUN_DELETE
#define DISTI_SPECIAL_MEM_FUN_DELETE
Macro to wrap function deletion, removed on compilers that don't support it.
Definition: gls_cpp_lang_support.h:246
DISTI_DEPRECATED
#define DISTI_DEPRECATED(msg)
Defines whether this compiler supports the C++14 deprecated attribute.
Definition: gls_cpp_lang_support.h:488
DISTI_METHOD_OVERRIDE
#define DISTI_METHOD_OVERRIDE
Macro to wrap the override keyword, removed on compilers that don't support it.
Definition: gls_cpp_lang_support.h:222
gls_font_base.h
The disti::GlsFontBase class and related classes.
gls_font_man.h
The disti::GlsFontMan class.
GLS_RUNTIME_FONT_NAME_PREFIX
#define GLS_RUNTIME_FONT_NAME_PREFIX
Definition: gls_font_man.h:53
GLS_UNICODE_FONT_NAME_PREFIX
#define GLS_UNICODE_FONT_NAME_PREFIX
Definition: gls_font_man.h:50
gls_gl.h
The gls_gl.
GLS_EXPORT
#define GLS_EXPORT
Macro denoting which functions should be visible from the runtime library.
Definition: gls_include.h:52
gls_metadata_attributes.h
Defines templated metadata classes for DisplayObjects and other uses.
gls_runtime_font_base.h
The disti::GlsRuntimeFontBase class and related classes.
operator>>
std::istream & operator>>(std::istream &instr, disti::GlsText::CharAttr_t &c)
operator<<
std::ostream & operator<<(std::ostream &outstr, const disti::GlsText::CharAttr_t &c)
gls_unicode_font_base.h
The disti::GlsUnicodeFontBase class and related classes.
disti
Definition: bmpimage.h:47
disti::operator<<
std::ostream & operator<<(std::ostream &outstr, const AttributeName &name)
disti::GetGlsRuntimeFontBase
GlsRuntimeFontBase * GetGlsRuntimeFontBase(const GlsFontBase *font)
Definition: gls_text.h:116
disti::Vector
VertexNoColor Vector
Definition: gls_font_base.h:69
disti::GlsTextInitializers_t
GlsTextInitializers_t
Initializers for text.
Definition: gls_text.h:94
disti::operator>>
std::istream & operator>>(std::istream &instr, GlsColor &color)
disti::GetGlsUnicodeFontBase
const GlsUnicodeFontBase * GetGlsUnicodeFontBase(const GlsFontBase *font)
Definition: gls_text.h:134
scoped_ptr.h
A smart pointer with unique ownership – poor man's std::unique_ptr.
disti::GlsText::CharAttr_t
Attributes for each character position in the grid.
Definition: gls_text.h:179
disti::GlsText::CharAttr_t::fauxBold
bool fauxBold
Whether or not faux bold is enabled.
Definition: gls_text.h:184
disti::GlsText::CharAttr_t::bgColor
GlsColor bgColor
The background color.
Definition: gls_text.h:182
disti::GlsText::CharAttr_t::scale
float scale
Scaled size of this character.
Definition: gls_text.h:186
disti::GlsText::CharAttr_t::inverse
bool inverse
Whether or not inverse is enabled.
Definition: gls_text.h:185
disti::GlsText::CharAttr_t::operator=
CharAttr_t & operator=(const CharAttr_t &r)
disti::GlsText::CharAttr_t::code
Char_t code
The code point for this character.
Definition: gls_text.h:180
disti::GlsText::CharAttr_t::baselineShift
float baselineShift
The base line shift in pixels.
Definition: gls_text.h:181
disti::GlsText::CharAttr_t::underline
bool underline
Whether or not underline is enabled.
Definition: gls_text.h:189
disti::GlsText::CharAttr_t::Clear
void Clear()
Reset values to their defaults.
disti::GlsText::CharAttr_t::CharAttr_t
CharAttr_t(const CharAttr_t &r)
disti::GlsText::CharAttr_t::spacing
float spacing
Scale of spacing between this character.
Definition: gls_text.h:187
disti::GlsText::CharAttr_t::fgColor
GlsColor fgColor
The foreground (glyph itself) color.
Definition: gls_text.h:183
disti::GlsText::CharAttr_t::strikeThru
bool strikeThru
Whether or not strike through is enabled.
Definition: gls_text.h:188
unhide_globals.h
The DistiUnhideGlobalsDummyClass class.