R-Type  2
Doom but in better
Loading...
Searching...
No Matches
TextComponent.hpp
Go to the documentation of this file.
1/*
2** EPITECH PROJECT, 2024
3** rtype (Workspace)
4** File description:
5** TextComponent.hpp
6*/
7
13#pragma once
14
15#include <any>
16#include <cstdint>
17#include <optional>
18#include <SFML/Graphics/Text.hpp>
19#include <SFML/Graphics/Font.hpp>
20#include <SFML/Graphics/Color.hpp>
21
22#include "Log.hpp"
23#include "LogMacros.hpp"
24#include "Utilities.hpp"
29
30namespace GUI
31{
32 namespace ECS
33 {
34 namespace Components
35 {
44 class TextComponent : public EntityNode {
45 public:
46
56 TextComponent(const std::uint32_t entityId);
63 TextComponent(const std::uint32_t entityId, const std::string &fontPath);
71 TextComponent(const std::uint32_t entityId, const std::string &fontPath, const std::string &text);
80 TextComponent(const std::uint32_t entityId, const std::string &fontPath, const std::string &text, const unsigned int &size);
92 TextComponent(const std::uint32_t entityId, const std::string &fontPath, const std::string &text, const unsigned int &size, const GUI::ECS::Systems::Colour &normalColor, const GUI::ECS::Systems::Colour &hoverColor, const GUI::ECS::Systems::Colour &clickedColor);
105 TextComponent(const std::uint32_t entityId, const std::string &fontPath, const std::string &text, const unsigned int &size, const GUI::ECS::Systems::Colour &normalColor, const GUI::ECS::Systems::Colour &hoverColor, const GUI::ECS::Systems::Colour &clickedColor, const std::pair<float, float> &position);
112 TextComponent(const std::uint32_t entityId, const GUI::ECS::Systems::Font &fontInstance);
120 TextComponent(const std::uint32_t entityId, const GUI::ECS::Systems::Font &fontInstance, const std::string &text);
129 TextComponent(const std::uint32_t entityId, const GUI::ECS::Systems::Font &fontInstance, const std::string &text, const unsigned int &size);
141 TextComponent(const std::uint32_t entityId, const GUI::ECS::Systems::Font &fontInstance, const std::string &text, const unsigned int &size, const GUI::ECS::Systems::Colour &normalColor, const GUI::ECS::Systems::Colour &hoverColor, const GUI::ECS::Systems::Colour &clickedColor);
154 TextComponent(const std::uint32_t entityId, const GUI::ECS::Systems::Font &fontInstance, const std::string &text, const unsigned int &size, const GUI::ECS::Systems::Colour &normalColor, const GUI::ECS::Systems::Colour &hoverColor, const GUI::ECS::Systems::Colour &clickedColor, const std::pair<float, float> &position);
155
160
166 void setFont(const GUI::ECS::Systems::Font &font);
167
173 void setNormalColor(const GUI::ECS::Systems::Colour &color);
179 void setHoverColor(const GUI::ECS::Systems::Colour &color);
186
192 void setText(const std::string &text);
193
199 void setSize(const std::uint32_t &size);
200
209 void setFontPath(const std::string &fontPath, const std::string &name = "");
210
216 void setPosition(const std::pair<float, float> &position);
217
225 void setVisible(const bool visible);
226
232 void setName(const std::string &name);
233
239 void setApplication(const std::string &application);
240
246 void toggleVisibility();
247
254 const bool isVisible() const;
255
261 const GUI::ECS::Systems::Font getFont() const;
262
268 const std::string getFontPath() const;
269
288
294 const std::string getText() const;
295
301 const std::uint32_t getSize() const;
302
308 const std::pair<float, float> getPosition() const;
309
316 const bool getVisible() const;
326 const std::string getInfo(const unsigned int indent = 0) const;
327
334
340 const std::string getName() const;
341
347 const std::string getApplication() const;
348
354 std::any render() const;
355
361 void update(const GUI::ECS::Systems::MouseInfo &mouse);
368
377
378 private:
383 void _initialiseText();
388 void _processTextComponent();
394 void _loadFont();
395
396 bool _visible = true;
397 bool _fontAltered = false;
398 bool _fontChanged = false;
399 bool _textAltered = false;
400 bool _sizeAltered = false;
401 bool _inConstructor = true;
402 bool _positionAltered = false;
403 std::string _text = "SampleText";
404 std::string _textName = "text";
405 std::string _textApplication = "text";
406 unsigned int _size = 30;
407 std::optional<sf::Text> _sfTextComponent;
413 };
414
422 std::ostream &operator<<(std::ostream &os, const TextComponent &item);
423
424 }
425 }
426}
427
This is the file that links the EntityNode children.
Header file for the Font class, responsible for managing fonts within the program.
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...
A class that represents a text component in the GUI system. It manages font, size,...
const GUI::ECS::Systems::Colour getHoverColor() const
Get the Hover Color of the text.
void setName(const std::string &name)
Set the Name of the component.
const std::string getFontPath() const
Get the Font Path object.
void setFontPath(const std::string &fontPath, const std::string &name="")
Set the font from a path (this will attempt to load the font internally)
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 ...
void setPosition(const std::pair< float, float > &position)
Set the Position of the text.
~TextComponent()
Destructor for TextComponent.
const std::string getText() const
Get the Text that was set in the class.
void toggleVisibility()
Toggle the visibility of the object. hidden.
void setVisible(const bool visible)
Set the visibility of the object using a boolean.
TextComponent()
Default constructor. Initializes the text component with default values.
const GUI::ECS::Systems::Collision getCollision() const
Function in charge of returning the collision instance of the text component.
const std::string getApplication() const
Get the Application context of the component.
const std::string getName() const
Get the Name text component.
const GUI::ECS::Systems::Colour getNormalColor() const
Get the Normal Color of the text.
const GUI::ECS::Systems::Colour getClickedColor() const
Get the Clicked Color of the text.
const bool getVisible() const
Get the Visibility of the text.
const bool isVisible() const
Check if the text is set to be rendered or not.
void setApplication(const std::string &application)
Set the application context of the component.
const std::uint32_t getSize() const
Get the Size of the text.
std::any render() const
Function in charge of rendering the text if it is set to visible, otherwise, does nothing.
void setNormalColor(const GUI::ECS::Systems::Colour &color)
Set the default colour of the text object.
void setFont(const GUI::ECS::Systems::Font &font)
Set the Font of the text using a loaded Font instance from GUI::ECS::Systems::Font.
void update(const GUI::ECS::Systems::MouseInfo &mouse)
The function in charge of updating the stored mouse information.
void setHoverColor(const GUI::ECS::Systems::Colour &color)
Set the Hover Color of the text object.
void setText(const std::string &text)
Set the Text.
void setSize(const std::uint32_t &size)
Set the Size of the text.
void setClickedColor(const GUI::ECS::Systems::Colour &color)
Set the Clicked Color of the text object.
const GUI::ECS::Systems::Font getFont() const
Get the Font object contained in the class.
const std::pair< float, float > getPosition() const
Get the Position of the text.
GUI::ECS::Components::TextComponent & operator=(const GUI::ECS::Components::TextComponent &copy)
The overload in charge of allowing a TextComponent update using the '=' sign.
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 Black
Definition Colour.hpp:969
Manages font entities in the GUI ECS.
Definition Font.hpp:45
std::ostream & operator<<(std::ostream &os, const AnimationComponent &item)
Outputs the animation's info to a stream.