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