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

Represents a rectangular component that can detect collisions and mouse interactions, such as hovering and clicking. More...

#include <Collision.hpp>

Inheritance diagram for GUI::ECS::Systems::Collision:
Inheritance graph
Collaboration diagram for GUI::ECS::Systems::Collision:
Collaboration graph

Public Member Functions

 Collision (const std::uint32_t entityId=0, const float width=0, const float height=0, const float positionX=0, const float positionY=0)
 Constructs a Collision with the specified dimensions and position.
 
 ~Collision ()
 Default destructor.
 
void setWidth (const float &width)
 Sets the width of the component and updates collision data.
 
void setHeight (const float &height)
 Sets the height of the component and updates collision data.
 
void setPositionX (const float &posX)
 Sets the X-coordinate of the component's position and updates collision data.
 
void setPositionY (const float &posY)
 Sets the Y-coordinate of the component's position and updates collision data.
 
void setPosition (const std::pair< float, float > &position)
 Set the position of the object.
 
void setDimension (const std::pair< float, float > &dimension)
 Set the dimension of the object.
 
void setGeometry (const Recoded::FloatRect &rect)
 Set the dimensions of the object using the FloatRect recode.
 
void setMousePosition (const std::pair< int, int > &position)
 Updates the mouse position for collision checks.
 
void update (const std::pair< int, int > &mousePosition)
 Update the mouse info object used for mouse tracking.
 
void update (const GUI::ECS::Systems::MouseInfo &mouse)
 Update the mouse info object used for mouse tracking.
 
void update (const GUI::ECS::Systems::Collision &copy)
 Update the info object used in the Collision class.
 
void updateMouseInfo (const GUI::ECS::Systems::MouseInfo &mouse)
 Updates the mouse info object used for collision checks.
 
const bool isClicked () const
 Checks if the component is clicked by the mouse.
 
const bool isHovered () const
 Checks if the component is currently hovered by the mouse.
 
const bool isColliding (const Collision &itemTwo) const
 Checks if this component is colliding with another Collision.
 
const float getWidth () const
 Gets the width of the component.
 
const float getHeight () const
 Gets the height of the component.
 
const float getPositionX () const
 Gets the X-coordinate of the component's position.
 
const float getPositionY () const
 Gets the Y-coordinate of the component's position.
 
const Recoded::FloatRect getGeometry () const
 This is the function in charge of returning the coordinates in the form of an sf::FloatRect.
 
const std::pair< float, float > getPosition () const
 Get the position of the item in the form of an sf::Vector2i.
 
const std::pair< float, float > getDimension () const
 Get the dimension of the item in the form of an sf::Vector2i.
 
const GUI::ECS::Systems::MouseInfo getMouseInfo () const
 This is the function in charge of returning the MouseInfo class instance.
 
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.
 
Collisionoperator= (const GUI::ECS::Systems::Collision &copy)
 This is the overload in charge of allowing the user to update their variables using the = sign.
 
- Public Member Functions inherited from GUI::ECS::EntityNode
 EntityNode (const size_t entityId=0)
 
virtual ~EntityNode ()=default
 
virtual size_t getEntityNodeId () const
 

Protected Member Functions

void _updateMouseCollisionData ()
 Updates the mouse collision data, setting hover and click states.
 

Protected Attributes

bool _isHovered = false
 
bool _isClicked = false
 
Recoded::FloatRect _rect = { {0,0}, {0,0} }
 
GUI::ECS::Systems::MouseInfo _mouse
 
- Protected Attributes inherited from GUI::ECS::EntityNode
size_t _entityID
 

Detailed Description

Represents a rectangular component that can detect collisions and mouse interactions, such as hovering and clicking.

Definition at line 39 of file Collision.hpp.

Constructor & Destructor Documentation

◆ Collision()

GUI::ECS::Systems::Collision::Collision ( const std::uint32_t entityId = 0,
const float width = 0,
const float height = 0,
const float positionX = 0,
const float positionY = 0 )

Constructs a Collision with the specified dimensions and position.

Parameters
widthWidth of the component.
heightHeight of the component.
positionXX-coordinate of the component's position.
positionYY-coordinate of the component's position.

Definition at line 24 of file Collision.cpp.

◆ ~Collision()

GUI::ECS::Systems::Collision::~Collision ( )

Default destructor.

Definition at line 33 of file Collision.cpp.

Member Function Documentation

◆ _updateMouseCollisionData()

void GUI::ECS::Systems::Collision::_updateMouseCollisionData ( )
protected

Updates the mouse collision data, setting hover and click states.

Definition at line 329 of file Collision.cpp.

◆ getDimension()

const std::pair< float, float > GUI::ECS::Systems::Collision::getDimension ( ) const

Get the dimension of the item in the form of an sf::Vector2i.

Returns
std::pair<float, float> of the dimension of the element.

Definition at line 255 of file Collision.cpp.

◆ getGeometry()

const Recoded::FloatRect GUI::ECS::Systems::Collision::getGeometry ( ) const

This is the function in charge of returning the coordinates in the form of an sf::FloatRect.

Returns
sf::FloatRect instance of the coordinates.

Definition at line 235 of file Collision.cpp.

◆ getHeight()

const float GUI::ECS::Systems::Collision::getHeight ( ) const

Gets the height of the component.

Returns
Height of the component.

Definition at line 205 of file Collision.cpp.

◆ getInfo()

const std::string GUI::ECS::Systems::Collision::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 290 of file Collision.cpp.

◆ getMouseInfo()

const GUI::ECS::Systems::MouseInfo GUI::ECS::Systems::Collision::getMouseInfo ( ) const

This is the function in charge of returning the MouseInfo class instance.

Returns
GUI::ECS::Systems::MouseInfo The MouseInfo class.

Definition at line 265 of file Collision.cpp.

◆ getPosition()

const std::pair< float, float > GUI::ECS::Systems::Collision::getPosition ( ) const

Get the position of the item in the form of an sf::Vector2i.

Returns
std::pair<float, float> of the position of the element

Definition at line 245 of file Collision.cpp.

◆ getPositionX()

const float GUI::ECS::Systems::Collision::getPositionX ( ) const

Gets the X-coordinate of the component's position.

Returns
X-coordinate of the component's position.

Definition at line 215 of file Collision.cpp.

◆ getPositionY()

const float GUI::ECS::Systems::Collision::getPositionY ( ) const

Gets the Y-coordinate of the component's position.

Returns
Y-coordinate of the component's position.

Definition at line 225 of file Collision.cpp.

◆ getWidth()

const float GUI::ECS::Systems::Collision::getWidth ( ) const

Gets the width of the component.

Returns
Width of the component.

Definition at line 195 of file Collision.cpp.

◆ isClicked()

const bool GUI::ECS::Systems::Collision::isClicked ( ) const

Checks if the component is clicked by the mouse.

Returns
true if the component is clicked; otherwise, false.

Definition at line 175 of file Collision.cpp.

◆ isColliding()

const bool GUI::ECS::Systems::Collision::isColliding ( const Collision & itemTwo) const

Checks if this component is colliding with another Collision.

Parameters
itemTwoThe other Collision to check against.
Returns
true if the components are colliding; otherwise, false.

Definition at line 276 of file Collision.cpp.

◆ isHovered()

const bool GUI::ECS::Systems::Collision::isHovered ( ) const

Checks if the component is currently hovered by the mouse.

Returns
true if the component is hovered; otherwise, false.

Definition at line 185 of file Collision.cpp.

◆ operator=()

GUI::ECS::Systems::Collision & GUI::ECS::Systems::Collision::operator= ( const GUI::ECS::Systems::Collision & copy)

This is the overload in charge of allowing the user to update their variables using the = sign.

Parameters
copy
Returns
GUI::ECS::Systems::Collision&

Definition at line 318 of file Collision.cpp.

◆ setDimension()

void GUI::ECS::Systems::Collision::setDimension ( const std::pair< float, float > & dimension)

Set the dimension of the object.

Parameters
dimensionan std::pair<float, float> of the of the object's dimension.

Definition at line 95 of file Collision.cpp.

◆ setGeometry()

void GUI::ECS::Systems::Collision::setGeometry ( const Recoded::FloatRect & rect)

Set the dimensions of the object using the FloatRect recode.

Parameters
recta Recoded::FloatRect rectangle instance of the object's dimension and position.

Definition at line 106 of file Collision.cpp.

◆ setHeight()

void GUI::ECS::Systems::Collision::setHeight ( const float & height)

Sets the height of the component and updates collision data.

Parameters
heightNew height of the component.

Definition at line 51 of file Collision.cpp.

◆ setMousePosition()

void GUI::ECS::Systems::Collision::setMousePosition ( const std::pair< int, int > & mousePosition)

Updates the mouse position for collision checks.

Parameters
mousePositionNew mouse position as an std::pair<int, int> vector.

Definition at line 117 of file Collision.cpp.

◆ setPosition()

void GUI::ECS::Systems::Collision::setPosition ( const std::pair< float, float > & position)

Set the position of the object.

Parameters
positionan std::pair<float, float> of the object's position.

Definition at line 84 of file Collision.cpp.

◆ setPositionX()

void GUI::ECS::Systems::Collision::setPositionX ( const float & posX)

Sets the X-coordinate of the component's position and updates collision data.

Parameters
posXNew X-coordinate of the component's position.

Definition at line 62 of file Collision.cpp.

◆ setPositionY()

void GUI::ECS::Systems::Collision::setPositionY ( const float & posY)

Sets the Y-coordinate of the component's position and updates collision data.

Parameters
posYNew Y-coordinate of the component's position.

Definition at line 73 of file Collision.cpp.

◆ setWidth()

void GUI::ECS::Systems::Collision::setWidth ( const float & width)

Sets the width of the component and updates collision data.

Parameters
widthNew width of the component.

Definition at line 40 of file Collision.cpp.

◆ update() [1/3]

void GUI::ECS::Systems::Collision::update ( const GUI::ECS::Systems::Collision & copy)

Update the info object used in the Collision class.

Parameters
copy

Definition at line 139 of file Collision.cpp.

◆ update() [2/3]

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

Update the mouse info object used for mouse tracking.

Parameters
copy

Definition at line 152 of file Collision.cpp.

◆ update() [3/3]

void GUI::ECS::Systems::Collision::update ( const std::pair< int, int > & mouse)

Update the mouse info object used for mouse tracking.

Parameters
copy

Definition at line 129 of file Collision.cpp.

◆ updateMouseInfo()

void GUI::ECS::Systems::Collision::updateMouseInfo ( const GUI::ECS::Systems::MouseInfo & mouse)

Updates the mouse info object used for collision checks.

Parameters
mouseMouse information object.

Definition at line 164 of file Collision.cpp.

Field Documentation

◆ _isClicked

bool GUI::ECS::Systems::Collision::_isClicked = false
protected

Definition at line 96 of file Collision.hpp.

◆ _isHovered

bool GUI::ECS::Systems::Collision::_isHovered = false
protected

Definition at line 95 of file Collision.hpp.

◆ _mouse

GUI::ECS::Systems::MouseInfo GUI::ECS::Systems::Collision::_mouse
protected

Definition at line 98 of file Collision.hpp.

◆ _rect

Recoded::FloatRect GUI::ECS::Systems::Collision::_rect = { {0,0}, {0,0} }
protected

Definition at line 97 of file Collision.hpp.


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