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