GL Studio Safety Critical Embedded C++ Runtime Library
gls_nine_patch.h
Go to the documentation of this file.
1#ifndef _GLS_NINE_PATCH_H
2#define _GLS_NINE_PATCH_H
3
4/*! \file gls_nine_patch.h
5\brief This header defines the GlsNinePatch class in
6 the GL Studio DO-178B Runtime Library.
7
8\par Copyright Information
9Copyright (C) 1999-2008 by Distributed Simulation Technology, Inc. (DiSTI)<br>
10Orlando, FL USA<br>
11All rights reserved.<br>
12
13 This file is copyrighted software and contains proprietary trade secrets of
14DiSTI, and embodies substantial creative efforts as well as confidential
15information, ideas, and expressions.
16
17 Permission to use, and copy this software and its documentation for any
18purpose is hereby granted per the Distribution Agreement and/or the Licensing
19Agreement signed with DiSTI. This permission is granted provided that:
20 1. The above copyright notice appears in all copies.
21 2. That both the copyright notice and this permission notice appear in
22 the supporting documentation.
23 3. That the names DiSTI and GL Studio not be used in advertising or
24 publicity pertaining to distribution of the software without specific,
25 written prior permission of DiSTI.
26
27 Permission to modify the software is granted, but not the right to
28distribute the source code whether modified, or non-modified. Modifying the
29software might invalidate the DO-178B certification package.
30
31 Permission to distribute binaries produced by compiling source code, or
32modified source code is granted, provided you:
33 1. Provide your name and address as the primary contact for the support
34 of your modified version.
35 2. Retain our contact information in regard to use of the base software.
36
37 DiSTI does not provide warranty for this software or guarantee that it
38satisfies any specification or requirement unless otherwise stated in a
39specific contractual arrangement between the customer and DiSTI.
40
41*** NOTICE *** This source code is not encompassed by the DO-178B certication
42package.
43
44*/
45
46#include "gls_include.h"
47#include "gls_render_object.h"
48#include "gls_vertex.h"
50#include "gls_state_manager.h"
51#include "gls_class_invariant.h"
52
53/** The GlsNinePatch abstracts a set of nine polygons which contain edges that maintain the same width/height
54 * after scaling the object.
55 * \invariant base class invariant holds,
56 * _vertices[].IsValid() for all vertices,
57 * _vertexEdge[] > 0 for all vertex edges,
58 * _textureEdge[] > 0 for all texture edges,
59 */
61{
62public:
64
65 // enumeration for the indicies into _vertexEdge and _textureEdge that represent the outer four sides for the nine patch
66 enum Edge
67 {
72 NUM_EDGES = 4u
73 };
74
75 // enumeration for constants used while drawing
76 enum
77 {
78 NUM_VERTS = 16u,
80 NUM_DRAW_VERTS = 36u
81 };
82
83 // enumeration for the indicies into _vertices that represent the four corners of the nine patch
84 enum
85 {
90 };
91
92 /** initialization parameters for the GlsNinePatch */
94 {
95 const GlsRenderObject::InitParameters renderInitParameters; /**< base class initialization */
96
97 const GlsTextureVertex vertices[NUM_VERTS]; /**< initial vertices */
98 const GlsUInt32 textureEdges[NUM_EDGES]; /**< initial texture edges in pixels. */
99 /**< values range from 0 to */
100 const GlsFloat32 vertexEdges[NUM_EDGES]; /**< initial vertex edges */
101 /**< values range from 0 to */
102 const GlsBool centerVisible; /**< initial center draw setting */
103
104 #if defined( GLS_DEBUG )
105 /** Determine if the initialization parameters are valid ( GLS_DEBUG only )
106 * \return GLS_TRUE if valid else GLS_FALSE
107 * \pre none
108 * \post none
109 */
110 GlsBool IsValid( void ) const;
111 #endif // GLS_DEBUG
112 };
113
114 /** Constructor - create instance
115 * \param initParameters initialization parametets
116 * \param eventDispatcher event dispatcher for this object else GLS_NULL
117 * \pre initParameters.IsValid()
118 * \post instance created
119 */
120 GlsNinePatch( const InitParameters &initParameters, GlsEventDispatcher* const eventDispatcher );
121
122 /** Draws this nine patch
123 * \param gl GL State manager for OpenGL into which polygon is drawn
124 * \param time the elaspsed time in seconds since program start
125 * \pre time >= 0.0
126 * \post polygon is drawn to OpenGL if visible and not blinked off, _previousDynamicScale = _dynamicScale
127 */
128 virtual void Draw( GlsStateManager &gl, const GlsFloat64 time );
129
130 /** Offset the texture on the object
131 * \param offset x, y offset for texture
132 * \pre offset.IsValid()
133 * \post offset is added to the texture coordinates
134 */
135 virtual void OffsetTexture( const GlsVector2D &offset );
136
137 /** Sets the texture edge value IN from the nine patch defined bounding region
138 * \param edge enumerated above
139 * \param value in pixel measurements
140 * \pre edge < NUM_EDGES, value >= 0,
141 * initial texture edge value at object creation must be have been > 0
142 * \post object texture edge has new value
143 */
144 void SetTextureEdge( const Edge edge, const GlsUInt32 value );
145
146 /** Sets the vertex edge value IN from the nine patch defined bounding region
147 * \param edge enumerated above
148 * \param value in unit measurements
149 * \pre edge < NUM_EDGES, value >= 0.0
150 * \post object vertex edge has new value
151 */
152 void SetVertexEdge( const Edge edge, const GlsFloat32 value );
153
154 /** Sets whether the center is drawn or not
155 * \param visible boolean to control visibility of center quad
156 * \pre none
157 * \post object has new condition for drawing center
158 */
159 void SetCenterVisible( const GlsBool visible );
160
161protected:
162
163 /** Array of vertices that defines the NinePatch, arranged as follows:
164 * 12--13---14---15
165 * | | | |
166 * 8----9---10---11
167 * | | | |
168 * 4----5----6----7
169 * | | | |
170 * 0----1----2----3
171 */
172 GlsTextureVertex _vertices[ NUM_VERTS ]; /**< array of vertices and texture vertices for nine patch */
173 GlsTextureVertex _unalteredVertices[ NUM_VERTS ]; /**< array of vertices and texture vertices that are unaltered from initialization */
174
175 GlsUInt32 _textureEdge[ NUM_EDGES ]; /**< Values representing the distance from the edge of the texture that makes up the NinePatch */
176 /**< borders. Units are in pixels and are the distance IN from the edge of the texture. */
177 GlsUInt32 _unalteredTextureEdge[ NUM_EDGES ]; /**< Values representing the original distance from the edge of the texture that makes up the NinePatch */
178 /**< borders. Units are in pixels and are the distance IN from the edge of the texture. */
179 GlsFloat32 _vertexEdge[ NUM_EDGES ]; /**< Values representing the size of edges of the NinePatch. Units are in logical units measure */
180 /**< going IN from the edge of the NinePatch */
181 /**< Values range from 0.0f to the total width of the nine patch minus the opposite edge. */
182
183 GlsBool _centerVisible; /**< Whether or not the center patch will be drawn */
184
185 GlsVector2D _currentTextureOffset; /**< current texture offset accumulated by OffsetTexture() */
186
187 /** Returns whether the total width or height is greater than the opposite edges combined
188 * \return GLS_TRUE if it is non-degenerate else GLS_FALSE
189 * \pre none
190 * \post none
191 */
192 const GlsBool SizeIsNonDegenerate( void ) const;
193
194 /** Output the vertices in the array to GL
195 * \param gl GL state manager to receive verts
196 * \param doTextureCoordinates GLS_TRUE to send texture coordinates with each vert else GLS_FALSE
197 * \param doVertexColors GLS_TRUE to send vertex colors with each vert else GLS_FALSE
198 * \pre called inside a GL begin/end pair
199 * \post vertices are output to GL
200 */
201 void OutputVertices( GlsStateManager &gl, const GlsBool doTextureCoordinates, const GlsBool doVertexColors ) const;
202
203 /** Output the vertices in the array to GL
204 * \param gl GL state manager to receive verts
205 * \param doTextureCoordinates GLS_TRUE to send texture coordinates with each vert else GLS_FALSE
206 * \param doVertexColors GLS_TRUE to send vertex colors with each vert else GLS_FALSE
207 * \pre called inside a GL begin/end pair
208 * \post vertices are output to GL
209 */
211
212 /** Adjusts the vertices based on the current texture and vertex edge settings.
213 * \pre none
214 * \post vertices are adjusted based on current texture and vertex edge settings
215 */
216 void RefactorVerts( void );
217
218 /** Destructor - shall never be called
219 * \pre none
220 * \post none
221 */
222 virtual ~GlsNinePatch();
223
224private:
225 typedef GlsRenderObject _BaseClass; /**< base class alias */
226
227 // Disable implicit generated Members
228 GlsNinePatch& operator=( const GlsNinePatch &rhs );
229 GlsNinePatch( const GlsNinePatch &src );
230};
231
232#if defined( GLS_DEBUG )
233#pragma BullseyeCoverage save off
234/** Determine if the given edge is valid ( GLS_DEBUG only )
235 * \param edge nine patch edge in question
236 * \return GLS_TRUE if valid else GLS_FALSE
237 * \pre none
238 * \post none
239 */
240inline GlsBool GlsNinePatchEdgeIsValid( const GlsNinePatch::Edge edge )
241{
242 return( ( GlsNinePatch::EDGE_LEFT == edge ) ||
243 ( GlsNinePatch::EDGE_RIGHT == edge ) ||
244 ( GlsNinePatch::EDGE_TOP == edge ) ||
245 ( GlsNinePatch::EDGE_BOTTOM == edge ) );
246
247}
248#pragma BullseyeCoverage restore
249#endif // GLS_DEBUG
250
251#endif // _GLS_POLYGON_H
Definition: gls_display_object.h:65
Definition: gls_event.h:305
Definition: gls_nine_patch.h:61
GlsTextureVertex _unalteredVertices[NUM_VERTS]
Definition: gls_nine_patch.h:173
virtual void Draw(GlsStateManager &gl, const GlsFloat64 time)
GlsTextureVertex _vertices[NUM_VERTS]
Definition: gls_nine_patch.h:172
const GlsBool SizeIsNonDegenerate(void) const
GlsUInt32 _unalteredTextureEdge[NUM_EDGES]
Definition: gls_nine_patch.h:177
void RefactorVerts(void)
Edge
Definition: gls_nine_patch.h:67
@ EDGE_TOP
Definition: gls_nine_patch.h:70
@ NUM_EDGES
Definition: gls_nine_patch.h:72
@ EDGE_BOTTOM
Definition: gls_nine_patch.h:71
@ EDGE_RIGHT
Definition: gls_nine_patch.h:69
@ EDGE_LEFT
Definition: gls_nine_patch.h:68
virtual ~GlsNinePatch()
void SetCenterVisible(const GlsBool visible)
void OutputVertices(GlsStateManager &gl, const GlsBool doTextureCoordinates, const GlsBool doVertexColors) const
void SetTextureEdge(const Edge edge, const GlsUInt32 value)
GlsUInt32 _textureEdge[NUM_EDGES]
Definition: gls_nine_patch.h:175
GlsFloat32 _vertexEdge[NUM_EDGES]
Definition: gls_nine_patch.h:179
GlsNinePatch(const InitParameters &initParameters, GlsEventDispatcher *const eventDispatcher)
void SetVertexEdge(const Edge edge, const GlsFloat32 value)
GlsBool _centerVisible
Definition: gls_nine_patch.h:183
@ LOWER_RIGHT_CORNER_INDEX
Definition: gls_nine_patch.h:87
@ LOWER_LEFT_CORNER_INDEX
Definition: gls_nine_patch.h:86
@ UPPER_RIGHT_CORNER_INDEX
Definition: gls_nine_patch.h:89
@ UPPER_LEFT_CORNER_INDEX
Definition: gls_nine_patch.h:88
@ NUM_DRAW_VERTS
Definition: gls_nine_patch.h:80
@ NUM_DRAW_VERTS_NO_CENTER
Definition: gls_nine_patch.h:79
@ NUM_VERTS
Definition: gls_nine_patch.h:78
virtual void OffsetTexture(const GlsVector2D &offset)
GlsVector2D _currentTextureOffset
Definition: gls_nine_patch.h:185
void OutputCornerVertices(GlsStateManager &gl) const
Definition: gls_render_object.h:70
Definition: gls_state_manager.h:64
This header defines a GLS_DEBUG only macro for facilitating evaluating class invariants in the GL Stu...
#define GLS_CLASS_INVARIANT_DECLARATION(ClassName)
Definition: gls_class_invariant.h:80
This header defines any preprocessor defines needed to configure the GL Studio DO-178B Runtime Librar...
This header defines an abstract class for a display object that is directly rendered to OpenGL (not a...
This header defines the GL State Manager class for managing the GL state in the GL Studio DO-178B Run...
This header defines GlsTextureVertexArray which encapsulates an array of GlsTextureVertex 's in the G...
bool GlsBool
Definition: gls_types.h:96
double GlsFloat64
Definition: gls_types.h:87
unsigned int GlsUInt32
Definition: gls_types.h:73
float GlsFloat32
Definition: gls_types.h:78
This header defines classes for working with 2D and 3D vectors, vertices and textured vertices in the...
Definition: gls_nine_patch.h:94
const GlsUInt32 textureEdges[NUM_EDGES]
Definition: gls_nine_patch.h:98
const GlsFloat32 vertexEdges[NUM_EDGES]
Definition: gls_nine_patch.h:100
const GlsTextureVertex vertices[NUM_VERTS]
Definition: gls_nine_patch.h:97
const GlsRenderObject::InitParameters renderInitParameters
Definition: gls_nine_patch.h:95
const GlsBool centerVisible
Definition: gls_nine_patch.h:102
Definition: gls_render_object.h:83
Definition: gls_vertex.h:117
Definition: gls_vertex.h:50