25 :
EntityNode(entityId), _rect({ {width, height}, {positionX, positionY} })
27 _updateMouseCollisionData();
42 _rect.size.first = width;
43 _updateMouseCollisionData();
53 _rect.size.second = height;
54 _updateMouseCollisionData();
64 _rect.position.first = posX;
65 _updateMouseCollisionData();
75 _rect.position.second = posY;
76 _updateMouseCollisionData();
86 _rect.position = position;
87 _updateMouseCollisionData();
97 _rect.size = dimension;
98 _updateMouseCollisionData();
109 _updateMouseCollisionData();
119 _mouse.update(mousePosition);
120 _updateMouseCollisionData();
131 _mouse.update(mouse);
132 _updateMouseCollisionData();
154 _mouse.update(mouse);
155 _updateMouseCollisionData();
166 _mouse.update(mouse);
167 _updateMouseCollisionData();
197 return _rect.size.first;
207 return _rect.size.second;
217 return _rect.position.first;
227 return _rect.position.second;
278 PRETTY_INFO <<
"Collision: Checking if 2 shapes are colliding" << std::endl;
279 const bool rightEdge = _rect.position.first + _rect.size.first <= itemTwo.
_rect.
position.first;
281 const bool bottomEdge = _rect.position.second + _rect.size.second <= itemTwo.
_rect.
position.second;
283 const bool noOverlap = (rightEdge || leftEdge || bottomEdge || topEdge);
293 std::string indentation =
"";
294 for (
unsigned int i = 0; i < indent; ++i) {
297 std::string result = indentation +
"Collision Info:\n";
302 result += indentation +
"- Mouse Info: {\n" + _mouse.getInfo(indent + 1) + indentation +
"}\n";
331 PRETTY_DEBUG <<
"Updating the collision between the mouse and the shape." << std::endl;
334 const std::pair<int, int> &mousePos = _mouse.getMousePosition();
335 const bool inFocus = _mouse.isMouseInFocus();
338 mousePos.first >= _rect.position.first && mousePos.first <= _rect.position.first + _rect.size.first
339 && mousePos.second >= _rect.position.second && mousePos.second <= _rect.position.second + _rect.size.second
345 if (_isHovered && (_mouse.isMouseLeftButtonClicked() || _mouse.isMouseRightButtonClicked())) {
359 return !(left == right);
#define PRETTY_DEBUG
Debug log with details and colour.
#define PRETTY_INFO
Info log with details and colour.
#define PRETTY_SUCCESS
Success log with details and colour.
Represents a rectangular component that can detect collisions and mouse interactions,...
void setPositionY(const float &posY)
Sets the Y-coordinate of the component's position and updates collision data.
const std::pair< float, float > getDimension() const
Get the dimension of the item in the form of an sf::Vector2i.
void setHeight(const float &height)
Sets the height of the component and updates collision data.
const bool isClicked() const
Checks if the component is clicked by the mouse.
void updateMouseInfo(const GUI::ECS::Systems::MouseInfo &mouse)
Updates the mouse info object used for collision checks.
void setWidth(const float &width)
Sets the width of the component and updates collision data.
void _updateMouseCollisionData()
Updates the mouse collision data, setting hover and click states.
const float getWidth() const
Gets the width of the component.
void setDimension(const std::pair< float, float > &dimension)
Set the dimension of the object.
void update(const std::pair< int, int > &mousePosition)
Update the mouse info object used for mouse tracking.
const float getHeight() const
Gets the height of the component.
~Collision()
Default destructor.
const bool isColliding(const Collision &itemTwo) const
Checks if this component is colliding with another Collision.
void setPositionX(const float &posX)
Sets the X-coordinate of the component's position and updates collision data.
const Recoded::FloatRect getGeometry() const
This is the function in charge of returning the coordinates in the form of an sf::FloatRect.
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 ...
const std::pair< float, float > getPosition() const
Get the position of the item in the form of an sf::Vector2i.
const float getPositionY() const
Gets the Y-coordinate of the component's position.
void setMousePosition(const std::pair< int, int > &position)
Updates the mouse position for collision checks.
const GUI::ECS::Systems::MouseInfo getMouseInfo() const
This is the function in charge of returning the MouseInfo class instance.
void setGeometry(const Recoded::FloatRect &rect)
Set the dimensions of the object using the FloatRect recode.
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.
void setPosition(const std::pair< float, float > &position)
Set the position of the object.
const float getPositionX() const
Gets the X-coordinate of the component's position.
const bool isHovered() const
Checks if the component is currently hovered by the mouse.
Collision & operator=(const GUI::ECS::Systems::Collision ©)
This is the overload in charge of allowing the user to update their variables using the = sign.
A generic 2D rectangle class that holds position and size as pairs.
std::pair< T, T > size
The size of the rectangle (width, height)
std::pair< T, T > position
the position (top and left corner)
const Collision operator+(Collision left, Collision right)
Adds two collision components component-wise.
const Collision & operator+=(Collision &left, Collision right)
Adds another collision component to the current collision component component-wise.
const Collision operator-(Collision left, Collision right)
Subtracts two collision components component-wise.
const Collision operator*(Collision left, Collision right)
Multiplies two collision components component-wise.
const bool operator==(Collision left, Collision right)
Compares two collision components for equality.
const bool operator!=(Collision left, Collision right)
Compares two collision components for inequality.
std::ostream & operator<<(std::ostream &os, const Clock &item)
Outputs the clock's info to a stream.
const Collision & operator*=(Collision &left, Collision right)
Multiplies another collision component with the current collision component component-wise.
const Collision & operator-=(Collision &left, Collision right)
Subtracts another collision component from the current collision component component-wise.
const std::string myToString(const Rect< RectType > &rectangle)
Converts a Rect<T> object to its string representation.