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