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

#include <tb_graphic_list.hpp>

Inheritance diagram for TurtleBrains::Graphics::GraphicList:
TurtleBrains::Graphics::Graphic TurtleBrains::Core::Noncopyable TurtleBrains::Game::Entity TurtleBrains::Game::EntityManager TurtleBrains::Game::GameScene TurtleBrains::Game::TransitionScene

Public Member Functions

 GraphicList (void)
 
virtual ~GraphicList (void)
 
void ClearGraphics (void)
 
void AddGraphic (Graphic *graphic)
 
void AddGraphic (std::unique_ptr< Graphic > &&graphic)
 
void AddGraphic (Graphic &graphic)
 
void RemoveGraphic (Graphic *graphic)
 
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)
 
virtual void SetColor (const tbGraphics::Color &newColor) override
 
virtual PixelSpace GetPixelWidth (void) const override
 
virtual PixelSpace GetPixelHeight (void) const override
 
void RecalculateWidthAndHeight (void)
 
- 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
 
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 OnUpdate (const float deltaTime) override
 
virtual void OnRender (void) const override
 
- Protected Member Functions inherited from TurtleBrains::Graphics::Graphic
virtual void ApplyTransform (void) const
 
virtual void PopTransform (void) const
 

Detailed Description

A GraphicList is a container of Graphic objects that get updated and rendered when the GraphicList gets updated or rendered. The contained Graphic objects are sorted and updated/rendered based on their depth in the scene. Depending on how the Graphic object is added to the GraphicList, the memory may also be deleted. See the difference between AddGraphic(Graphic&) and AddGraphic(Graphic*).

Constructor & Destructor Documentation

◆ GraphicList()

TurtleBrains::Graphics::GraphicList::GraphicList ( void  )

Constructs an empty list of Graphic objects. Use AddGraphic() to add Graphic objects to be updated and rendered by the GraphicList object.

◆ ~GraphicList()

virtual TurtleBrains::Graphics::GraphicList::~GraphicList ( void  )
virtual

Destructs the GraphicList object, which does not clean up any resources associated with the Graphic objects that were added to the list with AddGraphic.

Member Function Documentation

◆ AddGraphic() [1/3]

void TurtleBrains::Graphics::GraphicList::AddGraphic ( Graphic graphic)

Adds a Graphic to the list so it will be updated, if active, and rendered, if visible, whenever the object is updated or rendered. The memory for the graphic is NOT managed and must remain available and in scope until it is removed with RemoveGraphic(). The GraphicList will not 'own' a Graphic added this way.

◆ AddGraphic() [2/3]

void TurtleBrains::Graphics::GraphicList::AddGraphic ( Graphic graphic)

Adds a Graphic to the list so it will be updated, if active, and rendered, if visible, whenever the object is updated or rendered. The memory for the graphic is managed and delete graphic; will be called when either the GraphicList is destroyed or the Graphic is removed with RemoveGraphic().

Deprecated:
use AddGraphic(std::unique_ptr<Graphic>) instead, this will handle exceptional cases slightly better and is more 'modern' C++.

◆ AddGraphic() [3/3]

void TurtleBrains::Graphics::GraphicList::AddGraphic ( std::unique_ptr< Graphic > &&  graphic)

Adds a Graphic to the list so it will be updated, if active, and rendered, if visible. The memory for the graphic is managed and will be cleaned up automatically when either the GraphicList is destroyed or the Graphic is removed with RemoveGraphic().

◆ ClearGraphics()

void TurtleBrains::Graphics::GraphicList::ClearGraphics ( void  )

Removes all graphics from the GraphicList. If any Graphics objects are managed, this will delete the memory for those objects. TODO: TurtleBrains: Documentation: See Object Ownership / Management.

◆ GetPixelHeight()

virtual PixelSpace TurtleBrains::Graphics::GraphicList::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 PixelSpace TurtleBrains::Graphics::GraphicList::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::Graphics::GraphicList::OnRender ( void  ) const
overrideprotectedvirtual

Calls Render() on each Graphic object contained in the list which will then call OnRender() if the object is visible.

Note
This will currently trigger an error condition if the Graphic object is not relative to the parent location as this feature is currently unimplemented. TODO: TIM: Implementation: Needs to be implemented.

Implements TurtleBrains::Graphics::Graphic.

Reimplemented in TurtleBrains::Game::TransitionScene, TurtleBrains::Game::GameScene, and TurtleBrains::Game::Entity.

◆ OnUpdate()

virtual void TurtleBrains::Graphics::GraphicList::OnUpdate ( const float  deltaTime)
overrideprotectedvirtual

Calls Update() on each Graphic object contained in the list which will then call OnUpdate() if the object is active.

Reimplemented from TurtleBrains::Graphics::Graphic.

Reimplemented in TurtleBrains::Game::TransitionScene, TurtleBrains::Game::EntityManager, TurtleBrains::Game::GameScene, and TurtleBrains::Game::Entity.

◆ RecalculateWidthAndHeight()

void TurtleBrains::Graphics::GraphicList::RecalculateWidthAndHeight ( void  )

Iterates through ALL the graphics contained in the list and calculates the overall width and height of the area they contain.

Note
As of 2025-10-25 on v0.4.3 this does not account for any rotated graphics, in part because Graphic::GetAnchorPositionOf() does not account for the rotation and partly because implementation would need to handle things differently.

◆ RemoveGraphic()

void TurtleBrains::Graphics::GraphicList::RemoveGraphic ( Graphic graphic)

Removes a Graphic from the list so it will no longer be updated or rendered. This will only clean up memory or resources used by the graphic if added with AddGraphic(Graphic*), but those added with AddGraphic(Graphic&) are expected that the graphic remained available until it was removed.

◆ SetColor()

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

Changes the color of all the Graphic objects in the GraphicList.

Reimplemented from TurtleBrains::Graphics::Graphic.

◆ SetOrigin() [1/4]

void TurtleBrains::Graphics::GraphicList::SetOrigin ( const AnchorLocation anchor,
const float  offsetX,
const float  offsetY 
)
inline
Note
The size of the GraphicList can change on the fly for MANY reasons which may upset the origin, especially using an AnchorLocation. If a child graphic moves to a new location, gets scaled or the AddGraphic/RemoveGraphic functions are used, then the origin may need to be reset manually again, possibly after manually calling RecalculateWidthAndHeight().

◆ SetOrigin() [2/4]

void TurtleBrains::Graphics::GraphicList::SetOrigin ( const AnchorLocation anchor,
const tbMath::Vector2 offset = tbMath::Vector2::Zero() 
)
inline
Note
The size of the GraphicList can change on the fly for MANY reasons which may upset the origin, especially using an AnchorLocation. If a child graphic moves to a new location, gets scaled or the AddGraphic/RemoveGraphic functions are used, then the origin may need to be reset manually again, possibly after manually calling RecalculateWidthAndHeight().

◆ SetOrigin() [3/4]

void TurtleBrains::Graphics::GraphicList::SetOrigin ( const float  originX,
const float  originY 
)
inline
Note
The size of the GraphicList can change on the fly for MANY reasons which may upset the origin, especially using an AnchorLocation. If a child graphic moves to a new location, gets scaled or the AddGraphic/RemoveGraphic functions are used, then the origin may need to be reset manually again, possibly after manually calling RecalculateWidthAndHeight().

◆ SetOrigin() [4/4]

void TurtleBrains::Graphics::GraphicList::SetOrigin ( const tbMath::Vector2 origin)
inline
Note
The size of the GraphicList can change on the fly for MANY reasons which may upset the origin, especially using an AnchorLocation. If a child graphic moves to a new location, gets scaled or the AddGraphic/RemoveGraphic functions are used, then the origin may need to be reset manually again, possibly after manually calling RecalculateWidthAndHeight().