R-Type  2
Doom but in better
Loading...
Searching...
No Matches
GUI::ECS::Components::SpriteComponent Class Reference

Represents a drawable and interactive sprite in the ECS system. More...

#include <SpriteComponent.hpp>

Inheritance diagram for GUI::ECS::Components::SpriteComponent:
Inheritance graph
Collaboration diagram for GUI::ECS::Components::SpriteComponent:
Collaboration graph

Public Member Functions

 SpriteComponent ()
 Default constructor.
 
 SpriteComponent (const std::string &name)
 Constructs a sprite component with a specific name.
 
 SpriteComponent (const GUI::ECS::Systems::Collision &collision)
 Constructs a sprite component from a collision component.
 
 SpriteComponent (const GUI::ECS::Components::AnimationComponent &animation)
 Constructs a sprite component from an animation component.
 
 SpriteComponent (const GUI::ECS::Components::TextureComponent &spritesheetTexture)
 Constructs a sprite component from a texture component.
 
 SpriteComponent (const std::string &name, const std::string &spritesheetPath)
 Constructs a sprite component with:
 
 SpriteComponent (const std::string &name, const GUI::ECS::Systems::Collision &collision)
 Constructs a sprite component with:
 
 SpriteComponent (const std::string &name, const GUI::ECS::Components::AnimationComponent &animation)
 Constructs a sprite component with:
 
 SpriteComponent (const std::string &name, const GUI::ECS::Components::TextureComponent &spritesheetTexture)
 Constructs a sprite component with:
 
 SpriteComponent (const std::string &name, const GUI::ECS::Systems::Collision &collision, const GUI::ECS::Components::AnimationComponent &animation)
 Constructs a sprite component with:
 
 SpriteComponent (const std::string &name, const GUI::ECS::Systems::Collision &collision, const GUI::ECS::Components::TextureComponent &spritesheetTexture)
 Constructs a sprite component with:
 
 SpriteComponent (const std::string &name, const GUI::ECS::Systems::Colour &normalColor, const GUI::ECS::Systems::Colour &hoverColor, const GUI::ECS::Systems::Colour &clickedColor)
 Constructs a sprite component with:
 
 SpriteComponent (const std::string &name, const GUI::ECS::Systems::Collision &collision, const GUI::ECS::Systems::Colour &normalColor, const GUI::ECS::Systems::Colour &hoverColor, const GUI::ECS::Systems::Colour &clickedColor)
 Constructs a sprite component with:
 
 SpriteComponent (const std::string &name, const GUI::ECS::Components::AnimationComponent &animation, const GUI::ECS::Systems::Colour &normalColor, const GUI::ECS::Systems::Colour &hoverColor, const GUI::ECS::Systems::Colour &clickedColor)
 Constructs a sprite component with:
 
 SpriteComponent (const std::string &name, const GUI::ECS::Components::TextureComponent &spritesheetTexture, const GUI::ECS::Systems::Colour &normalColor, const GUI::ECS::Systems::Colour &hoverColor, const GUI::ECS::Systems::Colour &clickedColor)
 Constructs a sprite component with:
 
 SpriteComponent (const std::string &name, const GUI::ECS::Systems::Collision &collision, const GUI::ECS::Components::AnimationComponent &animation, const GUI::ECS::Systems::Colour &normalColor, const GUI::ECS::Systems::Colour &hoverColor, const GUI::ECS::Systems::Colour &clickedColor)
 Constructs a sprite component with:
 
 SpriteComponent (const std::string &name, const GUI::ECS::Systems::Collision &collision, const GUI::ECS::Components::TextureComponent &spritesheetTexture, const GUI::ECS::Systems::Colour &normalColor, const GUI::ECS::Systems::Colour &hoverColor, const GUI::ECS::Systems::Colour &clickedColor)
 Constructs a sprite component with:
 
 SpriteComponent (const std::uint32_t entityId)
 Construct a new Sprite Component object and assing a specific entity id.
 
 SpriteComponent (const std::uint32_t entityId, const std::string &name)
 Constructs a sprite component with:
 
 SpriteComponent (const std::uint32_t entityId, const GUI::ECS::Systems::Collision &collision)
 Constructs a sprite component with:
 
 SpriteComponent (const std::uint32_t entityId, const GUI::ECS::Components::AnimationComponent &animation)
 Constructs a sprite component with:
 
 SpriteComponent (const std::uint32_t entityId, const GUI::ECS::Components::TextureComponent &spritesheetTexture)
 Constructs a sprite component with:
 
 SpriteComponent (const std::uint32_t entityId, const std::string &name, const std::string &spritesheetPath)
 Constructs a sprite component with:
 
 SpriteComponent (const std::uint32_t entityId, const std::string &name, const GUI::ECS::Systems::Collision &collision)
 Constructs a sprite component with:
 
 SpriteComponent (const std::uint32_t entityId, const std::string &name, const GUI::ECS::Components::AnimationComponent &animation)
 Constructs a sprite component with:
 
 SpriteComponent (const std::uint32_t entityId, const std::string &name, const GUI::ECS::Components::TextureComponent &spritesheetTexture)
 Constructs a sprite component with:
 
 SpriteComponent (const std::uint32_t entityId, const std::string &name, const GUI::ECS::Systems::Collision &collision, const GUI::ECS::Components::AnimationComponent &animation)
 Constructs a sprite component with:
 
 SpriteComponent (const std::uint32_t entityId, const std::string &name, const GUI::ECS::Systems::Collision &collision, const GUI::ECS::Components::TextureComponent &spritesheetTexture)
 Constructs a sprite component with:
 
 SpriteComponent (const std::uint32_t entityId, const std::string &name, const GUI::ECS::Systems::Colour &normalColor, const GUI::ECS::Systems::Colour &hoverColor, const GUI::ECS::Systems::Colour &clickedColor)
 Constructs a sprite component with:
 
 SpriteComponent (const std::uint32_t entityId, const std::string &name, const GUI::ECS::Systems::Collision &collision, const GUI::ECS::Systems::Colour &normalColor, const GUI::ECS::Systems::Colour &hoverColor, const GUI::ECS::Systems::Colour &clickedColor)
 Constructs a sprite component with:
 
 SpriteComponent (const std::uint32_t entityId, const std::string &name, const GUI::ECS::Components::AnimationComponent &animation, const GUI::ECS::Systems::Colour &normalColor, const GUI::ECS::Systems::Colour &hoverColor, const GUI::ECS::Systems::Colour &clickedColor)
 Constructs a sprite component with:
 
 SpriteComponent (const std::uint32_t entityId, const std::string &name, const GUI::ECS::Components::TextureComponent &spritesheetTexture, const GUI::ECS::Systems::Colour &normalColor, const GUI::ECS::Systems::Colour &hoverColor, const GUI::ECS::Systems::Colour &clickedColor)
 Constructs a sprite component with:
 
 SpriteComponent (const std::uint32_t entityId, const std::string &name, const GUI::ECS::Systems::Collision &collision, const GUI::ECS::Components::AnimationComponent &animation, const GUI::ECS::Systems::Colour &normalColor, const GUI::ECS::Systems::Colour &hoverColor, const GUI::ECS::Systems::Colour &clickedColor)
 Constructs a sprite component with:
 
 SpriteComponent (const std::uint32_t entityId, const std::string &name, const GUI::ECS::Systems::Collision &collision, const GUI::ECS::Components::TextureComponent &spritesheetTexture, const GUI::ECS::Systems::Colour &normalColor, const GUI::ECS::Systems::Colour &hoverColor, const GUI::ECS::Systems::Colour &clickedColor)
 Constructs a sprite component with:
 
 ~SpriteComponent ()
 Destructor.
 
void setName (const std::string &name)
 Sets the name of the sprite.
 
void setApplication (const std::string &application)
 Sets the application name (the name is based on the configuration file) associated with the sprite.
 
void setCollision (const GUI::ECS::Systems::Collision &copy)
 Associates a collision component with the sprite.
 
void setNormalColor (const GUI::ECS::Systems::Colour &color)
 Set the default colour of the sprite.
 
void setHoverColor (const GUI::ECS::Systems::Colour &color)
 Set the Hover Color of the sprite.
 
void setClickedColor (const GUI::ECS::Systems::Colour &color)
 Set the Clicked Color of the sprite.
 
void setSpritesheet (const std::string &spritesheetPath)
 Sets the texture of the sprite using a file path.
 
void setSpritesheet (const GUI::ECS::Components::TextureComponent &spritesheetTexture)
 Sets the texture of the sprite using a TextureComponent.
 
void setAnimation (const GUI::ECS::Components::AnimationComponent &animation)
 Associates an animation component with the sprite.
 
void setVisible (const bool visible)
 Set the visible of the sprite.
 
void setPosition (const std::pair< int, int > &pos)
 Set the Position of the sprite.
 
void setDimension (const std::pair< float, float > &dim)
 Set the dimensions of the sprite.
 
void toggleVisibility ()
 Change the visibility of the sprite, if visible becomes invisible and vise versa.
 
void update (const GUI::ECS::Systems::MouseInfo &mouse)
 Updates the sprite based on mouse input.
 
void update (const GUI::ECS::Components::AnimationComponent &animation)
 Updates the animation component that is used by the sprite.
 
void update (const GUI::ECS::Components::SpriteComponent &copy)
 Updates the sprite by copying another SpriteComponent.
 
std::any render () const
 Renders the sprite to a window.
 
void start ()
 Start the playing of the animation from the current index in memory.
 
void pause ()
 Pause the playing of the animation but does not reset the index to the default frame.
 
void resume ()
 Resume the playing of the animation (has no effect if already playing)
 
void stop ()
 A function to stop the animation, and reset the index to the default frame.
 
const bool isCollisionSet () const
 Checks if collision data is set.
 
const bool isAnimationSet () const
 Checks if animation data is set.
 
const bool isSpritesheetSet () const
 Checks if a spritesheet texture is set.
 
const bool isSpriteSet () const
 Checks if the sprite is initialized.
 
const bool isVisible () const
 Check if the sprite is set to be rendred or not.
 
const bool isLooping () const
 Get the information about if the component is set to loop the animation.
 
const bool isPaused () const
 Get the information about the state of the animation (paused)
 
const bool isPlaying () const
 Get the information about the state of the animation (playing)
 
const bool isStopped () const
 Get the information about the state of the animation (stopped)
 
const bool hasTicked ()
 A function to check if the frame has changed.
 
const bool hasLooped () const
 A function to check if the animation has looped around (valid for the 1rst frame of the new loop)
 
void checkTick ()
 Processes and updates sprite properties based on tick state of the clock internal to it's animation component instance.
 
void forceTick ()
 Updates the animation frame regardless of the delay.
 
const bool getVisible () const
 Check if the sprite is set to be rendred or not.
 
const std::string getName () const
 Gets the name of the sprite.
 
const std::string getApplication () const
 Gets the application name associated with the sprite.
 
const GUI::ECS::Components::TextureComponent getSpritesheet () const
 Gets the texture component associated with the sprite.
 
const GUI::ECS::Systems::Collision getCollision () const
 Gets the collision component associated with the sprite.
 
const GUI::ECS::Components::AnimationComponent getAnimation () const
 Gets the animation component associated with the sprite.
 
const GUI::ECS::Systems::Colour getNormalColor () const
 Get the colour of the default state for the class.
 
const GUI::ECS::Systems::Colour getHoverColor () const
 Get the colour of the hover state for the class.
 
const GUI::ECS::Systems::Colour getClickedColor () const
 Get the colour of the clicked state for the class.
 
const std::string getInfo (const unsigned int indent=0) const
 This is a function meant for debugging purposes It will dump the current state of the variables upon call. It will dump them for itself and any of it's underlying classes.
 
SpriteComponentoperator= (const GUI::ECS::Components::SpriteComponent &copy)
 Overloads the assignment operator to copy from another SpriteComponent.
 
- Public Member Functions inherited from GUI::ECS::EntityNode
 EntityNode (const size_t entityId=0)
 
virtual ~EntityNode ()=default
 
virtual size_t getEntityNodeId () const
 

Additional Inherited Members

- Protected Attributes inherited from GUI::ECS::EntityNode
size_t _entityID
 

Detailed Description

Represents a drawable and interactive sprite in the ECS system.

This class manages a sprite's texture, animation, collision, and color states, while allowing it to interact with mouse events. It inherits from EntityNode to integrate with the ECS framework and supports a variety of configurations.

Definition at line 44 of file SpriteComponent.hpp.

Constructor & Destructor Documentation

◆ SpriteComponent() [1/34]

GUI::ECS::Components::SpriteComponent::SpriteComponent ( )

Default constructor.

Initializes an empty sprite component with default values.

Definition at line 16 of file SpriteComponent.cpp.

◆ SpriteComponent() [2/34]

GUI::ECS::Components::SpriteComponent::SpriteComponent ( const std::string & name)

Constructs a sprite component with a specific name.

Parameters
nameName of the sprite.

Definition at line 22 of file SpriteComponent.cpp.

◆ SpriteComponent() [3/34]

GUI::ECS::Components::SpriteComponent::SpriteComponent ( const GUI::ECS::Systems::Collision & collision)

Constructs a sprite component from a collision component.

Parameters
collisionCollision data to associate with the sprite.

Definition at line 29 of file SpriteComponent.cpp.

◆ SpriteComponent() [4/34]

GUI::ECS::Components::SpriteComponent::SpriteComponent ( const GUI::ECS::Components::AnimationComponent & animation)

Constructs a sprite component from an animation component.

Parameters
animationAnimation data to associate with the sprite.

Definition at line 37 of file SpriteComponent.cpp.

◆ SpriteComponent() [5/34]

GUI::ECS::Components::SpriteComponent::SpriteComponent ( const GUI::ECS::Components::TextureComponent & spritesheetTexture)

Constructs a sprite component from a texture component.

Parameters
spritesheetTextureTexture to associate with the sprite.

Definition at line 45 of file SpriteComponent.cpp.

◆ SpriteComponent() [6/34]

GUI::ECS::Components::SpriteComponent::SpriteComponent ( const std::string & name,
const std::string & spritesheetPath )

Constructs a sprite component with:

  • a name
  • a spritesheet path
Parameters
nameName of the sprite.
spritesheetPathFile path of the texture to load as the spritesheet.

Definition at line 53 of file SpriteComponent.cpp.

◆ SpriteComponent() [7/34]

GUI::ECS::Components::SpriteComponent::SpriteComponent ( const std::string & name,
const GUI::ECS::Systems::Collision & collision )

Constructs a sprite component with:

  • a name
  • a collision instance
Parameters
nameName of the sprite
collisionCollision instance

Definition at line 62 of file SpriteComponent.cpp.

◆ SpriteComponent() [8/34]

GUI::ECS::Components::SpriteComponent::SpriteComponent ( const std::string & name,
const GUI::ECS::Components::AnimationComponent & animation )

Constructs a sprite component with:

  • a name
  • an animation instance
Parameters
nameName of the sprite
animationAnimation instance

Definition at line 71 of file SpriteComponent.cpp.

◆ SpriteComponent() [9/34]

GUI::ECS::Components::SpriteComponent::SpriteComponent ( const std::string & name,
const GUI::ECS::Components::TextureComponent & spritesheetTexture )

Constructs a sprite component with:

  • a name
  • a spritesheet texture.
Parameters
nameName of the sprite
spritesheetTextureSpritesheet texture instance

Definition at line 80 of file SpriteComponent.cpp.

◆ SpriteComponent() [10/34]

GUI::ECS::Components::SpriteComponent::SpriteComponent ( const std::string & name,
const GUI::ECS::Systems::Collision & collision,
const GUI::ECS::Components::AnimationComponent & animation )

Constructs a sprite component with:

  • a name
  • a collision instance
  • an animation instance
Parameters
nameName of the sprite
collisionCollision instance
animationAnimation instance

Definition at line 89 of file SpriteComponent.cpp.

◆ SpriteComponent() [11/34]

GUI::ECS::Components::SpriteComponent::SpriteComponent ( const std::string & name,
const GUI::ECS::Systems::Collision & collision,
const GUI::ECS::Components::TextureComponent & spritesheetTexture )

Constructs a sprite component with:

  • a name
  • a collision instance
  • a texture component instance
Parameters
nameName of the sprite
collisionCollision instance
spritesheetTextureTexture instance containing a spritesheet

Definition at line 99 of file SpriteComponent.cpp.

◆ SpriteComponent() [12/34]

GUI::ECS::Components::SpriteComponent::SpriteComponent ( const std::string & name,
const GUI::ECS::Systems::Colour & normalColor,
const GUI::ECS::Systems::Colour & hoverColor,
const GUI::ECS::Systems::Colour & clickedColor )

Constructs a sprite component with:

  • a name
  • the colour when it is in it's normal state.
  • the colour when it is hovered
  • the colour when it is clicked
Parameters
nameName of the sprite
normalColorDefault sprite color
hoverColorHover colour
clickedColorClicked colour

Definition at line 109 of file SpriteComponent.cpp.

◆ SpriteComponent() [13/34]

GUI::ECS::Components::SpriteComponent::SpriteComponent ( const std::string & name,
const GUI::ECS::Systems::Collision & collision,
const GUI::ECS::Systems::Colour & normalColor,
const GUI::ECS::Systems::Colour & hoverColor,
const GUI::ECS::Systems::Colour & clickedColor )

Constructs a sprite component with:

  • a name
  • a collision component
  • the colour when it is in it's normal state
  • the colour when it is hovered
  • the colour when it is clicked
Parameters
nameName of the sprite
collisionSprite collision component
normalColorDefault sprite colour
hoverColorHover colour
clickedColorClicked colour

Definition at line 120 of file SpriteComponent.cpp.

◆ SpriteComponent() [14/34]

GUI::ECS::Components::SpriteComponent::SpriteComponent ( const std::string & name,
const GUI::ECS::Components::AnimationComponent & animation,
const GUI::ECS::Systems::Colour & normalColor,
const GUI::ECS::Systems::Colour & hoverColor,
const GUI::ECS::Systems::Colour & clickedColor )

Constructs a sprite component with:

  • a name
  • animation component
  • the colour when it is in it's normal state
  • the colour when it is hovered
  • the colour when it is clicked
Parameters
nameName of the sprite
animationAnimation component
normalColorDefault sprite colour
hoverColorHover colour
clickedColorClicked colour

Definition at line 132 of file SpriteComponent.cpp.

◆ SpriteComponent() [15/34]

GUI::ECS::Components::SpriteComponent::SpriteComponent ( const std::string & name,
const GUI::ECS::Components::TextureComponent & spritesheetTexture,
const GUI::ECS::Systems::Colour & normalColor,
const GUI::ECS::Systems::Colour & hoverColor,
const GUI::ECS::Systems::Colour & clickedColor )

Constructs a sprite component with:

  • a name
  • a spritesheet texture
  • the colour when it is in it's normal state
  • the colour when it is hovered
  • the colour when it is clicked
Parameters
nameName of the sprite
spritesheetTextureThe Texture of the spritesheet to process
normalColorDefault sprite colour
hoverColorHover colour
clickedColorClicked colour

Definition at line 144 of file SpriteComponent.cpp.

◆ SpriteComponent() [16/34]

GUI::ECS::Components::SpriteComponent::SpriteComponent ( const std::string & name,
const GUI::ECS::Systems::Collision & collision,
const GUI::ECS::Components::AnimationComponent & animation,
const GUI::ECS::Systems::Colour & normalColor,
const GUI::ECS::Systems::Colour & hoverColor,
const GUI::ECS::Systems::Colour & clickedColor )

Constructs a sprite component with:

  • a name
  • a collision component
  • an animation component
  • the colour when it is in it's normal state
  • the colour when it is hovered
  • the colour when it is clicked
Parameters
nameName of the sprite
collisionThe collision component
animationThe animation component
normalColorDefault sprite colour
hoverColorHover colour
clickedColorClicked colour

Definition at line 156 of file SpriteComponent.cpp.

◆ SpriteComponent() [17/34]

GUI::ECS::Components::SpriteComponent::SpriteComponent ( const std::string & name,
const GUI::ECS::Systems::Collision & collision,
const GUI::ECS::Components::TextureComponent & spritesheetTexture,
const GUI::ECS::Systems::Colour & normalColor,
const GUI::ECS::Systems::Colour & hoverColor,
const GUI::ECS::Systems::Colour & clickedColor )

Constructs a sprite component with:

  • a name
  • the collision component
  • a texture component containing a spritesheet
  • then colour when it iis in it's normal state
  • the colour when it is hovered
  • the colour when it is clicked
Parameters
nameName of the sprite
collisionThe collision component
spritesheetTextureThe texture containing the spritesheet
normalColorDefault colour
hoverColorHover colour
clickedColorClicked colour

Definition at line 169 of file SpriteComponent.cpp.

◆ SpriteComponent() [18/34]

GUI::ECS::Components::SpriteComponent::SpriteComponent ( const std::uint32_t entityId)

Construct a new Sprite Component object and assing a specific entity id.

Parameters
entityIdThe id of the class instance

Definition at line 184 of file SpriteComponent.cpp.

◆ SpriteComponent() [19/34]

GUI::ECS::Components::SpriteComponent::SpriteComponent ( const std::uint32_t entityId,
const std::string & name )

Constructs a sprite component with:

  • a specific id
  • a specific name.
Parameters
entityIdThe id of the class instance
nameName of the sprite.

Definition at line 190 of file SpriteComponent.cpp.

◆ SpriteComponent() [20/34]

GUI::ECS::Components::SpriteComponent::SpriteComponent ( const std::uint32_t entityId,
const GUI::ECS::Systems::Collision & collision )

Constructs a sprite component with:

  • a specific id
  • a collision component.
Parameters
entityIdThe id of the class instance
collisionCollision data to associate with the sprite.

Definition at line 198 of file SpriteComponent.cpp.

◆ SpriteComponent() [21/34]

GUI::ECS::Components::SpriteComponent::SpriteComponent ( const std::uint32_t entityId,
const GUI::ECS::Components::AnimationComponent & animation )

Constructs a sprite component with:

  • a specific id
  • an animation component.
Parameters
entityIdThe id of the class instance
animationAnimation data to associate with the sprite.

Definition at line 206 of file SpriteComponent.cpp.

◆ SpriteComponent() [22/34]

GUI::ECS::Components::SpriteComponent::SpriteComponent ( const std::uint32_t entityId,
const GUI::ECS::Components::TextureComponent & spritesheetTexture )

Constructs a sprite component with:

  • a specific id
  • a texture component.
Parameters
entityIdThe id of the class instance
spritesheetTextureTexture to associate with the sprite.

Definition at line 214 of file SpriteComponent.cpp.

◆ SpriteComponent() [23/34]

GUI::ECS::Components::SpriteComponent::SpriteComponent ( const std::uint32_t entityId,
const std::string & name,
const std::string & spritesheetPath )

Constructs a sprite component with:

  • a specific id
  • a name
  • a spritesheet path
Parameters
entityIdThe id of the class instance
nameName of the sprite.
spritesheetPathFile path of the texture to load as the spritesheet.

Definition at line 222 of file SpriteComponent.cpp.

◆ SpriteComponent() [24/34]

GUI::ECS::Components::SpriteComponent::SpriteComponent ( const std::uint32_t entityId,
const std::string & name,
const GUI::ECS::Systems::Collision & collision )

Constructs a sprite component with:

  • a specific id
  • a name
  • a collision instance
Parameters
entityIdThe id of the class instance
nameName of the sprite
collisionCollision instance

Definition at line 231 of file SpriteComponent.cpp.

◆ SpriteComponent() [25/34]

GUI::ECS::Components::SpriteComponent::SpriteComponent ( const std::uint32_t entityId,
const std::string & name,
const GUI::ECS::Components::AnimationComponent & animation )

Constructs a sprite component with:

  • a specific id
  • a name
  • an animation instance
Parameters
entityIdThe id of the class instance
nameName of the sprite
animationAnimation instance

Definition at line 240 of file SpriteComponent.cpp.

◆ SpriteComponent() [26/34]

GUI::ECS::Components::SpriteComponent::SpriteComponent ( const std::uint32_t entityId,
const std::string & name,
const GUI::ECS::Components::TextureComponent & spritesheetTexture )

Constructs a sprite component with:

  • a specific id
  • a name
  • a spritesheet texture.
Parameters
entityIdThe id of the class instance
nameName of the sprite
spritesheetTextureSpritesheet texture instance

Definition at line 250 of file SpriteComponent.cpp.

◆ SpriteComponent() [27/34]

GUI::ECS::Components::SpriteComponent::SpriteComponent ( const std::uint32_t entityId,
const std::string & name,
const GUI::ECS::Systems::Collision & collision,
const GUI::ECS::Components::AnimationComponent & animation )

Constructs a sprite component with:

  • a specific id
  • a name
  • a collision instance
  • an animation instance
Parameters
entityIdThe id of the class instance
nameName of the sprite
collisionCollision instance
animationAnimation instance

Definition at line 260 of file SpriteComponent.cpp.

◆ SpriteComponent() [28/34]

GUI::ECS::Components::SpriteComponent::SpriteComponent ( const std::uint32_t entityId,
const std::string & name,
const GUI::ECS::Systems::Collision & collision,
const GUI::ECS::Components::TextureComponent & spritesheetTexture )

Constructs a sprite component with:

  • a specific id
  • a name
  • a collision instance
  • a texture component instance
Parameters
entityIdThe id of the class instance
nameName of the sprite
collisionCollision instance
spritesheetTextureTexture instance containing a spritesheet

Definition at line 270 of file SpriteComponent.cpp.

◆ SpriteComponent() [29/34]

GUI::ECS::Components::SpriteComponent::SpriteComponent ( const std::uint32_t entityId,
const std::string & name,
const GUI::ECS::Systems::Colour & normalColor,
const GUI::ECS::Systems::Colour & hoverColor,
const GUI::ECS::Systems::Colour & clickedColor )

Constructs a sprite component with:

  • a specific id
  • a name
  • the colour when it is in it's normal state.
  • the colour when it is hovered
  • the colour when it is clicked
Parameters
entityIdThe id of the class instance
nameName of the sprite
normalColorDefault sprite color
hoverColorHover colour
clickedColorClicked colour

Definition at line 280 of file SpriteComponent.cpp.

◆ SpriteComponent() [30/34]

GUI::ECS::Components::SpriteComponent::SpriteComponent ( const std::uint32_t entityId,
const std::string & name,
const GUI::ECS::Systems::Collision & collision,
const GUI::ECS::Systems::Colour & normalColor,
const GUI::ECS::Systems::Colour & hoverColor,
const GUI::ECS::Systems::Colour & clickedColor )

Constructs a sprite component with:

  • a specific id
  • a name
  • a collision component
  • the colour when it is in it's normal state
  • the colour when it is hovered
  • the colour when it is clicked
Parameters
entityIdThe id of the class instance
nameName of the sprite
collisionSprite collision component
normalColorDefault sprite colour
hoverColorHover colour
clickedColorClicked colour

Definition at line 291 of file SpriteComponent.cpp.

◆ SpriteComponent() [31/34]

GUI::ECS::Components::SpriteComponent::SpriteComponent ( const std::uint32_t entityId,
const std::string & name,
const GUI::ECS::Components::AnimationComponent & animation,
const GUI::ECS::Systems::Colour & normalColor,
const GUI::ECS::Systems::Colour & hoverColor,
const GUI::ECS::Systems::Colour & clickedColor )

Constructs a sprite component with:

  • a specific id
  • a name
  • animation component
  • the colour when it is in it's normal state
  • the colour when it is hovered
  • the colour when it is clicked
Parameters
entityIdThe id of the class instance
nameName of the sprite
animationAnimation component
normalColorDefault sprite colour
hoverColorHover colour
clickedColorClicked colour

Definition at line 303 of file SpriteComponent.cpp.

◆ SpriteComponent() [32/34]

GUI::ECS::Components::SpriteComponent::SpriteComponent ( const std::uint32_t entityId,
const std::string & name,
const GUI::ECS::Components::TextureComponent & spritesheetTexture,
const GUI::ECS::Systems::Colour & normalColor,
const GUI::ECS::Systems::Colour & hoverColor,
const GUI::ECS::Systems::Colour & clickedColor )

Constructs a sprite component with:

  • a specific id
  • a name
  • a spritesheet texture
  • the colour when it is in it's normal state
  • the colour when it is hovered
  • the colour when it is clicked
Parameters
entityIdThe id of the class instance
nameName of the sprite
spritesheetTextureThe Texture of the spritesheet to process
normalColorDefault sprite colour
hoverColorHover colour
clickedColorClicked colour

Definition at line 315 of file SpriteComponent.cpp.

◆ SpriteComponent() [33/34]

GUI::ECS::Components::SpriteComponent::SpriteComponent ( const std::uint32_t entityId,
const std::string & name,
const GUI::ECS::Systems::Collision & collision,
const GUI::ECS::Components::AnimationComponent & animation,
const GUI::ECS::Systems::Colour & normalColor,
const GUI::ECS::Systems::Colour & hoverColor,
const GUI::ECS::Systems::Colour & clickedColor )

Constructs a sprite component with:

  • a specific id
  • a name
  • a collision component
  • an animation component
  • the colour when it is in it's normal state
  • the colour when it is hovered
  • the colour when it is clicked
Parameters
entityIdThe id of the class instance
nameName of the sprite
collisionThe collision component
animationThe animation component
normalColorDefault sprite colour
hoverColorHover colour
clickedColorClicked colour

Definition at line 327 of file SpriteComponent.cpp.

◆ SpriteComponent() [34/34]

GUI::ECS::Components::SpriteComponent::SpriteComponent ( const std::uint32_t entityId,
const std::string & name,
const GUI::ECS::Systems::Collision & collision,
const GUI::ECS::Components::TextureComponent & spritesheetTexture,
const GUI::ECS::Systems::Colour & normalColor,
const GUI::ECS::Systems::Colour & hoverColor,
const GUI::ECS::Systems::Colour & clickedColor )

Constructs a sprite component with:

  • a specific id
  • a name
  • the collision component
  • a texture component containing a spritesheet
  • then colour when it iis in it's normal state
  • the colour when it is hovered
  • the colour when it is clicked
Parameters
entityIdThe id of the class instance
nameName of the sprite
collisionThe collision component
spritesheetTextureThe texture containing the spritesheet
normalColorDefault colour
hoverColorHover colour
clickedColorClicked colour

Definition at line 340 of file SpriteComponent.cpp.

◆ ~SpriteComponent()

GUI::ECS::Components::SpriteComponent::~SpriteComponent ( )

Destructor.

Definition at line 354 of file SpriteComponent.cpp.

Member Function Documentation

◆ checkTick()

void GUI::ECS::Components::SpriteComponent::checkTick ( )

Processes and updates sprite properties based on tick state of the clock internal to it's animation component instance.

Definition at line 568 of file SpriteComponent.cpp.

◆ forceTick()

void GUI::ECS::Components::SpriteComponent::forceTick ( )

Updates the animation frame regardless of the delay.

Definition at line 608 of file SpriteComponent.cpp.

◆ getAnimation()

const GUI::ECS::Components::AnimationComponent GUI::ECS::Components::SpriteComponent::getAnimation ( ) const

Gets the animation component associated with the sprite.

Returns
The animation component.
Exceptions
CustomExceptions::NoAnimationIf no animation is set.

Definition at line 675 of file SpriteComponent.cpp.

◆ getApplication()

const std::string GUI::ECS::Components::SpriteComponent::getApplication ( ) const

Gets the application name associated with the sprite.

Returns
The application name.

Definition at line 654 of file SpriteComponent.cpp.

◆ getClickedColor()

const GUI::ECS::Systems::Colour GUI::ECS::Components::SpriteComponent::getClickedColor ( ) const

Get the colour of the clicked state for the class.

Returns
The colour instance that is stored for the clicked status.

Definition at line 693 of file SpriteComponent.cpp.

◆ getCollision()

const GUI::ECS::Systems::Collision GUI::ECS::Components::SpriteComponent::getCollision ( ) const

Gets the collision component associated with the sprite.

Returns
The collision component.
Exceptions
CustomExceptions::NoCollisionIf no collision is set.

Definition at line 667 of file SpriteComponent.cpp.

◆ getHoverColor()

const GUI::ECS::Systems::Colour GUI::ECS::Components::SpriteComponent::getHoverColor ( ) const

Get the colour of the hover state for the class.

Returns
The colour instance that is stored for the hover status.

Definition at line 688 of file SpriteComponent.cpp.

◆ getInfo()

const std::string GUI::ECS::Components::SpriteComponent::getInfo ( const unsigned int indent = 0) const

This is a function meant for debugging purposes It will dump the current state of the variables upon call. It will dump them for itself and any of it's underlying classes.

Parameters
indentThe level to which the class should be indented in the dump.
Returns
const std::string The formatted output.

Definition at line 699 of file SpriteComponent.cpp.

◆ getName()

const std::string GUI::ECS::Components::SpriteComponent::getName ( ) const

Gets the name of the sprite.

Returns
The name of the sprite.

Definition at line 649 of file SpriteComponent.cpp.

◆ getNormalColor()

const GUI::ECS::Systems::Colour GUI::ECS::Components::SpriteComponent::getNormalColor ( ) const

Get the colour of the default state for the class.

Returns
The colour instance that is stored for the default status.

Definition at line 683 of file SpriteComponent.cpp.

◆ getSpritesheet()

const GUI::ECS::Components::TextureComponent GUI::ECS::Components::SpriteComponent::getSpritesheet ( ) const

Gets the texture component associated with the sprite.

Returns
The texture component.
Exceptions
CustomExceptions::NoSpriteSheetIf no spritesheet is set.

Definition at line 659 of file SpriteComponent.cpp.

◆ getVisible()

const bool GUI::ECS::Components::SpriteComponent::getVisible ( ) const

Check if the sprite is set to be rendred or not.

Returns
true
false

Definition at line 644 of file SpriteComponent.cpp.

◆ hasLooped()

const bool GUI::ECS::Components::SpriteComponent::hasLooped ( ) const

A function to check if the animation has looped around (valid for the 1rst frame of the new loop)

Returns
true The animation has looped
false The animation has not looped

Definition at line 563 of file SpriteComponent.cpp.

◆ hasTicked()

const bool GUI::ECS::Components::SpriteComponent::hasTicked ( )

A function to check if the frame has changed.

Returns
true
false

Definition at line 558 of file SpriteComponent.cpp.

◆ isAnimationSet()

const bool GUI::ECS::Components::SpriteComponent::isAnimationSet ( ) const

Checks if animation data is set.

Returns
True if animation data is set, false otherwise.

Definition at line 518 of file SpriteComponent.cpp.

◆ isCollisionSet()

const bool GUI::ECS::Components::SpriteComponent::isCollisionSet ( ) const

Checks if collision data is set.

Returns
True if collision data is set, false otherwise.

Definition at line 513 of file SpriteComponent.cpp.

◆ isLooping()

const bool GUI::ECS::Components::SpriteComponent::isLooping ( ) const

Get the information about if the component is set to loop the animation.

Returns
true The component will loop the animation
false The component will not loop the animation

Definition at line 538 of file SpriteComponent.cpp.

◆ isPaused()

const bool GUI::ECS::Components::SpriteComponent::isPaused ( ) const

Get the information about the state of the animation (paused)

Returns
true The animation is paused
false The animation is playing or stopped

Definition at line 543 of file SpriteComponent.cpp.

◆ isPlaying()

const bool GUI::ECS::Components::SpriteComponent::isPlaying ( ) const

Get the information about the state of the animation (playing)

Returns
true The animation is playing
false The animation is paused or stopped

Definition at line 548 of file SpriteComponent.cpp.

◆ isSpriteSet()

const bool GUI::ECS::Components::SpriteComponent::isSpriteSet ( ) const

Checks if the sprite is initialized.

Returns
True if the sprite is set, false otherwise.

Definition at line 528 of file SpriteComponent.cpp.

◆ isSpritesheetSet()

const bool GUI::ECS::Components::SpriteComponent::isSpritesheetSet ( ) const

Checks if a spritesheet texture is set.

Returns
True if a spritesheet is set, false otherwise.

Definition at line 523 of file SpriteComponent.cpp.

◆ isStopped()

const bool GUI::ECS::Components::SpriteComponent::isStopped ( ) const

Get the information about the state of the animation (stopped)

Returns
true The animation is stopped
false The animation is playing or paused

Definition at line 553 of file SpriteComponent.cpp.

◆ isVisible()

const bool GUI::ECS::Components::SpriteComponent::isVisible ( ) const

Check if the sprite is set to be rendred or not.

Returns
true The sprite is visible
false The sprite is hidden

Definition at line 533 of file SpriteComponent.cpp.

◆ operator=()

GUI::ECS::Components::SpriteComponent & GUI::ECS::Components::SpriteComponent::operator= ( const GUI::ECS::Components::SpriteComponent & copy)

Overloads the assignment operator to copy from another SpriteComponent.

Parameters
copyThe SpriteComponent to copy data from.
Returns
A reference to the updated instance.

Definition at line 725 of file SpriteComponent.cpp.

◆ pause()

void GUI::ECS::Components::SpriteComponent::pause ( )

Pause the playing of the animation but does not reset the index to the default frame.

Definition at line 498 of file SpriteComponent.cpp.

◆ render()

std::any GUI::ECS::Components::SpriteComponent::render ( ) const

Renders the sprite to a window.

Returns
std::optional<std::any> the component to render
Exceptions
CustomExceptions::NoSpriteIf no sprite is set.

Definition at line 484 of file SpriteComponent.cpp.

◆ resume()

void GUI::ECS::Components::SpriteComponent::resume ( )

Resume the playing of the animation (has no effect if already playing)

Definition at line 503 of file SpriteComponent.cpp.

◆ setAnimation()

void GUI::ECS::Components::SpriteComponent::setAnimation ( const GUI::ECS::Components::AnimationComponent & animation)

Associates an animation component with the sprite.

Parameters
animationAnimation component to set.

Definition at line 420 of file SpriteComponent.cpp.

◆ setApplication()

void GUI::ECS::Components::SpriteComponent::setApplication ( const std::string & application)

Sets the application name (the name is based on the configuration file) associated with the sprite.

Parameters
applicationApplication name.

Definition at line 363 of file SpriteComponent.cpp.

◆ setClickedColor()

void GUI::ECS::Components::SpriteComponent::setClickedColor ( const GUI::ECS::Systems::Colour & color)

Set the Clicked Color of the sprite.

Parameters
colorThe colour the sprite takes when it is clicked by the user's mouse.

Definition at line 397 of file SpriteComponent.cpp.

◆ setCollision()

void GUI::ECS::Components::SpriteComponent::setCollision ( const GUI::ECS::Systems::Collision & copy)

Associates a collision component with the sprite.

Parameters
copyCollision component to set.

Updates the collision data and recalculates the sprite's position and scale.

Definition at line 368 of file SpriteComponent.cpp.

◆ setDimension()

void GUI::ECS::Components::SpriteComponent::setDimension ( const std::pair< float, float > & dim)

Set the dimensions of the sprite.

Parameters
dim

Definition at line 446 of file SpriteComponent.cpp.

◆ setHoverColor()

void GUI::ECS::Components::SpriteComponent::setHoverColor ( const GUI::ECS::Systems::Colour & color)

Set the Hover Color of the sprite.

Parameters
colorThe colour the sprite takes when it is hovered by the user's mouse.

Definition at line 392 of file SpriteComponent.cpp.

◆ setName()

void GUI::ECS::Components::SpriteComponent::setName ( const std::string & name)

Sets the name of the sprite.

Parameters
nameThe name to assign to the sprite.

Definition at line 356 of file SpriteComponent.cpp.

◆ setNormalColor()

void GUI::ECS::Components::SpriteComponent::setNormalColor ( const GUI::ECS::Systems::Colour & color)

Set the default colour of the sprite.

Parameters
colorThe colour of the sprite when it is in it's normal state

Definition at line 387 of file SpriteComponent.cpp.

◆ setPosition()

void GUI::ECS::Components::SpriteComponent::setPosition ( const std::pair< int, int > & pos)

Set the Position of the sprite.

Parameters
pos

Definition at line 440 of file SpriteComponent.cpp.

◆ setSpritesheet() [1/2]

void GUI::ECS::Components::SpriteComponent::setSpritesheet ( const GUI::ECS::Components::TextureComponent & spritesheetTexture)

Sets the texture of the sprite using a TextureComponent.

Parameters
spritesheetTextureTexture component to set.

Definition at line 402 of file SpriteComponent.cpp.

◆ setSpritesheet() [2/2]

void GUI::ECS::Components::SpriteComponent::setSpritesheet ( const std::string & spritesheetPath)

Sets the texture of the sprite using a file path.

Parameters
spritesheetPathPath to the spritesheet texture file.

Definition at line 375 of file SpriteComponent.cpp.

◆ setVisible()

void GUI::ECS::Components::SpriteComponent::setVisible ( const bool visible)

Set the visible of the sprite.

Parameters
visibleA boolean instance.

Definition at line 435 of file SpriteComponent.cpp.

◆ start()

void GUI::ECS::Components::SpriteComponent::start ( )

Start the playing of the animation from the current index in memory.

Definition at line 493 of file SpriteComponent.cpp.

◆ stop()

void GUI::ECS::Components::SpriteComponent::stop ( )

A function to stop the animation, and reset the index to the default frame.

Definition at line 508 of file SpriteComponent.cpp.

◆ toggleVisibility()

void GUI::ECS::Components::SpriteComponent::toggleVisibility ( )

Change the visibility of the sprite, if visible becomes invisible and vise versa.

Definition at line 452 of file SpriteComponent.cpp.

◆ update() [1/3]

void GUI::ECS::Components::SpriteComponent::update ( const GUI::ECS::Components::AnimationComponent & animation)

Updates the animation component that is used by the sprite.

Parameters
animationAnimation instance.

Definition at line 471 of file SpriteComponent.cpp.

◆ update() [2/3]

void GUI::ECS::Components::SpriteComponent::update ( const GUI::ECS::Components::SpriteComponent & copy)

Updates the sprite by copying another SpriteComponent.

Parameters
copyThe SpriteComponent to copy data from.

Definition at line 476 of file SpriteComponent.cpp.

◆ update() [3/3]

void GUI::ECS::Components::SpriteComponent::update ( const GUI::ECS::Systems::MouseInfo & mouse)

Updates the sprite based on mouse input.

Parameters
mouseMouse information.
Exceptions
CustomExceptions::NoCollisionIf no collision is set.

Definition at line 461 of file SpriteComponent.cpp.


The documentation for this class was generated from the following files: