GL Studio C++ Runtime API
gls_text_grid.h
Go to the documentation of this file.
1 /*! \file
2  \brief The disti::GlsTextGrid 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 #ifndef _GLS_TEXT_GRID_H
41 #define _GLS_TEXT_GRID_H
42 
43 #include "gls_gl.h"
44 #include "gls_text.h"
45 #include "unhide_globals.h"
46 #include <string>
47 
48 #ifdef GLES
49 # include "gls_quad_storage.h"
50 #endif
51 
52 //////////////////// Provides support for creating DLLs ////////////////////////
53 #if( defined( GLSGEN_EXPORT_GLSTEXTGRID ) || defined( GLSGEN_IMPORT_GLSTEXTGRID ) || defined( GLSGEN_GLSTEXTGRID_EXPORT_GENERATED ) || defined( GLS_IMPORT_GENERATED ) ) \
54  && defined( _MSC_VER )
55 # if defined( GLSGEN_EXPORT_GLSTEXTGRID ) || defined( GLSGEN_GLSTEXTGRID_EXPORT_GENERATED )
56 # define GLSGEN_GLSTEXTGRID_EXPORT __declspec( dllexport )
57 # else
58 # define GLSGEN_GLSTEXTGRID_EXPORT __declspec( dllimport )
59 # endif
60 #else
61 # define GLSGEN_GLSTEXTGRID_EXPORT
62 #endif
63 ///////////////////////////////////////////////////////////////////////////////
64 
65 #define LIB_BASE_NAME "gls_text_grid"
66 #include "gls_auto_lib.h"
67 #undef LIB_BASE_NAME
68 
69 //===========================================================================
70 // MACROS
71 //===========================================================================
72 
73 #define SET_CHAR_RANGE( startCol, startRow, len, attribute, value ) \
74  { \
75  unsigned int charsSet( 0 ); \
76  unsigned int col( startCol ); \
77  bool notifyChanged = false; \
78  \
79  if( startCol < _cols && startRow < _rows ) \
80  { \
81  for( unsigned int row = startRow; ( row < _rows ) && ( charsSet < len ); ++row ) \
82  { \
83  for( ; ( col < _cols ) && ( charsSet < len ); ++col ) \
84  { \
85  if( _chars[ IndexOf( col, row ) ].attribute != value ) \
86  { \
87  _chars[ IndexOf( col, row ) ].attribute = value; \
88  notifyChanged = true; \
89  } \
90  ++charsSet; \
91  } \
92  col = 0; \
93  } \
94  } \
95  if( notifyChanged ) \
96  { \
97  EnablePerCharAttribs(); \
98  InvalidatePainter(); \
99  } \
100  }
101 
102 //===========================================================================
103 // BEGIN NAMESPACE
104 //===========================================================================
105 namespace disti
106 {
107 #ifdef GLES
108 // Forward Declaration
109 class GlsGloFileAttribute;
110 #endif
111 
112 // Initializers for text
113 enum
114 {
115  GLS_TEXT_GRID_SIZE = GLS_LAST_TEXT_INITIALIZER + 1,
116  GLS_TEXT_GRID_LEFT_TO_RIGHT
117 };
118 
119 //===========================================================================
120 /**
121 * The GlsTextGrid
122 */
123 class GlsTextGrid : public GlsText
124 {
125 protected:
126  void DrawText();
127 
128 #ifdef GLES
129  GlsQuadListVC_3D _backgrounds;
130  GlsQuadListVCT_2D _shadows;
131  GlsQuadListVC_3D _shadowLines;
132  GlsQuadListVCT_2D _characters;
133  GlsQuadListVC_3D _lines;
134 
135  void PopulateQuadStorage();
136 #endif
137 
138 public:
139  DISTI_DEPRECATED( "This identifier is forbidden by the C++ standard. Use BaseClass instead." )
140  typedef GlsText _BaseClass;
141  typedef GlsText BaseClass;
142 
143  friend class GlsTextGridEditor;
144 
145  /** Class Constructor. */
146  GLSGEN_GLSTEXTGRID_EXPORT GlsTextGrid();
147 
148  /** Copy Constructor. */
149  GLSGEN_GLSTEXTGRID_EXPORT GlsTextGrid( const GlsTextGrid& that, const bool generateNames );
150 
151  /** Class Deconstructor. */
152  virtual GLSGEN_GLSTEXTGRID_EXPORT ~GlsTextGrid();
153 
154  // Need to declare using all base class methods that we overload
155  using BaseClass::Baseline;
156  using BaseClass::BgColor;
157  using BaseClass::CellHeight;
158  using BaseClass::CellWidth;
159  using BaseClass::Char;
160  using BaseClass::CharAttr;
163  using BaseClass::Erase;
164  using BaseClass::FauxBold;
165  using BaseClass::Inverse;
166  using BaseClass::StrikeThru;
167  using BaseClass::String;
168  using BaseClass::TextColor;
169  using BaseClass::Underline;
170 
171  virtual GLSGEN_GLSTEXTGRID_EXPORT void SetAvailableAttributes( unsigned int value ) DISTI_METHOD_OVERRIDE;
172 
173  /** Sets the baseline shift for one character
174  * \param col X coordinate of the character to set
175  * \param row Y coordinate of the character to set
176  * \param baselineShift multiplier used to shift the baseline.
177  */
178  GLSGEN_GLSTEXTGRID_EXPORT void Baseline(
179  unsigned int col,
180  unsigned int row,
181  float baselineShift );
182 
183  /** Sets the baseline shift for a range of characters
184  * \param startCol X coordinate of the first character to set
185  * \param startRow Y coordinate of the first character to set
186  * \param len Number of characters to set
187  * \param baselineShift multiplier used to shift the baseline.
188  */
189  GLSGEN_GLSTEXTGRID_EXPORT void Baseline(
190  unsigned int startCol,
191  unsigned int startRow,
192  unsigned int len,
193  float baselineShift );
194 
195  /** Sets the cell background color for one character.
196  * \param col X coordinate of the character to set
197  * \param row Y coordinate of the character to set
198  * \param color The background color to set
199  */
200  GLSGEN_GLSTEXTGRID_EXPORT void BgColor(
201  unsigned int col,
202  unsigned int row,
203  const GlsColor& color );
204 
205  /** Sets the cell background color for a range of characters.
206  * \param startCol X coordinate of the first character to set
207  * \param startRow Y coordinate of the first character to set
208  * \param len Number of characters to set
209  * \param color The background color to set
210  */
211  GLSGEN_GLSTEXTGRID_EXPORT void BgColor(
212  unsigned int startCol,
213  unsigned int startRow,
214  unsigned int len,
215  const GlsColor& color );
216 
217  /* Peform any necessary non-draw calculations like resizing
218  * the grid.
219  * \param time The time since the start of program execution
220  */
221  virtual GLSGEN_GLSTEXTGRID_EXPORT void Calculate( double time ) DISTI_METHOD_OVERRIDE;
222 
223  /** Sets the character code for one character
224  * \param col X coordinate of the character to set
225  * \param row Y coordinate of the character to set
226  * \param code The ASCII character code to set
227  */
228  GLSGEN_GLSTEXTGRID_EXPORT void Char( unsigned int col, unsigned int row, Char_t code );
229 
230  /** Sets the character code for a range of characters
231  * \param startCol X coordinate of the first character to set
232  * \param startRow Y coordinate of the first character to set
233  * \param len Number of characters to set
234  * \param code The ASCII character code to set
235  */
236  GLSGEN_GLSTEXTGRID_EXPORT void Char(
237  unsigned int startCol,
238  unsigned int startRow,
239  unsigned int len,
240  Char_t code );
241 
242  /** \return a particular cell's character attributes. */
243  CharAttr_t CharAttr( unsigned int col, unsigned int row ) const
244  {
245  return _chars[ IndexOf( col, row ) ];
246  }
247 
248  /** Sets the scale factor of one character NOTE: This is the size of the character in its
249  * cell not the overall scale of the entire object
250  * \param col X coordinate of the character to set
251  * \param row Y coordinate of the character to set
252  * \param newScale The new scale factor of the characters (0.0 < newScale <= 1.0)
253  */
254  GLSGEN_GLSTEXTGRID_EXPORT void CharScaling(
255  unsigned int col,
256  unsigned int row,
257  float newScale );
258 
259  /** Sets the scale factor of a range of characters NOTE: This is the size of the character in its
260  * cell not the overall scale of the entire object
261  * \param startCol X coordinate of the first character to set
262  * \param startRow Y coordinate of the first character to set
263  * \param len Number of characters to set
264  * \param newScale The new scale factor of the characters (0.0 < newScale <= 1.0)
265  */
266  GLSGEN_GLSTEXTGRID_EXPORT void CharScaling(
267  unsigned int startCol,
268  unsigned int startRow,
269  unsigned int len,
270  float newScale );
271 
272  /** Sets the horizontal character spacing for one character
273  * 1.0 is the default spacing 2.0 would be twice the normal spacing
274  * \param col X coordinate of the character to set
275  * \param row Y coordinate of the character to set
276  * \param horizontalSpacing The horizontalSpacing value
277  */
278  GLSGEN_GLSTEXTGRID_EXPORT void CharSpacing(
279  unsigned int col,
280  unsigned int row,
281  float horizontalSpacing );
282 
283  /** Sets the horizontal character spacing for a range of characters
284  * 1.0 is the default spacing 2.0 would be twice the normal spacing
285  * \param startCol X coordinate of the first character to set
286  * \param startRow Y coordinate of the first character to set
287  * \param len Number of characters to set
288  * \param horizontalSpacing The horizontalSpacing value
289  */
290  GLSGEN_GLSTEXTGRID_EXPORT void CharSpacing(
291  unsigned int startCol,
292  unsigned int startRow,
293  unsigned int len,
294  float horizontalSpacing );
295 
296  /* See base class */
297  virtual GLSGEN_GLSTEXTGRID_EXPORT DisplayObject* CloneObject( bool generateNames = false ) DISTI_METHOD_OVERRIDE;
298 
299  /** Gets the width of this object in characters
300  * \return The width of this object in characters (number of columns) */
301  unsigned int Columns() const
302  {
303  return _cols;
304  }
305 
306  /** Sets the number of columns the text grid contains.
307  * \param newCols new number of columns to size the grid with.
308  */
309  void Columns( unsigned int newCols )
310  {
311  Size( newCols, _rows );
312  }
313 
314  /* See base class */
315  virtual GLSGEN_GLSTEXTGRID_EXPORT void CopyGeometry( DisplayObject* src ) DISTI_METHOD_OVERRIDE;
316 
317  /* See base class */
318  GLSGEN_GLSTEXTGRID_EXPORT virtual void CopyProperties( DisplayObject* src ) DISTI_METHOD_OVERRIDE;
319 
320 #ifdef GLES
321  /* See base class */
322  virtual GLSGEN_GLSTEXTGRID_EXPORT void PreDraw( const OpenGLMatrices& current, Culler& culler ) DISTI_METHOD_OVERRIDE;
323 #endif
324 
325  /* See base class */
326  virtual GLSGEN_GLSTEXTGRID_EXPORT void Draw( void ) DISTI_METHOD_OVERRIDE;
327 
328  /** Erase one character.
329  * \param col X coordinate of the character to erase
330  * \param row Y coordinate of the character to erase
331  */
332  GLSGEN_GLSTEXTGRID_EXPORT void Erase( unsigned int col, unsigned int row );
333 
334  /** Erase all characters after a given position.
335  * \param startCol X coordinate of the first character to erase
336  * \param startRow Y coordinate of the first character to erase
337  * \param rows Number of rows to erase
338  */
339  GLSGEN_GLSTEXTGRID_EXPORT void Erase(
340  unsigned int startCol,
341  unsigned int startRow,
342  unsigned int rows );
343 
344  /** Erase a range of characters.
345  * \param startCol X coordinate of the first character to erase
346  * \param startRow Y coordinate of the first character to erase
347  * \param endCol X coordinate of the last character to erase
348  * \param endRow Y coordinate of the last character to erase.
349  */
350  GLSGEN_GLSTEXTGRID_EXPORT void Erase(
351  unsigned int startCol,
352  unsigned int startRow,
353  unsigned int endCol,
354  unsigned int endRow );
355 
356  /** Set the bold state on or off for one character
357  * \param col X coordinate of the character to set
358  * \param row Y coordinate of the character to set
359  * \param bold Bold state
360  */
361  GLSGEN_GLSTEXTGRID_EXPORT void FauxBold( unsigned int col, unsigned int row, bool bold );
362 
363  /** Set the bold state on or off for a range of characters
364  * \param startCol X coordinate of the first character to set
365  * \param startRow Y coordinate of the first character to set
366  * \param len Number of characters to set
367  * \param bold Bold state
368  */
369  GLSGEN_GLSTEXTGRID_EXPORT void FauxBold(
370  unsigned int startCol,
371  unsigned int startRow,
372  unsigned int len,
373  bool bold );
374 
375 #ifndef GLES
376  /* See base class */
377  virtual GLSGEN_GLSTEXTGRID_EXPORT InterfaceListType* GetCppInterfaceDescription( InterfaceListType* addToThisList = NULL ) DISTI_METHOD_OVERRIDE;
378 
379  /* See base class */
380  virtual GLSGEN_GLSTEXTGRID_EXPORT void GetCppInterfaceDescriptionFree( InterfaceListType* array ) DISTI_METHOD_OVERRIDE;
381 #endif
382 
383  /* See base class */
384  virtual GLSGEN_GLSTEXTGRID_EXPORT void Initialize();
385 
386  /** Set the inverse video state on or off for one character
387  * \param col X coordinate of the character to set
388  * \param row Y coordinate of the character to set
389  * \param inverse inverse video state
390  */
391  GLSGEN_GLSTEXTGRID_EXPORT void Inverse( unsigned int col, unsigned int row, bool inverse );
392 
393  /** Set the inverse video state on or off for a range of characters
394  * \param startCol X coordinate of the first character to set
395  * \param startRow Y coordinate of the first character to set
396  * \param len Number of characters to set
397  * \param inverse inverse video state
398  */
399  GLSGEN_GLSTEXTGRID_EXPORT void Inverse(
400  unsigned int startCol,
401  unsigned int startRow,
402  unsigned int len,
403  bool inverse );
404 
405  /** \return The length of a given line in characters. This will search the
406  * specified row until a \n or NULL is encountered or until it reaches the
407  * end of the row (number of columns in the grid).
408  * \param row The row to return the length of
409  */
410  GLSGEN_GLSTEXTGRID_EXPORT unsigned int LineLength( unsigned int row ) const;
411 
412  /** The number of rows in this text grid
413  * \return The number of rows in this text grid */
414  unsigned int Rows() const
415  {
416  return _rows;
417  }
418 
419  /** Change the number of rows the text grid contains.
420  * \param newRows new number of rows to size the grid with.
421  */
422  void Rows( unsigned int newRows )
423  {
424  Size( _cols, newRows );
425  }
426 
427  /* Unhides base class implementation. */
428  using BaseClass::Scale;
429 
430  /** Scales the object, either the handleBar, or the Anchor is
431  * used to translate the object, not both. Anchor takes
432  * presidence, if it is set HandleBar is ignored.
433  * The footprint is different from the 2D scale so the compiler can destinguish the two.
434  * \param px Value of the percentage of scale in x-axis
435  * \param py Value of the percentage of scale in y-axis
436  * \param pz Value of the percentage of scale in z-axis
437  * \param anchor Anchor from which to scale object relative to
438  * \param handleBar Vertex that is being dragged
439  */
440  virtual GLSGEN_GLSTEXTGRID_EXPORT void Scale( float px, float py, float pz, Vertex* anchor, int handleBar ) DISTI_METHOD_OVERRIDE;
441 
442  /* See base class */
443  virtual GLSGEN_GLSTEXTGRID_EXPORT void SetValue( int spec, va_list& args ) DISTI_METHOD_OVERRIDE;
444 
445  /* See base class */
446  virtual GLSGEN_GLSTEXTGRID_EXPORT void SetVertices( unsigned int nPoints, Vertex* vertices ) DISTI_METHOD_OVERRIDE;
447 
448  /** Sets the number of rows and columns for this object
449  * \param cols The new number of columns
450  * \param rows The new number of rows
451  */
452  GLSGEN_GLSTEXTGRID_EXPORT void Size( unsigned int cols, unsigned int rows );
453 
454  /** Sets the strikethru state for one character
455  * \param col X coordinate of the character to set
456  * \param row Y coordinate of the character to set
457  * \param strike Whether or not set strike to fit
458  */
459  GLSGEN_GLSTEXTGRID_EXPORT void StrikeThru( unsigned int col, unsigned int row, bool strike );
460 
461  /** Sets the strikethru state for a range of characters
462  * \param startCol X coordinate of the first character to set
463  * \param startRow Y coordinate of the first character to set
464  * \param len Number of characters to set
465  * \param strike Whether or not set strike to fit
466  */
467  GLSGEN_GLSTEXTGRID_EXPORT void StrikeThru(
468  unsigned int startCol,
469  unsigned int startRow,
470  unsigned int len,
471  bool strike );
472 
473  /** Sets the ASCII string to be displayed for this object starting
474  * at an col,row coordinate and wrapping on newlines and column count
475  * \param startCol X coordinate (column) to start at
476  * \param startRow Y coordinate (row) to start at
477  * \param s STD Template Library string to print
478  */
479  GLSGEN_GLSTEXTGRID_EXPORT void String(
480  unsigned int startCol,
481  unsigned int startRow,
482  const std::string& s );
483 
484  /** Sets the ASCII string to be displayed for this object starting
485  * at an col,row coordinate and wrapping on newlines and column count
486  * \param startCol X coordinate (column) to start at
487  * \param startRow Y coordinate (row) to start at
488  * \param s C style string to print
489  */
490  void String( unsigned int startCol, unsigned int startRow, const char* s )
491  {
492  String( startCol, startRow, std::string( s ) );
493  }
494 
495  /** Sets the foreground color for one character
496  * \param col X coordinate of the character to set
497  * \param row Y coordinate of the character to set
498  * \param color The foreground color to set
499  */
500  GLSGEN_GLSTEXTGRID_EXPORT void TextColor(
501  unsigned int col,
502  unsigned int row,
503  const GlsColor& color );
504 
505  /** Sets the foreground color for a range of characters
506  * \param startCol X coordinate of the first character to set
507  * \param startRow Y coordinate of the first character to set
508  * \param len Number of characters to set
509  * \param color The foreground color to set
510  */
511  GLSGEN_GLSTEXTGRID_EXPORT void TextColor(
512  unsigned int startCol,
513  unsigned int startRow,
514  unsigned int len,
515  const GlsColor& color );
516 
517  /** Returns the foreground color for the specified character.
518  * If no character is specified, the color at 0,0 will be returned.
519  * \param col X coordinate of the character of interest
520  * \param row Y coordinate of the character of interest
521  * \return The requested color
522  */
523  GLSGEN_GLSTEXTGRID_EXPORT GlsColor TextColor(
524  unsigned int col = 0,
525  unsigned int row = 0 ) const;
526 
527  /** Turns on/off underlines for one character
528  * \param col X coordinate of the character of interest
529  * \param row Y coordinate of the character of interest
530  * \param underline Whether or not to enable underline
531  */
532  GLSGEN_GLSTEXTGRID_EXPORT void Underline(
533  unsigned int col,
534  unsigned int row,
535  bool underline );
536 
537  /** Turns on/off underlines for a range character
538  * \param startCol X coordinate of the first character to set
539  * \param startRow Y coordinate of the first character to set
540  * \param len Number of characters to set
541  * \param underline Whether or not to enable underline
542  */
543  GLSGEN_GLSTEXTGRID_EXPORT void Underline(
544  unsigned int startCol,
545  unsigned int startRow,
546  unsigned int len,
547  bool underline );
548 
549  /** Print a string into this text object starting at 0,0 and proceeding Left
550  * to right. Wraps at newline characters. Does not change the color or any
551  * other modes. Replaces the entire string. If substring replacement is desired,
552  * use VaString(col, row, format) instead.
553  * \param format printf style varargs formatting string.
554  */
555  GLSGEN_GLSTEXTGRID_EXPORT void VaString( const char* format, ... );
556 
557  /** Print a string into this text object starting at col,row and proceeding Left
558  * to right. Assumes current string does not contain newline characters.
559  * If a newline is encountered it will be overwritten.
560  * Does not change the color or any other modes. Just inserts/overwrites
561  * characters.
562  * This replaces a substring within the current string. If you want full string replacement
563  * use VaString(format)
564  * \param startCol X position (column)
565  * \param startRow Y position (row)
566  * \param format printf style varargs formatting string.
567  */
568  GLSGEN_GLSTEXTGRID_EXPORT void VaString(
569  unsigned int startCol,
570  unsigned int startRow,
571  const char* format,
572  ... );
573 
574  /** Print a string into this text object starting at col,row and proceeding Left to right
575  * Assumes current string does not contain newline characters. If a newline is encountered it
576  * will be overwritten.
577  * Inserts/overwrites characters and changes the color.
578  * This replaces a substring within the current string. If you want full string replacement
579  * use VaString(format)
580  * (TextDisplay compatability method)
581  * \param col X position (column)
582  * \param row Y position (row)
583  * \param rgba The color to set
584  * \param format printf style varargs formatting string.
585  * \since GL Studio 6.0.1
586  */
587  GLSGEN_GLSTEXTGRID_EXPORT void VaString(
588  unsigned int col,
589  unsigned int row,
590  unsigned char rgba[],
591  const char* format,
592  ... );
593 
594  //-----------------------------------------------------------------------
595  //-----------------------------------------------------------------------
596  // Routines for comapability with TextDisplay.gls
597  //-----------------------------------------------------------------------
598  //-----------------------------------------------------------------------
599 
600  /** Enable/disable centering mode
601  * (TextDisplay compatability method)
602  * \param flag True if text should be centered, false if it should be
603  * left justified
604  * \deprecated use Justify instead
605  */
606  GLSGEN_GLSTEXTGRID_EXPORT void Center( bool flag )
607  {
608  Justify( CENTER );
609  }
610 
611  /** Clears all of the characters and resets the attributes of all
612  * characters (TextDisplay compatability method)
613  * \deprecated use Erase instead
614  */
615  GLSGEN_GLSTEXTGRID_EXPORT void Clear( void )
616  {
617  Erase();
618  }
619 
620  /** Clears all of the characters. Does NOT reset the attributes
621  * of the characters (TextDisplay compatability method)
622  * \deprecated
623  */
624  GLSGEN_GLSTEXTGRID_EXPORT void ClearChars( void )
625  {
626  _text.erase();
627  SetRebuild();
628  }
629 
630  /** Set an individual character at the given position
631  * Assumes current string does not contain newline characters.
632  * If a newline character is encountered in the current string it will be overwritten.
633  * (TextDisplay compatability method)
634  * \param col X position (column)
635  * \param row Y position (row)
636  * \param ch ASCII code of the character
637  * \deprecated use Char instead
638  */
639  GLSGEN_GLSTEXTGRID_EXPORT void SetChar( unsigned int col, unsigned int row, char ch )
640  {
641  Char( col, row, Char_t( ch ) );
642  }
643 
644  /** Set an individual character at the given position. Also set its color.
645  * Assumes current string does not contain newline characters.
646  * If a newline character is encountered in the current string it will be overwritten.
647  * (TextDisplay compatability method)
648  * \param col X position (column)
649  * \param row Y position (row)
650  * \param ch ASCII code of the character
651  * \param rgba Color value for character
652  * \deprecated use Char instead
653  */
654  GLSGEN_GLSTEXTGRID_EXPORT void SetChar(
655  unsigned int col,
656  unsigned int row,
657  char ch,
658  unsigned char rgba[] )
659  {
660  Char( col, row, Char_t( ch ) );
661  TextColor( col, row, GlsColor( rgba ) );
662  }
663 
664  /** SetColor() meaning has changed, now use TextColor */
665 
666  /** Print a string into this text object starting at 0,0 and proceeding Left
667  * to right. Wraps at newline characters. Does not change the color or any
668  * other modes. Replaces the entire string. If substring replacement is desired, use String(col, row, s).
669  * (TextDisplay compatability method)
670  * \param s The string to print
671  * \deprecated use String instead
672  */
673  GLSGEN_GLSTEXTGRID_EXPORT void SetString( const char* s )
674  {
675  String( s );
676  }
677 
678  /** Print a string into this text object starting at col,row and proceeding
679  * Assumes current string does not contain newline characters.
680  * If a newline is encountered in the current string it will be overwritten. Does not change the color
681  * or any other modes. Just inserts/overwrites characters.
682  * This replaces a substring within the current string. If you want full string replacement
683  * use String(s)
684  * (TextDisplay compatability method)
685  * \param col X position (column)
686  * \param row Y position (row)
687  * \param s The string to print
688  * \deprecated use String instead
689  */
690  GLSGEN_GLSTEXTGRID_EXPORT void SetString( unsigned int col, unsigned int row, const char* s )
691  {
692  String( col, row, s );
693  }
694 
695  /** Print a string into this text object starting at col,row and proceeding
696  * Assumes current string does not contain newline characters.
697  * If a newline is encountered in the current string it will be overwritten.
698  * Inserts/overwrites characters and changes the color.
699  * This replaces a substring within the current string. If you want full string replacement
700  * use String(s)
701  * (TextDisplay compatability method)
702  * \param col X position (column)
703  * \param row Y position (row)
704  * \param rgba The color to set
705  * \param s The string to print
706  * \deprecated use String instead
707  */
708  GLSGEN_GLSTEXTGRID_EXPORT void SetString(
709  unsigned int col,
710  unsigned int row,
711  unsigned char rgba[],
712  const char* s );
713 
714  /** Print a string into this text object starting at 0,0 and proceeding Left to right
715  * Assumes current string does not contain newline characters. If a newline is encountered in the
716  * current string it will be overwritten. Does not change the color or any other modes.
717  * Replaces the entire string. If substring replacement is desired, use VaString(col, row, format).
718  * (TextDisplay compatability method)
719  * \param format printf style varargs formatting string.
720  * \deprecated use VaString instead
721  */
722  GLSGEN_GLSTEXTGRID_EXPORT void VaSetString( const char* format, ... );
723 
724  /** Print a string into this text object starting at col,row and proceeding Left to right
725  * Assumes current string does not contain newline characters. Does not change the color or any other modes. Just
726  * inserts/overwrites characters.
727  * This replaces a substring within the current string. If you want full string replacement
728  * use VaString(format)
729  * (TextDisplay compatability method)
730  * \param col X position (column)
731  * \param row Y position (row)
732  * \param format printf style varargs formatting string.
733  * \deprecated use VaString instead
734  */
735  GLSGEN_GLSTEXTGRID_EXPORT void VaSetString(
736  unsigned int col,
737  unsigned int row,
738  const char* format,
739  ... );
740 
741  /** Print a string into this text object starting at col,row and proceeding Left to right
742  * Assumes current string does not contain newline characters. If a newline is
743  * encountered in the current string it will be overwritten.
744  * Inserts/overwrites characters and changes the color.
745  * This replaces a substring within the current string. If you want full string replacement
746  * use VaString(format)
747  * (TextDisplay compatability method)
748  * \param col X position (column)
749  * \param row Y position (row)
750  * \param rgba The color to set
751  * \param format printf style varargs formatting string.
752  * \deprecated use VaString instead
753  */
754  GLSGEN_GLSTEXTGRID_EXPORT void VaSetString(
755  unsigned int col,
756  unsigned int row,
757  unsigned char rgba[],
758  const char* format,
759  ... );
760 
761  /** Determine if the text direction is set to left->right or right->left
762  * \return true if if the text direction is set to left->right else false for right->left
763  */
764  GLSGEN_GLSTEXTGRID_EXPORT bool LeftToRight( void );
765 
766  /** Set the text direction
767  * \param leftToRight true for left->right else false for right->left
768  */
769  GLSGEN_GLSTEXTGRID_EXPORT void LeftToRight( bool leftToRight );
770 
771 protected:
772 #ifdef GLES
773  /** Set a single attribute from the GLO file.
774  * \param data The attribute to set and its associated data.
775  */
776  virtual GLSGEN_GLSTEXTGRID_EXPORT void SetFromGloData( GlsGloFileAttribute& data ) DISTI_METHOD_OVERRIDE;
777 #endif
778 
779  /** info for one row of text in the display */
780  struct RowInfo
781  {
782  unsigned int startingIndex; /**< starting text index into the _unicodeText for row
783  * else GLSUINT32_MAX if row has no characters */
784  unsigned int length; /**< the number of characters in row */
785  float pixelWidth; /**< the width of row in pixels */
786  };
787 
788  /** Number of columns of characters in the text grid (line length) */
789  unsigned int _cols;
790 
791  /** Number of rows of characters in the text grid (number of lines) */
792  unsigned int _rows;
793 
794  bool _numRowsChanged;
795 
796  /** true -> grid will draw characters using "per character attributes" else
797  * false -> all characters will be drawn using the first character's attribute
798  * NOTE: This defaults to false and automatically enables to true if the user calls
799  * a method that requires per character attributes
800  */
802 
803  RowInfo* _rowInfo; /**< array ( _rows number of elements ) of RowInfo */
804 
805  bool _leftToRight; /**< true to render characters from left to right else
806  * false for right to left */
807 
808  UTF16String _unicodeText; /**< unicode version of _text from base class, updated by CalculateRowData */
809 
810  /**
811  * Erase a single character at a given index. Use TextIndexOf to find the character using coordinates.
812  * \param textIndex index of the character to erase
813  */
814  GLSGEN_GLSTEXTGRID_EXPORT void EraseIndex( unsigned int textIndex );
815 
816  /**
817  * Enable per character attribute drawing for this grid
818  */
819  GLSGEN_GLSTEXTGRID_EXPORT void EnablePerCharAttribs( void )
820  {
821  if( !_perCharAttribs )
822  {
823  _perCharAttribs = true;
824  SetRebuild();
825  }
826  }
827 
828  /**
829  * Allocate a text buffer of the appropriate size for this grid and output snprintf style format
830  * into the buffer
831  * \param format snprintf style format spec
832  * \param args arguments for sprintf style formatting
833  * \return formatted textbuffer ( must be deleted by caller )
834  */
835  GLSGEN_GLSTEXTGRID_EXPORT char* FormatVarArgList( const char* format, va_list args );
836 
837  //-----------------------------------------------------------------------
838  /**
839  */
840  GLSGEN_GLSTEXTGRID_EXPORT float BoxHeight();
841 
842  //-----------------------------------------------------------------------
843  /**
844  */
845  GLSGEN_GLSTEXTGRID_EXPORT float BoxWidth();
846 
847  /** Converts col,row into linear index
848  * \param col The column number
849  * \param row The line number (row)
850  * \return The linear index of line & column
851  */
852  unsigned int IndexOf( unsigned int col, unsigned int row ) const
853  {
854  unsigned int index( 0 );
855 
856  if( col < _cols && row < _rows )
857  {
858  index = ( row * _cols ) + col;
859  }
860  else
861  {
862  index = _rows * _cols;
863  }
864  return index;
865  }
866 
867  //-----------------------------------------------------------------------
868  /**
869  */
870  GLSGEN_GLSTEXTGRID_EXPORT float JustificationOffset( unsigned int row );
871 
872  //-----------------------------------------------------------------------
873  /**
874  */
875  GLSGEN_GLSTEXTGRID_EXPORT float LinePixelWidth( unsigned int line, float cellWidth ) const;
876 
877  //-----------------------------------------------------------------------
878  /**
879  */
880  GLSGEN_GLSTEXTGRID_EXPORT void Rebuild();
881 
882  //-----------------------------------------------------------------------
883  /**
884  */
885  GLSGEN_GLSTEXTGRID_EXPORT void RecalcCellSize();
886 
887  //-----------------------------------------------------------------------
888  /**
889  */
890  GLSGEN_GLSTEXTGRID_EXPORT void RecalcVertices();
891 
892  //-----------------------------------------------------------------------
893  /**
894  */
895  GLSGEN_GLSTEXTGRID_EXPORT void ResizeGrid();
896 
897  /** Converts col,row into linear index returning the end of the string if this index would go beyond it
898  * \param col The column number
899  * \param row The line number (row)
900  * \param startRow The row to start the search from
901  * \return The linear index of line & column
902  */
903  GLSGEN_GLSTEXTGRID_EXPORT
904  unsigned int TextIndexOf( unsigned int col, unsigned int row, unsigned int startRow = 0 ) const;
905 
906  /** Converts col,row into grid index returning the end of the string if this index would go outside the bounds of the grid
907  * \param col The column number
908  * \param row The line number (row)
909  * \return The grid index of line & column
910  */
911  GLSGEN_GLSTEXTGRID_EXPORT
912  unsigned int GridIndexOf( unsigned int col, unsigned int row ) const;
913 
914  /** Populate the _rowInfo array based on the current display string
915  * \pre none
916  * \post _rowInfo array is populated based on the current display string
917  */
918  GLSGEN_GLSTEXTGRID_EXPORT virtual void CalculateRowData( void );
919 
920  /** helper class for processing underline and strike-thru when drawing text grid */
922  {
923  public:
924  /**
925  * \param cellWidth width of a character cell in the text grid
926  * \param cellHeight height of a character cell in the text grid
927  * \param cellYScale unused
928  * \param shadow true if text grid has shadow enabled
929  * \param shadowOffset offset for shadow
930  * \param shadowColor color of shadow in text grid
931  * \param underlineOffset offset of underline
932  * \param underlineSize size of underline
933  * \param halo true if text grid has halo enabled
934  * \param haloOffset offset for halo
935  * \param haloColor color of halo in text grid
936  * \param leftToRight true if text flows left to right else false for right to left
937  */
938  UnderlineStrikeThruHelper( float cellWidth, float cellHeight, float cellYScale, bool shadow, const Vector& shadowOffset, const GlsColor& shadowColor,
939  float underlineOffset, float underlineSize, bool halo, float haloOffset, GlsColor haloColor, bool leftToRight );
940 
941  /**
942  * Setup to process a new row in the text grid
943  */
944  void NewRow( void );
945 
946  /**
947  * Pre Process the given character attributes
948  * \param charAttr attributes in question
949  * \param cellX x coord of character cell
950  * \param nextCellX x coord of character cell one past the given character
951  * \param charY y coord of character
952  * \param endOfLine true if character was the end of the current line
953  */
954  void ProcessCharacter( const CharAttr_t& charAttr, float cellX, float nextCellX, float charY, bool endOfLine );
955 
956  /**
957  * Render the line segments for the underline / strikethru
958  */
959 #ifdef GLES
960  void RenderLineSegments( GlsQuadListVC_3D& quadStorage );
961 #else
962  void RenderLineSegments( void );
963 #endif
964  void IgnoreShadowAndHalo()
965  {
966  _allowShadow = false;
967  }
968 
969  protected:
970  // cell constants
971  const float _cellWidth;
972  const float _cellHeight;
973 
974  // shadow constants
975  const bool _shadow;
976  const Vector _shadowOffset;
977  const GlsColor _shadowColor;
978  bool _allowShadow;
979 
980  // underline constants
981  const float _underlineOffset;
982  const float _underlineSize;
983 
984  // halo constants
985  const bool _halo;
986  const float _haloOffset;
987  const GlsColor _haloColor;
988 
989  // left to right
990  const bool _leftToRight;
991 
992  // state vars for underline processing
993  float _underlineX1, _underlineX2, _underlineY, _underlineScale;
994  GlsColor _underlineColor;
995  bool _underlineOn;
996 
997  // state vars for strike-thru processing
998  float _strikeX1, _strikeX2, _strikeY, _strikeScale;
999  GlsColor _strikeColor;
1000  bool _strikeOn;
1001 
1002  // line segments to draw
1003  typedef std::list<LineSegment_t> LineSegmentCont_t;
1004  LineSegmentCont_t _lineSegments;
1005  };
1006 
1007 private:
1008  /* See base class */
1009  void OnCellDimensionChanged() DISTI_METHOD_OVERRIDE
1010  {
1011  RecalcVertices();
1012  }
1013 
1014  GlsTextGrid& operator=( const GlsTextGrid& );
1015  GlsTextGrid( const GlsTextGrid& );
1016 };
1017 
1018 } // namespace disti
1019 
1020 #endif
The DistiUnhideGlobalsDummyClass class.
Definition: cull.h:49
char * FormatVarArgList(const char *format, va_list args)
float Baseline()
void SetChar(unsigned int col, unsigned int row, char ch, unsigned char rgba[])
Definition: gls_text_grid.h:654
void SetString(unsigned int col, unsigned int row, const char *s)
Definition: gls_text_grid.h:690
Definition: vertex.h:409
Definition: gls_text_grid.h:123
#define DISTI_DEPRECATED(msg)
Defines whether this compiler supports the C++14 deprecated attribute.
Definition: gls_cpp_lang_support.h:436
UnderlineStrikeThruHelper(float cellWidth, float cellHeight, float cellYScale, bool shadow, const Vector &shadowOffset, const GlsColor &shadowColor, float underlineOffset, float underlineSize, bool halo, float haloOffset, GlsColor haloColor, bool leftToRight)
Definition: dynamic_array.h:66
Class to contain current OpenGL view, projection and draw matrices.
Definition: util.h:473
unsigned int _cols
Definition: gls_text_grid.h:789
virtual void SetVertices(unsigned int nPoints, Vertex *vertices) DISTI_METHOD_OVERRIDE
virtual void PreDraw(const OpenGLMatrices &current, Culler &culler)
The disti::GlsQuadListVC_3D and GlsQuadListVCT_2D classes.
bool _perCharAttribs
Definition: gls_text_grid.h:801
virtual InterfaceListType * GetCppInterfaceDescription(InterfaceListType *addToThisList=NULL) DISTI_METHOD_OVERRIDE
Attributes for each character position in the grid.
Definition: gls_text.h:177
unsigned int GridIndexOf(unsigned int col, unsigned int row) const
void EnablePerCharAttribs(void)
Definition: gls_text_grid.h:819
GlsColor TextColor()
Definition: display.h:98
unsigned int Columns() const
Definition: gls_text_grid.h:301
Definition: gls_text.h:151
std::string _text
Definition: gls_text.h:711
CharAttrCont_t _chars
Definition: gls_text.h:656
void EraseIndex(unsigned int textIndex)
Definition: gls_quad_storage.h:158
GlsColor BgColor()
The disti::GlsText class.
virtual void GetCppInterfaceDescriptionFree(InterfaceListType *array) DISTI_METHOD_OVERRIDE
void ProcessCharacter(const CharAttr_t &charAttr, float cellX, float nextCellX, float charY, bool endOfLine)
unsigned int LineLength(unsigned int row) const
void Char(Char_t code)
bool _leftToRight
Definition: gls_text_grid.h:805
void SetChar(unsigned int col, unsigned int row, char ch)
Definition: gls_text_grid.h:639
Definition: gls_glo_file.h:988
float pixelWidth
Definition: gls_text_grid.h:785
Justify_t Justify() const
Definition: gls_text.h:425
virtual void Calculate(double time) DISTI_METHOD_OVERRIDE
float CellWidth() const
Definition: gls_text.h:270
virtual void CalculateRowData(void)
Definition: gls_text_grid.h:921
RowInfo * _rowInfo
Definition: gls_text_grid.h:803
void VaString(const char *format,...)
void Char(unsigned int col, unsigned int row, Char_t code)
virtual void SetValue(int spec, va_list &args) DISTI_METHOD_OVERRIDE
void Clear(void)
Definition: gls_text_grid.h:615
unsigned int startingIndex
Definition: gls_text_grid.h:782
Definition: gls_color.h:53
unsigned int IndexOf(unsigned int col, unsigned int row) const
Definition: gls_text_grid.h:852
virtual DisplayObject * CloneObject(bool generateNames=false) DISTI_METHOD_OVERRIDE
unsigned int Rows() const
Definition: gls_text_grid.h:414
Definition: gls_text_grid.h:780
void Center(bool flag)
Definition: gls_text_grid.h:606
virtual void Draw(void) DISTI_METHOD_OVERRIDE
The gls_auto_lib.
float CharScaling()
bool LeftToRight(void)
void SetString(const char *s)
Definition: gls_text_grid.h:673
CharAttr_t CharAttr(unsigned int index) const
Definition: gls_text.h:292
virtual void Scale(float px, float py, float pz, Vertex *anchor, int handleBar=0)
float CharSpacing()
CharAttr_t CharAttr(unsigned int col, unsigned int row) const
Definition: gls_text_grid.h:243
void VaSetString(const char *format,...)
std::string String() const
Definition: gls_text.h:543
Definition: vertex.h:84
void SetRebuild()
Definition: gls_text.h:587
void String(unsigned int startCol, unsigned int startRow, const char *s)
Definition: gls_text_grid.h:490
unsigned int length
Definition: gls_text_grid.h:784
void ClearChars(void)
Definition: gls_text_grid.h:624
virtual void CopyProperties(DisplayObject *src) DISTI_METHOD_OVERRIDE
virtual void SetAvailableAttributes(unsigned int value) DISTI_METHOD_OVERRIDE
void Rows(unsigned int newRows)
Definition: gls_text_grid.h:422
void Columns(unsigned int newCols)
Definition: gls_text_grid.h:309
Definition: gls_quad_storage.h:63
unsigned int TextIndexOf(unsigned int col, unsigned int row, unsigned int startRow=0) const
virtual ~GlsTextGrid()
Definition: bmpimage.h:46
UTF16String _unicodeText
Definition: gls_text_grid.h:808
void Size(unsigned int cols, unsigned int rows)
virtual void CopyGeometry(DisplayObject *src) DISTI_METHOD_OVERRIDE
float CellHeight() const
Definition: gls_text.h:256
virtual void Scale(float px, float py, float pz, Vertex *anchor, int handleBar) DISTI_METHOD_OVERRIDE
unsigned int _rows
Definition: gls_text_grid.h:792
The gls_gl.