R-Type  2
Doom but in better
Loading...
Searching...
No Matches
TextComponent.cpp
Go to the documentation of this file.
1/*
2** EPITECH PROJECT, 2024
3** rtype (Workspace)
4** File description:
5** TextComponent.cpp
6*/
7
15
17 : EntityNode(0),
18 _font(0),
19 _textPos(0),
20 _color(0, GUI::ECS::Systems::Colour::Black),
21 _hoverColor(0, GUI::ECS::Systems::Colour::Black),
22 _clickedColor(0, GUI::ECS::Systems::Colour::Black)
23{
24};
25
27 : EntityNode(entityId),
28 _font(entityId),
29 _textPos(entityId),
30 _color(entityId, GUI::ECS::Systems::Colour::Black),
31 _hoverColor(entityId, GUI::ECS::Systems::Colour::Black),
32 _clickedColor(entityId, GUI::ECS::Systems::Colour::Black)
33{
34};
35
36GUI::ECS::Components::TextComponent::TextComponent(const std::uint32_t entityId, const std::string &fontPath)
37 : EntityNode(entityId),
38 _font(entityId),
39 _textPos(entityId),
40 _color(entityId, GUI::ECS::Systems::Colour::Black),
41 _hoverColor(entityId, GUI::ECS::Systems::Colour::Black),
42 _clickedColor(entityId, GUI::ECS::Systems::Colour::Black)
43{
44 _inConstructor = true;
45 setFontPath(fontPath);
46 _inConstructor = false;
47 _processTextComponent();
48};
49
50GUI::ECS::Components::TextComponent::TextComponent(const std::uint32_t entityId, const std::string &fontPath, const std::string &text)
51 : EntityNode(entityId),
52 _font(entityId),
53 _textPos(entityId),
54 _color(entityId, GUI::ECS::Systems::Colour::Black),
55 _hoverColor(entityId, GUI::ECS::Systems::Colour::Black),
56 _clickedColor(entityId, GUI::ECS::Systems::Colour::Black)
57{
58 _inConstructor = true;
59 setFontPath(fontPath);
60 setText(text);
61 _inConstructor = false;
62 _processTextComponent();
63};
64
65GUI::ECS::Components::TextComponent::TextComponent(const std::uint32_t entityId, const std::string &fontPath, const std::string &text, const unsigned int &size)
66 : EntityNode(entityId),
67 _font(entityId),
68 _textPos(entityId),
69 _color(entityId, GUI::ECS::Systems::Colour::Black),
70 _hoverColor(entityId, GUI::ECS::Systems::Colour::Black),
71 _clickedColor(entityId, GUI::ECS::Systems::Colour::Black)
72{
73 _inConstructor = true;
74 setFontPath(fontPath);
75 setText(text);
76 setSize(size);
77 _inConstructor = false;
78 _processTextComponent();
79};
80
81GUI::ECS::Components::TextComponent::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)
82 : EntityNode(entityId),
83 _font(entityId),
84 _textPos(entityId),
85 _color(entityId, GUI::ECS::Systems::Colour::Black),
86 _hoverColor(entityId, GUI::ECS::Systems::Colour::Black),
87 _clickedColor(entityId, GUI::ECS::Systems::Colour::Black)
88{
89 _inConstructor = true;
90 setFontPath(fontPath);
91 setText(text);
92 setSize(size);
93 setHoverColor(hoverColor);
94 setNormalColor(normalColor);
95 setClickedColor(clickedColor);
96 _inConstructor = false;
97 _processTextComponent();
98};
99
100GUI::ECS::Components::TextComponent::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)
101 : EntityNode(entityId),
102 _font(entityId),
103 _textPos(entityId),
104 _color(entityId, GUI::ECS::Systems::Colour::Black),
105 _hoverColor(entityId, GUI::ECS::Systems::Colour::Black),
106 _clickedColor(entityId, GUI::ECS::Systems::Colour::Black)
107{
108 _inConstructor = true;
109 setFontPath(fontPath);
110 setText(text);
111 setSize(size);
112 setPosition(position);
113 setHoverColor(hoverColor);
114 setNormalColor(normalColor);
115 setClickedColor(clickedColor);
116 _inConstructor = false;
117 _processTextComponent();
118};
119
120GUI::ECS::Components::TextComponent::TextComponent(const std::uint32_t entityId, const GUI::ECS::Systems::Font &fontInstance)
121 : EntityNode(entityId),
122 _font(entityId),
123 _textPos(entityId),
124 _color(entityId, GUI::ECS::Systems::Colour::Black),
125 _hoverColor(entityId, GUI::ECS::Systems::Colour::Black),
126 _clickedColor(entityId, GUI::ECS::Systems::Colour::Black)
127{
128 _inConstructor = true;
129 setFont(fontInstance);
130 _inConstructor = false;
131 _processTextComponent();
132};
133
134GUI::ECS::Components::TextComponent::TextComponent(const std::uint32_t entityId, const GUI::ECS::Systems::Font &fontInstance, const std::string &text)
135 : EntityNode(entityId),
136 _font(entityId),
137 _textPos(entityId),
138 _color(entityId, GUI::ECS::Systems::Colour::Black),
139 _hoverColor(entityId, GUI::ECS::Systems::Colour::Black),
140 _clickedColor(entityId, GUI::ECS::Systems::Colour::Black)
141{
142 _inConstructor = true;
143 setFont(fontInstance);
144 setText(text);
145 _inConstructor = false;
146 _processTextComponent();
147};
148
149GUI::ECS::Components::TextComponent::TextComponent(const std::uint32_t entityId, const GUI::ECS::Systems::Font &fontInstance, const std::string &text, const unsigned int &size)
150 : EntityNode(entityId),
151 _font(entityId),
152 _textPos(entityId),
153 _color(entityId, GUI::ECS::Systems::Colour::Black),
154 _hoverColor(entityId, GUI::ECS::Systems::Colour::Black),
155 _clickedColor(entityId, GUI::ECS::Systems::Colour::Black)
156{
157 _inConstructor = true;
158 setFont(fontInstance);
159 setText(text);
160 setSize(size);
161 _inConstructor = false;
162 _processTextComponent();
163};
164
165GUI::ECS::Components::TextComponent::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)
166 : EntityNode(entityId),
167 _font(0),
168 _textPos(0),
169 _color(0, GUI::ECS::Systems::Colour::Black),
170 _hoverColor(0, GUI::ECS::Systems::Colour::Black),
171 _clickedColor(0, GUI::ECS::Systems::Colour::Black)
172{
173 _inConstructor = true;
174 setFont(fontInstance);
175 setText(text);
176 setSize(size);
177 setHoverColor(hoverColor);
178 setNormalColor(normalColor);
179 setClickedColor(clickedColor);
180 _inConstructor = false;
181 _processTextComponent();
182};
183
184GUI::ECS::Components::TextComponent::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)
185 : EntityNode(entityId),
186 _font(0),
187 _textPos(0),
188 _color(0, GUI::ECS::Systems::Colour::Black),
189 _hoverColor(0, GUI::ECS::Systems::Colour::Black),
190 _clickedColor(0, GUI::ECS::Systems::Colour::Black)
191{
192 _inConstructor = true;
193 setFont(fontInstance);
194 setText(text);
195 setSize(size);
196 setPosition(position);
197 setHoverColor(hoverColor);
198 setNormalColor(normalColor);
199 setClickedColor(clickedColor);
200 _inConstructor = false;
201 _processTextComponent();
202};
203
204
206
208{
209 _font.update(font);
210 _fontChanged = true;
211 if (!_inConstructor) {
212 _processTextComponent();
213 }
214}
215
217{
218 if (_text != text) {
219 _text = text;
220 _textAltered = true;
221 if (!_inConstructor) {
222 _processTextComponent();
223 }
224 }
225}
226
227void GUI::ECS::Components::TextComponent::setSize(const std::uint32_t &size)
228{
229 if (_size != size) {
230 _size = size;
231 _sizeAltered = true;
232 if (!_inConstructor) {
233 _processTextComponent();
234 }
235 }
236}
237
239{
240 if (_color != color) {
241 _color = color;
242 if (!_inConstructor) {
243 _processTextComponent();
244 }
245 }
246}
247
249{
250 if (_hoverColor != color) {
251 _hoverColor = color;
252 if (!_inConstructor) {
253 _processTextComponent();
254 }
255 }
256}
257
259{
260 if (_clickedColor != color) {
261 _clickedColor = color;
262 if (!_inConstructor) {
263 _processTextComponent();
264 }
265 }
266}
267
268void GUI::ECS::Components::TextComponent::setFontPath(const std::string &fontPath, const std::string &name)
269{
270 if (fontPath.empty()) {
271 throw CustomExceptions::InvalidFontPath("<empty path>");
272 }
273 if (_font.getFontPath() != fontPath) {
274 std::string nameChild = name;
275 if (nameChild == "") {
276 nameChild = _font.getFontName();
277 }
278 GUI::ECS::Systems::Font font(nameChild, fontPath);
279 _font = font;
280 _fontChanged = true;
281 if (!_inConstructor) {
282 _processTextComponent();
283 }
284 }
285}
286
287void GUI::ECS::Components::TextComponent::setPosition(const std::pair<float, float> &position)
288{
289 if (_textPos.getPosition() != position) {
290 _textPos.setPosition(position);
291 _positionAltered = true;
292 if (!_inConstructor) {
293 _processTextComponent();
294 }
295 }
296}
297
299{
300 _visible = visible;
301}
302
304{
305 _textName = name;
306}
307
308void GUI::ECS::Components::TextComponent::setApplication(const std::string &application)
309{
310 _textApplication = application;
311}
312
314{
315 if (_visible) {
316 _visible = false;
317 } else {
318 _visible = true;
319 }
320}
321
323{
324 return _visible;
325}
326
331
333{
334 return _font.getFontPath();
335}
336
341
346
351
353{
354 return _text;
355}
356
358{
359 return _size;
360}
361
362const std::pair<float, float> GUI::ECS::Components::TextComponent::getPosition() const
363{
364 return _textPos.getPosition();
365}
366
368{
369 return _visible;
370}
371
372
373const std::string GUI::ECS::Components::TextComponent::getInfo(const unsigned int indent) const
374{
375
376 std::string indentation = "";
377 for (unsigned int i = 0; i < indent; ++i) {
378 indentation += "\t";
379 }
380 std::string result = indentation + "Text:\n";
381 result += indentation + "- Entity Id: " + Recoded::myToString(getEntityNodeId()) + "\n";
382 result += indentation + "- In Constructor: " + Recoded::myToString(_inConstructor) + "\n";
383 result += indentation + "- Font Altered: " + Recoded::myToString(_fontAltered) + "\n";
384 result += indentation + "- Font Changed: " + Recoded::myToString(_fontChanged) + "\n";
385 result += indentation + "- Text Altered: " + Recoded::myToString(_textAltered) + "\n";
386 result += indentation + "- Size Altered: " + Recoded::myToString(_sizeAltered) + "\n";
387 result += indentation + "- Position Altered: " + Recoded::myToString(_positionAltered) + "\n";
388 result += indentation + "- Visible: " + Recoded::myToString(_visible) + "\n";
389 result += indentation + "- Text: '" + _text + "'\n";
390 result += indentation + "- (sfText) Has text: " + Recoded::myToString(_sfTextComponent.has_value()) + "\n";
391 result += indentation + "- Size: " + Recoded::myToString(_size) + "\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";
397 return result;
398}
399
401{
402 if (!_visible || !_sfTextComponent.has_value()) {
403 PRETTY_INFO << "Instance is hidden or no sfImage instance found, not rendering" << std::endl;
404 return std::nullopt;
405 }
406 return std::make_any<sf::Text>(_sfTextComponent.value());
407};
408
413
415{
416 return _textName;
417}
418
420{
421 return _textApplication;
422}
423
425{
426 _textPos.update(mouse);
427 if (!_inConstructor) {
428 _processTextComponent();
429 }
430}
431
433{
434 _inConstructor = true;
435 setText(copy.getText());
436 setSize(copy.getSize());
437 setFont(copy.getFont());
438 setVisible(copy.getVisible());
439 setPosition(copy.getPosition());
440 setHoverColor(copy.getHoverColor());
441 setNormalColor(copy.getNormalColor());
442 setClickedColor(copy.getClickedColor());
443 setApplication(copy.getApplication());
444 setName(copy.getName());
445 _textPos = copy.getCollision();
446 _fontAltered = true;
447 _inConstructor = false;
448 _processTextComponent();
449}
450
451void GUI::ECS::Components::TextComponent::_initialiseText()
452{
453 if (!_sfTextComponent.has_value()) {
454 PRETTY_INFO << "No known instance of sf::Text, creating." << std::endl;
455 if (_font.getFontPath().empty()) {
456 PRETTY_WARNING << "No font, skipping update." << std::endl;
457 return;
458 }
459
460 PRETTY_DEBUG << "Fetching the font" << std::endl;
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()) {
464 PRETTY_CRITICAL << "BaseId: '" << Recoded::myToString(getEntityNodeId()) << "' "
465 << "No font found in the provided system font." << std::endl;
466 throw CustomExceptions::NoFont("<There is no sf::Font instance to apply>");
467 }
468 PRETTY_DEBUG << "Font instance has content, unpacking" << std::endl;
469 std::string errorMsg = "<There is no sf::Font instance to manipulate>, system error: ";
470 std::optional<std::shared_ptr<sf::Font>> fontCapsule = Utilities::unCast<std::shared_ptr<sf::Font>, CustomExceptions::NoFont>(systemFont, true, errorMsg);
471 PRETTY_DEBUG << "Font unpacked successfully into an std::optional, checking std::optional." << std::endl;
472 if (!fontCapsule.has_value()) {
473 PRETTY_CRITICAL << "BaseId: '" << Recoded::myToString(getEntityNodeId()) << "' "
474 << "Failed to cast sf::Font from system font, anycast failed." << std::endl;
475 throw CustomExceptions::NoFont(errorMsg);
476 }
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;
480 PRETTY_SUCCESS << "Font unpacked successfully" << 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);
484 } else {
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;
489 }
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;
495 } else {
496 PRETTY_CRITICAL << "BaseId: '" << Recoded::myToString(getEntityNodeId()) << "' "
497 << "Font loaded, but no valid texture found!" << std::endl;
498 }
499 PRETTY_DEBUG << "Text component updated." << std::endl;
500 _fontChanged = false;
501
502 }
503}
504
505void GUI::ECS::Components::TextComponent::_loadFont()
506{
507 if (!_font.isLoaded()) {
508 std::string msg = "Font name : '" + _font.getFontName() + "' (not found) in '" + _font.getFontPath() + "'";
509 PRETTY_CRITICAL << "BaseId: '" << Recoded::myToString(getEntityNodeId()) << "' " << msg << std::endl;
510 throw CustomExceptions::NoFont(msg);
511 }
512 if (!_sfTextComponent.has_value()) {
513 PRETTY_INFO << "Text not initialised, initialising..." << std::endl;
514 _initialiseText();
515 }
516 PRETTY_DEBUG << "Fetching the font" << 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()) {
520 PRETTY_CRITICAL << "BaseId: '" << Recoded::myToString(getEntityNodeId()) << "' "
521 << "No font found in the provided system font." << std::endl;
522 throw CustomExceptions::NoFont("<There is no sf::Font instance to apply>");
523 }
524 PRETTY_DEBUG << "Font instance has content, unpacking" << std::endl;
525 std::string errorMsg = "<There is no sf::Font instance to manipulate>, system error: ";
526 std::optional<std::shared_ptr<sf::Font>> fontCapsule = Utilities::unCast<std::shared_ptr<sf::Font>, CustomExceptions::NoFont>(systemFont, true, errorMsg);
527 PRETTY_DEBUG << "Font unpacked successfully into an std::optional, checking std::optional." << std::endl;
528 if (!fontCapsule.has_value()) {
529 PRETTY_CRITICAL << "BaseId: '" << Recoded::myToString(getEntityNodeId()) << "' "
530 << "Failed to cast sf::Font from system font, anycast failed." << std::endl;
531 throw CustomExceptions::NoFont(errorMsg);
532 }
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;
543 } else {
544 PRETTY_CRITICAL << "BaseId: '" << Recoded::myToString(getEntityNodeId()) << "' "
545 << "Font loaded, but no valid texture found!" << std::endl;
546 }
547
548}
549
550void GUI::ECS::Components::TextComponent::_processTextComponent()
551{
552 PRETTY_INFO << "Checking initiailisation" << std::endl;
553 _initialiseText();
554 if (_sfTextComponent.has_value()) {
555 if (_fontChanged) {
556 PRETTY_DEBUG << "Going to update the font." << std::endl;
557 _loadFont();
558 _fontChanged = false;
559 _fontAltered = true;
560 }
561 if (_textAltered) {
562 PRETTY_DEBUG << "Going to update the text." << std::endl;
563 _sfTextComponent->setString(_text);
564 _textAltered = false;
565 _fontAltered = true;
566 PRETTY_DEBUG << "Text Updated" << std::endl;
567 }
568 if (_sizeAltered) {
569 PRETTY_DEBUG << "Going to update the font size" << std::endl;
570 _sfTextComponent->setCharacterSize(_size);
571 _sizeAltered = false;
572 _fontAltered = true;
573 }
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;
579 _fontAltered = true;
580 }
581 if (_fontAltered) {
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;
588 } else {
589 PRETTY_CRITICAL << "BaseId: '" << Recoded::myToString(getEntityNodeId()) << "' "
590 << "Font loaded, but no valid texture found!" << std::endl;
591 }
592 sf::FloatRect textBounds = _sfTextComponent->getLocalBounds();
593 PRETTY_DEBUG << "Text bounds gathered." << std::endl;
594 _textPos.setDimension({ textBounds.size.x, textBounds.size.y });
595 PRETTY_DEBUG << "Text position updated." << std::endl;
596 _fontAltered = false;
597 }
598 } else {
599 PRETTY_WARNING << "No text component value to be managed" << std::endl;
600 }
601 PRETTY_INFO << "Font loaded, updating text colour" << std::endl;
602 std::any systemColour;
603 if (_textPos.isClicked()) {
604 PRETTY_DEBUG << "The colour being applied is : {\n"
605 << _clickedColor << "\n} and corresponds to the _clickedColour"
606 << std::endl;
607 systemColour = _clickedColor.getRenderColour();
608 } else if (_textPos.isHovered()) {
609 PRETTY_DEBUG << "The colour being applied is : {\n"
610 << _hoverColor << "\n} and corresponds to the _hoverColour"
611 << std::endl;
612 systemColour = _hoverColor.getRenderColour();
613 } else {
614 PRETTY_DEBUG << "The colour being applied is : {\n"
615 << _color << "\n} and corresponds to the _colour"
616 << std::endl;
617 systemColour = _color.getRenderColour();
618 }
619 if (!systemColour.has_value()) {
620 PRETTY_CRITICAL << "BaseId: '" << Recoded::myToString(getEntityNodeId()) << "' "
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)>");
623 }
624 std::string errMsg = "<The content returned by the getRenderColour function is not of type sf::Color>, system error: ";
625 std::optional<sf::Color> colourCapsule = Utilities::unCast<sf::Color, CustomExceptions::NoColour>(systemColour, true, errMsg);
626 PRETTY_DEBUG << "Colour capsule gathered, checking integrity" << std::endl;
627 if (!colourCapsule.has_value()) {
628 PRETTY_CRITICAL << "BaseId: '" << Recoded::myToString(getEntityNodeId()) << "' "
629 << "Colour capsule is empty" << std::endl;
630 throw CustomExceptions::NoColour(errMsg);
631 }
632 PRETTY_DEBUG << "Colour capsule is valid, updating text colour" << std::endl;
633 sf::Color result = colourCapsule.value();
634 _sfTextComponent->setFillColor(result);
635 PRECISE_SUCCESS << "Text colour updated" << std::endl;
636}
637
639{
640 if (this != &copy) {
641 update(copy);
642 }
643 return *this;
644};
645
647{
648 os << item.getInfo();
649 return os;
650}
#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.
Definition Invalid.hpp:458
This is the class in charge of informing the user that they tried to access a non-existant colour ins...
Definition No.hpp:388
This is the class in charge of informing the user that they tried to access a non-existant font insta...
Definition No.hpp:358
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
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...
Definition Colour.hpp:37
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 ...
Definition Colour.cpp:226
Manages font entities in the GUI ECS.
Definition Font.hpp:45
const std::string getFontPath() const
Retrieves the file path of the font.
Definition Font.cpp:190
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.
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