GL Studio C++ Runtime API
gls_text.h
Go to the documentation of this file.
1/// \file gls_text.h
2/// \brief The disti::GlsText class.
3///
4/// \par Copyright Information
5///
6/// Copyright (c) 2017 by The DiSTI Corporation.<br>
7/// 12249 Science Drive; Suite 300<br>
8/// Orlando, Florida 32826<br>
9/// USA<br>
10/// <br>
11/// All rights reserved.<br>
12///
13/// This Software contains proprietary trade secrets of DiSTI and may not be
14/// reproduced, in whole or part, in any form, or by any means of electronic,
15/// mechanical, or otherwise, without the written permission of DiSTI. Said
16/// permission may be derived through the purchase of applicable DiSTI product
17/// licenses which detail the distribution rights of this content and any
18/// Derivative Works based on this or other copyrighted DiSTI Software.
19///
20/// NO WARRANTY. THE SOFTWARE IS PROVIDED "AS-IS," WITHOUT WARRANTY OF ANY KIND,
21/// AND ANY USE OF THIS SOFTWARE PRODUCT IS AT YOUR OWN RISK. TO THE MAXIMUM EXTENT
22/// PERMITTED BY APPLICABLE LAW, DISTI AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES
23/// AND CONDITIONS, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
24/// IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY AND/OR FITNESS FOR A
25/// PARTICULAR PURPOSE, TITLE, AND NON-INFRINGEMENT, WITH REGARD TO THE SOFTWARE.
26///
27/// LIMITATION OF LIABILITY. TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW,
28/// IN NO EVENT SHALL DISTI OR ITS SUPPLIERS BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
29/// INDIRECT, OR CONSEQUENTIAL DAMAGES WHATSOEVER (INCLUDING, WITHOUT LIMITATION,
30/// DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS
31/// INFORMATION, OR ANY OTHER PECUNIARY LOSS) ARISING OUT OF THE USE OF OR
32/// INABILITY TO USE THE SOFTWARE, EVEN IF DISTI HAS BEEN ADVISED OF THE POSSIBILITY
33/// OF SUCH DAMAGES. DISTI'S ENTIRE LIABILITY AND YOUR EXCLUSIVE REMEDY SHALL NOT
34/// EXCEED FIVE DOLLARS (US$5.00).
35///
36/// The aforementioned terms and restrictions are governed by the laws of the
37/// State of Florida and the United States of America.
38
39#ifndef DISTI_INCLUDED_GLS_TEXT_H
40#define DISTI_INCLUDED_GLS_TEXT_H
41
42#include "unhide_globals.h"
43
44#include "gls_gl.h"
45#include <string>
46
47#include "glpolygon.h"
48#include "gls_color.h"
50#include "gls_font_base.h"
51#include "gls_font_man.h"
55#include "scoped_ptr.h"
56
57//===========================================================================
58// MACROS
59//===========================================================================
60/// Macro to refresh geometry in ES, that does nothing on Desktop.
61#ifdef GLES
62# define GLS_TEXT_SET_GEOMETRY_REFRESH GeometryRefresh();
63#else
64# define GLS_TEXT_SET_GEOMETRY_REFRESH
65#endif
66
67/// Macro to set a given attribute on all characters with the given value.
68#define SET_ALL_CHARS( attribute, value ) \
69 { \
70 for( CharAttrCont_t::iterator i = _chars.begin(); i != _chars.end(); ++i ) \
71 { \
72 i->attribute = value; \
73 } \
74 GLS_TEXT_SET_GEOMETRY_REFRESH \
75 }
76
77//===========================================================================
78// BEGIN NAMESPACE
79//===========================================================================
80namespace disti
81{
82#ifdef GLES
83// Forward Declaration
84class GlsGloFileAttribute;
85#endif
86
87// Forward Declaration
88class RuntimeGlyphGenerationText;
89
90/// Initializers for text
91typedef enum
92{
93 GLS_TEXT_BORDER = GLS_LAST_INITIALIZER + 1,
94 GLS_TEXT_CELL_HEIGHT,
95 GLS_TEXT_CELL_WIDTH,
96 GLS_TEXT_CONSTRAIN_CELL_RATIO,
97 GLS_TEXT_CONTROL_CELL_SIZE,
98 GLS_TEXT_FONT,
99 GLS_TEXT_HALO,
100 GLS_TEXT_LINESPACING,
101 GLS_TEXT_LOCK_CELL_SIZE,
102 GLS_TEXT_JUSTIFY,
103 GLS_TEXT_SHADOW,
104 GLS_TEXT_STRING,
105 GLS_TEXT_UPPERCASE,
106 GLS_TEXT_WRAP,
107 GLS_LAST_TEXT_INITIALIZER = GLS_TEXT_WRAP
109
110/** helper method for safely getting a runtime font base from a font base (if possible)
111 * \param font font in question
112 * \return runtime font else NULL
113 */
115{
116 GlsRuntimeFontBase* rtf = NULL;
117 if( font )
118 {
119 // determine if font can be safely cast to a runtime font by inspecting the family name
120 if( 0 == font->Family().find( GLS_RUNTIME_FONT_NAME_PREFIX ) )
121 {
122 rtf = static_cast<GlsRuntimeFontBase*>( (GlsFontBase*)font );
123 }
124 }
125 return ( rtf );
126}
127
128/** helper method for safely getting a unicode font base from a font base (if possible)
129 * \param font font in question
130 * \return unicode font else NULL
131 */
133{
134 const GlsUnicodeFontBase* unf = NULL;
135 if( font )
136 {
137 // determine if font can be safely cast to a unicode font by inspecting the family name
138 if( 0 == font->Family().find( GLS_UNICODE_FONT_NAME_PREFIX ) )
139 {
140 unf = static_cast<const GlsUnicodeFontBase*>( font );
141 }
142 }
143 return ( unf );
144}
145
146//===========================================================================
147/**
148* The GlsText class provides a base class for all GLStudio text components.
149*/
150//===========================================================================
151class GlsText : public GLPolygon
152{
153public:
154 DISTI_DEPRECATED( "This identifier is forbidden by the C++ standard. Use BaseClass instead." )
155 typedef GLPolygon _BaseClass; ///< Deprecated typedef for the base class.
156 typedef GLPolygon BaseClass; ///< Typedef for the base class.
157
158 typedef GlsFontBase::Char_t Char_t; ///< Typedef shorthand for GlsFontBase::Char_t.
159
160 static GLS_EXPORT const Char_t EOL; ///< Carriage return (end of line) character
161
162 enum
163 {
164 NUM_VERTICES = 4
165 };
166
167 /// Different text justifications.
169 {
170 LEFT,
171 CENTER,
172 RIGHT
173 };
174
175 /// Attributes for each character position in the grid.
177 {
178 Char_t code; ///< The code point for this character.
179 float baselineShift; ///< The base line shift in pixels.
180 GlsColor bgColor; ///< The background color.
181 GlsColor fgColor; ///< The foreground (glyph itself) color.
182 bool fauxBold; ///< Whether or not faux bold is enabled.
183 bool inverse; ///< Whether or not inverse is enabled.
184 float scale; ///< Scaled size of this character.
185 float spacing; ///< Scale of spacing between this character.
186 bool strikeThru; ///< Whether or not strike through is enabled.
187 bool underline; ///< Whether or not underline is enabled.
188
190
191 /// Copy constructor
192 /// \param r The object to copy from.
194
195 /// Reset values to their defaults.
197
198 /// Assignment operator
199 /// \param r The object to copy from.
200 /// \return The resulting object (this).
202 };
203
204 /** Class Constructor. */
206
207 /// Copy constructor
208 /// \param that The object to copy from.
209 /// \param generateNames Whether or not to generate an instance name for this object.
210 GLS_EXPORT GlsText( const GlsText& that, const bool generateNames );
211
212 /** Class Constructor. */
214
216
217 /** Sets the baseline shift for all characters.
218 * \param baselineShift multiplier used to shift the baseline. This will
219 * be multiplied by the character height to
220 * determine how much to shift. A value of 0 does
221 * not shift at all, a value of 1 will shift up
222 * by the height of 1 character.
223 */
224 virtual GLS_EXPORT void Baseline( const float& baselineShift );
225
226 /// \return The baseline shift for the first character.
227 virtual GLS_EXPORT float Baseline();
228
229 /** Sets the background color for all characters
230 * \param color The background color to set
231 */
232 virtual GLS_EXPORT void BgColor( const GlsColor& color );
233
234 /// \return The background color for the first character.
236
237 /** Sets the spacing between the box outline and the text in logical units.
238 * \param units Border offset value in logical units
239 */
240 virtual GLS_EXPORT void Border( const float& units );
241
242 /// \return The spacing between the box outline and the text in logical units.
243 virtual float Border() const
244 {
245 return _border;
246 }
247
248 /** Sets the height of a character cell of the grid in logical units
249 * when stretch to fit mode is in effect. When stretch to fit mode
250 * is not in effect, this call will not affect the grid since the
251 * font determines the cell size.
252 * \param height the new character cell height.
253 */
254 virtual GLS_EXPORT void CellHeight( float height );
255
256 /** \return the height of a char cell of the grid in logical units.
257 */
258 virtual float CellHeight() const
259 {
260 return _cellHeight;
261 }
262
263 /** Sets the width of a character cell of the grid in logical units
264 * when stretch to fit mode is in effect. When stretch to fit mode
265 * is not in effect, this call will not affect the grid since the
266 * font determines the cell size.
267 * \param width the new character cell width.
268 */
269 virtual GLS_EXPORT void CellWidth( float width );
270
271 /** \return the width of a char cell of the grid in logical units. */
272 virtual float CellWidth() const
273 {
274 return _cellWidth;
275 }
276
277 /** Sets the character code for all cell positions in the text grid
278 * \param code The Unicode character code to set
279 */
280 virtual GLS_EXPORT void Char( Char_t code );
281
282 /** Accessor method used by metadata to read and write the character attributes
283 * for this object. Currently only allows you to load and save attributes for the
284 * entire object, not on a per character basis.
285 * \return The character attribute for the first character in the object and therefore
286 * for every character in the object
287 */
288 virtual CharAttr_t CharAttribs() const
289 {
290 return _chars[ 0 ];
291 }
292
293 /// \return A particular cell's character attributes.
294 /// \param index The index whose attributes are to be returned.
295 virtual CharAttr_t CharAttr( unsigned int index ) const
296 {
297 return _chars[ index < _chars.size() ? index : 0 ];
298 }
299
300 /** Sets the scale factor of all characters NOTE: This is the size of the character in its
301 * cell not the overall scale of the entire object
302 * \param newScale The new scale factor of the characters (0.0 < newScale <= 1.0)
303 */
304 virtual GLS_EXPORT void CharScaling( const float& newScale );
305
306 /// \return The scale factor of the first character.
307 virtual GLS_EXPORT float CharScaling();
308
309 /** Sets the horizontal character spacing for all characters (spacing
310 * from the start of one character to the start of the next character.
311 * 1.0 is the default spacing 2.0 would be twice the normal spacing
312 * \param horizontalSpacing The horizontalSpacing value
313 */
314 virtual GLS_EXPORT void CharSpacing( const float& horizontalSpacing );
315
316 /// \return The horizontal character spacing for the first character.
317 virtual GLS_EXPORT float CharSpacing();
318
319 /** Sets whether to constrain cell width and height proportions when
320 * in stretch to fit mode and changing the size of character cells.
321 * \param constrain true to constrain proportions.
322 */
323 virtual GLS_EXPORT void ConstrainCellRatio( bool constrain );
324
325 /** \return whether to constrain cell width and height proportions when
326 * in stretch to fit mode and changing the size of character cells.
327 */
328 virtual bool ConstrainCellRatio() const
329 {
330 return _constrainRatio;
331 }
332
333 /** Sets whether or not the character cell size will stretch to fit
334 * this object's bounding box or if it is based on its font and font.
335 * \param control True if stretch to fit will be enabled
336 */
337 virtual GLS_EXPORT void ControlCellSize( bool control );
338
339 /** \return whether or not the character cell size will stretch to fit
340 * this object's bounding box or if it is based on its font and font
341 */
342 virtual bool ControlCellSize() const
343 {
344 return _controlCellSize;
345 }
346
349
350 /** Erase all characters. */
351 virtual GLS_EXPORT void Erase();
352
353 /** Set the bold state on or off for all characters
354 * \param bold Bold state
355 */
356 virtual GLS_EXPORT void FauxBold( const bool& bold );
357
358 /// \return The bold state on or off for the first character.
359 virtual GLS_EXPORT bool FauxBold();
360
361 /** \return The font currently being used to render this text.
362 */
363 virtual GlsFontBase* Font() const
364 {
365 return _font;
366 }
367
368 /** Set the font used to render this text.
369 * \param font Pointer to a font instance to set
370 */
371 virtual GLS_EXPORT void Font( GlsFontBase* font );
372
373#ifndef GLES
376#endif
377
378 /** Set the halo state to on or off for the text
379 * \param halo halo state
380 */
381 virtual GLS_EXPORT void Halo( bool halo );
382
383 /// \return Whether or not the halo is visible.
384 virtual bool Halo() const
385 {
386 return _halo;
387 }
388
389 /** Set the color of the halo around the text
390 * \param color halo color
391 */
392 virtual GLS_EXPORT void HaloColor( const GlsColor& color );
393
394 /// \return The current halo color.
395 virtual GlsColor HaloColor() const
396 {
397 return _haloColor;
398 }
399
400 /** Invalidates the font for this object. If the font is invalidated, this object will
401 * draw using the default font. This is used in the editor and should not need to
402 * be called by any user code at run-time.
403 */
405
406 /** Set the inverse video state on or off for all characters
407 * \param inverse inverse video state
408 */
409 virtual GLS_EXPORT void Inverse( const bool& inverse );
410
411 /// \return The inverse video state on or off for the first character.
412 virtual GLS_EXPORT bool Inverse();
413
414 /** Set the justification mode for this text object
415 * \param justification The justification mode (LEFT, RIGHT, CENTER)
416 */
417 virtual GLS_EXPORT void Justify( Justify_t justification );
418
419 /** \return the justification mode (LEFT, RIGHT, CENTER)*/
420 virtual Justify_t Justify() const
421 {
422 return _justify;
423 }
424
425 /** Sets the linespacing for the text object. A line spacing of 1.0 indicates normal
426 * "single spaced" text. 2.0 would be double spaced, etc.
427 * \param spacing The new linespacing value
428 */
429 virtual GLS_EXPORT void LineSpacing( float spacing );
430
431 /** \return the linespacing for the text object. */
432 virtual float LineSpacing() const
433 {
434 return _lineSpacing;
435 }
436
437 /** Sets whether or not the cell size is locked while in stretch to fit
438 * mode. If locked, changing other attributes will not affect the
439 * cell size, but the box size instead. If not locked, changing
440 * certain attributes, eg. border, will affect the cell size.
441 * \param lock true to lock cell size, false otherwise
442 */
443 virtual GLS_EXPORT void LockCellSize( bool lock );
444
445 /** \return the setting of lock cell size. */
446 virtual bool LockCellSize() const
447 {
448 return _lockCellSize;
449 }
450
451#if !defined( GCC_2_95 )
452 /* Unhides base class implementation. */
453 using BaseClass::Rotate;
454#endif
455 GLS_EXPORT void Rotate( const Vector& orig, float angle, const Vector& axis ) DISTI_METHOD_OVERRIDE;
456
457 GLS_EXPORT void SetValue( int spec, va_list& args ) DISTI_METHOD_OVERRIDE;
458
459#ifdef GLES
460 /** Set a single attribute from the GLO file.
461 * \param data The attribute to set and its associated data.
462 */
463 GLS_EXPORT void SetFromGloData( GlsGloFileAttribute& data ) DISTI_METHOD_OVERRIDE;
464#endif
465
466 /** Set the shadow state to on or off for the text
467 * \param shadow shadow state
468 */
469 virtual GLS_EXPORT void Shadow( bool shadow );
470
471 /// \return Whether or not text shadow is visible.
472 virtual bool Shadow() const
473 {
474 return _shadow;
475 }
476
477 /** Set the color of the shadow behind the text
478 * \param color shadow color
479 */
480 virtual GLS_EXPORT void ShadowColor( const GlsColor& color );
481
482 /// \return The current shadow color.
483 virtual GlsColor ShadowColor() const
484 {
485 return _shadowColor;
486 }
487
488 /** Set the distance of the shadow from the text. Distance represent a percentage of the character
489 * width. Negative values are up and to the left. Positive values are down and to the right. Note that the
490 * corresponding getter was removed because ShadowDistance is deprecated in favor of ShadowOffset.
491 * \param dist shadow distance
492 */
493 virtual void ShadowDistance( const float& dist )
494 {
495 ShadowOffset( Vector( dist, -dist, 0.0f ) );
496 }
497
498 /** Set the Cartesian offset of the shadow from the text. Offset represent a percentage of the character
499 * width. Negative values are down and to the left. Positive values are up and to the right.
500 * Z component is ignored.
501 * \param offset shadow offset
502 */
503 virtual GLS_EXPORT void ShadowOffset( const Vector& offset );
504
505 /// \return The current shadow offset.
507 {
508 return _shadowOffset;
509 }
510
511 /** Sets the strikethru state for all characters
512 * \param strike Whether or not set strikethru
513 */
514 virtual GLS_EXPORT void StrikeThru( const bool& strike );
515
516 /// \return The strikethru state for the first character.
517 virtual GLS_EXPORT bool StrikeThru();
518
519 /** Sets the Unicode string to be displayed for this object
520 * \param s STD Template Library String
521 */
522 virtual GLS_EXPORT void String( const std::string& s );
523
524 /** Sets the Unicode string to be displayed for this object
525 * \param s C Style string
526 */
527 virtual void String( const char* s )
528 {
529 String( std::string( s ) );
530 }
531
532 /** \return The string currently stored in this object.
533 * NOTE: This can contain extra characters not being displayed
534 * in the grid if the string size is greater than will
535 * fit within the grid.
536 */
537 virtual std::string String() const
538 {
539 return _text;
540 }
541
542 /** Sets the foreground color for all characters in the text grid.
543 * \param color The foreground color to set
544 */
545 virtual GLS_EXPORT void TextColor( const GlsColor& color );
546
547 /// \return The foreground color for the first character in the text grid.
549
550 /** Turns on/off underlines for all characters
551 * \param underline Whether or not to enable underline
552 */
553 virtual GLS_EXPORT void Underline( const bool& underline );
554
555 /// \return The on/off state of underline for the first character.
556 virtual GLS_EXPORT bool Underline();
557
558 /** Makes all characters uppercase when rendered.
559 * \param uppercase Whether or not to enable uppercase
560 */
561 virtual GLS_EXPORT void Uppercase( bool uppercase );
562
563 /// \return The current uppercase state.
564 virtual bool Uppercase() const
565 {
566 return _uppercase;
567 }
568
569 /** Enable/disable word wrap behavior for this object
570 * \param wrap Whether or not to enable word wrap
571 */
572 virtual GLS_EXPORT void WrapText( bool wrap );
573
574 /** \return current word wrap behavior for this object */
575 virtual bool WrapText() const
576 {
577 return _wrapText;
578 }
579
580 /** Sets the rebuild flag, which forces the text object to rebuild itself on the next call to Calculate, PreDraw, or Draw. */
581 virtual void SetRebuild()
582 {
583 _needToRebuild = true;
585 }
586
587 /// \return Whether or not this text object requires a font file to work..
588 /// If this returns true, the text object may not work with the generated ASCII / UNICODE font types.
589 virtual bool RequiresFontFile() const
590 {
591 return false;
592 }
593
594public: // protected is prefered, but VC 7.0 has issues with it.
595 /** Line Segment_t */
597 {
598 public:
599 float x1; ///< Left side of the segment.
600 float x2; ///< Right side of the segment.
601 float y; ///< Vertical position of the segment.
602 float thickness; ///< Thickness of the segment in logical units.
603 float shadowOffsetX; ///< X offset of the shadow in logical units.
604 float shadowOffsetY; ///< Y offset of the shadow in logical units.
605 GlsColor color; ///< Color the segment is to be drawn.
606
608 : x1( 0.0f )
609 , x2( 0.0f )
610 , y( 0.0f )
611 , thickness( 0.0f )
612 , shadowOffsetX( 0.0f )
613 , shadowOffsetY( 0.0f )
614 {
615 }
616
617 /// Constructor
618 /// \param segmentX1 Left side of the segment.
619 /// \param segmentX2 Right side of the segment.
620 /// \param segmentY Vertical position of the segment.
621 /// \param segmentThickness Thickness of the segment in logical units.
622 /// \param segmentShadowOffsetX X offset of the shadow in logical units.
623 /// \param segmentShadowOffsetY Y offset of the shadow in logical units.
624 /// \param segmentColor Color the segment is to be drawn.
626 const float segmentX1,
627 const float segmentX2,
628 const float segmentY,
629 const float segmentThickness,
630 const float segmentShadowOffsetX,
631 const float segmentShadowOffsetY,
632 const GlsColor& segmentColor )
633 : x1( segmentX1 )
634 , x2( segmentX2 )
635 , y( segmentY )
636 , thickness( segmentThickness )
637 , shadowOffsetX( segmentShadowOffsetX )
638 , shadowOffsetY( segmentShadowOffsetY )
639 , color( segmentColor )
640 {
641 }
642 };
643
644protected:
645 typedef std::vector<CharAttr_t> CharAttrCont_t; ///< Typedef for a list of character attributes.
646
647 static GLS_EXPORT const Vector XAXIS; ///< Vector for the global X axis.
648 static GLS_EXPORT const Vector YAXIS; ///< Vector for the global Y axis.
649
650 static GLS_EXPORT Vertex INITIAL_VERTICES[ NUM_VERTICES ]; ///< Default corners for new text objects.
651
652 /** The border offset in logical units for this object.
653 * Defines the size of the empty space between the outline of the box
654 * and its text
655 */
656 float _border;
657
658 /** Container of character attributes */
660
661 Vertex _currentVertices[ NUM_VERTICES ]; ///< The corners of the text object.
662
663 /** Height of each character cell in the grid in logical units */
665
666 /** Width of each character cell in the grid in logical units */
668
669 /** Only effective when _controlCellSize is true. Whether or not to
670 * constrain cell size ratio when changing cell height or width.
671 */
673
674 /** If true, font size does not control cell size */
676
677 /** Current font being used for the text */
679
680 bool _halo; ///< Whether or not the halo effect is on.
681
682 /** Color of the halo effect behind the characters */
684
685 /** Justification setting (LEFT, RIGHT, CENTER) */
687
688 /** Line spacing between grid rows as a percentage */
690
691 /** Only effective when _controlCellSize is true. If true, changes to
692 * rows, columns, border, line spacing, column spacing, etc. will
693 * not change the cell size. Normally, when _controlCellSize is true
694 * these attributes affect the cell size.
695 */
697
698 /** This is set to true whenever an attribute changes that will affect
699 * the size of the grid or its cells.
700 */
702
703 bool _shadow; ///< Whether or not the shadow effect is on.
704
705 /** Color of the shadow effect behind the characters */
707
708 /** Offset of the shadow effect from the characters. Z component is ignored. */
710
711 /** String of text to be displayed. */
712 std::string _text;
713
714 /** If true, all characters will be displayed in uppercase */
716
717 /** Direction vector indicating direction of horizontal travel for rendering */
719
720 /** Direction vector indicating direction of vertical travel for rendering */
722
723 /** Normal to the Vx Vy plane */
725
726 /** Whether or not to word wrap text */
728
729public: // protected is preferred, but VC 7.0 has issues with it.
730#ifndef GLES
731
732 /// Draw a line by rendering a filled polygon with a line around it so that
733 /// the thickness scales and anti-aliasing will work if enabled.
734 /// \param x1 The left point.
735 /// \param y1 The top point.
736 /// \param x2 The right point.
737 /// \param y2 The bottom point.
738 static void DrawScalableLine( GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2 )
739 {
740 // APR: The Text Objects send x1,y1 as TOP-RIGHT. Rewrote glVertex calls to support CCW drawing.
741 glBegin( GL_POLYGON );
742 glVertex2f( x1, y1 );
743 glVertex2f( x1, y2 );
744 glVertex2f( x2, y2 );
745 glVertex2f( x2, y1 );
746 glEnd();
747 }
748#endif
749protected:
750 /**
751 * Allocate a text buffer of the appropriate size for this grid and output snprintf style format
752 * into the buffer
753 * \param format snprintf style format spec
754 * \param args arguments for sprintf style formatting
755 * \param initialBufferLength the length of the initial character buffer
756 * \return formatted textbuffer ( must be deleted by caller )
757 */
758 virtual GLS_EXPORT char* FormatVarArgList( const int initialBufferLength, const char* format, va_list args );
759
760 /// Calculates direction vectors based on the orientation of its vertices.
761 /// \note Not normally called by users.
763
764 /** Pointer to the internal data needed for runtime glyph generation. */
766
767private:
768 // Allow derived classes to perform a custom action when cell height/width changes.
769 virtual void OnCellDimensionChanged()
770 {}
771
772 // Disable copying.
774 void operator=( const GlsText& ) DISTI_SPECIAL_MEM_FUN_DELETE;
775};
776
777/// Stream in operator
778/// \param instr The stream to read from.
779/// \param j The returned value read from the stream.
780/// \return The stream in its current state.
781inline std::istream& operator>>( std::istream& instr, disti::GlsText::Justify_t& j )
782{
783 std::string str;
784 instr >> str;
785
786 if( str == "LEFT" )
787 {
788 j = disti::GlsText::LEFT;
789 }
790 else if( str == "CENTER" )
791 {
792 j = disti::GlsText::CENTER;
793 }
794 else if( str == "RIGHT" )
795 {
796 j = disti::GlsText::RIGHT;
797 }
798 return instr;
799}
800
801/// Stream out operator
802/// \param outstr The stream to write to.
803/// \param j The value to write to the stream.
804/// \return The stream in its current state.
805inline std::ostream& operator<<( std::ostream& outstr, disti::GlsText::Justify_t j )
806{
807 switch( j )
808 {
809 case disti::GlsText::LEFT:
810 outstr << "LEFT";
811 break;
812 case disti::GlsText::CENTER:
813 outstr << "CENTER";
814 break;
815 case disti::GlsText::RIGHT:
816 outstr << "RIGHT";
817 break;
818 }
819 return outstr;
820}
821
822//===========================================================================
823/**
824* Attributes of a text character.
825* NOTE: Use of this attribute is deprecated.
826* Instead use individual top-level attributes such as ("FauxBold" and "TextColor").
827*/
828//===========================================================================
830{
831public:
832 DISTI_DEPRECATED( "This identifier is forbidden by the C++ standard. Use BaseClass instead." )
833 typedef DistiAttributeDictionaryAttribute _BaseClass; ///< Deprecated typedef for the base class.
834 typedef DistiAttributeDictionaryAttribute BaseClass; ///< Typedef for the base class.
835
836 /// Constructor
837 /// \param name The name to use for this attribute.
838 /// \param text The text object associated with this attribute.
839 GlsTextCharAttr( const AttributeName& name, GlsText* text );
840
841 virtual ~GlsTextCharAttr()
842 {
843 delete _dict;
844 }
845
846 // Do not write out, because this interface is only for backward compatability.
848 {
849 return false;
850 }
851
852 std::ostream& WriteValue( std::ostream& outstr ) DISTI_METHOD_OVERRIDE
853 {
854 _charAttr = _text->CharAttr( 0 );
855 return BaseClass::WriteValue( outstr );
856 }
857
858 std::istream& ReadValue( std::istream& instr ) DISTI_METHOD_OVERRIDE
859 {
860 // First get _charAttr to the current value.
861 // This is because the instr may not contain
862 // new values for all the attributes.
863 _charAttr = _text->CharAttr( 0 );
864
865 BaseClass::ReadValue( instr );
866
876
877 return instr;
878 }
879
880protected:
881 GlsText* _text; ///< Observing pointer to the text object holding the attributes.
882 GlsText::CharAttr_t _charAttr; ///< Character attribute structure to apply to text.
883};
884
885} // namespace disti
886
887/// Stream out operator
888/// \param outstr The stream to write to.
889/// \param c The value to write to the stream.
890/// \return The stream in its current state.
891DISTI_EXPORT std::ostream& operator<<( std::ostream& outstr, const disti::GlsText::CharAttr_t& c );
892
893/// Stream in operator
894/// \param instr The stream to read from.
895/// \param c The returned value read from the stream.
896/// \return The stream in its current state.
897DISTI_EXPORT std::istream& operator>>( std::istream& instr, disti::GlsText::CharAttr_t& c );
898
899#endif
Definition: disti_metadata.h:87
Definition: display.h:95
virtual void Rotate(float angle, int axis=Z_AXIS)
Definition: gls_metadata_attributes.h:478
std::istream & ReadValue(std::istream &instr) override
std::ostream & WriteValue(std::ostream &outstr) override
DistiAttribDict * _dict
An observing pointer to a dictionary of attributes.
Definition: gls_metadata_attributes.h:480
Definition: dynamic_array.h:79
The Polygon class. Implements Polygons.
Definition: glpolygon.h:55
Definition: gls_color.h:53
Definition: gls_font_base.h:86
std::string Family() const
Definition: gls_font_base.h:274
Definition: gls_glo_file.h:1241
Definition: gls_runtime_font_base.h:66
Definition: gls_text.h:830
GlsText::CharAttr_t _charAttr
Character attribute structure to apply to text.
Definition: gls_text.h:882
bool OkToWrite() const override
Definition: gls_text.h:847
std::istream & ReadValue(std::istream &instr) override
Definition: gls_text.h:858
std::ostream & WriteValue(std::ostream &outstr) override
Definition: gls_text.h:852
GlsText * _text
Observing pointer to the text object holding the attributes.
Definition: gls_text.h:881
Definition: gls_text.h:597
float x2
Right side of the segment.
Definition: gls_text.h:600
float x1
Left side of the segment.
Definition: gls_text.h:599
float shadowOffsetY
Y offset of the shadow in logical units.
Definition: gls_text.h:604
LineSegment_t(const float segmentX1, const float segmentX2, const float segmentY, const float segmentThickness, const float segmentShadowOffsetX, const float segmentShadowOffsetY, const GlsColor &segmentColor)
Definition: gls_text.h:625
float thickness
Thickness of the segment in logical units.
Definition: gls_text.h:602
GlsColor color
Color the segment is to be drawn.
Definition: gls_text.h:605
float y
Vertical position of the segment.
Definition: gls_text.h:601
float shadowOffsetX
X offset of the shadow in logical units.
Definition: gls_text.h:603
Definition: gls_text.h:152
static const Vector XAXIS
Vector for the global X axis.
Definition: gls_text.h:647
float _cellWidth
Definition: gls_text.h:667
virtual CharAttr_t CharAttr(unsigned int index) const
Definition: gls_text.h:295
virtual void TextColor(const GlsColor &color)
virtual bool Halo() const
Definition: gls_text.h:384
virtual void String(const std::string &s)
GlsColor _haloColor
Definition: gls_text.h:683
void SetAvailableAttributes(unsigned int value) override
Justify_t
Different text justifications.
Definition: gls_text.h:169
virtual Justify_t Justify() const
Definition: gls_text.h:420
virtual char * FormatVarArgList(const int initialBufferLength, const char *format, va_list args)
std::vector< CharAttr_t > CharAttrCont_t
Typedef for a list of character attributes.
Definition: gls_text.h:645
virtual void Justify(Justify_t justification)
void CopyProperties(DisplayObject *src) override
virtual bool RequiresFontFile() const
Definition: gls_text.h:589
virtual void ShadowOffset(const Vector &offset)
virtual float Border() const
Definition: gls_text.h:243
float _lineSpacing
Definition: gls_text.h:689
Vector _shadowOffset
Definition: gls_text.h:709
virtual float CellWidth() const
Definition: gls_text.h:272
virtual GlsColor BgColor()
virtual void Font(GlsFontBase *font)
virtual Vector ShadowOffset()
Definition: gls_text.h:506
GlsText(const GlsText &that, const bool generateNames)
virtual float Baseline()
virtual ~GlsText()
virtual void HaloColor(const GlsColor &color)
virtual void Char(Char_t code)
virtual bool Inverse()
float _border
Definition: gls_text.h:656
void CopyGeometry(DisplayObject *src) override
bool _uppercase
Definition: gls_text.h:715
void SetValue(int spec, va_list &args) override
virtual void String(const char *s)
Definition: gls_text.h:527
ScopedPtr< RuntimeGlyphGenerationText > _runtimeGlyphGenerationText
Definition: gls_text.h:765
virtual float CharSpacing()
virtual GlsFontBase * Font() const
Definition: gls_text.h:363
virtual bool LockCellSize() const
Definition: gls_text.h:446
bool _needToRebuild
Definition: gls_text.h:701
virtual bool Underline()
virtual GlsColor TextColor()
virtual void SetRebuild()
Definition: gls_text.h:581
virtual void CellWidth(float width)
InterfaceListType * GetCppInterfaceDescription(InterfaceListType *addToThisList=NULL) override
float _cellHeight
Definition: gls_text.h:664
virtual void Uppercase(bool uppercase)
virtual bool Uppercase() const
Definition: gls_text.h:564
static const Char_t EOL
Carriage return (end of line) character.
Definition: gls_text.h:160
virtual void Border(const float &units)
virtual void CellHeight(float height)
virtual CharAttr_t CharAttribs() const
Definition: gls_text.h:288
virtual float CharScaling()
Vertex _currentVertices[NUM_VERTICES]
The corners of the text object.
Definition: gls_text.h:661
virtual void Inverse(const bool &inverse)
virtual float CellHeight() const
Definition: gls_text.h:258
virtual bool StrikeThru()
virtual bool FauxBold()
virtual bool ControlCellSize() const
Definition: gls_text.h:342
virtual void Baseline(const float &baselineShift)
static const Vector YAXIS
Vector for the global Y axis.
Definition: gls_text.h:648
CharAttrCont_t _chars
Definition: gls_text.h:659
virtual void CharScaling(const float &newScale)
bool _halo
Whether or not the halo effect is on.
Definition: gls_text.h:680
virtual GlsColor HaloColor() const
Definition: gls_text.h:395
bool _shadow
Whether or not the shadow effect is on.
Definition: gls_text.h:703
virtual void BgColor(const GlsColor &color)
virtual bool Shadow() const
Definition: gls_text.h:472
virtual void ConstrainCellRatio(bool constrain)
virtual std::string String() const
Definition: gls_text.h:537
static Vertex INITIAL_VERTICES[NUM_VERTICES]
Default corners for new text objects.
Definition: gls_text.h:650
virtual void ControlCellSize(bool control)
virtual bool WrapText() const
Definition: gls_text.h:575
virtual void ShadowDistance(const float &dist)
Definition: gls_text.h:493
virtual void CharSpacing(const float &horizontalSpacing)
bool _lockCellSize
Definition: gls_text.h:696
void GetCppInterfaceDescriptionFree(InterfaceListType *array) override
bool _wrapText
Definition: gls_text.h:727
void Rotate(const Vector &orig, float angle, const Vector &axis) override
bool _constrainRatio
Definition: gls_text.h:672
GlsFontBase::Char_t Char_t
Typedef shorthand for GlsFontBase::Char_t.
Definition: gls_text.h:158
virtual void Underline(const bool &underline)
virtual float LineSpacing() const
Definition: gls_text.h:432
GlsColor _shadowColor
Definition: gls_text.h:706
virtual void LineSpacing(float spacing)
Vector _vZ
Definition: gls_text.h:724
virtual void ShadowColor(const GlsColor &color)
virtual void Shadow(bool shadow)
GlsFontBase * _font
Definition: gls_text.h:678
virtual void Halo(bool halo)
virtual void FauxBold(const bool &bold)
virtual void LockCellSize(bool lock)
virtual void WrapText(bool wrap)
virtual void RecalcDirectionVectors()
virtual GlsColor ShadowColor() const
Definition: gls_text.h:483
virtual void InvalidateFont()
bool _controlCellSize
Definition: gls_text.h:675
static void DrawScalableLine(GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2)
Definition: gls_text.h:738
virtual void StrikeThru(const bool &strike)
virtual void Erase()
Justify_t _justify
Definition: gls_text.h:686
std::string _text
Definition: gls_text.h:712
Vector _vX
Definition: gls_text.h:718
Vector _vY
Definition: gls_text.h:721
virtual bool ConstrainCellRatio() const
Definition: gls_text.h:328
Definition: gls_unicode_font_base.h:65
Definition: vertex.h:84
Definition: vertex.h:419
The disti::GLPolygon class. Implements Polygons.
The Color class: Implements a 4 component RGBA color.
Macros and helper code to determine what subset of C++11/14/17 is available.
#define DISTI_SPECIAL_MEM_FUN_DELETE
Macro to wrap function deletion, removed on compilers that don't support it.
Definition: gls_cpp_lang_support.h:245
#define DISTI_DEPRECATED(msg)
Defines whether this compiler supports the C++14 deprecated attribute.
Definition: gls_cpp_lang_support.h:487
#define DISTI_METHOD_OVERRIDE
Macro to wrap the override keyword, removed on compilers that don't support it.
Definition: gls_cpp_lang_support.h:221
The disti::GlsFontBase class and related classes.
The disti::GlsFontMan class.
#define GLS_RUNTIME_FONT_NAME_PREFIX
Definition: gls_font_man.h:52
#define GLS_UNICODE_FONT_NAME_PREFIX
Definition: gls_font_man.h:49
The gls_gl.
#define GLS_EXPORT
Macro denoting which functions should be visible from the runtime library.
Definition: gls_include.h:50
Defines templated metadata classes for DisplayObjects and other uses.
The disti::GlsRuntimeFontBase class and related classes.
std::istream & operator>>(std::istream &instr, disti::GlsText::CharAttr_t &c)
std::ostream & operator<<(std::ostream &outstr, const disti::GlsText::CharAttr_t &c)
The disti::GlsUnicodeFontBase class and related classes.
Definition: bmpimage.h:46
std::ostream & operator<<(std::ostream &outstr, const AttributeName &name)
GlsRuntimeFontBase * GetGlsRuntimeFontBase(const GlsFontBase *font)
Definition: gls_text.h:114
VertexNoColor Vector
Definition: gls_font_base.h:68
GlsTextInitializers_t
Initializers for text.
Definition: gls_text.h:92
std::istream & operator>>(std::istream &instr, GlsColor &color)
const GlsUnicodeFontBase * GetGlsUnicodeFontBase(const GlsFontBase *font)
Definition: gls_text.h:132
A smart pointer with unique ownership – poor man's std::unique_ptr.
Attributes for each character position in the grid.
Definition: gls_text.h:177
bool fauxBold
Whether or not faux bold is enabled.
Definition: gls_text.h:182
GlsColor bgColor
The background color.
Definition: gls_text.h:180
float scale
Scaled size of this character.
Definition: gls_text.h:184
bool inverse
Whether or not inverse is enabled.
Definition: gls_text.h:183
CharAttr_t & operator=(const CharAttr_t &r)
Char_t code
The code point for this character.
Definition: gls_text.h:178
float baselineShift
The base line shift in pixels.
Definition: gls_text.h:179
bool underline
Whether or not underline is enabled.
Definition: gls_text.h:187
void Clear()
Reset values to their defaults.
CharAttr_t(const CharAttr_t &r)
float spacing
Scale of spacing between this character.
Definition: gls_text.h:185
GlsColor fgColor
The foreground (glyph itself) color.
Definition: gls_text.h:181
bool strikeThru
Whether or not strike through is enabled.
Definition: gls_text.h:186
The DistiUnhideGlobalsDummyClass class.