R-Type  2
Doom but in better
Loading...
Searching...
No Matches
ShapeComponent.hpp
Go to the documentation of this file.
1/*
2** EPITECH PROJECT, 2024
3** rtype (Workspace)
4** File description:
5** ShapeComponent.hpp
6*/
7
13#pragma once
14
15#include <any>
16#include <memory>
17#include <string>
18#include <utility>
19#include <ostream>
20#include <optional>
21#include <SFML/Graphics/Texture.hpp>
22#include <SFML/Graphics/CircleShape.hpp>
23#include <SFML/Graphics/ConvexShape.hpp>
24#include <SFML/Graphics/RectangleShape.hpp>
25
26#include "Log.hpp"
27#include "LogMacros.hpp"
28#include "Utilities.hpp"
29#include "CustomExceptions.hpp"
35
36namespace GUI
37{
38 namespace ECS
39 {
40 namespace Components
41 {
47 class ShapeComponent : public EntityNode {
48 public:
54 ShapeComponent(const std::uint32_t entityId = 0);
65 ShapeComponent(const std::size_t pointCount, const std::pair<float, float> &position = { 0,0 }, const GUI::ECS::Systems::Colour &normalColour = GUI::ECS::Systems::Colour::AliceBlue, const GUI::ECS::Systems::Colour &hoverColour = GUI::ECS::Systems::Colour::White, const GUI::ECS::Systems::Colour &clickedColour = GUI::ECS::Systems::Colour::CornflowerBlue, const bool visible = true);
77 ShapeComponent(const std::size_t pointCount, const float radius, const std::pair<float, float> &position = { 0,0 }, const GUI::ECS::Systems::Colour &normalColour = GUI::ECS::Systems::Colour::AliceBlue, const GUI::ECS::Systems::Colour &hoverColour = GUI::ECS::Systems::Colour::White, const GUI::ECS::Systems::Colour &clickedColour = GUI::ECS::Systems::Colour::CornflowerBlue, const bool visible = true);
88 ShapeComponent(const std::pair<float, float> &size, const std::pair<float, float> &position = { 0,0 }, const GUI::ECS::Systems::Colour &normalColour = GUI::ECS::Systems::Colour::AliceBlue, const GUI::ECS::Systems::Colour &hoverColour = GUI::ECS::Systems::Colour::White, const GUI::ECS::Systems::Colour &clickedColour = GUI::ECS::Systems::Colour::CornflowerBlue, const bool visible = true);
110 ShapeComponent(const std::uint32_t entityId, const std::size_t pointCount, const std::pair<float, float> &position = { 0,0 }, const GUI::ECS::Systems::Colour &normalColour = GUI::ECS::Systems::Colour::AliceBlue, const GUI::ECS::Systems::Colour &hoverColour = GUI::ECS::Systems::Colour::White, const GUI::ECS::Systems::Colour &clickedColour = GUI::ECS::Systems::Colour::CornflowerBlue, const bool visible = true);
123 ShapeComponent(const std::uint32_t entityId, const std::size_t pointCount, const float radius, const std::pair<float, float> &position = { 0,0 }, const GUI::ECS::Systems::Colour &normalColour = GUI::ECS::Systems::Colour::AliceBlue, const GUI::ECS::Systems::Colour &hoverColour = GUI::ECS::Systems::Colour::White, const GUI::ECS::Systems::Colour &clickedColour = GUI::ECS::Systems::Colour::CornflowerBlue, const bool visible = true);
135 ShapeComponent(const std::uint32_t entityId, const std::pair<float, float> &size, const std::pair<float, float> &position = { 0,0 }, const GUI::ECS::Systems::Colour &normalColour = GUI::ECS::Systems::Colour::AliceBlue, const GUI::ECS::Systems::Colour &hoverColour = GUI::ECS::Systems::Colour::White, const GUI::ECS::Systems::Colour &clickedColour = GUI::ECS::Systems::Colour::CornflowerBlue, const bool visible = true);
146 ShapeComponent(const std::uint32_t entityId, const Recoded::FloatRect &rect, const GUI::ECS::Systems::Colour &normalColour = GUI::ECS::Systems::Colour::AliceBlue, const GUI::ECS::Systems::Colour &hoverColour = GUI::ECS::Systems::Colour::White, const GUI::ECS::Systems::Colour &clickedColour = GUI::ECS::Systems::Colour::CornflowerBlue, const bool visible = true);
147
152
158 void setHoverColor(const GUI::ECS::Systems::Colour &hoverColor);
164 void setNormalColor(const GUI::ECS::Systems::Colour &normalColor);
170 void setClickedColor(const GUI::ECS::Systems::Colour &clickedColor);
171
179 void setShape(const std::size_t pointCount);
188 void setShape(const std::size_t pointCount, const float radius);
196 void setShape(const std::pair<float, float> &size);
204 void setShape(const Recoded::FloatRect &rect);
219 void setShape(const GUI::ECS::Systems::ActiveShape &type, const std::any &shape);
225 void setShape(const std::pair<GUI::ECS::Systems::ActiveShape, std::any> &shape);
226
232 void setVisible(const bool visible);
233
239 void setPosition(const std::pair<float, float> position);
245 void setDimension(const std::pair<float, float> dimension);
251 void setCollision(const GUI::ECS::Systems::Collision &collision);
252
258 void setName(const std::string &name);
259
265 void setApplication(const std::string &application);
266
270 void toggleVisibility();
271
278 const bool isVisible() const;
285 const bool isShapeInitialised() const;
286
298 const std::string getShapeTypeString() const;
304 const std::pair<GUI::ECS::Systems::ActiveShape, std::any> getActiveShape() const;
305
324
330 const std::pair<float, float> getPosition() const;
336 const std::pair<float, float> getDimension() const;
342 const std::pair<GUI::ECS::Systems::ActiveShape, std::any> getShape() const;
356 const std::string getName() const;
362 const std::string getApplication() const;
372 const std::string getInfo(const unsigned int indent = 0) const;
373
382 const bool getVisible() const;
383
389 void update(const GUI::ECS::Systems::MouseInfo &mouse);
395 void update(const ShapeComponent &copy);
396
401 void clearShapes();
402
410 std::optional<std::pair<GUI::ECS::Systems::ActiveShape, std::any>> render() const;
411
420
421 private:
426 void _processColor();
431 void _processCollisions();
432
441 template <typename T>
442 void _assignShape(const std::any &shape, std::optional<T> &shapeStorage);
443
444 bool _visible = true;
445 bool _inConstructor = true;
447
448 std::optional<sf::CircleShape> _sfShapeCircle;
449 std::optional<sf::ConvexShape> _sfShapeConvex;
450 std::optional<sf::RectangleShape> _sfShapeRectangle;
451
452 std::string _name = "";
453 std::string _application = "";
454
455 GUI::ECS::Systems::Colour _hoverColor;
456 GUI::ECS::Systems::Colour _normalColor;
457 GUI::ECS::Systems::Colour _clickedColor;
458
460 };
461
470 std::ostream &operator<<(std::ostream &os, const ShapeComponent &item);
471 }
472 }
473}
File in charge of containing the active shape enum the one in charge of tracking the type of shape st...
File in charge of containing the custom errors that are going to be used for custom description error...
This is the file that links the EntityNode children.
Macro definitions for logging messages with varying levels of detail and formatting.
This is the file in charge of containing the Log class (the one in charge of outputing info only when...
This is the header file containing the class for the mouse information.
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
A class for representing and manipulating colors using RGBA components. Inherits from EntityNode to a...
Definition Colour.hpp:37
static const Colour White
Definition Colour.hpp:757
static const Colour AliceBlue
Definition Colour.hpp:469
static const Colour CornflowerBlue
Definition Colour.hpp:450
A generic 2D rectangle class that holds position and size as pairs.
Definition Rect.hpp:38
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.