GL Studio SCECpp Runtime Library
gls_text_box.h
Go to the documentation of this file.
1 #ifndef _GLS_TEXT_BOX_H
2 #define _GLS_TEXT_BOX_H
3 
4 /*! \file gls_text_box.h
5 
6 \brief This header defines the GlsTextBox class
7  in the GL Studio DO-178B Runtime Library.
8 
9 \par Copyright Information
10 Copyright (C) 1999-2012 The DiSTI Corporation<br>
11 Orlando, FL USA<br>
12 All rights reserved.<br>
13 
14  This file is copyrighted software and contains proprietary trade secrets of
15 DiSTI, and embodies substantial creative efforts as well as confidential
16 information, ideas, and expressions.
17 
18  Permission to use, and copy this software and its documentation for any
19 purpose is hereby granted per the Distribution Agreement and/or the Licensing
20 Agreement signed with DiSTI. This permission is granted provided that:
21  1. The above copyright notice appears in all copies.
22  2. That both the copyright notice and this permission notice appear in
23  the supporting documentation.
24  3. That the names DiSTI and GL Studio not be used in advertising or
25  publicity pertaining to distribution of the software without specific,
26  written prior permission of DiSTI.
27 
28  Permission to modify the software is granted, but not the right to
29 distribute the source code whether modified, or non-modified. Modifying the
30 software might invalidate the DO-178B certification package.
31 
32  Permission to distribute binaries produced by compiling source code, or
33 modified source code is granted, provided you:
34  1. Provide your name and address as the primary contact for the support
35  of your modified version.
36  2. Retain our contact information in regard to use of the base software.
37 
38  DiSTI does not provide warranty for this software or guarantee that it
39 satisfies any specification or requirement unless otherwise stated in a
40 specific contractual arrangement between the customer and DiSTI.
41 
42 */
43 
44 #include "gls_include.h"
45 #include "gls_text.h"
47 #include "gls_class_invariant.h"
48 
49 // forward ref
50 class GlsPolygon;
51 
52 /** This class implements a box of proportionally spaced text
53  * \invariant base class invariant holds,
54  * GlsTextBoxVerticalAlignmentIsValid( _verticalAlignment ),
55  * _charAttribute.IsValid(),
56  * GlsFloatIsValid( _cellWidthRatio ), GlsFloatIsValid( _startingCellY )
57  */
58 class GlsTextBox : public GlsText
59 {
60 public:
62 
63  /** enumeration describing possible vertical alignment modes */
65  {
66  VERTICAL_ALIGNMENT_TOP, /**< align to top of box */
67  VERTICAL_ALIGNMENT_CENTER, /**< align to center of box */
68  VERTICAL_ALIGNMENT_BOTTOM, /**< align to bottom of box */
69 
70  #if defined( GLS_DEBUG )
71  VERTICAL_ALIGNMENT_INVALID /**< invalid vertical alignment ( GLS_DEBUG only ) */
72  #endif // GLS_DEBUG
73  };
74 
75  /** initialization parameters for a GlsTextBox */
77  {
78  const GlsText::InitParameters textInitParameters; /**< base class initialization parameters */
79 
80  const VerticalAlignment verticalAlignment; /**< vertical alignment mode for text */
81 
82  #if defined( GLS_DEBUG )
83  /** Determine if the initialization parameters are valid
84  * \return GLS_TRUE if valid else GLS_FALSE
85  * \pre none
86  * \post none
87  */
88  GlsBool IsValid( void ) const;
89  #endif // GLS_DEBUG
90  };
91 
92  /** Constructor - create an instance
93  * \param initParameters initialization parameters
94  * \param eventDispatcher event dispatcher for this object else GLS_NULL
95  * \pre initParameters.IsValid()
96  * \post instance created
97  */
98  GlsTextBox( const InitParameters &initParameters, GlsEventDispatcher* const eventDispatcher );
99 
100  /** Set the character attributes for all of the text
101  * \param charAttribute new character attributes for the text
102  * \pre charAttribue.IsValid()
103  * \post text has new character attribute
104  */
105  virtual void SetCharAttributes( const GlsText::CharAttribute &charAttribute );
106 
107 protected:
108  static const GlsFloat32 TAB_SPACING; /**< number of tab char widths to count for one tab char */
109 
110  const VerticalAlignment _verticalAlignment; /**< vertical alignment mode for text */
111  GlsText::CharAttribute _charAttribute; /**< character attribute for all characters */
112 
113  const GlsFloat32 _cellWidthRatio; /**< ratio of cell width to width of widest character in
114  * the font */
115  GlsFloat32 _startingCellY; /**< starting Y coordinate of first cell in text box
116  * ( populated by CalculateRowData() ) */
117 
118  /** Draw the characters associated with the text box
119  * \param gl GL state manager to draw into
120  * \pre all necessary GL matrix adjustments have been applied,
121  * the font texture has been bound to GL with GlsFontBase::BindFontTexture()
122  * and its texture filter settings have been setup
123  * \post text characters are drawn to GL
124  */
125  virtual void DrawCharacters( GlsStateManager &gl );
126 
127  /** Populate the _rowInfo array and _startingCellY based on the current display string
128  * \pre none
129  * \post _rowInfo array and _startingCellY are populated based on the current display string
130  */
131  virtual void CalculateRowData( void );
132 
133  /** Get the row info for the row starting at the given string index
134  * \param strIndex starting index into string
135  * \param rowLength [out] gets number of characters in row
136  * \param rowPixelWidth [out] gets pixel width of row
137  * \param nextRowStartIndex [out] gets starting string index for next row
138  * else GLSUINT32_MAX if there is no string data for the next row
139  * \pre strIndex < _str.GetLength()
140  * \post rowLength has the number of characters in the row,
141  * rowPixelWidth has the pixel width of the row,
142  * nextRowStartIndex has the starting string index for the next row
143  * else GLSUINT32_MAX if there is no string data for the next row
144  */
145  void GetNextRowInfo( const GlsUInt32 strIndex, GlsUInt32 &rowLength, GlsFloat32 &rowPixelWidth,
146  GlsUInt32 &nextRowStartIndex ) const;
147 
148  /** Get the width for the given character taking into account cell sizing, character spacing, uppercasing
149  * and tab characters width being expanded
150  * \param c character in question
151  * \return width for given character
152  * \pre none
153  * \post none
154  */
155  GlsFloat32 GetCharWidth( const GlsChar c ) const;
156 
157  /** Destructor - shall never be called
158  * \pre none
159  * \post none
160  */
161  virtual ~GlsTextBox();
162 
163 private:
164  typedef GlsText _BaseClass; /**< base class alias */
165 
166  // Disable implicit generated Members
167  GlsTextBox& operator=( const GlsTextBox &rhs );
168  GlsTextBox( const GlsTextBox &src );
169 };
170 
171 #if defined( GLS_DEBUG )
172 #pragma BullseyeCoverage save off
173 /** Determine if the given vertical alignment is valid ( GLS_DEBUG only )
174  * \param verticalAlignment alignment in question
175  * \return GLS_TRUE if valid else GLS_FALSE
176  * \pre none
177  * \post none
178  */
179 inline GlsBool GlsTextBoxVerticalAlignmentIsValid( const GlsTextBox::VerticalAlignment verticalAlignment )
180 {
181  return( ( GlsTextBox::VERTICAL_ALIGNMENT_TOP == verticalAlignment ) ||
182  ( GlsTextBox::VERTICAL_ALIGNMENT_CENTER == verticalAlignment ) ||
183  ( GlsTextBox::VERTICAL_ALIGNMENT_BOTTOM == verticalAlignment ) );
184 
185 }
186 #pragma BullseyeCoverage restore
187 #endif // GLS_DEBUG
188 
189 #endif // _GLS_TEXT_BOX_H
Definition: gls_text_box.h:68
Definition: gls_text_box.h:58
virtual void SetCharAttributes(const GlsText::CharAttribute &charAttribute)
bool GlsBool
Definition: gls_types.h:96
VerticalAlignment
Definition: gls_text_box.h:64
virtual ~GlsTextBox()
#define GLS_CLASS_INVARIANT_DECLARATION(ClassName)
Definition: gls_class_invariant.h:80
const GlsText::InitParameters textInitParameters
Definition: gls_text_box.h:78
char GlsChar
Definition: gls_types.h:54
Definition: gls_state_manager.h:63
This header defines GlsTextureVertexArray which encapsulates an array of GlsTextureVertex 's in the G...
unsigned int GlsUInt32
Definition: gls_types.h:73
Definition: gls_text_box.h:66
This header defines the GlsText base class in the GL Studio DO-178B Runtime Library.
Definition: gls_event.h:304
This header defines any preprocessor defines needed to configure the GL Studio DO-178B Runtime Librar...
static const GlsFloat32 TAB_SPACING
Definition: gls_text_box.h:108
virtual void CalculateRowData(void)
Definition: gls_text_box.h:76
const GlsFloat32 _cellWidthRatio
Definition: gls_text_box.h:113
float GlsFloat32
Definition: gls_types.h:78
const VerticalAlignment verticalAlignment
Definition: gls_text_box.h:80
Definition: gls_display_object.h:64
virtual void DrawCharacters(GlsStateManager &gl)
This header defines a GLS_DEBUG only macro for facilitating evaluating class invariants in the GL Stu...
GlsFloat32 _startingCellY
Definition: gls_text_box.h:115
GlsFloat32 GetCharWidth(const GlsChar c) const
const VerticalAlignment _verticalAlignment
Definition: gls_text_box.h:110
GlsTextBox(const InitParameters &initParameters, GlsEventDispatcher *const eventDispatcher)
void GetNextRowInfo(const GlsUInt32 strIndex, GlsUInt32 &rowLength, GlsFloat32 &rowPixelWidth, GlsUInt32 &nextRowStartIndex) const
GlsText::CharAttribute _charAttribute
Definition: gls_text_box.h:111
Definition: gls_polygon.h:55
Definition: gls_text.h:90
Definition: gls_text_box.h:67
Definition: gls_text.h:114
Definition: gls_text.h:72