R-Type  2
Doom but in better
Loading...
Searching...
No Matches
ButtonComponent.hpp
Go to the documentation of this file.
1/*
2** EPITECH PROJECT, 2024
3** rtype (Workspace)
4** File description:
5** ButtonComponent.hpp
6*/
7
13#pragma once
14
15#include <any>
16#include <optional>
17#include <typeindex>
18#include <functional>
19#include <SFML/Graphics/Color.hpp>
20
21#include "Log.hpp"
22#include "LogMacros.hpp"
23#include "Utilities.hpp"
30
31namespace GUI
32{
33 namespace ECS
34 {
35 namespace Components
36 {
41 class ButtonComponent : public EntityNode {
42 public:
48 ButtonComponent(const std::uint32_t entityId = 0);
49
64 ButtonComponent(const GUI::ECS::Components::ShapeComponent &shapeItem, const GUI::ECS::Components::TextComponent &textItem, std::function<void()> callback);
73 ButtonComponent(const GUI::ECS::Components::ShapeComponent &shapeItem, const GUI::ECS::Components::TextComponent &textItem, const GUI::ECS::Systems::Collision &collisionItem, const std::uint32_t textSize = 40);
83 ButtonComponent(const GUI::ECS::Components::ShapeComponent &shapeItem, const GUI::ECS::Components::TextComponent &textItem, std::function<void()> callback, const GUI::ECS::Systems::Collision &collisionItem, const std::uint32_t textSize = 40);
84
92 ButtonComponent(const std::uint32_t entityId, const GUI::ECS::Components::ShapeComponent &shapeItem, const GUI::ECS::Components::TextComponent &textItem);
101 ButtonComponent(const std::uint32_t entityId, const GUI::ECS::Components::ShapeComponent &shapeItem, const GUI::ECS::Components::TextComponent &textItem, std::function<void()> callback);
111 ButtonComponent(const std::uint32_t entityId, const GUI::ECS::Components::ShapeComponent &shapeItem, const GUI::ECS::Components::TextComponent &textItem, const GUI::ECS::Systems::Collision &collisionItem, const std::uint32_t textSize = 40);
122 ButtonComponent(const std::uint32_t entityId, const GUI::ECS::Components::ShapeComponent &shapeItem, const GUI::ECS::Components::TextComponent &textItem, std::function<void()> callback, const GUI::ECS::Systems::Collision &collisionItem, const std::uint32_t textSize = 40);
123
128
134 void setHoverColor(const GUI::ECS::Systems::Colour &hoverColor);
140 void setNormalColor(const GUI::ECS::Systems::Colour &normalColor);
146 void setClickedColor(const GUI::ECS::Systems::Colour &clickedColor);
152 void setTextHoverColor(const GUI::ECS::Systems::Colour &hoverColor);
158 void setTextNormalColor(const GUI::ECS::Systems::Colour &normalColor);
164 void setTextClickedColor(const GUI::ECS::Systems::Colour &clickedColor);
170 void setTextString(const std::string &text);
171
177 void setPosition(const std::pair<float, float> &position);
184 void setDimension(const std::pair<float, float> &dimension, const std::uint32_t textSize = 40);
190 void setTextPosition(const std::pair<float, float> &position);
196 void setTextSize(const std::uint32_t textSize);
202 void setShapePosition(const std::pair<float, float> &position);
208 void setShapeDimension(const std::pair<float, float> &dimension);
215 void setCollision(const GUI::ECS::Systems::Collision &collision, const std::uint32_t textSize = 40);
216
223 void setCallback(std::function<void()> callback, const std::string &callbackName = "Callback Function");
224
230 void setVisible(const bool visible);
231
237 void setName(const std::string &name);
238
244 void setApplication(const std::string &application);
245
251 std::function<void()> callback();
252
259 const bool isVisible() const;
260
265 void toggleVisibility();
266
285
304
310 const std::uint32_t getTextSize() const;
316 const std::pair<float, float> getPosition() const;
322 const std::pair<float, float> getDimension() const;
328 const std::pair<float, float> getTextPosition() const;
334 const std::pair<float, float> getShapePosition() const;
340 const std::pair<float, float> getShapeDimension() const;
347
353 const std::string getCallbackName() const;
359 const std::function<void()> getCallback() const;
360
370 const bool getVisible() const;
371
377 const std::string getName() const;
378
384 const std::string getApplication() const;
385
407 const std::string getInfo(const unsigned int indent = 0) const;
408
414 void update(const GUI::ECS::Systems::MouseInfo &mouse);
433
442 std::unordered_map<std::type_index, std::any> render() const;
443
452
453 private:
454 bool _visible = true;
455 std::string _name = "Button";
456 std::string _application = "Button";
457 std::string _callbackName = "callback";
458 std::uint32_t _textSize = 40;
459 std::function<void()> _callback;
463
464 };
465
474 std::ostream &operator<<(std::ostream &os, const ButtonComponent &item);
475 }
476 }
477}
478
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 file that contains the class in charge of managing shapes.
This is the file that contains the class in charge of managing a sprite.
This is the file that contains a class in charge of managing a test component.
Manages button functionalities, including appearance, position, and callbacks.
~ButtonComponent()
Destructor for ButtonComponent.
void setName(const std::string &name)
Set the Name of the button.
ButtonComponent(const std::uint32_t entityId=0)
Default constructor for ButtonComponent.
void setShapePosition(const std::pair< float, float > &position)
Set the Shape Position.
const std::string getName() const
Get the Name button component.
const std::function< void()> getCallback() const
Get the Callback object.
void setTextNormalColor(const GUI::ECS::Systems::Colour &normalColor)
Set the Text Normal Color.
const GUI::ECS::Systems::Colour getTextNormalColor() const
Get the Text Normal Color.
void setDimension(const std::pair< float, float > &dimension, const std::uint32_t textSize=40)
Set the Dimension of all objects contained in the button.
void update(const GUI::ECS::Systems::MouseInfo &mouse)
Update the mouse position information for all the entities in the button.
const GUI::ECS::Components::ShapeComponent & getShapeComponent() const
Get the Shape Component.
const GUI::ECS::Systems::Collision getCollision() const
Get the button collision object.
void setCollision(const GUI::ECS::Systems::Collision &collision, const std::uint32_t textSize=40)
Set the Collision for all objects of the Button class.
const std::pair< float, float > getShapeDimension() const
Get the Shape's Dimensions.
void setPosition(const std::pair< float, float > &position)
Set the Position of all objects contained in the button.
const std::string getApplication() const
Get the Application of the button component.
const GUI::ECS::Systems::Colour getTextClickedColor() const
Get the Text Clicked Color.
const bool isVisible() const
Get the information about if the element is visible.
std::function< void()> callback()
Get the callback function.
void setHoverColor(const GUI::ECS::Systems::Colour &hoverColor)
Set the Hover Color of the button for the child components.
void setNormalColor(const GUI::ECS::Systems::Colour &normalColor)
Set the Normal Color of the button for the child objects.
void setTextPosition(const std::pair< float, float > &position)
Set the Text Position.
const GUI::ECS::Components::TextComponent getTextComponent() const
Get the Text Component.
const GUI::ECS::Systems::Colour getTextHoverColor() const
Get the Text Hover Color.
const std::pair< float, float > getDimension() const
Get the Dimensions of the button.
const GUI::ECS::Systems::Colour getNormalColor() const
Get the Normal Color.
void setTextHoverColor(const GUI::ECS::Systems::Colour &hoverColor)
Set the Text Hover Color.
const GUI::ECS::Systems::Colour getClickedColor() const
Get the Clicked Color.
void setCallback(std::function< void()> callback, const std::string &callbackName="Callback Function")
Set the Callback function for the the button is clicked.
std::unordered_map< std::type_index, std::any > render() const
Get the components that need rendering.
const GUI::ECS::Systems::Colour getHoverColor() const
Get the Hover Color.
void toggleVisibility()
Toggle the visibility of the component.
void setTextClickedColor(const GUI::ECS::Systems::Colour &clickedColor)
Set the Text Clicked Color.
void setApplication(const std::string &application)
Set the Application context of the button.
const bool getVisible() const
Get the information about if the Button is visible or hidden.
const std::uint32_t getTextSize() const
Get the Text Size.
void setTextSize(const std::uint32_t textSize)
Set the Text Size.
const std::pair< float, float > getPosition() const
Get the Position of the button.
void setVisible(const bool visible)
Set the visibility of the element.
void setTextString(const std::string &text)
Set the text contained in the Text component.
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 ...
ButtonComponent & operator=(const GUI::ECS::Components::ButtonComponent &copy)
A operator to allow seemless updating/asining from one button class to another.
const std::string getCallbackName() const
Get the Callback Name of the callback function.
const std::pair< float, float > getShapePosition() const
Get the Shape Position.
void setShapeDimension(const std::pair< float, float > &dimension)
Set the Shape Dimensions.
void setClickedColor(const GUI::ECS::Systems::Colour &clickedColor)
Set the Clicked Color of the button for the child objects.
const std::pair< float, float > getTextPosition() const
Get the Text Position.
Manages shapes and their associated properties in the ECS framework.
A class that represents a text component in the GUI system. It manages font, size,...
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
std::ostream & operator<<(std::ostream &os, const AnimationComponent &item)
Outputs the animation's info to a stream.