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