R-Type  2
Doom but in better
Loading...
Searching...
No Matches
ShapeComponent.cpp
Go to the documentation of this file.
1/*
2** EPITECH PROJECT, 2024
3** rtype (Workspace)
4** File description:
5** ShapeComponent.hpp
6*/
7
15
17 : EntityNode(entityID),
18 _hoverColor(entityID, GUI::ECS::Systems::Colour::White),
19 _normalColor(entityID, GUI::ECS::Systems::Colour::White),
20 _clickedColor(entityID, GUI::ECS::Systems::Colour::White),
21 _shape(GUI::ECS::Systems::ActiveShape::NONE),
22 _visible(true),
23 _collision(entityID)
24{
25 _inConstructor = false;
26};
27
28GUI::ECS::Components::ShapeComponent::ShapeComponent(const std::size_t pointCount, const std::pair<float, float> &position, const GUI::ECS::Systems::Colour &normalColour, const GUI::ECS::Systems::Colour &hoverColour, const GUI::ECS::Systems::Colour &clickedColour, const bool visible)
29 : EntityNode(0), _hoverColor(0), _normalColor(0), _clickedColor(0), _collision(0)
30{
31 _inConstructor = true;
32 setShape(pointCount);
33 setPosition(position);
34 setNormalColor(normalColour);
35 setHoverColor(hoverColour);
36 setClickedColor(clickedColour);
37 setVisible(visible);
38 _inConstructor = false;
39 _processColor();
40 _processCollisions();
41
42};
43
44GUI::ECS::Components::ShapeComponent::ShapeComponent(const std::size_t pointCount, const float radius, const std::pair<float, float> &position, const GUI::ECS::Systems::Colour &normalColour, const GUI::ECS::Systems::Colour &hoverColour, const GUI::ECS::Systems::Colour &clickedColour, const bool visible)
45 : EntityNode(0), _hoverColor(0), _normalColor(0), _clickedColor(0), _collision(0)
46{
47 _inConstructor = true;
48 setShape(pointCount, radius);
49 setPosition(position);
50 setNormalColor(normalColour);
51 setHoverColor(hoverColour);
52 setClickedColor(clickedColour);
53 setVisible(visible);
54 _inConstructor = false;
55 _processColor();
56 _processCollisions();
57};
58
59GUI::ECS::Components::ShapeComponent::ShapeComponent(const std::pair<float, float> &size, const std::pair<float, float> &position, const GUI::ECS::Systems::Colour &normalColour, const GUI::ECS::Systems::Colour &hoverColour, const GUI::ECS::Systems::Colour &clickedColour, const bool visible)
60 : EntityNode(0), _hoverColor(0), _normalColor(0), _clickedColor(0), _collision(0)
61{
62 _inConstructor = true;
63 setShape(size);
64 setPosition(position);
65 setNormalColor(normalColour);
66 setHoverColor(hoverColour);
67 setClickedColor(clickedColour);
68 setVisible(visible);
69 _inConstructor = false;
70 _processColor();
71 _processCollisions();
72};
73
74GUI::ECS::Components::ShapeComponent::ShapeComponent(const Recoded::FloatRect &rect, const GUI::ECS::Systems::Colour &normalColour, const GUI::ECS::Systems::Colour &hoverColour, const GUI::ECS::Systems::Colour &clickedColour, const bool visible)
75 : EntityNode(0), _hoverColor(0), _normalColor(0), _clickedColor(0), _collision(0)
76{
77 _inConstructor = true;
78 setShape(rect);
79 setNormalColor(normalColour);
80 setHoverColor(hoverColour);
81 setClickedColor(clickedColour);
82 setVisible(visible);
83 _inConstructor = false;
84 _processColor();
85 _processCollisions();
86};
87
88GUI::ECS::Components::ShapeComponent::ShapeComponent(const std::uint32_t entityId, const std::size_t pointCount, const std::pair<float, float> &position, const GUI::ECS::Systems::Colour &normalColour, const GUI::ECS::Systems::Colour &hoverColour, const GUI::ECS::Systems::Colour &clickedColour, const bool visible)
89 : EntityNode(entityId), _hoverColor(entityId), _normalColor(entityId), _clickedColor(entityId), _collision(entityId)
90{
91 _inConstructor = true;
92 setShape(pointCount);
93 setPosition(position);
94 setNormalColor(normalColour);
95 setHoverColor(hoverColour);
96 setClickedColor(clickedColour);
97 setVisible(visible);
98 _inConstructor = false;
99 _processColor();
100 _processCollisions();
101};
102
103GUI::ECS::Components::ShapeComponent::ShapeComponent(const std::uint32_t entityId, const std::size_t pointCount, const float radius, const std::pair<float, float> &position, const GUI::ECS::Systems::Colour &normalColour, const GUI::ECS::Systems::Colour &hoverColour, const GUI::ECS::Systems::Colour &clickedColour, const bool visible)
104 : EntityNode(entityId), _hoverColor(entityId), _normalColor(entityId), _clickedColor(entityId), _collision(entityId)
105{
106 _inConstructor = true;
107 setShape(pointCount, radius);
108 setPosition(position);
109 setNormalColor(normalColour);
110 setHoverColor(hoverColour);
111 setClickedColor(clickedColour);
112 setVisible(visible);
113 _inConstructor = false;
114 _processColor();
115 _processCollisions();
116};
117
118GUI::ECS::Components::ShapeComponent::ShapeComponent(const std::uint32_t entityId, const std::pair<float, float> &size, const std::pair<float, float> &position, const GUI::ECS::Systems::Colour &normalColour, const GUI::ECS::Systems::Colour &hoverColour, const GUI::ECS::Systems::Colour &clickedColour, const bool visible)
119 : EntityNode(entityId), _hoverColor(entityId), _normalColor(entityId), _clickedColor(entityId), _collision(entityId)
120{
121 _inConstructor = true;
122 setShape(size);
123 setPosition(position);
124 setNormalColor(normalColour);
125 setHoverColor(hoverColour);
126 setClickedColor(clickedColour);
127 setVisible(visible);
128 _inConstructor = false;
129 _processColor();
130 _processCollisions();
131};
132
133GUI::ECS::Components::ShapeComponent::ShapeComponent(const std::uint32_t entityId, const Recoded::FloatRect &rect, const GUI::ECS::Systems::Colour &normalColour, const GUI::ECS::Systems::Colour &hoverColour, const GUI::ECS::Systems::Colour &clickedColour, const bool visible)
134 : EntityNode(entityId), _hoverColor(entityId), _normalColor(entityId), _clickedColor(entityId), _collision(entityId)
135{
136 _inConstructor = true;
137 setShape(rect);
138 setNormalColor(normalColour);
139 setHoverColor(hoverColour);
140 setClickedColor(clickedColour);
141 setVisible(visible);
142 _inConstructor = false;
143 _processColor();
144 _processCollisions();
145};
146
147
149
151{
152 _hoverColor = hoverColor;
153}
154
156{
157 _normalColor = normalColor;
158}
159
161{
162 _clickedColor = clickedColor;
163}
164
165void GUI::ECS::Components::ShapeComponent::setShape(const std::size_t pointCount)
166{
167 clearShapes();
168 _sfShapeConvex.emplace(pointCount);
170 if (!_inConstructor) {
171 _processCollisions();
172 }
173 PRETTY_DEBUG << "Convex shape is set, pointCount: " << Recoded::myToString(pointCount) << std::endl;
174}
175
176void GUI::ECS::Components::ShapeComponent::setShape(const std::size_t pointCount, const float radius)
177{
178 clearShapes();
179 _sfShapeCircle.emplace(radius, pointCount);
181 if (!_inConstructor) {
182 _processCollisions();
183 }
184 PRETTY_DEBUG << "Circle shape is set, pointCount: " << Recoded::myToString(pointCount) << " radius: " << Recoded::myToString(radius) << std::endl;
185}
186
187void GUI::ECS::Components::ShapeComponent::setShape(const std::pair<float, float> &size)
188{
189 clearShapes();
190 sf::Vector2f dim;
191 dim.x = size.first;
192 dim.y = size.second;
193 _sfShapeRectangle.emplace(dim);
194 _collision.setDimension(size);
196 if (!_inConstructor) {
197 _processCollisions();
198 }
199 PRETTY_DEBUG << "Rectange shape is set, size: " << Recoded::myToString(size) << std::endl;
200}
201
203{
204 clearShapes();
205 sf::Vector2f dim = { rect.size.first, rect.size.second };
206 sf::Vector2f pos = { rect.position.first, rect.position.second };
207 _sfShapeRectangle.emplace(dim);
208 _sfShapeRectangle->setPosition(pos);
209 _collision.setDimension(rect.size);
210 _collision.setPosition(rect.position);
212 if (!_inConstructor) {
213 _processCollisions();
214 }
215 PRETTY_DEBUG << "Rectange shape is set, rect: " << Recoded::myToString(rect) << std::endl;
216}
217
219{
220 clearShapes();
221 _shape = shape;
222}
223
225{
226 PRETTY_INFO << "Clearing any instances of any previous shapes" << std::endl;
227 clearShapes();
228 PRETTY_SUCCESS << "The shapes have been cleared" << std::endl;
229 _shape = type;
230 PRETTY_INFO << "Setting the shape type to : '" << Recoded::myToString(type) << "'." << std::endl;
231
233 PRETTY_INFO << "Setting the shape to a rectangle." << std::endl;
234 _assignShape(shape, _sfShapeRectangle);
235 } else if (type == GUI::ECS::Systems::ActiveShape::CIRCLE) {
236 PRETTY_INFO << "Setting the shape to a circle." << std::endl;
237 _assignShape(shape, _sfShapeCircle);
238 } else if (type == GUI::ECS::Systems::ActiveShape::CONVEX) {
239 PRETTY_INFO << "Setting the shape to a convex." << std::endl;
240 _assignShape(shape, _sfShapeConvex);
241 } else if (type != GUI::ECS::Systems::ActiveShape::NONE) {
242 PRETTY_INFO << "Setting the shape to none." << std::endl;
243 throw CustomExceptions::InvalidShape("<Unknown shape type>");
244 }
245}
246
247void GUI::ECS::Components::ShapeComponent::setShape(const std::pair<GUI::ECS::Systems::ActiveShape, std::any> &shape)
248{
249 setShape(shape.first, shape.second);
250}
251
253{
254 _visible = visible;
255}
256
257void GUI::ECS::Components::ShapeComponent::setPosition(const std::pair<float, float> position)
258{
259 _collision.setPosition(position);
260 if (!_inConstructor) {
261 _processCollisions();
262 }
263}
264
265void GUI::ECS::Components::ShapeComponent::setDimension(const std::pair<float, float> dimension)
266{
267 _collision.setDimension(dimension);
268}
269
271{
272 _collision.update(collision);
273 if (_shape != GUI::ECS::Systems::ActiveShape::NONE && !_inConstructor) {
274 _processCollisions();
275 _processColor();
276 }
277}
278
280{
281 _name = name;
282}
283
285{
286 _application = application;
287}
288
290{
291 if (_visible) {
292 _visible = false;
293 } else {
294 _visible = true;
295 }
296}
297
299{
300 return _visible;
301}
302
304{
306 return false;
307 }
308 if (_sfShapeRectangle.has_value() || _sfShapeCircle.has_value() || _sfShapeConvex.has_value()) {
309 return true;
310 }
311 return false;
312}
313
318
320{
321 return Recoded::myToString(_shape);
322}
323
324const std::pair<GUI::ECS::Systems::ActiveShape, std::any> GUI::ECS::Components::ShapeComponent::getActiveShape() const
325{
327 return std::pair<GUI::ECS::Systems::ActiveShape, std::any>(_shape, std::make_any<std::string>(""));
328 }
330 if (!_sfShapeRectangle.has_value()) {
331 sf::RectangleShape tt({ 10,10 });
332 return std::pair<GUI::ECS::Systems::ActiveShape, std::any>(_shape, std::make_any<sf::RectangleShape>(tt));
333 }
334 return std::pair<GUI::ECS::Systems::ActiveShape, std::any>(
335 _shape,
336 std::make_any<sf::RectangleShape>(_sfShapeRectangle.value())
337 );
338 }
340 if (!_sfShapeCircle.has_value()) {
341 sf::CircleShape tt(10, 30);
342 return std::pair<GUI::ECS::Systems::ActiveShape, std::any>(_shape, std::make_any<sf::CircleShape>(tt));
343 }
344 return std::pair<GUI::ECS::Systems::ActiveShape, std::any>(
345 _shape,
346 std::make_any<sf::CircleShape>(_sfShapeCircle.value())
347 );
348 }
350 if (!_sfShapeConvex.has_value()) {
351 sf::ConvexShape tt(10);
352 return std::pair<GUI::ECS::Systems::ActiveShape, std::any>(_shape, std::make_any<sf::ConvexShape>(tt));
353 }
354 return std::pair<GUI::ECS::Systems::ActiveShape, std::any>(
355 _shape,
356 std::make_any<sf::ConvexShape>(_sfShapeConvex.value())
357 );
358 }
359 return std::pair<GUI::ECS::Systems::ActiveShape, std::any>(_shape, std::make_any<std::string>(""));
360}
361
366
371
376
377const std::pair<float, float> GUI::ECS::Components::ShapeComponent::getPosition() const
378{
379 return _collision.getPosition();
380}
381
382const std::pair<float, float> GUI::ECS::Components::ShapeComponent::getDimension() const
383{
384 return _collision.getDimension();
385}
386
387const std::pair<GUI::ECS::Systems::ActiveShape, std::any> GUI::ECS::Components::ShapeComponent::getShape() const
388{
389 return getActiveShape();
390}
391
396
397
399{
400 return _name;
401}
402
404{
405 return _application;
406}
407
408const std::string GUI::ECS::Components::ShapeComponent::getInfo(const unsigned int indent) const
409{
410
411 std::string indentation = "";
412 for (unsigned int i = 0; i < indent; ++i) {
413 indentation += "\t";
414 }
415 std::string result = indentation + "Shape:\n";
416 result += indentation + "- Entity Id: " + Recoded::myToString(getEntityNodeId()) + "\n";
417 result += indentation + "- Visible: " + Recoded::myToString(_visible) + "\n";
418 result += indentation + "- shape type: " + getShapeTypeString() + "\n";
419 result += indentation + "- Shape rectangle set?: " + Recoded::myToString(_sfShapeRectangle.has_value()) + "\n";
420 result += indentation + "- Shape circle set?: " + Recoded::myToString(_sfShapeCircle.has_value()) + "\n";
421 result += indentation + "- Shape convex set?: " + Recoded::myToString(_sfShapeConvex.has_value()) + "\n";
422 result += indentation + "- Hover Color: {\n" + _hoverColor.getInfo(indent + 1) + indentation + "}\n";
423 result += indentation + "- Normal Color: {\n" + _normalColor.getInfo(indent + 1) + indentation + "}\n";
424 result += indentation + "- Clicked Color: {\n" + _clickedColor.getInfo(indent + 1) + indentation + "}\n";
425 result += indentation + "- Collision: {\n" + _collision.getInfo(indent + 1) + indentation + "}\n";
426 return result;
427}
428
430{
431 return _visible;
432}
433
435{
436 _collision.update(mouse);
437 if (!_inConstructor) {
438 _processColor();
439 }
440}
441
443{
444 if (this != &copy) {
445 setShape(copy.getActiveShape());
446 setHoverColor(copy.getHoverColor());
447 setNormalColor(copy.getNormalColor());
448 setClickedColor(copy.getClickedColor());
449 _collision.update(copy.getCollision());
450 _processColor();
451 } else {
452 throw CustomExceptions::InvalidShape("No existing shape");
453 }
454}
455
457{
458 PRETTY_DEBUG << "Clearing all shape instances" << std::endl;
460
461 _sfShapeCircle.reset();
462 _sfShapeConvex.reset();
463 _sfShapeRectangle.reset();
464 PRETTY_DEBUG << "All Shapes are cleared" << std::endl;
465}
466
467std::optional<std::pair<GUI::ECS::Systems::ActiveShape, std::any>> GUI::ECS::Components::ShapeComponent::render() const
468{
469 if (!_visible || _shape == GUI::ECS::Systems::ActiveShape::NONE) {
470 PRETTY_WARNING << "The shape is either hidden or it's value is None" << std::endl;
471 PRETTY_DEBUG << "Visibility status: '" << Recoded::myToString(_visible) << "'" << std::endl;
472 PRETTY_DEBUG << "Shape status: '" << getShapeTypeString() << "'." << std::endl;
473 return std::nullopt;
474 }
475 if (_shape == GUI::ECS::Systems::ActiveShape::RECTANGLE && _sfShapeRectangle.has_value()) {
476 PRETTY_DEBUG << "Returning value for the Rectangle shape." << std::endl;
477 return std::optional(
478 std::pair(
480 std::make_any<sf::RectangleShape>(_sfShapeRectangle.value())
481 )
482 );
483 }
484 if (_shape == GUI::ECS::Systems::ActiveShape::CIRCLE && _sfShapeCircle.has_value()) {
485 PRETTY_DEBUG << "Returning value for the Circle shape." << std::endl;
486 return std::optional(
487 std::pair(
489 std::make_any<sf::CircleShape>(_sfShapeCircle.value())
490 )
491 );
492 }
493 if (_shape == GUI::ECS::Systems::ActiveShape::CONVEX && _sfShapeConvex.has_value()) {
494 PRETTY_DEBUG << "Returning value for the Convex shape." << std::endl;
495 return std::optional(
496 std::pair(
498 std::make_any<sf::ConvexShape>(_sfShapeConvex.value())
499 )
500 );
501 }
502 PRETTY_WARNING << "No shape is set for this component" << std::endl;
503 return std::nullopt;
504}
505
507{
508 if (this != &copy) {
509 update(copy);
510 }
511 return *this;
512}
513
514void GUI::ECS::Components::ShapeComponent::_processColor()
515{
516 std::any systemColour;
517 if (_collision.isClicked()) {
518 PRETTY_DEBUG << "The colour being applied is : {\n"
519 << _clickedColor << "\n} and corresponds to the _clickedColour"
520 << std::endl;
521 systemColour = _clickedColor.getRenderColour();
522 } else if (_collision.isHovered()) {
523 PRETTY_DEBUG << "The colour being applied is : {\n"
524 << _hoverColor << "\n} and corresponds to the _hoverColour"
525 << std::endl;
526 systemColour = _hoverColor.getRenderColour();
527 } else {
528 PRETTY_DEBUG << "The colour being applied is : {\n"
529 << _normalColor << "\n} and corresponds to the _normalColour"
530 << std::endl;
531 systemColour = _normalColor.getRenderColour();
532 }
533 const std::string errMsg = "<The content returned by the getRenderColour function is not of type sf::Color>, system error: ";
534 const std::optional<sf::Color> colourCapsule = Utilities::unCast<sf::Color, CustomExceptions::NoColour>(systemColour, true, errMsg);
535 if (!colourCapsule.has_value()) {
536 PRETTY_CRITICAL << "BaseId: '" << Recoded::myToString(getEntityNodeId()) << "' "
537 << errMsg << std::endl;
538 throw CustomExceptions::NoColour(errMsg);
539 }
540 if (_sfShapeCircle.has_value()) {
541 _sfShapeCircle->setFillColor(colourCapsule.value());
542 }
543 if (_sfShapeConvex.has_value()) {
544 _sfShapeConvex->setFillColor(colourCapsule.value());
545 }
546 if (_sfShapeRectangle.has_value()) {
547 _sfShapeRectangle->setFillColor(colourCapsule.value());
548 }
549}
550
551void GUI::ECS::Components::ShapeComponent::_processCollisions()
552{
554 PRETTY_WARNING << "There are no shapes with which to calculate collisions." << std::endl;
555 return;
556 }
557
558 bool hitboxUpdated = false;
559 const sf::Vector2f pos = { _collision.getPositionX(), _collision.getPositionY() };
560 const sf::Vector2f size = { _collision.getWidth(), _collision.getHeight() };
561
562 sf::FloatRect collisionHitBox = { pos, size };
563 if (_shape == GUI::ECS::Systems::ActiveShape::CIRCLE && _sfShapeCircle.has_value()) {
564 PRETTY_DEBUG << "Setting positions for : Circle shape" << std::endl;
565 _sfShapeCircle->setPosition(pos);
566 collisionHitBox = _sfShapeCircle->getGlobalBounds();
567 hitboxUpdated = true;
568 }
569 if (_shape == GUI::ECS::Systems::ActiveShape::CONVEX && _sfShapeConvex.has_value()) {
570 PRETTY_DEBUG << "Setting positions for : Convex shape" << std::endl;
571 _sfShapeConvex->setPosition(pos);
572 collisionHitBox = _sfShapeConvex->getGlobalBounds();
573 hitboxUpdated = true;
574 }
575 if (_shape == GUI::ECS::Systems::ActiveShape::RECTANGLE && _sfShapeRectangle.has_value()) {
576 PRETTY_DEBUG << "Setting positions for : Rectangle shape" << std::endl;
577 _sfShapeRectangle->setPosition(pos);
578 collisionHitBox = _sfShapeRectangle->getGlobalBounds();
579 hitboxUpdated = true;
580 }
581 if (hitboxUpdated) {
582 _collision.setDimension({ collisionHitBox.size.x, collisionHitBox.size.y });
583 }
584}
585
586
587template <typename T>
588void GUI::ECS::Components::ShapeComponent::_assignShape(const std::any &shape, std::optional<T> &shapeStorage)
589{
590 const std::string errMsg = "<Unknown shape type>, any_cast error: ";
591 std::optional<T> instanceCapsule = Utilities::unCast<T, CustomExceptions::InvalidShape>(shape, true, errMsg);
592 if (!instanceCapsule.has_value()) {
593 PRETTY_CRITICAL << "BaseId: '" << Recoded::myToString(getEntityNodeId()) << "' "
594 << "The shape that was attempted to be uncast failed." << std::endl;
595 throw CustomExceptions::InvalidShape(errMsg);
596 }
597 T instance = instanceCapsule.value();
598 shapeStorage.emplace(instance);
599}
600
601
603{
604 os << item.getInfo();
605 return os;
606}
#define PRETTY_DEBUG
Debug log with details and colour.
#define PRETTY_INFO
Info log with details and colour.
#define PRETTY_CRITICAL
Critical log with details and colour.
#define PRETTY_WARNING
Warning log with details and colour.
#define PRETTY_SUCCESS
Success log with details and colour.
@ NONE
Definition LootDrop.hpp:11
This is the file that contains the class in charge of managing shapes.
This is the class in charge of informing the user that they tried to display a non-existent or invali...
Definition Invalid.hpp:487
This is the class in charge of informing the user that they tried to access a non-existant colour ins...
Definition No.hpp:388
Manages shapes and their associated properties in the ECS framework.
const bool isVisible() const
Get the visibility status of the component.
void setCollision(const GUI::ECS::Systems::Collision &collision)
Set the internal collision class using another Collision component.
void setName(const std::string &name)
Set the Name of the component.
void setClickedColor(const GUI::ECS::Systems::Colour &clickedColor)
Sets the clicked color for the shape.
const bool isShapeInitialised() const
Know if there is a shape initialised or not.
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::string getName() const
Get the Name of the component.
const GUI::ECS::Systems::Colour getHoverColor() const
Get the Hover Color of the shape.
std::optional< std::pair< GUI::ECS::Systems::ActiveShape, std::any > > render() const
Get an optional std::pair of the object so that it can be displayed on screen.
const std::pair< GUI::ECS::Systems::ActiveShape, std::any > getActiveShape() const
Get the Active Shape and it's type all contained in an std::pair.
void setShape(const std::size_t pointCount)
Create a convex shape.
const std::pair< float, float > getDimension() const
Get the Dimension of the shape.
const bool getVisible() const
Get the info about if the shape is visible or not.
const GUI::ECS::Systems::Colour getNormalColor() const
Get the Normal Color of the shape.
ShapeComponent & operator=(const ShapeComponent &copy)
'=' operator in charge of allowing the user to seamlessly assing the content of one ShapeComponent to...
void update(const GUI::ECS::Systems::MouseInfo &mouse)
Update the mouse information of the component (this is used for mouse collision calculations)
void setDimension(const std::pair< float, float > dimension)
Set the Dimension object.
const std::string getApplication() const
Get the Application context of the component.
const GUI::ECS::Systems::ActiveShape getShapeType() const
Get the Shape Type shape, none is returned if none are initialised.
const GUI::ECS::Systems::Collision getCollision() const
Get the Collision Component of the object.
const std::string getShapeTypeString() const
Get the Shape Type shape, none is returned if none are initialised.
void setHoverColor(const GUI::ECS::Systems::Colour &hoverColor)
Sets the hover color for the shape.
void clearShapes()
Remove all and any initialised shapes in the class, this will reset the type to NONE.
ShapeComponent(const std::uint32_t entityId=0)
Default constructor.
void setVisible(const bool visible)
Set the visible toggle informing the program if it should (or not) render the component.
void toggleVisibility()
Toggles the visibility of the shape.
const std::pair< GUI::ECS::Systems::ActiveShape, std::any > getShape() const
Get the Shape and it's type all packaged in an std::pair.
const GUI::ECS::Systems::Colour getClickedColor() const
Get the Clicked Color shape.
void setNormalColor(const GUI::ECS::Systems::Colour &normalColor)
Sets the normal color for the shape.
void setPosition(const std::pair< float, float > position)
Set the position of the component.
void setApplication(const std::string &application)
Set the Application context of the component.
const std::pair< float, float > getPosition() const
Get the Position of the shape.
Represents a rectangular component that can detect collisions and mouse interactions,...
Definition Collision.hpp:39
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 ...
A class for representing and manipulating colors using RGBA components. Inherits from EntityNode to a...
Definition Colour.hpp:37
A generic 2D rectangle class that holds position and size as pairs.
Definition Rect.hpp:38
std::pair< T, T > size
The size of the rectangle (width, height)
Definition Rect.hpp:98
std::pair< T, T > position
the position (top and left corner)
Definition Rect.hpp:97
std::ostream & operator<<(std::ostream &os, const AnimationComponent &item)
Outputs the animation's info to a stream.
ActiveShape
Enum representing different types of shapes managed by the ShapeComponent.
@ NONE
No shape initialized.
const std::string myToString(const Rect< RectType > &rectangle)
Converts a Rect<T> object to its string representation.
Definition Rect.hpp:223
std::optional< T > unCast(const std::any &classNode, const bool raiseOnError=true, const std::string customErrorMessage="")
Casts the content of a std::any back to its original type.
Definition UnCast.hpp:65