20 _color(0,
GUI::ECS::Systems::Colour::Black),
21 _hoverColor(0,
GUI::ECS::Systems::Colour::Black),
22 _clickedColor(0,
GUI::ECS::Systems::Colour::Black)
30 _color(entityId,
GUI::ECS::Systems::Colour::Black),
31 _hoverColor(entityId,
GUI::ECS::Systems::Colour::Black),
32 _clickedColor(entityId,
GUI::ECS::Systems::Colour::Black)
40 _color(entityId,
GUI::ECS::Systems::Colour::Black),
41 _hoverColor(entityId,
GUI::ECS::Systems::Colour::Black),
42 _clickedColor(entityId,
GUI::ECS::Systems::Colour::Black)
44 _inConstructor =
true;
46 _inConstructor =
false;
47 _processTextComponent();
54 _color(entityId,
GUI::ECS::Systems::Colour::Black),
55 _hoverColor(entityId,
GUI::ECS::Systems::Colour::Black),
56 _clickedColor(entityId,
GUI::ECS::Systems::Colour::Black)
58 _inConstructor =
true;
61 _inConstructor =
false;
62 _processTextComponent();
69 _color(entityId,
GUI::ECS::Systems::Colour::Black),
70 _hoverColor(entityId,
GUI::ECS::Systems::Colour::Black),
71 _clickedColor(entityId,
GUI::ECS::Systems::Colour::Black)
73 _inConstructor =
true;
77 _inConstructor =
false;
78 _processTextComponent();
85 _color(entityId,
GUI::ECS::Systems::Colour::Black),
86 _hoverColor(entityId,
GUI::ECS::Systems::Colour::Black),
87 _clickedColor(entityId,
GUI::ECS::Systems::Colour::Black)
89 _inConstructor =
true;
96 _inConstructor =
false;
97 _processTextComponent();
104 _color(entityId,
GUI::ECS::Systems::Colour::Black),
105 _hoverColor(entityId,
GUI::ECS::Systems::Colour::Black),
106 _clickedColor(entityId,
GUI::ECS::Systems::Colour::Black)
108 _inConstructor =
true;
116 _inConstructor =
false;
117 _processTextComponent();
124 _color(entityId,
GUI::ECS::Systems::Colour::Black),
125 _hoverColor(entityId,
GUI::ECS::Systems::Colour::Black),
126 _clickedColor(entityId,
GUI::ECS::Systems::Colour::Black)
128 _inConstructor =
true;
130 _inConstructor =
false;
131 _processTextComponent();
138 _color(entityId,
GUI::ECS::Systems::Colour::Black),
139 _hoverColor(entityId,
GUI::ECS::Systems::Colour::Black),
140 _clickedColor(entityId,
GUI::ECS::Systems::Colour::Black)
142 _inConstructor =
true;
145 _inConstructor =
false;
146 _processTextComponent();
153 _color(entityId,
GUI::ECS::Systems::Colour::Black),
154 _hoverColor(entityId,
GUI::ECS::Systems::Colour::Black),
155 _clickedColor(entityId,
GUI::ECS::Systems::Colour::Black)
157 _inConstructor =
true;
161 _inConstructor =
false;
162 _processTextComponent();
169 _color(0,
GUI::ECS::Systems::Colour::Black),
170 _hoverColor(0,
GUI::ECS::Systems::Colour::Black),
171 _clickedColor(0,
GUI::ECS::Systems::Colour::Black)
173 _inConstructor =
true;
180 _inConstructor =
false;
181 _processTextComponent();
188 _color(0,
GUI::ECS::Systems::Colour::Black),
189 _hoverColor(0,
GUI::ECS::Systems::Colour::Black),
190 _clickedColor(0,
GUI::ECS::Systems::Colour::Black)
192 _inConstructor =
true;
200 _inConstructor =
false;
201 _processTextComponent();
211 if (!_inConstructor) {
212 _processTextComponent();
221 if (!_inConstructor) {
222 _processTextComponent();
232 if (!_inConstructor) {
233 _processTextComponent();
240 if (_color != color) {
242 if (!_inConstructor) {
243 _processTextComponent();
250 if (_hoverColor != color) {
252 if (!_inConstructor) {
253 _processTextComponent();
260 if (_clickedColor != color) {
261 _clickedColor = color;
262 if (!_inConstructor) {
263 _processTextComponent();
270 if (fontPath.empty()) {
273 if (_font.getFontPath() != fontPath) {
274 std::string nameChild = name;
275 if (nameChild ==
"") {
276 nameChild = _font.getFontName();
281 if (!_inConstructor) {
282 _processTextComponent();
289 if (_textPos.getPosition() != position) {
290 _textPos.setPosition(position);
291 _positionAltered =
true;
292 if (!_inConstructor) {
293 _processTextComponent();
310 _textApplication = application;
349 return _clickedColor;
364 return _textPos.getPosition();
376 std::string indentation =
"";
377 for (
unsigned int i = 0; i < indent; ++i) {
380 std::string result = indentation +
"Text:\n";
387 result += indentation +
"- Position Altered: " +
Recoded::myToString(_positionAltered) +
"\n";
389 result += indentation +
"- Text: '" + _text +
"'\n";
390 result += indentation +
"- (sfText) Has text: " +
Recoded::myToString(_sfTextComponent.has_value()) +
"\n";
392 result += indentation +
"- Text Position: {\n" + _textPos.
getInfo(indent + 1) + indentation +
"}\n";
393 result += indentation +
"- Font: {\n" + _font.getInfo(indent + 1) + indentation +
"}\n";
394 result += indentation +
"- Normal Color: {\n" + _color.getInfo(indent + 1) + indentation +
"}\n";
395 result += indentation +
"- Hover Color: {\n" + _hoverColor.getInfo(indent + 1) + indentation +
"}\n";
396 result += indentation +
"- Clicked Color: {\n" + _clickedColor.getInfo(indent + 1) + indentation +
"}\n";
402 if (!_visible || !_sfTextComponent.has_value()) {
403 PRETTY_INFO <<
"Instance is hidden or no sfImage instance found, not rendering" << std::endl;
406 return std::make_any<sf::Text>(_sfTextComponent.value());
421 return _textApplication;
427 if (!_inConstructor) {
428 _processTextComponent();
434 _inConstructor =
true;
447 _inConstructor =
false;
448 _processTextComponent();
451void GUI::ECS::Components::TextComponent::_initialiseText()
453 if (!_sfTextComponent.has_value()) {
454 PRETTY_INFO <<
"No known instance of sf::Text, creating." << std::endl;
455 if (_font.getFontPath().empty()) {
461 std::any systemFont = _font.getFontInstance();
462 PRETTY_DEBUG <<
"Font package received, checking that it is not empty." << std::endl;
463 if (!systemFont.has_value()) {
465 <<
"No font found in the provided system font." << std::endl;
468 PRETTY_DEBUG <<
"Font instance has content, unpacking" << std::endl;
469 std::string errorMsg =
"<There is no sf::Font instance to manipulate>, system error: ";
471 PRETTY_DEBUG <<
"Font unpacked successfully into an std::optional, checking std::optional." << std::endl;
472 if (!fontCapsule.has_value()) {
474 <<
"Failed to cast sf::Font from system font, anycast failed." << std::endl;
477 PRETTY_DEBUG <<
"std::optional has content, unpacking" << std::endl;
478 const std::shared_ptr<sf::Font> font = fontCapsule.value();
479 PRETTY_DEBUG <<
"std::optional unpacked successfully into an sf::Font" << std::endl;
481 if (_sfTextComponent.has_value()) {
482 PRETTY_DEBUG <<
"An instance of sf::Text already exists, updating it's font." << std::endl;
483 _sfTextComponent->setFont(*font);
485 PRETTY_DEBUG <<
"No instance of sf::Text, creating a new one." << std::endl;
486 sf::Text node(*font, _text, _size);
487 _sfTextComponent = node;
488 _textAltered =
false;
490 PRETTY_DEBUG <<
"Checking that the font is still present" << std::endl;
491 const sf::Font fontTest = _sfTextComponent->getFont();
492 const sf::Texture fontTexture = fontTest.getTexture(30);
493 if (fontTexture.getSize().x > 0 && fontTexture.getSize().y > 0) {
494 PRETTY_SUCCESS <<
"Font loaded and has a valid texture!" << std::endl;
497 <<
"Font loaded, but no valid texture found!" << std::endl;
500 _fontChanged =
false;
505void GUI::ECS::Components::TextComponent::_loadFont()
507 if (!_font.isLoaded()) {
508 std::string msg =
"Font name : '" + _font.getFontName() +
"' (not found) in '" + _font.getFontPath() +
"'";
512 if (!_sfTextComponent.has_value()) {
513 PRETTY_INFO <<
"Text not initialised, initialising..." << std::endl;
517 std::any systemFont = _font.getFontInstance();
518 PRETTY_DEBUG <<
"Font package received, checking that it is not empty." << std::endl;
519 if (!systemFont.has_value()) {
521 <<
"No font found in the provided system font." << std::endl;
524 PRETTY_DEBUG <<
"Font instance has content, unpacking" << std::endl;
525 std::string errorMsg =
"<There is no sf::Font instance to manipulate>, system error: ";
527 PRETTY_DEBUG <<
"Font unpacked successfully into an std::optional, checking std::optional." << std::endl;
528 if (!fontCapsule.has_value()) {
530 <<
"Failed to cast sf::Font from system font, anycast failed." << std::endl;
533 PRETTY_DEBUG <<
"std::optional has content, unpacking" << std::endl;
534 const std::shared_ptr<sf::Font> font = fontCapsule.value();
535 PRETTY_DEBUG <<
"std::optional unpacked successfully into an sf::Font, applying font to sf::Text" << std::endl;
536 _sfTextComponent->setFont(*font);
537 PRETTY_DEBUG <<
"Font applied to sf::Text, text component updated." << std::endl;
538 PRETTY_DEBUG <<
"Checking that the font is still present" << std::endl;
539 const sf::Font fontTest = _sfTextComponent->getFont();
540 const sf::Texture fontTexture = fontTest.getTexture(30);
541 if (fontTexture.getSize().x > 0 && fontTexture.getSize().y > 0) {
542 PRETTY_SUCCESS <<
"Font loaded and has a valid texture!" << std::endl;
545 <<
"Font loaded, but no valid texture found!" << std::endl;
550void GUI::ECS::Components::TextComponent::_processTextComponent()
552 PRETTY_INFO <<
"Checking initiailisation" << std::endl;
554 if (_sfTextComponent.has_value()) {
556 PRETTY_DEBUG <<
"Going to update the font." << std::endl;
558 _fontChanged =
false;
562 PRETTY_DEBUG <<
"Going to update the text." << std::endl;
563 _sfTextComponent->setString(_text);
564 _textAltered =
false;
569 PRETTY_DEBUG <<
"Going to update the font size" << std::endl;
570 _sfTextComponent->setCharacterSize(_size);
571 _sizeAltered =
false;
574 if (_positionAltered) {
575 PRETTY_DEBUG <<
"Going to check the position" << std::endl;
576 std::pair<float, float> pos = _textPos.getPosition();
577 _sfTextComponent->setPosition({ pos.first, pos.second });
578 _positionAltered =
false;
582 PRETTY_DEBUG <<
"Going to update the font" << std::endl;
583 PRETTY_DEBUG <<
"Text component has a value" << std::endl;
584 const sf::Font font = _sfTextComponent->getFont();
585 const sf::Texture fontTexture = font.getTexture(30);
586 if (fontTexture.getSize().x > 0 && fontTexture.getSize().y > 0) {
587 PRETTY_SUCCESS <<
"Font loaded and has a valid texture!" << std::endl;
590 <<
"Font loaded, but no valid texture found!" << std::endl;
592 sf::FloatRect textBounds = _sfTextComponent->getLocalBounds();
594 _textPos.setDimension({ textBounds.size.x, textBounds.size.y });
596 _fontAltered =
false;
599 PRETTY_WARNING <<
"No text component value to be managed" << std::endl;
601 PRETTY_INFO <<
"Font loaded, updating text colour" << std::endl;
602 std::any systemColour;
603 if (_textPos.isClicked()) {
605 << _clickedColor <<
"\n} and corresponds to the _clickedColour"
607 systemColour = _clickedColor.getRenderColour();
608 }
else if (_textPos.isHovered()) {
610 << _hoverColor <<
"\n} and corresponds to the _hoverColour"
612 systemColour = _hoverColor.getRenderColour();
615 << _color <<
"\n} and corresponds to the _colour"
617 systemColour = _color.getRenderColour();
619 if (!systemColour.has_value()) {
621 <<
"No color value to be managed" << std::endl;
622 throw CustomExceptions::NoColour(
"<There was no content returned by getRenderColour when std::any (containing sf::Font was expected)>");
624 std::string errMsg =
"<The content returned by the getRenderColour function is not of type sf::Color>, system error: ";
626 PRETTY_DEBUG <<
"Colour capsule gathered, checking integrity" << std::endl;
627 if (!colourCapsule.has_value()) {
629 <<
"Colour capsule is empty" << std::endl;
632 PRETTY_DEBUG <<
"Colour capsule is valid, updating text colour" << std::endl;
633 sf::Color result = colourCapsule.value();
634 _sfTextComponent->setFillColor(result);
#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 PRECISE_SUCCESS
Success log with precise details.
#define PRETTY_SUCCESS
Success log with details and colour.
This is the file that contains a class in charge of managing a test component.
This is the class in charge of informing the user that the height they entered is invalid.
This is the class in charge of informing the user that they tried to access a non-existant colour ins...
This is the class in charge of informing the user that they tried to access a non-existant font insta...
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 ©)
The overload in charge of allowing a TextComponent update using the '=' sign.
Represents a rectangular component that can detect collisions and mouse interactions,...
void update(const std::pair< int, int > &mousePosition)
Update the mouse info object used for mouse tracking.
A class for representing and manipulating colors using RGBA components. Inherits from EntityNode to a...
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 ...
Manages font entities in the GUI ECS.
const std::string getFontPath() const
Retrieves the file path of the font.
std::ostream & operator<<(std::ostream &os, const AnimationComponent &item)
Outputs the animation's info to a stream.
const std::string myToString(const Rect< RectType > &rectangle)
Converts a Rect<T> object to its string representation.
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.