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