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