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"
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 #ifdef GLES
63 # define GLS_TEXT_SET_GEOMETRY_REFRESH GeometryRefresh();
64 #else
65 # define GLS_TEXT_SET_GEOMETRY_REFRESH
66 #endif
67 
68 #define SET_ALL_CHARS( attribute, value ) \
69  { \
70  for( CharAttrCont_t::iterator i = _chars.begin(); i != _chars.end(); ++i ) \
71  { \
72  i->attribute = value; \
73  } \
74  GLS_TEXT_SET_GEOMETRY_REFRESH \
75  }
76 
77 //===========================================================================
78 // BEGIN NAMESPACE
79 //===========================================================================
80 namespace disti
81 {
82 #ifdef GLES
83 // Forward Declaration
84 class GlsGloFileAttribute;
85 #endif
86 
87 // Forward Declaration
88 class RuntimeGlyphGenerationText;
89 
90 // Initializers for text
91 typedef enum
92 {
93  GLS_TEXT_BORDER = GLS_LAST_INITIALIZER + 1,
94  GLS_TEXT_CELL_HEIGHT,
95  GLS_TEXT_CELL_WIDTH,
96  GLS_TEXT_CONSTRAIN_CELL_RATIO,
97  GLS_TEXT_CONTROL_CELL_SIZE,
98  GLS_TEXT_FONT,
99  GLS_TEXT_HALO,
100  GLS_TEXT_LINESPACING,
101  GLS_TEXT_LOCK_CELL_SIZE,
102  GLS_TEXT_JUSTIFY,
103  GLS_TEXT_SHADOW,
104  GLS_TEXT_STRING,
105  GLS_TEXT_UPPERCASE,
106  GLS_TEXT_WRAP,
107  GLS_LAST_TEXT_INITIALIZER = GLS_TEXT_WRAP
108 } GlsTextInitializers_t;
109 
110 /** helper method for safely getting a runtime font base from a font base (if possible)
111  * \param font font in question
112  * \return runtime font else NULL
113  */
115 {
116  GlsRuntimeFontBase* rtf = NULL;
117  if( font )
118  {
119  // determine if font can be safely cast to a runtime font by inspecting the family name
120  if( 0 == font->Family().find( GLS_RUNTIME_FONT_NAME_PREFIX ) )
121  {
122  rtf = static_cast<GlsRuntimeFontBase*>( (GlsFontBase*)font );
123  }
124  }
125  return ( rtf );
126 }
127 
128 /** helper method for safely getting a unicode font base from a font base (if possible)
129  * \param font font in question
130  * \return unicode font else NULL
131  */
133 {
134  const GlsUnicodeFontBase* unf = NULL;
135  if( font )
136  {
137  // determine if font can be safely cast to a unicode font by inspecting the family name
138  if( 0 == font->Family().find( GLS_UNICODE_FONT_NAME_PREFIX ) )
139  {
140  unf = static_cast<const GlsUnicodeFontBase*>( font );
141  }
142  }
143  return ( unf );
144 }
145 
146 //===========================================================================
147 /**
148 * The GlsText class provides a base class for all GLStudio text components.
149 */
150 //===========================================================================
151 class GlsText : public GLPolygon
152 {
153 public:
154  DISTI_DEPRECATED( "This identifier is forbidden by the C++ standard. Use BaseClass instead." )
155  typedef GLPolygon _BaseClass;
156  typedef GLPolygon BaseClass;
157 
158  typedef GlsFontBase::Char_t Char_t;
159 
160  // Carriage return (end of line) character
161  static GLS_EXPORT const Char_t EOL;
162 
163  enum
164  {
165  NUM_VERTICES = 4
166  };
167 
168  /// Different text justifications.
170  {
171  LEFT,
172  CENTER,
173  RIGHT
174  };
175 
176  /// Attributes for each character position in the grid.
177  struct CharAttr_t
178  {
179  Char_t code;
180  float baselineShift;
181  GlsColor bgColor;
182  GlsColor fgColor;
183  bool fauxBold;
184  bool inverse;
185  float scale;
186  float spacing;
187  bool strikeThru;
188  bool underline;
189 
190  //----------------------------------------------------------------------
191  GLS_EXPORT CharAttr_t();
192 
193  //----------------------------------------------------------------------
194  GLS_EXPORT CharAttr_t( const CharAttr_t& r );
195 
196  //----------------------------------------------------------------------
197  GLS_EXPORT void Clear();
198 
199  //----------------------------------------------------------------------
200  GLS_EXPORT CharAttr_t& operator=( const CharAttr_t& r );
201  };
202 
203 #ifndef WIN32
204 
205  /** helper class that enables use of basic_string< unsigned short > on unix
206  * \see std::char_traits
207  */
209  {
210  typedef unsigned short char_type;
211  typedef int int_type;
212  typedef std::streampos pos_type;
213  typedef std::streamoff off_type;
214  typedef std::mbstate_t state_type;
215 
216  static void assign( char_type& c1, const char_type& c2 )
217  {
218  c1 = c2;
219  }
220 
221  static bool eq( const char_type& c1, const char_type& c2 )
222  {
223  return c1 == c2;
224  }
225 
226  static bool lt( const char_type& c1, const char_type& c2 )
227  {
228  return c1 < c2;
229  }
230 
231  static int compare( const char_type* s1, const char_type* s2, size_t n )
232  {
233  if( n == 0 )
234  {
235  return ( 0 );
236  }
237  do
238  {
239  if( *s1 != *s2++ )
240  {
241  return ( *s1 - *( s2 - 1 ) );
242  }
243  if( *s1++ == 0 )
244  {
245  break;
246  }
247  } while( --n != 0 );
248  return ( 0 );
249  }
250 
251  static size_t length( const char_type* s )
252  {
253  size_t x = 0u;
254  while( *s++ )
255  {
256  ++x;
257  }
258  return ( x );
259  }
260 
261  static const char_type* find( const char_type* s, size_t n, const char_type& a )
262  {
263  while( n-- > 0 )
264  {
265  if( *s == a )
266  {
267  return s;
268  }
269  s++;
270  }
271  return NULL;
272  }
273 
274  static char_type* move( char_type* s1, const char_type* s2, size_t n )
275  {
276  return static_cast<char_type*>( memmove( s1, s2, n * sizeof( char_type ) ) );
277  }
278 
279  static char_type* copy( char_type* s1, const char_type* s2, size_t n )
280  {
281  return static_cast<char_type*>( memcpy( s1, s2, n * sizeof( char_type ) ) );
282  }
283 
284  static char_type* assign( char_type* s, size_t n, char_type a )
285  {
286  for( size_t idx = 0u; idx < n; ++idx )
287  {
288  s[ idx ] = a;
289  }
290  return ( s );
291  }
292 
293  static char_type to_char_type( const int_type& c )
294  {
295  return static_cast<char_type>( c );
296  }
297 
298  static int_type to_int_type( const char_type& c )
299  {
300  return static_cast<int_type>( c );
301  }
302 
303  static bool eq_int_type( const int_type& c1, const int_type& c2 )
304  {
305  return c1 == c2;
306  }
307 
308  static int_type eof()
309  {
310  return static_cast<int_type>( EOF );
311  }
312 
313  static int_type not_eof( const int_type& c )
314  {
315  return ( c == eof() ) ? 0 : c;
316  }
317  };
318 
319  typedef std::basic_string<unsigned short, CharTraitsUnsignedShort> UnicodeString;
320 
321 #else
322 
323  typedef std::wstring UnicodeString;
324 
325 #endif
326 
327  /** Class Constructor. */
328  GLS_EXPORT GlsText();
329  GLS_EXPORT GlsText( const GlsText& that, const bool generateNames );
330 
331  /** Class Constructor. */
332  GLS_EXPORT virtual ~GlsText();
333 
334  virtual GLS_EXPORT void SetAvailableAttributes( unsigned int value );
335 
336  /** Sets the baseline shift for all characters.
337  * \param baselineShift multiplier used to shift the baseline. This will
338  * be multiplied by the character height to
339  * determine how much to shift. A value of 0 does
340  * not shift at all, a value of 1 will shift up
341  * by the height of 1 character.
342  */
343  GLS_EXPORT void Baseline( const float& baselineShift );
344 
345  /** Gets the baseline shift for the first character
346  */
347  GLS_EXPORT float Baseline();
348 
349  /** Sets the background color for all characters
350  * \param color The background color to set
351  */
352  GLS_EXPORT void BgColor( const GlsColor& color );
353 
354  /** Gets the background color for the first character
355  */
356  GLS_EXPORT GlsColor BgColor();
357 
358  /** Sets the spacing between the box outline and the text in logical units.
359  * \param units Border offset value in logical units
360  */
361  GLS_EXPORT void Border( const float& units );
362 
363  /** Sets the spacing between the box outline and the text in logical units.
364  */
365  float Border() const
366  {
367  return _border;
368  }
369 
370  /** Sets the height of a character cell of the grid in logical units
371  * when stretch to fit mode is in effect. When stretch to fit mode
372  * is not in effect, this call will not affect the grid since the
373  * font determines the cell size.
374  * \param height the new character cell height.
375  */
376  GLS_EXPORT void CellHeight( float height );
377 
378  /** \return the height of a char cell of the grid in logical units.
379  */
380  float CellHeight() const
381  {
382  return _cellHeight;
383  }
384 
385  /** Sets the width of a character cell of the grid in logical units
386  * when stretch to fit mode is in effect. When stretch to fit mode
387  * is not in effect, this call will not affect the grid since the
388  * font determines the cell size.
389  * \param width the new character cell width.
390  */
391  GLS_EXPORT void CellWidth( float width );
392 
393  /** \return the width of a char cell of the grid in logical units. */
394  float CellWidth() const
395  {
396  return _cellWidth;
397  }
398 
399  /** Sets the character code for all cell positions in the text grid
400  * \param code The ASCII character code to set
401  */
402  GLS_EXPORT void Char( Char_t code );
403 
404  /** Accessor method used by metadata to read and write the character attributes
405  * for this object. Currently only allows you to load and save attributes for the
406  * entire object, not on a per character basis.
407  * \return The character attribute for the first character in the object and therefore
408  * for every character in the object
409  */
411  {
412  return _chars[ 0 ];
413  }
414 
415  /** \return a particular cell's character attributes. */
416  CharAttr_t CharAttr( unsigned int index ) const
417  {
418  return _chars[ index < _chars.size() ? index : 0 ];
419  }
420 
421  /** Sets the scale factor of all characters NOTE: This is the size of the character in its
422  * cell not the overall scale of the entire object
423  * \param newScale The new scale factor of the characters (0.0 < newScale <= 1.0)
424  */
425  GLS_EXPORT void CharScaling( const float& newScale );
426 
427  /** Gets the scale factor of the first character
428  */
429  GLS_EXPORT float CharScaling();
430 
431  /** Sets the horizontal character spacing for all characters (spacing
432  * from the start of one character to the start of the next character.
433  * 1.0 is the default spacing 2.0 would be twice the normal spacing
434  * \param horizontalSpacing The horizontalSpacing value
435  */
436  GLS_EXPORT void CharSpacing( const float& horizontalSpacing );
437 
438  /** Gets the horizontal character spacing for the first character
439  */
440  GLS_EXPORT float CharSpacing();
441 
442  /** Sets whether to constrain cell width and height proportions when
443  * in stretch to fit mode and changing the size of character cells.
444  * \param constrain true to constrain proportions.
445  */
446  GLS_EXPORT void ConstrainCellRatio( bool constrain );
447 
448  /** \return whether to constrain cell width and height proportions when
449  * in stretch to fit mode and changing the size of character cells.
450  */
451  bool ConstrainCellRatio() const
452  {
453  return _constrainRatio;
454  }
455 
456  /** Sets whether or not the character cell size will stretch to fit
457  * this object's bounding box or if it is based on its font and font.
458  * \param control True if stretch to fit will be enabled
459  */
460  GLS_EXPORT void ControlCellSize( bool control );
461 
462  /** \return whether or not the character cell size will stretch to fit
463  * this object's bounding box or if it is based on its font and font
464  */
465  bool ControlCellSize() const
466  {
467  return _controlCellSize;
468  }
469 
470  /* See base class */
471  GLS_EXPORT virtual void CopyGeometry( DisplayObject* src );
472 
473  /* See base class */
474  GLS_EXPORT virtual void CopyProperties( DisplayObject* src );
475 
476  /** Erase all characters. */
477  GLS_EXPORT void Erase();
478 
479  /** Set the bold state on or off for all characters
480  * \param bold Bold state
481  */
482  GLS_EXPORT void FauxBold( const bool& bold );
483 
484  /** Gets the bold state on or off for the first character
485  */
486  GLS_EXPORT bool FauxBold();
487 
488  /** \return The font currently being used to render this text.
489  */
490  GlsFontBase* Font() const
491  {
492  return _font;
493  }
494 
495  /** Set the font used to render this text.
496  * \param font Pointer to a font instance to set
497  */
498  GLS_EXPORT void Font( GlsFontBase* font );
499 
500 #ifndef GLES
501  /* See base class */
502  virtual GLS_EXPORT InterfaceListType* GetCppInterfaceDescription(
503  InterfaceListType* addToThisList = NULL );
504 
505  /* See base class */
506  virtual GLS_EXPORT void GetCppInterfaceDescriptionFree(
507  InterfaceListType* array );
508 #endif
509 
510  /** Set the halo state to on or off for the text
511  * \param halo halo state
512  */
513  GLS_EXPORT void Halo( bool halo );
514 
515  bool Halo() const
516  {
517  return _halo;
518  }
519 
520  /** Set the color of the halo around the text
521  * \param color halo color
522  */
523  GLS_EXPORT void HaloColor( const GlsColor& color );
524 
525  GlsColor HaloColor() const
526  {
527  return _haloColor;
528  }
529 
530  /** Invalidates the font for this object. If the font is invalidated, this object will
531  * draw using the default font. This is used in the editor and should not need to
532  * be called by any user code at run-time.
533  */
534  GLS_EXPORT void InvalidateFont();
535 
536  /** Set the inverse video state on or off for all characters
537  * \param inverse inverse video state
538  */
539  GLS_EXPORT void Inverse( const bool& inverse );
540 
541  /** Gets the inverse video state on or off for the first character
542  */
543  GLS_EXPORT bool Inverse();
544 
545  /** Set the justification mode for this text object
546  * \param justification The justification mode (LEFT, RIGHT, CENTER)
547  */
548  GLS_EXPORT void Justify( Justify_t justification );
549 
550  /** \return the justification mode (LEFT, RIGHT, CENTER)*/
552  {
553  return _justify;
554  }
555 
556  /** Sets the linespacing for the text object. A line spacing of 1.0 indicates normal
557  * "single spaced" text. 2.0 would be double spaced, etc.
558  * \param spacing The new linespacing value
559  */
560  GLS_EXPORT void LineSpacing( float spacing );
561 
562  /** \return the linespacing for the text object. */
563  float LineSpacing() const
564  {
565  return _lineSpacing;
566  }
567 
568  /** Sets whether or not the cell size is locked while in stretch to fit
569  * mode. If locked, changing other attributes will not affect the
570  * cell size, but the box size instead. If not locked, changing
571  * certain attributes, eg. border, will affect the cell size.
572  * \param lock true to lock cell size, false otherwise
573  */
574  GLS_EXPORT void LockCellSize( bool lock );
575 
576  /** \return the setting of lock cell size. */
577  bool LockCellSize() const
578  {
579  return _lockCellSize;
580  }
581 
582 #if !defined( GCC_2_95 )
583  /* Unhides base class implementation. */
584  using BaseClass::Rotate;
585 #endif
586 
587  /* See base class */
588  virtual GLS_EXPORT void Rotate( const Vector& orig, float angle, const Vector& axis );
589 
590  /* See base class */
591  virtual GLS_EXPORT void SetValue( int spec, va_list& args );
592 
593 #ifdef GLES
594  /** Set a single attribute from the GLO file.
595  * \param data The attribute to set and its associated data.
596  */
597  virtual GLS_EXPORT void SetFromGloData( GlsGloFileAttribute& data );
598 #endif
599 
600  /** Set the shadow state to on or off for the text
601  * \param shadow shadow state
602  */
603  GLS_EXPORT void Shadow( bool shadow );
604 
605  bool Shadow() const
606  {
607  return _shadow;
608  }
609 
610  /** Set the color of the shadow behind the text
611  * \param color shadow color
612  */
613  GLS_EXPORT void ShadowColor( const GlsColor& color );
614 
615  GlsColor ShadowColor() const
616  {
617  return _shadowColor;
618  }
619 
620  /** Set the distance of the shadow from the text. Distance represent a percentage of the character
621  * width. Negative values are up and to the left. Positive values are down and to the right. Note that the
622  * corresponding getter was removed because ShadowDistance is deprecated in favor of ShadowOffset.
623  * \param dist shadow distance
624  */
625  void ShadowDistance( const float& dist )
626  {
627  ShadowOffset( Vector( dist, -dist, 0.0f ) );
628  }
629 
630  /** Set the Cartesian offset of the shadow from the text. Offset represent a percentage of the character
631  * width. Negative values are down and to the left. Positive values are up and to the right.
632  * Z component is ignored.
633  * \param offset shadow offset
634  */
635  GLS_EXPORT void ShadowOffset( const Vector& offset );
636 
637  Vector ShadowOffset()
638  {
639  return _shadowOffset;
640  }
641 
642  /** Sets the strikethru state for all characters
643  * \param strike Whether or not set strikethru
644  */
645  GLS_EXPORT void StrikeThru( const bool& strike );
646 
647  /** Gets the strikethru state for the first character
648  */
649  GLS_EXPORT bool StrikeThru();
650 
651  /** Sets the ASCII string to be displayed for this object
652  * \param s STD Template Library String
653  */
654  GLS_EXPORT void String( const std::string& s );
655 
656  /** Sets the ASCII string to be displayed for this object
657  * \param s C Style string
658  */
659  void String( const char* s )
660  {
661  String( std::string( s ) );
662  }
663 
664  /** \return The string currently stored in this object.
665  * NOTE: This can contain extra characters not being displayed
666  * in the grid if the string size is greater than will
667  * fit within the grid.
668  */
669  std::string String() const
670  {
671  return _text;
672  }
673 
674  /** Sets the foreground color for all characters in the text grid.
675  * \param color The foreground color to set
676  */
677  GLS_EXPORT void TextColor( const GlsColor& color );
678 
679  /** Gets the foreground color for the first character in the text grid.
680  */
681  GLS_EXPORT GlsColor TextColor();
682 
683  /** Turns on/off underlines for all characters
684  * \param underline Whether or not to enable underline
685  */
686  GLS_EXPORT void Underline( const bool& underline );
687 
688  /** Gets the on/off state of underline for the first character
689  */
690  GLS_EXPORT bool Underline();
691 
692  /** Makes all characters uppercase when rendered.
693  * \param uppercase Whether or not to enable uppercase
694  */
695  GLS_EXPORT void Uppercase( bool uppercase );
696  bool Uppercase() const
697  {
698  return _uppercase;
699  }
700 
701  /** Enable/disable word wrap behavior for this object
702  * \param wrap Whether or not to enable word wrap
703  */
704  GLS_EXPORT void WrapText( bool wrap );
705 
706  /** \return current word wrap behavior for this object */
707  bool WrapText() const
708  {
709  return _wrapText;
710  }
711 
712  /** Sets the rebuild flag, which forces the text object to rebuild itself on the next call to Calculate, PreDraw, or Draw. */
713  void SetRebuild()
714  {
715  _needToRebuild = true;
717  }
718 
719  /** whether or not this text object requires a font file to work. If this returns true, the text object may not work with the generated ASCII / UNICODE font types */
720  virtual bool RequiresFontFile() const
721  {
722  return false;
723  }
724 
725 public: // protected is prefered, but VC 7.0 has issues with it.
726  /** Line Segment_t */
728  {
729  public:
730  float x1;
731  float x2;
732  float y;
733  float thickness;
734  float shadowOffsetX;
735  float shadowOffsetY;
736  GlsColor color;
737 
738  LineSegment_t()
739  : x1( 0.0f )
740  , x2( 0.0f )
741  , y( 0.0f )
742  , thickness( 0.0f )
743  , shadowOffsetX( 0.0f )
744  , shadowOffsetY( 0.0f )
745  {
746  }
747 
749  const float segmentX1,
750  const float segmentX2,
751  const float segmentY,
752  const float segmentThickness,
753  const float segmentShadowOffsetX,
754  const float segmentShadowOffsetY,
755  const GlsColor& segmentColor )
756  : x1( segmentX1 )
757  , x2( segmentX2 )
758  , y( segmentY )
759  , thickness( segmentThickness )
760  , shadowOffsetX( segmentShadowOffsetX )
761  , shadowOffsetY( segmentShadowOffsetY )
762  , color( segmentColor )
763  {
764  }
765  };
766 
767 protected:
768  typedef std::vector<CharAttr_t> CharAttrCont_t;
769 
770  static GLS_EXPORT const Vector XAXIS;
771  static GLS_EXPORT const Vector YAXIS;
772 
773  static GLS_EXPORT Vertex INITIAL_VERTICES[ NUM_VERTICES ];
774 
775  /** The border offset in logical units for this object.
776  * Defines the size of the empty space between the outline of the box
777  * and its text
778  */
779  float _border;
780 
781  /** Container of character attributes */
782  CharAttrCont_t _chars;
783 
784  Vertex _currentVertices[ NUM_VERTICES ];
785 
786  /** Height of each character cell in the grid in logical units */
787  float _cellHeight;
788 
789  /** Width of each character cell in the grid in logical units */
790  float _cellWidth;
791 
792  /** Only effective when _controlCellSize is true. Whether or not to
793  * constrain cell size ratio when changing cell height or width.
794  */
796 
797  /** If true, font size does not control cell size */
799 
800  /** Current font being used for the text */
802 
803  /* Whether or not the halo effect is on. */
804  bool _halo;
805 
806  /** Color of the halo effect behind the characters */
808 
809  /** Justification setting (LEFT, RIGHT, CENTER) */
811 
812  /** Line spacing between grid rows as a percentage */
814 
815  /** Only effective when _controlCellSize is true. If true, changes to
816  * rows, columns, border, line spacing, column spacing, etc. will
817  * not change the cell size. Normally, when _controlCellSize is true
818  * these attributes affect the cell size.
819  */
821 
822  /** This is set to true whenever an attribute changes that will affect
823  * the size of the grid or its cells.
824  */
826 
827  /* Whether or not the shadow effect is on. */
828  bool _shadow;
829 
830  /** Color of the shadow effect behind the characters */
832 
833  /** Offset of the shadow effect from the characters. Z component is ignored. */
835 
836  /** String of text to be displayed. */
837  std::string _text;
838 
839  /** If true, all characters will be displayed in uppercase */
841 
842  /** Direction vector indicating direction of horizontal travel for rendering */
844 
845  /** Direction vector indicating direction of vertical travel for rendering */
847 
848  /** Normal to the Vx Vy plane */
850 
851  /** Whether or not to word wrap text */
852  bool _wrapText;
853 
854  //-----------------------------------------------------------------------
855  /**
856  * Draw a line by rendering a filled polygon with a line around it so that
857  * the thickness scales and anti-aliasing will work if enabled.
858  */
859  //-----------------------------------------------------------------------
860 public: // protected is preferred, but VC 7.0 has issues with it.
861 #ifndef GLES
862  static void DrawScalableLine(
863  GLfloat x1, // Left point
864  GLfloat y1, // Top point
865  GLfloat x2, // Right Point
866  GLfloat y2 ) // Bottom Point
867  {
868  // APR: The Text Objects send x1,y1 as TOP-RIGHT. Rewrote glVertex calls to support CCW drawing.
869  glBegin( GL_POLYGON );
870  glVertex2f( x1, y1 );
871  glVertex2f( x1, y2 );
872  glVertex2f( x2, y2 );
873  glVertex2f( x2, y1 );
874  glEnd();
875  /*
876  glBegin(GL_LINE_LOOP);
877  glVertex2f(x1, y1);
878  glVertex2f(x2, y1);
879  glVertex2f(x2, y2);
880  glVertex2f(x1, y2);
881  glEnd();
882  */
883  }
884 #endif
885 protected:
886  /**
887  * Allocate a text buffer of the appropriate size for this grid and output snprintf style format
888  * into the buffer
889  * \param format snprintf style format spec
890  * \param args arguments for sprintf style formatting
891  * \param initialBufferLength the length of the initial character buffer
892  * \return formatted textbuffer ( must be deleted by caller )
893  */
894  GLS_EXPORT char* FormatVarArgList( const int initialBufferLength, const char* format, va_list args );
895 
896  //-----------------------------------------------------------------------
897  /**
898  */
899  //-----------------------------------------------------------------------
900  GLS_EXPORT void RecalcDirectionVectors();
901 
902  /** Pointer to the internal data needed for runtime glyph generation. */
904 
905 private:
906  // Allow derived classes to perform a custom action when cell height/width changes.
907  virtual GLS_EXPORT void OnCellDimensionChanged()
908  {}
909 
910  // Disable copying.
911  GlsText( const GlsText& ) DISTI_SPECIAL_MEM_FUN_DELETE;
912  void operator=( const GlsText& ) DISTI_SPECIAL_MEM_FUN_DELETE;
913 };
914 
915 //---------------------------------------------------------------------------
916 // Stream operators for text enumeration types
917 //---------------------------------------------------------------------------
918 inline std::istream& operator>>(
919  std::istream& instr, disti::GlsText::Justify_t& j )
920 {
921  std::string str;
922  instr >> str;
923 
924  if( str == "LEFT" )
925  {
926  j = disti::GlsText::LEFT;
927  }
928  else if( str == "CENTER" )
929  {
930  j = disti::GlsText::CENTER;
931  }
932  else if( str == "RIGHT" )
933  {
934  j = disti::GlsText::RIGHT;
935  }
936  return instr;
937 }
938 
939 //---------------------------------------------------------------------------
940 inline std::ostream& operator<<( std::ostream& outstr, disti::GlsText::Justify_t j )
941 {
942  switch( j )
943  {
944  case disti::GlsText::LEFT:
945  outstr << "LEFT";
946  break;
947  case disti::GlsText::CENTER:
948  outstr << "CENTER";
949  break;
950  case disti::GlsText::RIGHT:
951  outstr << "RIGHT";
952  break;
953  }
954  return outstr;
955 }
956 
957 //===========================================================================
958 /**
959 * Attributes of a text character.
960 * NOTE: Use of this attribute is deprecated.
961 * Instead use individual top-level attributes such as ("FauxBold" and "TextColor").
962 */
963 //===========================================================================
965 {
966 public:
967  DISTI_DEPRECATED( "This identifier is forbidden by the C++ standard. Use BaseClass instead." )
968  typedef DistiAttributeDictionaryAttribute _BaseClass;
969  typedef DistiAttributeDictionaryAttribute BaseClass;
970 
971  GlsTextCharAttr( const AttributeName& name, GlsText* text );
972 
973  virtual ~GlsTextCharAttr()
974  {
975  delete _dict;
976  }
977 
978  // Do not write out, because this interface is only for backward
979  // compatability
980  virtual bool OkToWrite() const
981  {
982  return false;
983  }
984 
985  virtual std::ostream& WriteValue( std::ostream& outstr )
986  {
987  _charAttr = _text->CharAttr( 0 );
988  return BaseClass::WriteValue( outstr );
989  }
990  virtual std::istream& ReadValue( std::istream& instr )
991  {
992  // First get _charAttr to the current value.
993  // This is because the instr may not contain
994  // new values for all the attributes.
995  _charAttr = _text->CharAttr( 0 );
996 
997  BaseClass::ReadValue( instr );
998 
999  _text->Baseline( _charAttr.baselineShift );
1000  _text->BgColor( _charAttr.bgColor );
1001  _text->CharSpacing( _charAttr.spacing );
1002  _text->TextColor( _charAttr.fgColor );
1003  _text->FauxBold( _charAttr.fauxBold );
1004  _text->Inverse( _charAttr.inverse );
1005  _text->CharScaling( _charAttr.scale );
1006  _text->StrikeThru( _charAttr.strikeThru );
1007  _text->Underline( _charAttr.underline );
1008 
1009  return instr;
1010  }
1011 
1012 protected:
1013  GlsText* _text;
1014  GlsText::CharAttr_t _charAttr;
1015 };
1016 
1017 } // namespace disti
1018 
1019 DISTI_EXPORT std::ostream& operator<<( std::ostream& outstr, const disti::GlsText::CharAttr_t& c );
1020 DISTI_EXPORT std::istream& operator>>( std::istream& instr, disti::GlsText::CharAttr_t& c );
1021 
1022 #endif
The DistiUnhideGlobalsDummyClass class.
virtual void Rotate(const Vector &orig, float angle, const Vector &axis)
Vector _vX
Definition: gls_text.h:843
float Baseline()
void InvalidateFont()
void ShadowOffset(const Vector &offset)
virtual void SetValue(int spec, va_list &args)
Definition: vertex.h:409
bool _uppercase
Definition: gls_text.h:840
#define DISTI_DEPRECATED(msg)
Defines whether this compiler supports the C++14 deprecated attribute.
Definition: gls_cpp_lang_support.h:436
virtual bool OkToWrite() const
Definition: gls_text.h:980
bool ConstrainCellRatio() const
Definition: gls_text.h:451
#define GLS_UNICODE_FONT_NAME_PREFIX
Definition: gls_font_man.h:50
Definition: dynamic_array.h:66
virtual std::istream & ReadValue(std::istream &instr)
Definition: gls_text.h:990
char * FormatVarArgList(const int initialBufferLength, const char *format, va_list args)
The disti::GlsFontBase class and related classes.
The Polygon class. Implements Polygons.
Definition: glpolygon.h:55
bool _constrainRatio
Definition: gls_text.h:795
Attributes for each character position in the grid.
Definition: gls_text.h:177
Justify_t _justify
Definition: gls_text.h:810
virtual bool RequiresFontFile() const
Definition: gls_text.h:720
float LineSpacing() const
Definition: gls_text.h:563
virtual void GetCppInterfaceDescriptionFree(InterfaceListType *array)
GlsColor TextColor()
Definition: display.h:98
Definition: gls_text.h:964
void ShadowDistance(const float &dist)
Definition: gls_text.h:625
The disti::GLPolygon class. Implements Polygons.
float _cellHeight
Definition: gls_text.h:787
Definition: gls_text.h:151
std::string _text
Definition: gls_text.h:837
CharAttrCont_t _chars
Definition: gls_text.h:782
GlsColor BgColor()
The Color class: Implements a 4 component RGBA color.
Justify_t
Different text justifications.
Definition: gls_text.h:169
float _lineSpacing
Definition: gls_text.h:813
void Char(Char_t code)
Definition: gls_glo_file.h:982
Definition: gls_unicode_font_base.h:65
std::ostream & operator<<(std::ostream &outstr, const AttributeName &name)
Defines the stream out operator.
Justify_t Justify() const
Definition: gls_text.h:551
virtual InterfaceListType * GetCppInterfaceDescription(InterfaceListType *addToThisList=NULL)
ScopedPtr< RuntimeGlyphGenerationText > _runtimeGlyphGenerationText
Definition: gls_text.h:903
GlsRuntimeFontBase * GetGlsRuntimeFontBase(const GlsFontBase *font)
Definition: gls_text.h:114
float CellWidth() const
Definition: gls_text.h:394
bool LockCellSize() const
Definition: gls_text.h:577
The disti::GlsFontMan class.
VertexNoColor Vector
Definition: gls_font_base.h:66
bool _lockCellSize
Definition: gls_text.h:820
bool _controlCellSize
Definition: gls_text.h:798
float _border
Definition: gls_text.h:779
bool ControlCellSize() const
Definition: gls_text.h:465
CharAttr_t CharAttribs() const
Definition: gls_text.h:410
GlsColor _haloColor
Definition: gls_text.h:807
Definition: gls_runtime_font_base.h:66
static void DrawScalableLine(GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2)
Definition: gls_text.h:862
Definition: gls_text.h:208
bool WrapText() const
Definition: gls_text.h:707
Definition: gls_color.h:53
virtual void Rotate(float angle, int axis=Z_AXIS)
GlsFontBase * Font() const
Definition: gls_text.h:490
Vector _vZ
Definition: gls_text.h:849
float _cellWidth
Definition: gls_text.h:790
virtual std::ostream & WriteValue(std::ostream &outstr)
Definition: gls_text.h:985
float CharScaling()
CharAttr_t CharAttr(unsigned int index) const
Definition: gls_text.h:416
float CharSpacing()
Vector _vY
Definition: gls_text.h:846
Defines templated metadata classes for DisplayObjects and other uses.
GlsFontBase * _font
Definition: gls_text.h:801
Definition: gls_metadata_attributes.h:610
The disti::GlsUnicodeFontBase class and related classes.
std::string String() const
Definition: gls_text.h:669
Definition: vertex.h:84
void SetRebuild()
Definition: gls_text.h:713
A smart pointer with unique ownership – poor man's std::unique_ptr.
virtual void CopyProperties(DisplayObject *src)
bool _wrapText
Definition: gls_text.h:852
const GlsUnicodeFontBase * GetGlsUnicodeFontBase(const GlsFontBase *font)
Definition: gls_text.h:132
std::string Family() const
Definition: gls_font_base.h:258
virtual void CopyGeometry(DisplayObject *src)
Vector _shadowOffset
Definition: gls_text.h:834
Macros and helper code to determine what subset of C++11/14/17 is available.
Definition: disti_metadata.h:85
bool _needToRebuild
Definition: gls_text.h:825
Definition: bmpimage.h:46
void String(const char *s)
Definition: gls_text.h:659
float Border() const
Definition: gls_text.h:365
virtual ~GlsText()
Definition: gls_text.h:727
The disti::GlsRuntimeFontBase class and related classes.
float CellHeight() const
Definition: gls_text.h:380
virtual void SetAvailableAttributes(unsigned int value)
GlsColor _shadowColor
Definition: gls_text.h:831
Definition: gls_font_base.h:85
The gls_gl.
#define GLS_RUNTIME_FONT_NAME_PREFIX
Definition: gls_font_man.h:53