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;
714  }
715 
716  /** 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 */
717  virtual bool RequiresFontFile() const
718  {
719  return false;
720  }
721 
722 public: // protected is prefered, but VC 7.0 has issues with it.
723  /** Line Segment_t */
725  {
726  public:
727  float x1;
728  float x2;
729  float y;
730  float thickness;
731  float shadowOffsetX;
732  float shadowOffsetY;
733  GlsColor color;
734 
735  LineSegment_t()
736  : x1( 0.0f )
737  , x2( 0.0f )
738  , y( 0.0f )
739  , thickness( 0.0f )
740  , shadowOffsetX( 0.0f )
741  , shadowOffsetY( 0.0f )
742  {
743  }
744 
746  const float segmentX1,
747  const float segmentX2,
748  const float segmentY,
749  const float segmentThickness,
750  const float segmentShadowOffsetX,
751  const float segmentShadowOffsetY,
752  const GlsColor& segmentColor )
753  : x1( segmentX1 )
754  , x2( segmentX2 )
755  , y( segmentY )
756  , thickness( segmentThickness )
757  , shadowOffsetX( segmentShadowOffsetX )
758  , shadowOffsetY( segmentShadowOffsetY )
759  , color( segmentColor )
760  {
761  }
762  };
763 
764 protected:
765  typedef std::vector<CharAttr_t> CharAttrCont_t;
766 
767  static GLS_EXPORT const Vector XAXIS;
768  static GLS_EXPORT const Vector YAXIS;
769 
770  static GLS_EXPORT Vertex INITIAL_VERTICES[ NUM_VERTICES ];
771 
772  /** The border offset in logical units for this object.
773  * Defines the size of the empty space between the outline of the box
774  * and its text
775  */
776  float _border;
777 
778  /** Container of character attributes */
779  CharAttrCont_t _chars;
780 
781  Vertex _currentVertices[ NUM_VERTICES ];
782 
783  /** Height of each character cell in the grid in logical units */
784  float _cellHeight;
785 
786  /** Width of each character cell in the grid in logical units */
787  float _cellWidth;
788 
789  /** Only effective when _controlCellSize is true. Whether or not to
790  * constrain cell size ratio when changing cell height or width.
791  */
793 
794  /** If true, font size does not control cell size */
796 
797  /** Current font being used for the text */
799 
800  /* Whether or not the halo effect is on. */
801  bool _halo;
802 
803  /** Color of the halo effect behind the characters */
805 
806  /** Justification setting (LEFT, RIGHT, CENTER) */
808 
809  /** Line spacing between grid rows as a percentage */
811 
812  /** Only effective when _controlCellSize is true. If true, changes to
813  * rows, columns, border, line spacing, column spacing, etc. will
814  * not change the cell size. Normally, when _controlCellSize is true
815  * these attributes affect the cell size.
816  */
818 
819  /** This is set to true whenever an attribute changes that will affect
820  * the size of the grid or its cells.
821  */
823 
824  /* Whether or not the shadow effect is on. */
825  bool _shadow;
826 
827  /** Color of the shadow effect behind the characters */
829 
830  /** Offset of the shadow effect from the characters. Z component is ignored. */
832 
833  /** String of text to be displayed. */
834  std::string _text;
835 
836  /** If true, all characters will be displayed in uppercase */
838 
839  /** Direction vector indicating direction of horizontal travel for rendering */
841 
842  /** Direction vector indicating direction of vertical travel for rendering */
844 
845  /** Normal to the Vx Vy plane */
847 
848  /** Whether or not to word wrap text */
849  bool _wrapText;
850 
851  //-----------------------------------------------------------------------
852  /**
853  * Draw a line by rendering a filled polygon with a line around it so that
854  * the thickness scales and anti-aliasing will work if enabled.
855  */
856  //-----------------------------------------------------------------------
857 public: // protected is preferred, but VC 7.0 has issues with it.
858 #ifndef GLES
859  static void DrawScalableLine(
860  GLfloat x1, // Left point
861  GLfloat y1, // Top point
862  GLfloat x2, // Right Point
863  GLfloat y2 ) // Bottom Point
864  {
865  // APR: The Text Objects send x1,y1 as TOP-RIGHT. Rewrote glVertex calls to support CCW drawing.
866  glBegin( GL_POLYGON );
867  glVertex2f( x1, y1 );
868  glVertex2f( x1, y2 );
869  glVertex2f( x2, y2 );
870  glVertex2f( x2, y1 );
871  glEnd();
872  /*
873  glBegin(GL_LINE_LOOP);
874  glVertex2f(x1, y1);
875  glVertex2f(x2, y1);
876  glVertex2f(x2, y2);
877  glVertex2f(x1, y2);
878  glEnd();
879  */
880  }
881 #endif
882 protected:
883  /**
884  * Allocate a text buffer of the appropriate size for this grid and output snprintf style format
885  * into the buffer
886  * \param format snprintf style format spec
887  * \param args arguments for sprintf style formatting
888  * \param initialBufferLength the length of the initial character buffer
889  * \return formatted textbuffer ( must be deleted by caller )
890  */
891  GLS_EXPORT char* FormatVarArgList( const int initialBufferLength, const char* format, va_list args );
892 
893  //-----------------------------------------------------------------------
894  /**
895  */
896  //-----------------------------------------------------------------------
897  GLS_EXPORT void RecalcDirectionVectors();
898 
899  /** Pointer to the internal data needed for runtime glyph generation. */
901 
902 private:
903  // Allow derived classes to perform a custom action when cell height/width changes.
904  virtual GLS_EXPORT void OnCellDimensionChanged()
905  {}
906 
907  // Disable copying.
908  GlsText( const GlsText& ) DISTI_SPECIAL_MEM_FUN_DELETE;
909  void operator=( const GlsText& ) DISTI_SPECIAL_MEM_FUN_DELETE;
910 };
911 
912 //---------------------------------------------------------------------------
913 // Stream operators for text enumeration types
914 //---------------------------------------------------------------------------
915 inline std::istream& operator>>(
916  std::istream& instr, disti::GlsText::Justify_t& j )
917 {
918  std::string str;
919  instr >> str;
920 
921  if( str == "LEFT" )
922  {
923  j = disti::GlsText::LEFT;
924  }
925  else if( str == "CENTER" )
926  {
927  j = disti::GlsText::CENTER;
928  }
929  else if( str == "RIGHT" )
930  {
931  j = disti::GlsText::RIGHT;
932  }
933  return instr;
934 }
935 
936 //---------------------------------------------------------------------------
937 inline std::ostream& operator<<( std::ostream& outstr, disti::GlsText::Justify_t j )
938 {
939  switch( j )
940  {
941  case disti::GlsText::LEFT:
942  outstr << "LEFT";
943  break;
944  case disti::GlsText::CENTER:
945  outstr << "CENTER";
946  break;
947  case disti::GlsText::RIGHT:
948  outstr << "RIGHT";
949  break;
950  }
951  return outstr;
952 }
953 
954 //===========================================================================
955 /**
956 * Attributes of a text character.
957 * NOTE: Use of this attribute is deprecated.
958 * Instead use individual top-level attributes such as ("FauxBold" and "TextColor").
959 */
960 //===========================================================================
962 {
963 public:
964  typedef DistiAttributeDictionaryAttribute _BaseClass;
965 
966  GlsTextCharAttr( const AttributeName& name, GlsText* text );
967 
968  virtual ~GlsTextCharAttr()
969  {
970  delete _dict;
971  }
972 
973  // Do not write out, because this interface is only for backward
974  // compatability
975  virtual bool OkToWrite() const
976  {
977  return false;
978  }
979 
980  virtual std::ostream& WriteValue( std::ostream& outstr )
981  {
982  _charAttr = _text->CharAttr( 0 );
983  return _BaseClass::WriteValue( outstr );
984  }
985  virtual std::istream& ReadValue( std::istream& instr )
986  {
987  // First get _charAttr to the current value.
988  // This is because the instr may not contain
989  // new values for all the attributes.
990  _charAttr = _text->CharAttr( 0 );
991 
992  _BaseClass::ReadValue( instr );
993 
994  _text->Baseline( _charAttr.baselineShift );
995  _text->BgColor( _charAttr.bgColor );
996  _text->CharSpacing( _charAttr.spacing );
997  _text->TextColor( _charAttr.fgColor );
998  _text->FauxBold( _charAttr.fauxBold );
999  _text->Inverse( _charAttr.inverse );
1000  _text->CharScaling( _charAttr.scale );
1001  _text->StrikeThru( _charAttr.strikeThru );
1002  _text->Underline( _charAttr.underline );
1003 
1004  return instr;
1005  }
1006 
1007 protected:
1008  GlsText* _text;
1009  GlsText::CharAttr_t _charAttr;
1010 };
1011 
1012 } // namespace disti
1013 
1014 DISTI_EXPORT std::ostream& operator<<( std::ostream& outstr, const disti::GlsText::CharAttr_t& c );
1015 DISTI_EXPORT std::istream& operator>>( std::istream& instr, disti::GlsText::CharAttr_t& c );
1016 
1017 #endif
The DistiUnhideGlobalsDummyClass class.
virtual void Rotate(const Vector &orig, float angle, const Vector &axis)
Vector _vX
Definition: gls_text.h:840
float Baseline()
void InvalidateFont()
void ShadowOffset(const Vector &offset)
virtual void SetValue(int spec, va_list &args)
Definition: vertex.h:408
bool _uppercase
Definition: gls_text.h:837
virtual bool OkToWrite() const
Definition: gls_text.h:975
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:985
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:792
Attributes for each character position in the grid.
Definition: gls_text.h:175
Justify_t _justify
Definition: gls_text.h:807
virtual bool RequiresFontFile() const
Definition: gls_text.h:717
float LineSpacing() const
Definition: gls_text.h:561
virtual void GetCppInterfaceDescriptionFree(InterfaceListType *array)
GlsColor TextColor()
Definition: display.h:97
Definition: gls_text.h:961
void ShadowDistance(const float &dist)
Definition: gls_text.h:623
The disti::GLPolygon class. Implements Polygons.
float _cellHeight
Definition: gls_text.h:784
Definition: gls_text.h:151
std::string _text
Definition: gls_text.h:834
CharAttrCont_t _chars
Definition: gls_text.h:779
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:810
void Char(Char_t code)
Definition: gls_glo_file.h:835
Definition: gls_unicode_font_base.h:65
Justify_t Justify() const
Definition: gls_text.h:549
virtual InterfaceListType * GetCppInterfaceDescription(InterfaceListType *addToThisList=NULL)
ScopedPtr< RuntimeGlyphGenerationText > _runtimeGlyphGenerationText
Definition: gls_text.h:900
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:817
bool _controlCellSize
Definition: gls_text.h:795
float _border
Definition: gls_text.h:776
bool ControlCellSize() const
Definition: gls_text.h:463
CharAttr_t CharAttribs() const
Definition: gls_text.h:408
GlsColor _haloColor
Definition: gls_text.h:804
Definition: gls_runtime_font_base.h:66
static void DrawScalableLine(GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2)
Definition: gls_text.h:859
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:846
float _cellWidth
Definition: gls_text.h:787
virtual std::ostream & WriteValue(std::ostream &outstr)
Definition: gls_text.h:980
float CharScaling()
CharAttr_t CharAttr(unsigned int index) const
Definition: gls_text.h:414
float CharSpacing()
Vector _vY
Definition: gls_text.h:843
Defines templated metadata classes for DisplayObjects and other uses.
GlsFontBase * _font
Definition: gls_text.h:798
Definition: gls_metadata_attributes.h:591
The disti::GlsUnicodeFontBase class and related classes.
std::string String() const
Definition: gls_text.h:667
Definition: vertex.h:83
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:849
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:831
Macros and helper code to determine what subset of C++11/14/17 is available.
Definition: disti_metadata.h:79
bool _needToRebuild
Definition: gls_text.h:822
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:724
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:828
Definition: gls_font_base.h:85
The gls_gl.
#define GLS_RUNTIME_FONT_NAME_PREFIX
Definition: gls_font_man.h:53