GL Studio Safety Critical Embedded C++ Runtime Library
All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros
GlsNinePatch Class Reference

#include <gls_nine_patch.h>

+ Inheritance diagram for GlsNinePatch:

Classes

struct  InitParameters
 

Public Types

enum  Edge {
  EDGE_LEFT = 0u , EDGE_RIGHT = 1u , EDGE_TOP = 2u , EDGE_BOTTOM = 3u ,
  NUM_EDGES = 4u
}
 
enum  { NUM_VERTS = 16u , NUM_DRAW_VERTS_NO_CENTER = 32u , NUM_DRAW_VERTS = 36u }
 
enum  { LOWER_LEFT_CORNER_INDEX = 0u , LOWER_RIGHT_CORNER_INDEX = 3u , UPPER_LEFT_CORNER_INDEX = 12u , UPPER_RIGHT_CORNER_INDEX = 15u }
 
- Public Types inherited from GlsDisplayObject
enum  ObjectType { OBJECT_TYPE_COMPOSITE , OBJECT_TYPE_RENDERABLE }
 
enum  PickMode { PICK_MODE_NEVER , PICK_MODE_FIRST , PICK_MODE_ALWAYS }
 

Public Member Functions

 GlsNinePatch (const InitParameters &initParameters, GlsEventDispatcher *const eventDispatcher)
 
virtual void Draw (GlsStateManager &gl, const GlsFloat64 time)
 
virtual void OffsetTexture (const GlsVector2D &offset)
 
void SetTextureEdge (const Edge edge, const GlsUInt32 value)
 
void SetVertexEdge (const Edge edge, const GlsFloat32 value)
 
void SetCenterVisible (const GlsBool visible)
 
- Public Member Functions inherited from GlsRenderObject
virtual void SetAlphaMode (const GlsAlphaMode alphaMode)
 
virtual void SetFillColor (const GlsColor &fillColor)
 
virtual void SetLineColor (const GlsColor &lineColor)
 
virtual void SetLineWidth (const GlsFloat32 lineWidth)
 
virtual void SetPolygonMode (const GlsPolygonMode polygonMode)
 
virtual void SetTextureIndex (const GlsUInt32 textureIndex)
 
virtual void OffsetTexture (const GlsVector2D &offset)=0
 
- Public Member Functions inherited from GlsDisplayObject
virtual void Draw (GlsStateManager &gl, const GlsFloat64 time)=0
 
virtual void Calculate (const GlsFloat64 time)
 
virtual GlsDisplayObjectPickTest (const GlsVector2D &windowCoord, GlsInputManager &inputManager, const GlsMatrixAffineD::GLMatrixAffineF &parentDrawMatrix)
 
GlsDisplayObjectHandleEvent (GlsEvent &event)
 
ObjectType GetObjectType (void) const
 
void SetBlinking (const GlsBool blinking)
 
void SetBlinkRate (const GlsFloat32 blinkRate)
 
void SetDynamicRotation (const GlsVector3D &dynamicRotation)
 
void SetDynamicScale (const GlsVector3D &dynamicScale)
 
void SetDynamicTranslation (const GlsVector3D &dynamicTranslation)
 
void SetVisibility (const GlsBool visible)
 
void SetParent (GlsDisplayObject *const parent)
 
void SetPickMode (const PickMode pickMode)
 
GlsBool NeedCalculate (void) const
 
void InvalidatePickCache (void)
 

Protected Member Functions

const GlsBool SizeIsNonDegenerate (void) const
 
void OutputVertices (GlsStateManager &gl, const GlsBool doTextureCoordinates, const GlsBool doVertexColors) const
 
void OutputCornerVertices (GlsStateManager &gl) const
 
void RefactorVerts (void)
 
virtual ~GlsNinePatch ()
 
- Protected Member Functions inherited from GlsRenderObject
 GlsRenderObject (const InitParameters &initParameters, GlsEventDispatcher *const eventDispatcher)
 
GLint GlsTextureFilterModeToGL (const GlsTextureFilterMode mode) const
 
void SetupDepthTest (GlsStateManager &gl) const
 
void SetupAlpha (GlsStateManager &gl) const
 
GlsBool SetupTexture (GlsStateManager &gl, const GlsUInt32 textureIndex) const
 
void SetupTextureFilterSettings (GlsStateManager &gl) const
 
void SetupBackfaceCulling (GlsStateManager &gl) const
 
void SetupShading (GlsStateManager &gl) const
 
void SetupLineStyle (GlsStateManager &gl) const
 
void SetupAntiAlias (GlsStateManager &gl) const
 
virtual ~GlsRenderObject ()
 
- Protected Member Functions inherited from GlsDisplayObject
 GlsDisplayObject (const InitParameters &initParameters, const ObjectType objectType, GlsEventDispatcher *const eventDispatcher)
 
virtual ~GlsDisplayObject ()
 
GlsBool CalcDrawMatrix (const GlsMatrixAffineD *const additionalTransform, const GlsBool includeLocation)
 
virtual void CalcWindowPickRegion (GlsInputManager &inputManager, const GlsMatrixAffineD::GLMatrixAffineF &parentDrawMatrix)
 
GlsBool IsBlinkedOff (const GlsFloat64 time) const
 

Protected Attributes

GlsTextureVertex _vertices [NUM_VERTS]
 
GlsTextureVertex _unalteredVertices [NUM_VERTS]
 
GlsUInt32 _textureEdge [NUM_EDGES]
 
GlsUInt32 _unalteredTextureEdge [NUM_EDGES]
 
GlsFloat32 _vertexEdge [NUM_EDGES]
 
GlsBool _centerVisible
 
GlsVector2D _currentTextureOffset
 
- Protected Attributes inherited from GlsRenderObject
const GlsBool _antiAlias
 
const GlsTexturePalette_texturePalette
 
const GlsBool _textureRepeat
 
const GlsTextureMapMode _textureMapMode
 
const GlsTextureFilterMode _textureMagFilterMode
 
const GlsTextureFilterMode _textureMinFilterMode
 
const GlsBool _cullBackFace
 
const GlsDepthBufferMode _depthBufferMode
 
const GlsPolygonEndMode _polygonEndMode
 
const GlsShadingMode _shadingMode
 
GlsAlphaMode _alphaMode
 
GlsColor _lineColor
 
GlsUInt32 _textureIndex
 
GlsPolygonMode _polygonMode
 
GlsColor _fillColor
 
GlsFloat32 _lineWidth
 
- Protected Attributes inherited from GlsDisplayObject
const GlsMatrixAffineD _dcsMatrix
 
const GlsMatrixAffineD _dcsMatrixInverse
 
const GlsBool _dcsMatrixIsIdentity
 
const GlsVector3D _location
 
const GlsBool _needCalculate
 
const ObjectType _objectType
 
const PickRegion _pickRegion
 
GlsEventDispatcher *const _eventDispatcher
 
const GlsVector3D _rotationPoint
 
GlsBool _blinking
 
GlsFloat32 _blinkRate
 
GlsMatrixAffineD::GLMatrixAffineF _drawMatrix
 
GlsVector3D _dynamicRotation
 
GlsVector3D _dynamicScale
 
GlsBool _dynamicScaleIsUnity
 
GlsVector3D _dynamicTranslation
 
GlsBool _needCalcDrawMatrix
 
GlsBool _visible
 
PickMode _pickMode
 
GlsBool _windowPickRegionValid
 
GlsVector2D _windowPickLowerLeft
 
GlsVector2D _windowPickUpperRight
 
GlsVector2D _windowPickUpperLeft
 
GlsVector2D _windowPickLowerRight
 
GlsMatrixAffineD::GLMatrixAffineF _pickMatrix
 
GlsDisplayObject_parent
 

Additional Inherited Members

- Static Protected Attributes inherited from GlsRenderObject
static const GLclampf ALPHA_MODE_2_LEVEL_REF
 

Detailed Description

The GlsNinePatch abstracts a set of nine polygons which contain edges that maintain the same width/height after scaling the object.

Invariant
base class invariant holds, _vertices[].IsValid() for all vertices, _vertexEdge[] > 0 for all vertex edges, _textureEdge[] > 0 for all texture edges,

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
NUM_VERTS 
NUM_DRAW_VERTS_NO_CENTER 
NUM_DRAW_VERTS 

◆ anonymous enum

anonymous enum
Enumerator
LOWER_LEFT_CORNER_INDEX 
LOWER_RIGHT_CORNER_INDEX 
UPPER_LEFT_CORNER_INDEX 
UPPER_RIGHT_CORNER_INDEX 

◆ Edge

Enumerator
EDGE_LEFT 
EDGE_RIGHT 
EDGE_TOP 
EDGE_BOTTOM 
NUM_EDGES 

Constructor & Destructor Documentation

◆ GlsNinePatch()

GlsNinePatch::GlsNinePatch ( const InitParameters initParameters,
GlsEventDispatcher *const  eventDispatcher 
)

Constructor - create instance

Parameters
initParametersinitialization parametets
eventDispatcherevent dispatcher for this object else GLS_NULL
Precondition
initParameters.IsValid()
Postcondition
instance created

◆ ~GlsNinePatch()

virtual GlsNinePatch::~GlsNinePatch ( )
protectedvirtual

Destructor - shall never be called

Precondition
none
Postcondition
none

Member Function Documentation

◆ Draw()

virtual void GlsNinePatch::Draw ( GlsStateManager gl,
const GlsFloat64  time 
)
virtual

Draws this nine patch

Parameters
glGL State manager for OpenGL into which polygon is drawn
timethe elaspsed time in seconds since program start
Precondition
time >= 0.0
Postcondition
polygon is drawn to OpenGL if visible and not blinked off, _previousDynamicScale = _dynamicScale

Implements GlsDisplayObject.

◆ OffsetTexture()

virtual void GlsNinePatch::OffsetTexture ( const GlsVector2D offset)
virtual

Offset the texture on the object

Parameters
offsetx, y offset for texture
Precondition
offset.IsValid()
Postcondition
offset is added to the texture coordinates

Implements GlsRenderObject.

◆ OutputCornerVertices()

void GlsNinePatch::OutputCornerVertices ( GlsStateManager gl) const
protected

Output the vertices in the array to GL

Parameters
glGL state manager to receive verts
doTextureCoordinatesGLS_TRUE to send texture coordinates with each vert else GLS_FALSE
doVertexColorsGLS_TRUE to send vertex colors with each vert else GLS_FALSE
Precondition
called inside a GL begin/end pair
Postcondition
vertices are output to GL

◆ OutputVertices()

void GlsNinePatch::OutputVertices ( GlsStateManager gl,
const GlsBool  doTextureCoordinates,
const GlsBool  doVertexColors 
) const
protected

Output the vertices in the array to GL

Parameters
glGL state manager to receive verts
doTextureCoordinatesGLS_TRUE to send texture coordinates with each vert else GLS_FALSE
doVertexColorsGLS_TRUE to send vertex colors with each vert else GLS_FALSE
Precondition
called inside a GL begin/end pair
Postcondition
vertices are output to GL

◆ RefactorVerts()

void GlsNinePatch::RefactorVerts ( void  )
protected

Adjusts the vertices based on the current texture and vertex edge settings.

Precondition
none
Postcondition
vertices are adjusted based on current texture and vertex edge settings

◆ SetCenterVisible()

void GlsNinePatch::SetCenterVisible ( const GlsBool  visible)

Sets whether the center is drawn or not

Parameters
visibleboolean to control visibility of center quad
Precondition
none
Postcondition
object has new condition for drawing center

◆ SetTextureEdge()

void GlsNinePatch::SetTextureEdge ( const Edge  edge,
const GlsUInt32  value 
)

Sets the texture edge value IN from the nine patch defined bounding region

Parameters
edgeenumerated above
valuein pixel measurements
Precondition
edge < NUM_EDGES, value >= 0, initial texture edge value at object creation must be have been > 0
Postcondition
object texture edge has new value

◆ SetVertexEdge()

void GlsNinePatch::SetVertexEdge ( const Edge  edge,
const GlsFloat32  value 
)

Sets the vertex edge value IN from the nine patch defined bounding region

Parameters
edgeenumerated above
valuein unit measurements
Precondition
edge < NUM_EDGES, value >= 0.0
Postcondition
object vertex edge has new value

◆ SizeIsNonDegenerate()

const GlsBool GlsNinePatch::SizeIsNonDegenerate ( void  ) const
protected

Returns whether the total width or height is greater than the opposite edges combined

Returns
GLS_TRUE if it is non-degenerate else GLS_FALSE
Precondition
none
Postcondition
none

Member Data Documentation

◆ _centerVisible

GlsBool GlsNinePatch::_centerVisible
protected

Whether or not the center patch will be drawn

◆ _currentTextureOffset

GlsVector2D GlsNinePatch::_currentTextureOffset
protected

current texture offset accumulated by OffsetTexture()

◆ _textureEdge

GlsUInt32 GlsNinePatch::_textureEdge[NUM_EDGES]
protected

Values representing the distance from the edge of the texture that makes up the NinePatch borders. Units are in pixels and are the distance IN from the edge of the texture.

◆ _unalteredTextureEdge

GlsUInt32 GlsNinePatch::_unalteredTextureEdge[NUM_EDGES]
protected

Values representing the original distance from the edge of the texture that makes up the NinePatch borders. Units are in pixels and are the distance IN from the edge of the texture.

◆ _unalteredVertices

GlsTextureVertex GlsNinePatch::_unalteredVertices[NUM_VERTS]
protected

array of vertices and texture vertices that are unaltered from initialization

◆ _vertexEdge

GlsFloat32 GlsNinePatch::_vertexEdge[NUM_EDGES]
protected

Values representing the size of edges of the NinePatch. Units are in logical units measure going IN from the edge of the NinePatch Values range from 0.0f to the total width of the nine patch minus the opposite edge.

◆ _vertices

GlsTextureVertex GlsNinePatch::_vertices[NUM_VERTS]
protected

Array of vertices that defines the NinePatch, arranged as follows: 12–13—14—15 | | | | 8-—9—10—11 | | | | 4-—5-—6-—7 | | | | 0-—1-—2-—3 array of vertices and texture vertices for nine patch