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