GL Studio API
gls_text_box.h
Go to the documentation of this file.
1 /*! \file
2  \brief The disti::GlsTextBox 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_BOX_H
41 #define _GLS_TEXT_BOX_H
42 
43 //////////////////// Provides support for creating DLLs ////////////////////////
44 #if (defined(GLSGEN_EXPORT_GLSTEXTBOX) || \
45  defined(GLSGEN_IMPORT_GLSTEXTBOX) || \
46  defined(GLSGEN_GLSTEXTBOX_EXPORT_GENERATED) || \
47  defined(GLS_IMPORT_GENERATED)) \
48  && defined(_MSC_VER)
49 # if defined(GLSGEN_EXPORT_GLSTEXTBOX) || defined(GLSGEN_GLSTEXTBOX_EXPORT_GENERATED)
50 # define GLSGEN_GLSTEXTBOX_EXPORT __declspec(dllexport)
51 # else
52 # define GLSGEN_GLSTEXTBOX_EXPORT __declspec(dllimport)
53 # endif
54 #else
55 # define GLSGEN_GLSTEXTBOX_EXPORT
56 #endif
57 ///////////////////////////////////////////////////////////////////////////////
58 
59 #include <string>
60 #include "gls_gl.h"
61 
62 #include "unhide_globals.h"
63 #include "gls_text.h"
64 #include "gls_cpp_lang_support.h"
65 
66 #ifdef GLES
67 #include "gls_quad_storage.h"
68 #include "gls_state_manager.h"
69 #endif
70 
71 #define LIB_BASE_NAME "gls_text_box"
72 #include "gls_auto_lib.h"
73 #undef LIB_BASE_NAME
74 
75 //===========================================================================
76 // BEGIN NAMESPACE
77 //===========================================================================
78 namespace disti
79 {
80 
81 #ifdef GLES
82 // Forward Declaration
83 class GlsGloFileAttribute;
84 #endif
85 
86 //===========================================================================
87 /**
88 * The GlsTextBox
89 */
90 class GlsTextBox : public GlsText
91 {
92 protected:
94  void DrawText();
95 
96 #ifdef GLES
97  GlsQuadListVC_3D _backgrounds;
98  GlsQuadListVCT_2D _shadows;
99  GlsQuadListVC_3D _shadowLines;
100  GlsQuadListVCT_2D _characters;
101  GlsQuadListVC_3D _lines;
102 
103  void PopulateQuadStorage();
104 #endif
105 
106 public:
107  typedef GlsText _BaseClass;
108 
109  friend class GlsTextBoxEditor;
110 
111  /** Class Constructor. */
112  GLSGEN_GLSTEXTBOX_EXPORT GlsTextBox();
113  GLSGEN_GLSTEXTBOX_EXPORT GlsTextBox( const GlsTextBox& that, const bool generateNames );
114 
115  /** Class Constructor. */
116  virtual GLSGEN_GLSTEXTBOX_EXPORT ~GlsTextBox();
117 
118  // Need to declare using all base class methods that we overload
119  using _BaseClass::Baseline;
120  using _BaseClass::BgColor;
121  using _BaseClass::Char;
122  using _BaseClass::CharAttr;
126  using _BaseClass::CellWidth;
127  using _BaseClass::Erase;
128  using _BaseClass::FauxBold;
129  using _BaseClass::Inverse;
131  using _BaseClass::String;
132  using _BaseClass::TextColor;
133  using _BaseClass::Underline;
134 
135  /* See base class */
136  virtual GLSGEN_GLSTEXTBOX_EXPORT void SetAvailableAttributes(unsigned int value);
137 
138  /* Peform any necessary non-draw calculations like resizing
139  * the grid.
140  * \param time The time since the start of program execution
141  */
142  virtual GLSGEN_GLSTEXTBOX_EXPORT void Calculate(double time);
143 
144  /* See base class */
145  virtual GLSGEN_GLSTEXTBOX_EXPORT DisplayObject* CloneObject(bool generateNames = false);
146 
147  /* See base class */
148  virtual GLSGEN_GLSTEXTBOX_EXPORT void CopyGeometry(DisplayObject* src);
149 
150  /* See base class */
151  virtual GLSGEN_GLSTEXTBOX_EXPORT void CopyProperties(DisplayObject* src);
152 
153  /* See base class */
154  virtual GLSGEN_GLSTEXTBOX_EXPORT void Draw(void);
155 
156 #ifndef GLES
157  /* See base class */
158  virtual GLSGEN_GLSTEXTBOX_EXPORT InterfaceListType* GetCppInterfaceDescription(
159  InterfaceListType* addToThisList = NULL );
160 
161  /* See base class */
162  virtual GLSGEN_GLSTEXTBOX_EXPORT void GetCppInterfaceDescriptionFree(
163  InterfaceListType* array);
164 #endif
165 
166 #ifdef GLES
167  /* See base class */
168  virtual GLSGEN_GLSTEXTBOX_EXPORT void PreDraw(const OpenGLMatrices& current, Culler& culler);
169 #endif
170 
171  /* See base class */
172  virtual GLSGEN_GLSTEXTBOX_EXPORT void SetVertices(unsigned int nPoints,Vertex *vertices);
173 
174  /* See base class */
175  virtual GLSGEN_GLSTEXTBOX_EXPORT void Initialize();
176 
177  /* Unhides base class implementation. */
178  using _BaseClass::Scale;
179 
180  /**
181  We need to know the Max number of lines/rows possible to display, we
182  may run out of characters to print/display before we hit the max
183  number of lines though.
184  \return A value between Zero and INT_MAX, representing the max lines/rows to draw
185  \pre The TextBox object has been initialized
186  \post The value of max lines returned to the caller
187  */
188  virtual GLSGEN_GLSTEXTBOX_EXPORT unsigned int MaxLinesToDraw(void);
189 
190  /* See base class */
191  virtual GLSGEN_GLSTEXTBOX_EXPORT void Scale(float px, float py, float pz, Vertex *anchor, int handleBar);
192 
193  // Different text justifications.
194  enum Align_t
195  {
196  ALIGN_CENTER,
197  ALIGN_TOP,
198  ALIGN_BOTTOM
199  };
200 
201  /** Set the vertical justification for this text object
202  * \param justification The justification mode (TOP, BOTTOM, CENTER)
203  */
204  GLSGEN_GLSTEXTBOX_EXPORT void VerticalAlignment(Align_t justification);
205 
206  /** Get the vertical justification for this text object
207  * \return vertical justification
208  */
209  virtual Align_t VerticalAlignment() const
210  {
211  return _verticalAlignment;
212  }
213 
214  //-----------------------------------------------------------------------
215  //-----------------------------------------------------------------------
216  // Routines for compatbility with TextDisplay.gls
217  //-----------------------------------------------------------------------
218  //-----------------------------------------------------------------------
219 
220  /** Clears all of the characters and resets the attributes of all
221  * characters (TextDisplay compatability method)
222  * \deprecated use Erase instead
223  */
224  GLSGEN_GLSTEXTBOX_EXPORT void Clear(void)
225  {
226  Erase();
227  }
228 
229  /** Clears all of the characters. Does NOT reset the attributes
230  * of the characters (TextDisplay compatability method)
231  * \deprecated
232  */
233  GLSGEN_GLSTEXTBOX_EXPORT void ClearChars(void)
234  {
235  _text.erase();
236  SetRebuild();
237  }
238 
239  /** SetColor() meaning has changed, now use TextColor */
240 
241  /** Print a string into this text object starting at index 0 and proceeding Left
242  * to right Wraps at newline characters. Does not change the color or any
243  * other modes. Replaces the entire string.
244  * (TextDisplay compatability method)
245  * \param s The string to print
246  * \deprecated use String instead
247  */
248  GLSGEN_GLSTEXTBOX_EXPORT void SetString(const char* s)
249  {
250  _needToRebuild = true;
251  String(s);
252  }
253 
254  /** Print a string into this text object
255  * to right. Wraps at newline characters. Does not change the color or any
256  * other modes. Replaces the entire string.
257  * \param format printf style varargs formatting string.
258  */
259  GLSGEN_GLSTEXTBOX_EXPORT void VaString(const char* format, ...);
260 
261  /* Undocumented.
262  * This method is used to calculate the lines of the text box and is likely to change in future releases.
263  */
264  GLSGEN_GLSTEXTBOX_EXPORT void NextLineInfo(const unsigned int currentStringIndex,
265  unsigned int* lineEndIndex,
266  unsigned int* nextLineStringIndex,
267  float* startXpixels,
268  float* lineLengthPixels);
269 
270  /* Undocumented.
271  * This method is used to calculate the lines of the text box and may change in future releases.
272  */
273  GLSGEN_GLSTEXTBOX_EXPORT unsigned int GetLineCount();
274 
275  /** Sets tab space multiplier, 1.0 == same as specified in font */
276  GLSGEN_GLSTEXTBOX_EXPORT void TabSpacing(float);
277 
278  /** Returns the current tab space multiplier
279  * \return the current tab space multiplier
280  */
281  GLSGEN_GLSTEXTBOX_EXPORT float TabSpacing();
282 
283  /** Determine if the text direction is set to left->right or right->left
284  * \return true if if the text direction is set to left->right else false for right->left
285  */
286  GLSGEN_GLSTEXTBOX_EXPORT bool LeftToRight( void );
287 
288  /** Set the text direction
289  * \param leftToRight true for left->right else false for right->left
290  */
291  GLSGEN_GLSTEXTBOX_EXPORT void LeftToRight( bool leftToRight );
292 
293 protected:
294 
295 #ifdef GLES
296  /** Set a single attribute from the GLO file.
297  * \param data The attribute to set and its associated data.
298  */
299  virtual GLSGEN_GLSTEXTBOX_EXPORT void SetFromGloData(GlsGloFileAttribute &data);
300 #endif
301 
302  /*
303  * Allocate a text buffer of the appropriate size for this grid and output snprintf style format
304  * into the buffer
305  * \param format snprintf style format spec
306  * \param args arguments for sprintf style formatting
307  * \return formatted textbuffer ( must be deleted by caller )
308  */
309  GLSGEN_GLSTEXTBOX_EXPORT char* FormatVarArgList( const char* format, va_list args );
310 
311  /* true -> grid will draw characters using "per character attributes" else
312  * false -> all characters will be drawn using the first character's attribute
313  * NOTE: This defaults to false and automatically enables to true if the user calls
314  * a method that requires per character attributes
315  */
316  bool _perCharAttribs;
317 
318  /*
319  * Enable per character attribute drawing for this grid
320  */
321  GLSGEN_GLSTEXTBOX_EXPORT void EnablePerCharAttribs( void )
322  {
323  if( !_perCharAttribs )
324  {
325  _perCharAttribs = true;
326  SetRebuild();
327  }
328  }
329 
330  /* Justification setting (TOP, CENTER, BOTTOM) */
331  Align_t _verticalAlignment;
332 
333  /* Space multiplier for tabs */
334  float _tabSpacing;
335 
336  //-----------------------------------------------------------------------
337  /*
338  */
339  GLSGEN_GLSTEXTBOX_EXPORT void Rebuild();
340 
341  //-----------------------------------------------------------------------
342  /*
343  */
344  GLSGEN_GLSTEXTBOX_EXPORT void RecalcCellSize();
345 
346  //-----------------------------------------------------------------------
347  /*
348  */
349  GLSGEN_GLSTEXTBOX_EXPORT void RecalcVertices();
350 
351  /** Populate the _rowInfo array based on the current display string
352  * \pre none
353  * \post _rowInfo array is populated based on the current display string
354  */
355  virtual void CalculateRowData( void );
356 
357  /* Get the row info for the row starting at the given string index
358  * \param strIndex starting index into string
359  * \param rowLength [out] gets number of characters in row
360  * \param rowPixelWidth [out] gets pixel width of row
361  * \param nextRowStartIndex [out] gets starting string index for next row
362  * else GLSUINT32_MAX if there is no string data for the next row
363  * \pre strIndex < _str.GetLength()
364  * \post rowLength has the number of characters in the row,
365  * rowPixelWidth has the pixel width of the row,
366  * nextRowStartIndex has the starting string index for the next row
367  * else GLSUINT32_MAX if there is no string data for the next row
368  */
369  void GetNextRowInfo(const unsigned int strIndex,
370  unsigned int &rowLength,
371  float &rowPixelWidth,
372  unsigned int &nextRowStartIndex) const;
373 
374 public:
375  /* Get the width for the given character taking into account cell sizing, character spacing, uppercasing
376  * and tab characters width being expanded
377  * \param c character in question
378  * \return width for given character
379  * \pre none
380  * \post none
381  */
382  float GetCharWidth(const unsigned short c) const;
383 
384 protected:
385 
386  /** info for one row of text in the display */
387  struct RowInfo
388  {
389  unsigned int startingIndex; /**< starting text index into the display for row
390  * else GLSUINT32_MAX if row has no characters */
391  unsigned int length; /**< the number of characters in row */
392  float pixelWidth; /**< the width of row in pixels */
393  };
394 
395  /** Number of rows of characters in the text grid (number of lines) */
396  unsigned int _lineCount;
397  bool _lineCountChanged;
398 
399  RowInfo* _rowInfo; /**< array ( _rows number of elements ) of RowInfo */
400 
401  float _cellWidthRatio;
402 
403  float _maxLineLengthPixels;
404  float _maxTextHeightPixels;
405  unsigned int _maxLinesToDraw;
406 
407  bool _leftToRight; /**< true to render characters from left to right else
408  * false for right to left */
409 
410  UnicodeString _unicodeText; /**< unicode version of _text from base class, updated by CalculateRowData */
411 
412  /* helper class for processing underline and strike-thru when drawing text grid */
414  {
415  public:
416 
417  /**
418  * \param cellWidth maximum width of a character cell in the text box
419  * \param cellHeight height of a character cell in the text box
420  * \param cellYScale unused
421  * \param shadow true if text box has shadow enabled
422  * \param shadowOffset offset for shadow
423  * \param shadowColor color of shadow in text box
424  * \param underlineOffset offset of underline
425  * \param underlineSize size of underline
426  * \param halo true if text box has halo enabled
427  * \param haloOffset offset for halo
428  * \param haloColor color of halo in text box
429  * \param leftToRight true if text flows left to right else false for right to left
430  */
431  UnderlineStrikeThruHelper( float cellWidth, float cellHeight, float cellYScale, bool shadow, const Vector& shadowOffset, const glsColor& shadowColor,
432  float underlineOffset, float underlineSize, bool halo, float haloOffset, glsColor haloColor, bool leftToRight );
433 
434  /**
435  * Setup to process a new row in the text box.
436  */
437  void NewRow( void );
438 
439  /**
440  * Pre Process the given character attributes
441  * \param charAttr attributes in question
442  * \param c the character code to process.
443  * \param cellX x coord of character cell
444  * \param charY y coord of character
445  */
446  void PreProcessCharacter( const CharAttr_t& charAttr, const Char_t& c, float cellX, float charY );
447 
448  /**
449  * Post Process the given character attributes
450  * \param charAttr attributes in question
451  * \param c the character code to process.
452  * \param cellX x coord of character cell
453  * \param charY y coord of character cell
454  * \param cellWidth the width of the current character
455  * \param endOfLine true if character was the end of the current line
456  */
457  void PostProcessCharacter( const CharAttr_t& charAttr, const Char_t& c, float cellX, float charY, float cellWidth, bool endOfLine );
458 
459 #ifdef GLES
460  /**
461  * Render the line segments for the underline / strikethru
462  * \param quadStorage The quad storage list to render
463  */
464  void RenderLineSegments( GlsQuadListVC_3D &quadStorage );
465 #else
466  /**
467  * Render the line segments for the underline / strikethru
468  */
469  void RenderLineSegments( void );
470 #endif
471 
472  void IgnoreShadow( void );
473 
474  void AllowShadow( void );
475  protected:
476  // cell constants
477  const float _cellWidth;
478  const float _cellHeight;
479 
480  // shadow constants
481  const bool _shadow;
482  const Vector _shadowOffset;
483  const glsColor _shadowColor;
484  bool _allowShadow;
485 
486  // underline constants
487  const float _underlineOffset;
488  const float _underlineSize;
489 
490  // halo constants
491  const bool _halo;
492  const float _haloOffset;
493  const glsColor _haloColor;
494 
495  // left to right
496  const bool _leftToRight;
497 
498  // state vars for underline processing
499  float _underlineX1, _underlineX2, _underlineY, _underlineScale;
500  glsColor _underlineColor;
501  bool _underlineOn;
502 
503  // state vars for strike-thru processing
504  float _strikeX1, _strikeX2, _strikeY, _strikeScale;
505  glsColor _strikeColor;
506  bool _strikeOn;
507 
508  // state vars for line processing
509  bool _whiteSpaceYes;
510 
511  // line segments to draw
512  typedef std::list<LineSegment_t> LineSegmentCont_t;
513  LineSegmentCont_t _lineSegments;
514  };
515 
516 private:
517  GlsTextBox& operator=( const GlsTextBox& ) DISTI_SPECIAL_MEM_FUN_DELETE;
518  GlsTextBox( const GlsTextBox& ) DISTI_SPECIAL_MEM_FUN_DELETE;
519 
520  /* See base class */
521  void OnCellDimensionChanged()
522  {
523  _needToRebuild = true;
524  }
525 };
526 
527 //---------------------------------------------------------------------------
528 // Stream operators for text enumeration types
529 //---------------------------------------------------------------------------
530 inline std::istream& operator>>(
531  std::istream& instr, disti::GlsTextBox::Align_t& j)
532 {
533  std::string str;
534  instr >> str;
535 
536  if (str == "ALIGN_TOP")
537  {
538  j = disti::GlsTextBox::ALIGN_TOP;
539  }
540  else if (str == "ALIGN_CENTER")
541  {
542  j = disti::GlsTextBox::ALIGN_CENTER;
543  }
544  else if (str == "ALIGN_BOTTOM")
545  {
546  j = disti::GlsTextBox::ALIGN_BOTTOM;
547  }
548  return instr;
549 }
550 
551 //---------------------------------------------------------------------------
552 inline std::ostream& operator<<(std::ostream& outstr, disti::GlsTextBox::Align_t j)
553 {
554  switch (j)
555  {
556  case disti::GlsTextBox::ALIGN_TOP:
557  outstr << "ALIGN_TOP";
558  break;
559  case disti::GlsTextBox::ALIGN_CENTER:
560  outstr << "ALIGN_CENTER";
561  break;
562  case disti::GlsTextBox::ALIGN_BOTTOM:
563  outstr << "ALIGN_BOTTOM";
564  break;
565  }
566  return outstr;
567 }
568 
569 } // end namespace
570 
571 #endif
The DistiUnhideGlobalsDummyClass class.
Definition: cull.h:50
virtual void SetVertices(unsigned int nPoints, Vertex *vertices)
float Baseline()
UnicodeString _unicodeText
Definition: gls_text_box.h:410
Definition: vertex.h:365
virtual DisplayObject * CloneObject(bool generateNames=false)
virtual void SetAvailableAttributes(unsigned int value)
Definition: dynamic_array.h:63
Class to contain current OpenGL view, projection and draw matrices.
Definition: util.h:281
virtual void PreDraw(const OpenGLMatrices &current, Culler &culler)
virtual unsigned int MaxLinesToDraw(void)
unsigned int length
Definition: gls_text_box.h:391
void VaString(const char *format,...)
glsColor BgColor()
Attributes for each character position in the grid.
Definition: gls_text.h:173
void PostProcessCharacter(const CharAttr_t &charAttr, const Char_t &c, float cellX, float charY, float cellWidth, bool endOfLine)
RowInfo * _rowInfo
Definition: gls_text_box.h:399
Definition: display.h:98
void Clear(void)
Definition: gls_text_box.h:224
Definition: gls_text_box.h:387
Definition: gls_text.h:152
std::string _text
Definition: gls_text.h:828
The disti::GlsText class.
void PreProcessCharacter(const CharAttr_t &charAttr, const Char_t &c, float cellX, float charY)
void SetString(const char *s)
Definition: gls_text_box.h:248
void Char(Char_t code)
Definition: gls_text_box.h:413
virtual void Scale(float px, float py, float pz, Vertex *anchor, int handleBar)
float CellWidth() const
Definition: gls_text.h:390
unsigned int _lineCount
Definition: gls_text_box.h:396
void ClearChars(void)
Definition: gls_text_box.h:233
virtual void CopyGeometry(DisplayObject *src)
bool LeftToRight(void)
bool _leftToRight
Definition: gls_text_box.h:407
Definition: gls_text_box.h:90
float pixelWidth
Definition: gls_text_box.h:392
virtual ~GlsTextBox()
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)
The gls_auto_lib.
Definition: gls_color.h:54
virtual void CopyProperties(DisplayObject *src)
virtual InterfaceListType * GetCppInterfaceDescription(InterfaceListType *addToThisList=NULL)
glsColor TextColor()
virtual void GetCppInterfaceDescriptionFree(InterfaceListType *array)
float CharScaling()
CharAttr_t CharAttr(unsigned int index) const
Definition: gls_text.h:412
float CharSpacing()
void Scale(int handleBar, float px, float py, Vertex *anchor=NULL)
Definition: display.h:1111
std::string String() const
Definition: gls_text.h:665
Definition: vertex.h:84
void SetRebuild()
Definition: gls_text.h:709
virtual Align_t VerticalAlignment() const
Definition: gls_text_box.h:209
virtual void CalculateRowData(void)
Macros and helper code to determine what subset of C++11/14/17 is available.
bool _needToRebuild
Definition: gls_text.h:816
Definition: bmpimage.h:46
virtual void Calculate(double time)
virtual void Draw(void)
float CellHeight() const
Definition: gls_text.h:376
unsigned int startingIndex
Definition: gls_text_box.h:389
The gls_gl.