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