TurtleBrains  0.3.5
High quality, portable, C++ framework for rapid 2D game development.
TurtleBrains::Express::Graphics::NineSlice Class Reference

#include <tbx_nine_slice.hpp>

Inheritance diagram for TurtleBrains::Express::Graphics::NineSlice:
TurtleBrains::Graphics::Graphic

Public Member Functions

 NineSlice (const std::array< tbGraphics::Sprite, 9 > sprites, tbGraphics::PixelSpace width, tbGraphics::PixelSpace height)
 
 NineSlice (const tbCore::String &spriteSheetName, const tbCore::String &spriteName, tbGraphics::PixelSpace width, tbGraphics::PixelSpace height)
 
virtual ~NineSlice (void)
 
virtual tbGraphics::PixelSpace GetPixelWidth (void) const override
 
virtual tbGraphics::PixelSpace GetPixelHeight (void) const override
 
- Public Member Functions inherited from TurtleBrains::Graphics::Graphic
 Graphic (void)
 
 Graphic (const Graphic &other)=default
 
virtual ~Graphic (void)=default
 
Graphicoperator= (const Graphic &other)=default
 
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 float offsetX, const float offsetY)
 
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)
 
tbMath::Angle GetRotation (void) const
 
void SetRotation (const tbMath::Angle &angle)
 
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)
 
float GetWidth (void) const
 
float GetHeight (void) const
 
float GetScaledWidth (void) const
 
float GetScaledHeight (void) const
 
tbMath::Vector2 GetAnchorPosition (const tbGraphics::AnchorLocation &anchor, const float offsetX, const float offsetY) const
 
tbMath::Vector2 GetAnchorPosition (const tbGraphics::AnchorLocation &anchor, const tbMath::Vector2 &offset=tbMath::Vector2::Zero()) const
 
bool UnstableIsPointContained (const tbMath::Vector2 &point) const
 

Protected Member Functions

virtual void OnRender (void) const override
 
- Protected Member Functions inherited from TurtleBrains::Graphics::Graphic
virtual void OnUpdate (const float deltaTime)
 
virtual void ApplyTransform (void) const
 
virtual void PopTransform (void) const
 

Detailed Description

TODO: TurtleBrains: Documentation: Teach the user how to use this.

Constructor & Destructor Documentation

◆ NineSlice() [1/2]

TurtleBrains::Express::Graphics::NineSlice::NineSlice ( const std::array< tbGraphics::Sprite, 9 >  sprites,
tbGraphics::PixelSpace  width,
tbGraphics::PixelSpace  height 
)
explicit
Parameters
spritesIs an array of sprites for the nine slices, sub 0 being the top-left edge, and continuing along the top row before moving down.

0 | 1 | 2

3 | 4 | 5

6 | 7 | 8

Note
All the sprites must exist on a single spriteSheet / texture for the NineSlice to work with some rendering optimizations, which is also likely to stretch the sprites rather than be a nice repeated pattern like initial intentions. Sprite 4, then, must be a solid color.
width must be at least the the sum of the widths of left edge, right edge and center sprite or an error condition will be triggered.
height must be at least the the sum of the height of top edge, bottom edge and center sprite or an error condition will be triggered.

◆ NineSlice() [2/2]

TurtleBrains::Express::Graphics::NineSlice::NineSlice ( const tbCore::String spriteSheetName,
const tbCore::String spriteName,
tbGraphics::PixelSpace  width,
tbGraphics::PixelSpace  height 
)
explicit

This will append 0 through 8 to the spriteName to setup each sprite easily with more convenience.

◆ ~NineSlice()

virtual TurtleBrains::Express::Graphics::NineSlice::~NineSlice ( void  )
virtual

Cleans up all the resources created for the NineSlice.

Member Function Documentation

◆ GetPixelHeight()

virtual tbGraphics::PixelSpace TurtleBrains::Express::Graphics::NineSlice::GetPixelHeight ( void  ) const
inlineoverridevirtual

This should be overridden to return the height of the graphic in PixelSpace units to be used in placement and anchor point computations.

Reimplemented from TurtleBrains::Graphics::Graphic.

◆ GetPixelWidth()

virtual tbGraphics::PixelSpace TurtleBrains::Express::Graphics::NineSlice::GetPixelWidth ( void  ) const
inlineoverridevirtual

This should be overridden to return the width of the graphic in PixelSpace units to be used in placement and anchor point computations.

Reimplemented from TurtleBrains::Graphics::Graphic.

◆ OnRender()

virtual void TurtleBrains::Express::Graphics::NineSlice::OnRender ( void  ) const
overrideprotectedvirtual

This must be overridden by a subclass to actually display the Graphic on the screen. The function will be invoked when Render() is called and the object IsVisible().

Note
OnRender() should not be called directly, even from a subclass. Use Render() which will first check if the Graphic IsVisible() before displaying with OnRender().

Implements TurtleBrains::Graphics::Graphic.