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 );
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 );
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 );
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 );
316 
317  /* See base class */
318  GLSGEN_GLSTEXTGRID_EXPORT virtual void CopyProperties( DisplayObject* src );
319 
320 #ifdef GLES
321  /* See base class */
322  virtual GLSGEN_GLSTEXTGRID_EXPORT void PreDraw( const OpenGLMatrices& current, Culler& culler );
323 #endif
324 
325  /* See base class */
326  virtual GLSGEN_GLSTEXTGRID_EXPORT void Draw( void );
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(
378  InterfaceListType* addToThisList = NULL );
379 
380  /* See base class */
381  virtual GLSGEN_GLSTEXTGRID_EXPORT void GetCppInterfaceDescriptionFree(
382  InterfaceListType* array );
383 #endif
384 
385  /* See base class */
386  virtual GLSGEN_GLSTEXTGRID_EXPORT void Initialize();
387 
388  /** Set the inverse video state on or off for one character
389  * \param col X coordinate of the character to set
390  * \param row Y coordinate of the character to set
391  * \param inverse inverse video state
392  */
393  GLSGEN_GLSTEXTGRID_EXPORT void Inverse( unsigned int col, unsigned int row, bool inverse );
394 
395  /** Set the inverse video state on or off for a range of characters
396  * \param startCol X coordinate of the first character to set
397  * \param startRow Y coordinate of the first character to set
398  * \param len Number of characters to set
399  * \param inverse inverse video state
400  */
401  GLSGEN_GLSTEXTGRID_EXPORT void Inverse(
402  unsigned int startCol,
403  unsigned int startRow,
404  unsigned int len,
405  bool inverse );
406 
407  /** \return The length of a given line in characters. This will search the
408  * specified row until a \n or NULL is encountered or until it reaches the
409  * end of the row (number of columns in the grid).
410  * \param row The row to return the length of
411  */
412  GLSGEN_GLSTEXTGRID_EXPORT unsigned int LineLength( unsigned int row ) const;
413 
414  /** The number of rows in this text grid
415  * \return The number of rows in this text grid */
416  unsigned int Rows() const
417  {
418  return _rows;
419  }
420 
421  /** Change the number of rows the text grid contains.
422  * \param newRows new number of rows to size the grid with.
423  */
424  void Rows( unsigned int newRows )
425  {
426  Size( _cols, newRows );
427  }
428 
429  /* Unhides base class implementation. */
430  using BaseClass::Scale;
431 
432  /** Scales the object, either the handleBar, or the Anchor is
433  * used to translate the object, not both. Anchor takes
434  * presidence, if it is set HandleBar is ignored.
435  * The footprint is different from the 2D scale so the compiler can destinguish the two.
436  * \param px Value of the percentage of scale in x-axis
437  * \param py Value of the percentage of scale in y-axis
438  * \param pz Value of the percentage of scale in z-axis
439  * \param anchor Anchor from which to scale object relative to
440  * \param handleBar Vertex that is being dragged
441  */
442  virtual GLSGEN_GLSTEXTGRID_EXPORT void Scale( float px, float py, float pz, Vertex* anchor, int handleBar );
443 
444  /* See base class */
445  virtual GLSGEN_GLSTEXTGRID_EXPORT void SetValue( int spec, va_list& args );
446 
447  /** Sets the number of rows and columns for this object
448  * \param cols The new number of columns
449  * \param rows The new number of rows
450  */
451  GLSGEN_GLSTEXTGRID_EXPORT void Size( unsigned int cols, unsigned int rows );
452 
453  /** Sets the strikethru state for one character
454  * \param col X coordinate of the character to set
455  * \param row Y coordinate of the character to set
456  * \param strike Whether or not set strike to fit
457  */
458  GLSGEN_GLSTEXTGRID_EXPORT void StrikeThru( unsigned int col, unsigned int row, bool strike );
459 
460  /** Sets the strikethru state for a range of characters
461  * \param startCol X coordinate of the first character to set
462  * \param startRow Y coordinate of the first character to set
463  * \param len Number of characters to set
464  * \param strike Whether or not set strike to fit
465  */
466  GLSGEN_GLSTEXTGRID_EXPORT void StrikeThru(
467  unsigned int startCol,
468  unsigned int startRow,
469  unsigned int len,
470  bool strike );
471 
472  /** Sets the ASCII string to be displayed for this object starting
473  * at an col,row coordinate and wrapping on newlines and column count
474  * \param startCol X coordinate (column) to start at
475  * \param startRow Y coordinate (row) to start at
476  * \param s STD Template Library string to print
477  */
478  GLSGEN_GLSTEXTGRID_EXPORT void String(
479  unsigned int startCol,
480  unsigned int startRow,
481  const std::string& s );
482 
483  /** Sets the ASCII string to be displayed for this object starting
484  * at an col,row coordinate and wrapping on newlines and column count
485  * \param startCol X coordinate (column) to start at
486  * \param startRow Y coordinate (row) to start at
487  * \param s C style string to print
488  */
489  void String( unsigned int startCol, unsigned int startRow, const char* s )
490  {
491  String( startCol, startRow, std::string( s ) );
492  }
493 
494  /** Sets the foreground color for one character
495  * \param col X coordinate of the character to set
496  * \param row Y coordinate of the character to set
497  * \param color The foreground color to set
498  */
499  GLSGEN_GLSTEXTGRID_EXPORT void TextColor(
500  unsigned int col,
501  unsigned int row,
502  const GlsColor& color );
503 
504  /** Sets the foreground color for a range of characters
505  * \param startCol X coordinate of the first character to set
506  * \param startRow Y coordinate of the first character to set
507  * \param len Number of characters to set
508  * \param color The foreground color to set
509  */
510  GLSGEN_GLSTEXTGRID_EXPORT void TextColor(
511  unsigned int startCol,
512  unsigned int startRow,
513  unsigned int len,
514  const GlsColor& color );
515 
516  /** Returns the foreground color for the specified character.
517  * If no character is specified, the color at 0,0 will be returned.
518  * \param col X coordinate of the character of interest
519  * \param row Y coordinate of the character of interest
520  * \return The requested color
521  */
522  GLSGEN_GLSTEXTGRID_EXPORT GlsColor TextColor(
523  unsigned int col = 0,
524  unsigned int row = 0 ) const;
525 
526  /** Turns on/off underlines for one character
527  * \param col X coordinate of the character of interest
528  * \param row Y coordinate of the character of interest
529  * \param underline Whether or not to enable underline
530  */
531  GLSGEN_GLSTEXTGRID_EXPORT void Underline(
532  unsigned int col,
533  unsigned int row,
534  bool underline );
535 
536  /** Turns on/off underlines for a range character
537  * \param startCol X coordinate of the first character to set
538  * \param startRow Y coordinate of the first character to set
539  * \param len Number of characters to set
540  * \param underline Whether or not to enable underline
541  */
542  GLSGEN_GLSTEXTGRID_EXPORT void Underline(
543  unsigned int startCol,
544  unsigned int startRow,
545  unsigned int len,
546  bool underline );
547 
548  /** Print a string into this text object starting at 0,0 and proceeding Left
549  * to right. Wraps at newline characters. Does not change the color or any
550  * other modes. Replaces the entire string. If substring replacement is desired,
551  * use VaString(col, row, format) instead.
552  * \param format printf style varargs formatting string.
553  */
554  GLSGEN_GLSTEXTGRID_EXPORT void VaString( const char* format, ... );
555 
556  /** Print a string into this text object starting at col,row and proceeding Left
557  * to right. Assumes current string does not contain newline characters.
558  * If a newline is encountered it will be overwritten.
559  * Does not change the color or any other modes. Just inserts/overwrites
560  * characters.
561  * This replaces a substring within the current string. If you want full string replacement
562  * use VaString(format)
563  * \param startCol X position (column)
564  * \param startRow Y position (row)
565  * \param format printf style varargs formatting string.
566  */
567  GLSGEN_GLSTEXTGRID_EXPORT void VaString(
568  unsigned int startCol,
569  unsigned int startRow,
570  const char* format,
571  ... );
572 
573  /** Print a string into this text object starting at col,row and proceeding Left to right
574  * Assumes current string does not contain newline characters. If a newline is encountered it
575  * will be overwritten.
576  * Inserts/overwrites characters and changes the color.
577  * This replaces a substring within the current string. If you want full string replacement
578  * use VaString(format)
579  * (TextDisplay compatability method)
580  * \param col X position (column)
581  * \param row Y position (row)
582  * \param rgba The color to set
583  * \param format printf style varargs formatting string.
584  * \since GL Studio 6.0.1
585  */
586  GLSGEN_GLSTEXTGRID_EXPORT void VaString(
587  unsigned int col,
588  unsigned int row,
589  unsigned char rgba[],
590  const char* format,
591  ... );
592 
593  //-----------------------------------------------------------------------
594  //-----------------------------------------------------------------------
595  // Routines for comapability with TextDisplay.gls
596  //-----------------------------------------------------------------------
597  //-----------------------------------------------------------------------
598 
599  /** Enable/disable centering mode
600  * (TextDisplay compatability method)
601  * \param flag True if text should be centered, false if it should be
602  * left justified
603  * \deprecated use Justify instead
604  */
605  GLSGEN_GLSTEXTGRID_EXPORT void Center( bool flag )
606  {
607  Justify( CENTER );
608  }
609 
610  /** Clears all of the characters and resets the attributes of all
611  * characters (TextDisplay compatability method)
612  * \deprecated use Erase instead
613  */
614  GLSGEN_GLSTEXTGRID_EXPORT void Clear( void )
615  {
616  Erase();
617  }
618 
619  /** Clears all of the characters. Does NOT reset the attributes
620  * of the characters (TextDisplay compatability method)
621  * \deprecated
622  */
623  GLSGEN_GLSTEXTGRID_EXPORT void ClearChars( void )
624  {
625  _text.erase();
626  SetRebuild();
627  }
628 
629  /** Set an individual character at the given position
630  * Assumes current string does not contain newline characters.
631  * If a newline character is encountered in the current string it will be overwritten.
632  * (TextDisplay compatability method)
633  * \param col X position (column)
634  * \param row Y position (row)
635  * \param ch ASCII code of the character
636  * \deprecated use Char instead
637  */
638  GLSGEN_GLSTEXTGRID_EXPORT void SetChar( unsigned int col, unsigned int row, char ch )
639  {
640  Char( col, row, Char_t( ch ) );
641  }
642 
643  /** Set an individual character at the given position. Also set its color.
644  * Assumes current string does not contain newline characters.
645  * If a newline character is encountered in the current string it will be overwritten.
646  * (TextDisplay compatability method)
647  * \param col X position (column)
648  * \param row Y position (row)
649  * \param ch ASCII code of the character
650  * \param rgba Color value for character
651  * \deprecated use Char instead
652  */
653  GLSGEN_GLSTEXTGRID_EXPORT void SetChar(
654  unsigned int col,
655  unsigned int row,
656  char ch,
657  unsigned char rgba[] )
658  {
659  Char( col, row, Char_t( ch ) );
660  TextColor( col, row, GlsColor( rgba ) );
661  }
662 
663  /** SetColor() meaning has changed, now use TextColor */
664 
665  /** Print a string into this text object starting at 0,0 and proceeding Left
666  * to right. Wraps at newline characters. Does not change the color or any
667  * other modes. Replaces the entire string. If substring replacement is desired, use String(col, row, s).
668  * (TextDisplay compatability method)
669  * \param s The string to print
670  * \deprecated use String instead
671  */
672  GLSGEN_GLSTEXTGRID_EXPORT void SetString( const char* s )
673  {
674  String( s );
675  }
676 
677  /** Print a string into this text object starting at col,row and proceeding
678  * Assumes current string does not contain newline characters.
679  * If a newline is encountered in the current string it will be overwritten. Does not change the color
680  * or any other modes. Just inserts/overwrites characters.
681  * This replaces a substring within the current string. If you want full string replacement
682  * use String(s)
683  * (TextDisplay compatability method)
684  * \param col X position (column)
685  * \param row Y position (row)
686  * \param s The string to print
687  * \deprecated use String instead
688  */
689  GLSGEN_GLSTEXTGRID_EXPORT void SetString( unsigned int col, unsigned int row, const char* s )
690  {
691  String( col, row, s );
692  }
693 
694  /** Print a string into this text object starting at col,row and proceeding
695  * Assumes current string does not contain newline characters.
696  * If a newline is encountered in the current string it will be overwritten.
697  * Inserts/overwrites characters and changes the color.
698  * This replaces a substring within the current string. If you want full string replacement
699  * use String(s)
700  * (TextDisplay compatability method)
701  * \param col X position (column)
702  * \param row Y position (row)
703  * \param rgba The color to set
704  * \param s The string to print
705  * \deprecated use String instead
706  */
707  GLSGEN_GLSTEXTGRID_EXPORT void SetString(
708  unsigned int col,
709  unsigned int row,
710  unsigned char rgba[],
711  const char* s );
712 
713  /** Print a string into this text object starting at 0,0 and proceeding Left to right
714  * Assumes current string does not contain newline characters. If a newline is encountered in the
715  * current string it will be overwritten. Does not change the color or any other modes.
716  * Replaces the entire string. If substring replacement is desired, use VaString(col, row, format).
717  * (TextDisplay compatability method)
718  * \param format printf style varargs formatting string.
719  * \deprecated use VaString instead
720  */
721  GLSGEN_GLSTEXTGRID_EXPORT void VaSetString( const char* format, ... );
722 
723  /** Print a string into this text object starting at col,row and proceeding Left to right
724  * Assumes current string does not contain newline characters. Does not change the color or any other modes. Just
725  * inserts/overwrites characters.
726  * This replaces a substring within the current string. If you want full string replacement
727  * use VaString(format)
728  * (TextDisplay compatability method)
729  * \param col X position (column)
730  * \param row Y position (row)
731  * \param format printf style varargs formatting string.
732  * \deprecated use VaString instead
733  */
734  GLSGEN_GLSTEXTGRID_EXPORT void VaSetString(
735  unsigned int col,
736  unsigned int row,
737  const char* format,
738  ... );
739 
740  /** Print a string into this text object starting at col,row and proceeding Left to right
741  * Assumes current string does not contain newline characters. If a newline is
742  * encountered in the current string it will be overwritten.
743  * Inserts/overwrites characters and changes the color.
744  * This replaces a substring within the current string. If you want full string replacement
745  * use VaString(format)
746  * (TextDisplay compatability method)
747  * \param col X position (column)
748  * \param row Y position (row)
749  * \param rgba The color to set
750  * \param format printf style varargs formatting string.
751  * \deprecated use VaString instead
752  */
753  GLSGEN_GLSTEXTGRID_EXPORT void VaSetString(
754  unsigned int col,
755  unsigned int row,
756  unsigned char rgba[],
757  const char* format,
758  ... );
759 
760  /** Determine if the text direction is set to left->right or right->left
761  * \return true if if the text direction is set to left->right else false for right->left
762  */
763  GLSGEN_GLSTEXTGRID_EXPORT bool LeftToRight( void );
764 
765  /** Set the text direction
766  * \param leftToRight true for left->right else false for right->left
767  */
768  GLSGEN_GLSTEXTGRID_EXPORT void LeftToRight( bool leftToRight );
769 
770 protected:
771 #ifdef GLES
772  /** Set a single attribute from the GLO file.
773  * \param data The attribute to set and its associated data.
774  */
775  virtual GLSGEN_GLSTEXTGRID_EXPORT void SetFromGloData( GlsGloFileAttribute& data );
776 #endif
777 
778  /** info for one row of text in the display */
779  struct RowInfo
780  {
781  unsigned int startingIndex; /**< starting text index into the _unicodeText for row
782  * else GLSUINT32_MAX if row has no characters */
783  unsigned int length; /**< the number of characters in row */
784  float pixelWidth; /**< the width of row in pixels */
785  };
786 
787  /** Number of columns of characters in the text grid (line length) */
788  unsigned int _cols;
789 
790  /** Number of rows of characters in the text grid (number of lines) */
791  unsigned int _rows;
792 
793  bool _numRowsChanged;
794 
795  /** true -> grid will draw characters using "per character attributes" else
796  * false -> all characters will be drawn using the first character's attribute
797  * NOTE: This defaults to false and automatically enables to true if the user calls
798  * a method that requires per character attributes
799  */
801 
802  RowInfo* _rowInfo; /**< array ( _rows number of elements ) of RowInfo */
803 
804  bool _leftToRight; /**< true to render characters from left to right else
805  * false for right to left */
806 
807  UnicodeString _unicodeText; /**< unicode version of _text from base class, updated by CalculateRowData */
808 
809  /**
810  * Erase a single character at a given index. Use TextIndexOf to find the character using coordinates.
811  * \param textIndex index of the character to erase
812  */
813  GLSGEN_GLSTEXTGRID_EXPORT void EraseIndex( unsigned int textIndex );
814 
815  /**
816  * Enable per character attribute drawing for this grid
817  */
818  GLSGEN_GLSTEXTGRID_EXPORT void EnablePerCharAttribs( void )
819  {
820  if( !_perCharAttribs )
821  {
822  _perCharAttribs = true;
823  SetRebuild();
824  }
825  }
826 
827  /**
828  * Allocate a text buffer of the appropriate size for this grid and output snprintf style format
829  * into the buffer
830  * \param format snprintf style format spec
831  * \param args arguments for sprintf style formatting
832  * \return formatted textbuffer ( must be deleted by caller )
833  */
834  GLSGEN_GLSTEXTGRID_EXPORT char* FormatVarArgList( const char* format, va_list args );
835 
836  //-----------------------------------------------------------------------
837  /**
838  */
839  GLSGEN_GLSTEXTGRID_EXPORT float BoxHeight();
840 
841  //-----------------------------------------------------------------------
842  /**
843  */
844  GLSGEN_GLSTEXTGRID_EXPORT float BoxWidth();
845 
846  /** Converts col,row into linear index
847  * \param col The column number
848  * \param row The line number (row)
849  * \return The linear index of line & column
850  */
851  unsigned int IndexOf( unsigned int col, unsigned int row ) const
852  {
853  unsigned int index( 0 );
854 
855  if( col < _cols && row < _rows )
856  {
857  index = ( row * _cols ) + col;
858  }
859  else
860  {
861  index = _rows * _cols;
862  }
863  return index;
864  }
865 
866  //-----------------------------------------------------------------------
867  /**
868  */
869  GLSGEN_GLSTEXTGRID_EXPORT float JustificationOffset( unsigned int row );
870 
871  //-----------------------------------------------------------------------
872  /**
873  */
874  GLSGEN_GLSTEXTGRID_EXPORT float LinePixelWidth( unsigned int line, float cellWidth ) const;
875 
876  //-----------------------------------------------------------------------
877  /**
878  */
879  GLSGEN_GLSTEXTGRID_EXPORT void Rebuild();
880 
881  //-----------------------------------------------------------------------
882  /**
883  */
884  GLSGEN_GLSTEXTGRID_EXPORT void RecalcCellSize();
885 
886  //-----------------------------------------------------------------------
887  /**
888  */
889  GLSGEN_GLSTEXTGRID_EXPORT void RecalcVertices();
890 
891  //-----------------------------------------------------------------------
892  /**
893  */
894  GLSGEN_GLSTEXTGRID_EXPORT void ResizeGrid();
895 
896  /** Converts col,row into linear index returning the end of the string if this index would go beyond it
897  * \param col The column number
898  * \param row The line number (row)
899  * \param startRow The row to start the search from
900  * \return The linear index of line & column
901  */
902  GLSGEN_GLSTEXTGRID_EXPORT
903  unsigned int TextIndexOf( unsigned int col, unsigned int row, unsigned int startRow = 0 ) const;
904 
905  /** Converts col,row into grid index returning the end of the string if this index would go outside the bounds of the grid
906  * \param col The column number
907  * \param row The line number (row)
908  * \return The grid index of line & column
909  */
910  GLSGEN_GLSTEXTGRID_EXPORT
911  unsigned int GridIndexOf( unsigned int col, unsigned int row ) const;
912 
913  /** Populate the _rowInfo array based on the current display string
914  * \pre none
915  * \post _rowInfo array is populated based on the current display string
916  */
917  GLSGEN_GLSTEXTGRID_EXPORT virtual void CalculateRowData( void );
918 
919  /** helper class for processing underline and strike-thru when drawing text grid */
921  {
922  public:
923  /**
924  * \param cellWidth width of a character cell in the text grid
925  * \param cellHeight height of a character cell in the text grid
926  * \param cellYScale unused
927  * \param shadow true if text grid has shadow enabled
928  * \param shadowOffset offset for shadow
929  * \param shadowColor color of shadow in text grid
930  * \param underlineOffset offset of underline
931  * \param underlineSize size of underline
932  * \param halo true if text grid has halo enabled
933  * \param haloOffset offset for halo
934  * \param haloColor color of halo in text grid
935  * \param leftToRight true if text flows left to right else false for right to left
936  */
937  UnderlineStrikeThruHelper( float cellWidth, float cellHeight, float cellYScale, bool shadow, const Vector& shadowOffset, const GlsColor& shadowColor,
938  float underlineOffset, float underlineSize, bool halo, float haloOffset, GlsColor haloColor, bool leftToRight );
939 
940  /**
941  * Setup to process a new row in the text grid
942  */
943  void NewRow( void );
944 
945  /**
946  * Pre Process the given character attributes
947  * \param charAttr attributes in question
948  * \param cellX x coord of character cell
949  * \param nextCellX x coord of character cell one past the given character
950  * \param charY y coord of character
951  * \param endOfLine true if character was the end of the current line
952  */
953  void ProcessCharacter( const CharAttr_t& charAttr, float cellX, float nextCellX, float charY, bool endOfLine );
954 
955  /**
956  * Render the line segments for the underline / strikethru
957  */
958 #ifdef GLES
959  void RenderLineSegments( GlsQuadListVC_3D& quadStorage );
960 #else
961  void RenderLineSegments( void );
962 #endif
963  void IgnoreShadowAndHalo()
964  {
965  _allowShadow = false;
966  }
967 
968  protected:
969  // cell constants
970  const float _cellWidth;
971  const float _cellHeight;
972 
973  // shadow constants
974  const bool _shadow;
975  const Vector _shadowOffset;
976  const GlsColor _shadowColor;
977  bool _allowShadow;
978 
979  // underline constants
980  const float _underlineOffset;
981  const float _underlineSize;
982 
983  // halo constants
984  const bool _halo;
985  const float _haloOffset;
986  const GlsColor _haloColor;
987 
988  // left to right
989  const bool _leftToRight;
990 
991  // state vars for underline processing
992  float _underlineX1, _underlineX2, _underlineY, _underlineScale;
993  GlsColor _underlineColor;
994  bool _underlineOn;
995 
996  // state vars for strike-thru processing
997  float _strikeX1, _strikeX2, _strikeY, _strikeScale;
998  GlsColor _strikeColor;
999  bool _strikeOn;
1000 
1001  // line segments to draw
1002  typedef std::list<LineSegment_t> LineSegmentCont_t;
1003  LineSegmentCont_t _lineSegments;
1004  };
1005 
1006 private:
1007  /* See base class */
1008  void OnCellDimensionChanged()
1009  {
1010  RecalcVertices();
1011  }
1012 
1013  GlsTextGrid& operator=( const GlsTextGrid& );
1014  GlsTextGrid( const GlsTextGrid& );
1015 };
1016 
1017 } // namespace disti
1018 
1019 #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:653
virtual InterfaceListType * GetCppInterfaceDescription(InterfaceListType *addToThisList=NULL)
void SetString(unsigned int col, unsigned int row, const char *s)
Definition: gls_text_grid.h:689
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)
virtual void SetValue(int spec, va_list &args)
Definition: dynamic_array.h:66
Class to contain current OpenGL view, projection and draw matrices.
Definition: util.h:296
unsigned int _cols
Definition: gls_text_grid.h:788
virtual void PreDraw(const OpenGLMatrices &current, Culler &culler)
The disti::GlsQuadListVC_3D and GlsQuadListVCT_2D classes.
bool _perCharAttribs
Definition: gls_text_grid.h:800
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:818
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:837
CharAttrCont_t _chars
Definition: gls_text.h:782
void EraseIndex(unsigned int textIndex)
Definition: gls_quad_storage.h:158
GlsColor BgColor()
The disti::GlsText class.
virtual void CopyGeometry(DisplayObject *src)
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:804
void SetChar(unsigned int col, unsigned int row, char ch)
Definition: gls_text_grid.h:638
Definition: gls_glo_file.h:982
float pixelWidth
Definition: gls_text_grid.h:784
Justify_t Justify() const
Definition: gls_text.h:551
virtual void Calculate(double time)
float CellWidth() const
Definition: gls_text.h:394
UnicodeString _unicodeText
Definition: gls_text_grid.h:807
virtual void CalculateRowData(void)
Definition: gls_text_grid.h:920
RowInfo * _rowInfo
Definition: gls_text_grid.h:802
void VaString(const char *format,...)
virtual DisplayObject * CloneObject(bool generateNames=false)
void Char(unsigned int col, unsigned int row, Char_t code)
void Clear(void)
Definition: gls_text_grid.h:614
unsigned int startingIndex
Definition: gls_text_grid.h:781
Definition: gls_color.h:53
virtual void CopyProperties(DisplayObject *src)
unsigned int IndexOf(unsigned int col, unsigned int row) const
Definition: gls_text_grid.h:851
unsigned int Rows() const
Definition: gls_text_grid.h:416
Definition: gls_text_grid.h:779
void Center(bool flag)
Definition: gls_text_grid.h:605
The gls_auto_lib.
virtual void GetCppInterfaceDescriptionFree(InterfaceListType *array)
virtual void Draw(void)
virtual void SetAvailableAttributes(unsigned int value)
float CharScaling()
virtual void Scale(float px, float py, float pz, Vertex *anchor, int handleBar)
bool LeftToRight(void)
void SetString(const char *s)
Definition: gls_text_grid.h:672
CharAttr_t CharAttr(unsigned int index) const
Definition: gls_text.h:416
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:669
Definition: vertex.h:84
void SetRebuild()
Definition: gls_text.h:713
void String(unsigned int startCol, unsigned int startRow, const char *s)
Definition: gls_text_grid.h:489
unsigned int length
Definition: gls_text_grid.h:783
void ClearChars(void)
Definition: gls_text_grid.h:623
void Rows(unsigned int newRows)
Definition: gls_text_grid.h:424
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
void Size(unsigned int cols, unsigned int rows)
float CellHeight() const
Definition: gls_text.h:380
unsigned int _rows
Definition: gls_text_grid.h:791
The gls_gl.