TurtleBrains  0.3.5
High quality, portable, C++ framework for rapid 2D game development.
TurtleBrains::Graphics::Graphic Class Referenceabstract

#include <tb_graphic.hpp>

Inheritance diagram for TurtleBrains::Graphics::Graphic:
TurtleBrains::Game::TileSystem TurtleBrains::Graphics::GraphicList TurtleBrains::Graphics::LineContainer TurtleBrains::Graphics::PolygonShape TurtleBrains::Graphics::Sprite TurtleBrains::Graphics::Text TurtleBrainsExpress::Counters::HealthBar TurtleBrainsExpress::Counters::HealthIcons TurtleBrainsExpress::Graphics::NineSlice TurtleBrainsExpress::Graphics::ParallaxBackdrop TurtleBrainsExpress::Graphics::ShadowedText TurtleBrainsExpress::Graphics::WebSprite

Public Member Functions

 Graphic (void)
 
 Graphic (const Graphic &other)
 
virtual ~Graphic (void)
 
bool IsActive (void) const
 
void SetActive (const bool isActive)
 
void Update (const float deltaTime)
 
bool IsVisible (void) const
 
void SetVisible (const bool isVisible)
 
void Render (void) const
 
const tbMath::Vector2GetPosition (void) const
 
void SetPosition (const float x, const float y)
 
void SetPosition (const tbMath::Vector2 &position)
 
const tbMath::Vector2GetOrigin (void) const
 
void SetOrigin (const AnchorLocation &anchor, const tbMath::Vector2 &offset=tbMath::Vector2::Zero())
 
void SetOrigin (const float originX, const float originY)
 
void SetOrigin (const tbMath::Vector2 &origin)
 
float GetDepth (void) const
 
void SetDepth (const float newDepth)
 
const tbMath::Vector2GetScale (void) const
 
void SetScale (const float scale)
 
void SetScale (const tbMath::Vector2 &scale)
 
void SetScale (const float scaleX, const float scaleY)
 
float GetRotation (void) const
 
void SetRotation (const float rotation)
 
void SetScroll (const float scroll)
 
void SetScroll (const float scrollX, const float scrollY)
 
bool IsRelative (void) const
 
const ColorGetColor (void) const
 
virtual void SetColor (const tbGraphics::Color &newColor)
 
virtual PixelSpace GetPixelWidth (void) const
 
virtual PixelSpace GetPixelHeight (void) const
 
float GetWidth (void) const
 
float GetHeight (void) const
 
float GetScaledWidth (void) const
 
float GetScaledHeight (void) const
 
bool UnstableIsPointContained (const tbMath::Vector2 &point) const
 

Protected Member Functions

virtual void OnUpdate (const float deltaTime)
 
virtual void OnRender (void) const =0
 
virtual void ApplyTransform (void) const
 
virtual void PopTransform (void) const
 

Detailed Description

The Graphic is an abstract interface for Text, Sprite and other graphical objects that can be updated and displayed.

Constructor & Destructor Documentation

TurtleBrains::Graphics::Graphic::Graphic ( void  )

Constructs a Graphic object that starts out active and visible with a position of (0.0f, 0.0f) and depth at 0.0f.

TurtleBrains::Graphics::Graphic::Graphic ( const Graphic other)

Constructs a Graphic object by copying the details from the other Graphic object.

Parameters
otherThe Graphic object to copy and mimic.
virtual TurtleBrains::Graphics::Graphic::~Graphic ( void  )
virtual

Destroys the Graphic object by doing nothing since no resources need to be cleaned up.

Member Function Documentation

virtual void TurtleBrains::Graphics::Graphic::ApplyTransform ( void  ) const
protectedvirtual

Applies the objects scaling, rotation, camera and translation transform before it gets rendered. This is automatically called in Render() before OnRender() gets called if the object is visible.

const Color& TurtleBrains::Graphics::Graphic::GetColor ( void  ) const

Returns the color of the Graphic which defaults to White (0xFFFFFFFF) but can be changed with SetColor().

float TurtleBrains::Graphics::Graphic::GetDepth ( void  ) const

Returns the depth, Z value, of the Graphic object.

float TurtleBrains::Graphics::Graphic::GetHeight ( void  ) const
inline

This is really the height of the graphic object in PixelSpace converted to a floating point for convenience.

const tbMath::Vector2& TurtleBrains::Graphics::Graphic::GetOrigin ( void  ) const

Returns the origin, or hot-spot, of the Graphic. The origin is an offset from where the graphic will be position by and rotated around.

virtual PixelSpace TurtleBrains::Graphics::Graphic::GetPixelHeight ( void  ) const
inlinevirtual
virtual PixelSpace TurtleBrains::Graphics::Graphic::GetPixelWidth ( void  ) const
inlinevirtual
const tbMath::Vector2& TurtleBrains::Graphics::Graphic::GetPosition ( void  ) const

Returns the position of the sprite as a Vector2 object.

float TurtleBrains::Graphics::Graphic::GetRotation ( void  ) const
inline

Returns the current rotation/orientation of the sprite.

const tbMath::Vector2& TurtleBrains::Graphics::Graphic::GetScale ( void  ) const
inline

Returns the scale of the of the graphic as a Vector2 for horizontal (x component) and vertical (y component) scaling.

float TurtleBrains::Graphics::Graphic::GetScaledHeight ( void  ) const
inline

This is the height of the graphic object multiplied by the vertical scale factor.

float TurtleBrains::Graphics::Graphic::GetScaledWidth ( void  ) const
inline

This is the width of the graphic object multiplied by the horizontal scale factor.

float TurtleBrains::Graphics::Graphic::GetWidth ( void  ) const
inline

This is really the width of the graphic object in PixelSpace converted to a floating point for convenience.

bool TurtleBrains::Graphics::Graphic::IsActive ( void  ) const

Returns true if the Graphic is currently active and needing to be updated, or false if the OnUpdate() calls should be skipped.

bool TurtleBrains::Graphics::Graphic::IsRelative ( void  ) const

This will return true if the Graphic object is relative to it's parent object, such as the contained GraphicList. Currently all Graphics are always relative, although this may be updated in future versions of TurtleBrains.

bool TurtleBrains::Graphics::Graphic::IsVisible ( void  ) const

Returns true if the Graphic is currently visible and needing to be displayed, or false if the OnRender() calls should be skipped.

virtual void TurtleBrains::Graphics::Graphic::OnUpdate ( const float  deltaTime)
protectedvirtual

This should be overridden by a subclass if it needs to perform any updates per frame before displaying / rendering a new frame. This function will be invoked when Update() is called and the object IsActive().

Note
OnUpdate() should not be called directly, even from a subclass. Use Update() which will first check if the Graphic IsActive() before updating with OnUpdate().

Reimplemented in TurtleBrains::Game::Entity, TurtleBrains::Graphics::AnimatedSprite, TurtleBrainsExpress::Counters::Counter, TurtleBrains::Game::EntityManager, TurtleBrainsExpress::Counters::HealthBar, TurtleBrains::Game::GameScene, and TurtleBrains::Graphics::GraphicList.

virtual void TurtleBrains::Graphics::Graphic::PopTransform ( void  ) const
protectedvirtual

Removes all transformations that were applied during ApplyTransform as if nothing even happened. This is automatically called in Render() after OnRender() was called if the object is visible.

void TurtleBrains::Graphics::Graphic::Render ( void  ) const

First checks to see if the object IsVisible() and calls OnRender() if it is. If the object is not visible nothing happens.

void TurtleBrains::Graphics::Graphic::SetActive ( const bool  isActive)

Sets a flag that when false causes the Graphic to skip the OnUpdate() calls and when true will proceed with the OnUpdate() calls. Defaults to true, may lead to better performance if false when the object does not need to be updated.

virtual void TurtleBrains::Graphics::Graphic::SetColor ( const tbGraphics::Color newColor)
virtual

Change the color of the sprite so it can fade in/out with alpha, or modify the color for other effects.

Reimplemented in TurtleBrains::Graphics::Text, TurtleBrains::Graphics::GraphicList, TurtleBrains::Graphics::PolygonShape, TurtleBrains::Graphics::LineContainer, and TurtleBrainsExpress::Graphics::ShadowedText.

void TurtleBrains::Graphics::Graphic::SetDepth ( const float  newDepth)

Sets the depth of the graphic object which should be within a range of -1.0f for objects far in the background and 1.0f for the objects nearest to the camera. The default value is 0.0f.

Parameters
newDepthThe depth of the Graphic object, smaller being farther away and larger being closer to the camera.
void TurtleBrains::Graphics::Graphic::SetOrigin ( const AnchorLocation anchor,
const tbMath::Vector2 offset = tbMath::Vector2::Zero() 
)

Sets the origin or hot-spot of the sprite. This is an offset where the sprite will be positioned by and rotated around. The AnchorLocation will describe where the origin offset with a 9 locations, the four corners, and center points of each edge.

void TurtleBrains::Graphics::Graphic::SetOrigin ( const float  originX,
const float  originY 
)
inline

Sets the origin or a hot-spot of the sprite. This is an offset where the sprite will be positioned by and rotated around.

Note
Defaults to center, may default to top-left in future versions.
void TurtleBrains::Graphics::Graphic::SetOrigin ( const tbMath::Vector2 origin)
inline

Sets the origin or a hot-spot of the sprite. This is an offset where the sprite will be positioned by and rotated around.

Note
Defaults to center, may default to top-left in future versions.
void TurtleBrains::Graphics::Graphic::SetPosition ( const float  x,
const float  y 
)

Sets the position of the object to the x and y location in world space.

Parameters
xThe position in the world along the worlds X-axis. 0 being the origin, by default the world X-axis is horizontal with 0 being the left edge of the screen and positive numbers toward the right.
yThe position in the world along the worlds Y-axis. 0 being the origin, by default the world Y-axis is vertical with 0 being the top edge of the screen and positive numbers toward the bottom.
void TurtleBrains::Graphics::Graphic::SetPosition ( const tbMath::Vector2 position)

Sets the position of the object to the location in world space with the given x and y components of the Vector2.

Parameters
positionWhere in the world along the each axis the Graphic should be placed. By default the world X-axis is horizontal with 0 being the left edge of the screen and positive numbers toward the right and the Y-axis is vertical with 0 being the top edge of the screen and positive numbers toward the bottom.
void TurtleBrains::Graphics::Graphic::SetRotation ( const float  rotation)
inline

Set the rotation/orientation of the sprite so it can rotate around the game world and animate things such as windmills, tires, etc.

Parameters
rotationThe angle in degrees of the sprite, positive values rotate clockwise.
void TurtleBrains::Graphics::Graphic::SetScale ( const float  scale)

Changes the scaling of the sprite uniformly on each axis.

Parameters
scaleThe amount of scaling to apply, 1.0 is normal scale, 0.5 is half size and 2.0 is double.
Note
Triggers an error condition if scale is a negative value, should use SetFlipped on sprite for this effect.
void TurtleBrains::Graphics::Graphic::SetScale ( const tbMath::Vector2 scale)

Changes the scaling of the sprite on each axis separately.

Parameters
scaleThe amount of scaling to apply on the X-axis or Y-axis of the graphic stored in the X and Y components of the Vector2 respectively: 1.0 is normal scale, 0.5 is half size and 2.0f is double.
Note
Triggers an error condition if scale is a negative value, should use SetFlipped on sprite for this effect.
void TurtleBrains::Graphics::Graphic::SetScale ( const float  scaleX,
const float  scaleY 
)

Changes the scaling of the sprite on each axis separately, this is a convenient function that will call SetScale(tbMath::Vector2&) version.

Parameters
scaleXThe amount of scaling to apply on the X-axis, 1.0 is normal scale, 0.5 is half size.
scaleYThe amount of scaling to apply on the Y-axis, 1.0 is normal scale, 2.0 is double size.
Note
Triggers an error condition if scale is a negative value, should use SetFlipped on sprite for this effect.
void TurtleBrains::Graphics::Graphic::SetScroll ( const float  scroll)
inline

This value changes how the graphic interacts with the camera, a scroll value of 0 will attach the graphic to the camera which can be useful for UI graphic objects. A scroll value of 1 will scroll at a normal rate as the camera moves around while other values can create a parallax effect.

void TurtleBrains::Graphics::Graphic::SetScroll ( const float  scrollX,
const float  scrollY 
)
inline

This value changes how the graphic interacts with the camera, a scroll value of 0 will attach the graphic to the camera which can be useful for UI graphic objects. A scroll value of 1 will scroll at a normal rate as the camera moves around while other values can create a parallax effect.

Parameters
scrollXThe scroll value for horizontal movement/interaction with the camera.
scrollYThe scroll value for vertical movement/interaction with the camera.
void TurtleBrains::Graphics::Graphic::SetVisible ( const bool  isVisible)

Sets a flag that when false causes the Graphic to skip the OnRender() calls and when true will proceed with the OnRender() calls. Defaults to true, may lead to better performance if false when the object does not need to be displayed.

void TurtleBrains::Graphics::Graphic::Update ( const float  deltaTime)

First checks to see if the object IsActive() and calls OnUpdate() if it is. If the object is not active nothing happens.