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