18 _normalColor(0,
GUI::ECS::Systems::Colour::White), _hoverColor(0,
GUI::ECS::Systems::Colour::White), _clickedColor(0,
GUI::ECS::Systems::Colour::White)
23 :
EntityNode(entityId), _collision(entityId), _base(entityId),
24 _normalColor(entityId,
GUI::ECS::Systems::Colour::White), _hoverColor(entityId,
GUI::ECS::Systems::Colour::White), _clickedColor(entityId,
GUI::ECS::Systems::Colour::White)
29 :
EntityNode(entityId), _collision(entityId), _base(entityId),
30 _normalColor(entityId,
GUI::ECS::Systems::Colour::White), _hoverColor(entityId,
GUI::ECS::Systems::Colour::White), _clickedColor(entityId,
GUI::ECS::Systems::Colour::White)
32 _inConstructor =
true;
35 _inConstructor =
false;
36 _processImageComponent();
40 :
EntityNode(entityId), _collision(entityId), _base(entityId),
41 _normalColor(entityId,
GUI::ECS::Systems::Colour::White), _hoverColor(entityId,
GUI::ECS::Systems::Colour::White), _clickedColor(entityId,
GUI::ECS::Systems::Colour::White)
43 _inConstructor =
true;
47 _inConstructor =
false;
48 _processImageComponent();
52 :
EntityNode(entityId), _collision(entityId), _base(entityId),
53 _normalColor(entityId,
GUI::ECS::Systems::Colour::White), _hoverColor(entityId,
GUI::ECS::Systems::Colour::White), _clickedColor(entityId,
GUI::ECS::Systems::Colour::White)
55 _inConstructor =
true;
62 _inConstructor =
false;
63 _processImageComponent();
66GUI::ECS::Components::ImageComponent::ImageComponent(
const std::uint32_t entityId,
const GUI::ECS::Components::TextureComponent &imageTexture, std::pair<unsigned int, unsigned int> dimensions,
const std::pair<float, float> &position,
const GUI::ECS::Systems::Colour &normalColor,
const GUI::ECS::Systems::Colour &hoverColor,
const GUI::ECS::Systems::Colour &clickedColor,
const std::string &name,
const std::string &application)
67 :
EntityNode(entityId), _collision(entityId), _base(entityId),
68 _normalColor(entityId,
GUI::ECS::Systems::Colour::White), _hoverColor(entityId,
GUI::ECS::Systems::Colour::White), _clickedColor(entityId,
GUI::ECS::Systems::Colour::White)
70 _inConstructor =
true;
78 _inConstructor =
false;
79 _processImageComponent();
83 :
EntityNode(entityId), _base(entityId), _collision(entityId),
84 _normalColor(entityId,
GUI::ECS::Systems::Colour::White), _hoverColor(entityId,
GUI::ECS::Systems::Colour::White), _clickedColor(entityId,
GUI::ECS::Systems::Colour::White)
86 _inConstructor =
true;
89 _inConstructor =
false;
90 _processImageComponent();
94 :
EntityNode(entityId), _base(entityId), _collision(entityId),
95 _normalColor(entityId,
GUI::ECS::Systems::Colour::White), _hoverColor(entityId,
GUI::ECS::Systems::Colour::White), _clickedColor(entityId,
GUI::ECS::Systems::Colour::White)
97 _inConstructor =
true;
101 _inConstructor =
false;
102 _processImageComponent();
106 :
EntityNode(entityId), _base(entityId), _collision(entityId),
107 _normalColor(entityId,
GUI::ECS::Systems::Colour::White), _hoverColor(entityId,
GUI::ECS::Systems::Colour::White), _clickedColor(entityId,
GUI::ECS::Systems::Colour::White)
109 _inConstructor =
true;
116 _inConstructor =
false;
117 _processImageComponent();
120GUI::ECS::Components::ImageComponent::ImageComponent(
const std::uint32_t entityId,
const std::string &imagePath, std::pair<unsigned int, unsigned int> dimensions,
const std::pair<float, float> &position,
const GUI::ECS::Systems::Colour &normalColor,
const GUI::ECS::Systems::Colour &hoverColor,
const GUI::ECS::Systems::Colour &clickedColor,
const std::string &name,
const std::string &application)
121 :
EntityNode(entityId), _base(entityId), _collision(entityId),
122 _normalColor(entityId,
GUI::ECS::Systems::Colour::White), _hoverColor(entityId,
GUI::ECS::Systems::Colour::White), _clickedColor(entityId,
GUI::ECS::Systems::Colour::White)
124 _inConstructor =
true;
132 _inConstructor =
false;
133 _processImageComponent();
146 _application = application;
151 _normalColor = color;
161 _clickedColor = color;
170 _textureAltered =
true;
171 if (!_inConstructor) {
172 _processImageComponent();
182 if (!_inConstructor) {
183 _processImageComponent();
189 _base.setSize(dimension);
190 _collision.setDimension(_base.getCollisionInfo().getDimension());
192 if (!_inConstructor) {
193 _processImageComponent();
199 _collision.setPosition(position);
200 _base.setPosition(position);
201 _positionAltered =
true;
202 if (!_inConstructor) {
203 _processImageComponent();
214 _levelBackground = levelBackground;
233 return _levelBackground;
263 return _clickedColor;
268 return _collision.getDimension();
273 return _collision.getPosition();
288 std::string indentation =
"";
289 for (
unsigned int i = 0; i < indent; ++i) {
292 std::string result = indentation +
"Image:\n";
297 result += indentation +
"- Texture altered: " +
Recoded::myToString(_textureAltered) +
"\n";
298 result += indentation +
"- Position altered: " +
Recoded::myToString(_positionAltered) +
"\n";
299 result += indentation +
"- Name: " + _name +
"\n";
300 result += indentation +
"- Application: " + _application +
"\n";
301 result += indentation +
"- Image Component present?: " +
Recoded::myToString(_sfImage.has_value()) +
"\n";
302 result += indentation +
"- Position: {\n" + _collision.
getInfo(indent + 1) + indentation +
"}\n";
303 result += indentation +
"- Texture Base: {\n" + _base.getInfo(indent + 1) + indentation +
"}\n";
304 result += indentation +
"- Hover Color: {\n" + _hoverColor.getInfo(indent + 1) + indentation +
"}\n";
305 result += indentation +
"- Normal Color: {\n" + _normalColor.getInfo(indent + 1) + indentation +
"}\n";
306 result += indentation +
"- Clicked Color: {\n" + _clickedColor.getInfo(indent + 1) + indentation +
"}\n";
312 return isLevelBackgroundCompatible();
317 if (!_visible || !_sfImage.has_value()) {
318 PRETTY_INFO <<
"Instance is hidden or no sfImage instance found, not rendering" << std::endl;
321 return std::make_any<sf::Sprite>(_sfImage.value());
326 _collision.update(mouse);
327 _processImageComponent();
332 _inConstructor =
true;
350 _inConstructor =
false;
351 _processImageComponent();
360void GUI::ECS::Components::ImageComponent::_initialiseImage()
362 if (!_sfImage.has_value()) {
363 const std::any textureCapsule = _base.getTexture();
364 if (textureCapsule.has_value()) {
365 const std::string errMsg =
"<No texture was found when a texture of type sf::Texture was expected>, system error: ";
367 if (!texture.has_value()) {
371 _sfImage.emplace(*(texture.value()));
373 const sf::FloatRect bounds = _sfImage->getGlobalBounds();
374 const Recoded::FloatRect sysBounds = { {bounds.position.x, bounds.position.y}, {bounds.size.x, bounds.size.y} };
375 PRETTY_INFO <<
"Image dimensions = " << sysBounds << std::endl;
376 node.setGeometry(sysBounds);
377 PRETTY_INFO <<
"Collision node = " << node << std::endl;
378 _collision.update(node);
384void GUI::ECS::Components::ImageComponent::_processColour()
386 if (!_sfImage.has_value()) {
390 std::any systemColour;
391 if (_collision.isClicked()) {
393 << _clickedColor <<
"\n} and corresponds to the _clickedColour"
395 systemColour = _clickedColor.getRenderColour();
396 }
else if (_collision.isHovered()) {
398 << _hoverColor <<
"\n} and corresponds to the _hoverColour"
400 systemColour = _hoverColor.getRenderColour();
403 << _normalColor <<
"\n} and corresponds to the _normalColour"
405 systemColour = _normalColor.getRenderColour();
407 const std::string errMsg =
"<The content returned by the getRenderColour function is not of type sf::Color>, system error: ";
409 if (!color.has_value()) {
411 <<
"No Color found, " << errMsg << std::endl;
414 _sfImage->setColor(color.value());
418void GUI::ECS::Components::ImageComponent::_processImageComponent()
420 if (!_sfImage.has_value()) {
424 if (_sfImage.has_value()) {
426 PRETTY_DEBUG <<
"The size has been altered, updating size." << std::endl;
427 std::pair<float, float> dimension = _collision.getDimension();
428 _sfImage->setScale({ dimension.first, dimension.second });
429 _sizeAltered =
false;
431 if (_positionAltered) {
432 PRETTY_DEBUG <<
"The position has been altered, updating position." << std::endl;
433 std::pair<float, float> position = _collision.getPosition();
434 _sfImage->setPosition({ position.first, position.second });
435 _positionAltered =
false;
437 if (_textureAltered) {
438 PRETTY_DEBUG <<
"The texture has been altered, updating image." << std::endl;
439 const std::any textureCapsule = _base.getTexture();
440 const std::string errMsg =
"<There is no texture instance in this cast, expected a cast of type sf::Texture>, system error: ";
442 if (texture.has_value()) {
443 _sfImage->setTexture(*(texture.value()));
444 _textureAltered =
false;
This is the file that contains a class in charge of managing a test component.
#define PRETTY_ERROR
Error log with details and colour.
#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 PRETTY_SUCCESS
Success log with details and colour.
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 texture in...
Represents an image component in the GUI ECS system.
void setHoverColor(const GUI::ECS::Systems::Colour &color)
Sets the hover color of the image.
~ImageComponent()
Destructor for ImageComponent.
void setClickedColor(const GUI::ECS::Systems::Colour &color)
Sets the clicked color of the image.
std::any render() const
Renders the image to the given window.
void setName(const std::string &name)
Set the Name of the image.
const std::string getName() const
Get the Name of the image.
const GUI::ECS::Systems::Colour getHoverColor() const
Retrieves the hover color of the image.
void setPosition(const std::pair< int, int > &position)
Sets the position of the image.
void setApplication(const std::string &application)
Set the Application (the context) of the image.
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 GUI::ECS::Systems::Collision getCollision() const
Get the Collision object.
GUI::ECS::Components::ImageComponent & operator=(const GUI::ECS::Components::ImageComponent ©)
Assigns values from another ImageComponent.
const std::pair< int, int > getPosition() const
Get the Position of the image.
const GUI::ECS::Systems::Colour getNormalColor() const
Retrieves the normal color of the image.
const bool isVisible() const
Get the visibility state of the Image.
void update(const GUI::ECS::Systems::MouseInfo &mouse)
Updates the image based on mouse interactions.
void setLevelBackgroundCompatible(const bool levelBackground)
Set the Level Background Compatible variable.
const bool isLevelBackgroundCompatible() const
Know if the background can be used as a level bacground.
void setImage(const GUI::ECS::Components::TextureComponent &image, const std::string &name="")
Assigns a texture to the image component.
const GUI::ECS::Systems::Colour getClickedColor() const
Retrieves the clicked color of the image.
const bool getLevelBackgroundCompatibility() const
Get the Level Background Compatibility object.
const bool getVisible() const
Get the Visibility of the text.
void setDimension(const std::pair< float, float > &dimension)
Sets the dimensions of the image.
const std::pair< float, float > getDimension() const
Get the Size of the text.
void toggleVisibility()
Toggles the visibility of the image.
const GUI::ECS::Components::TextureComponent getImage() const
Retrieves the texture associated with the image.
void setNormalColor(const GUI::ECS::Systems::Colour &color)
Sets the normal color of the image.
void setVisible(const bool visible)
Set the visibility of the object using a boolean.
const std::string getApplication() const
Get the Application of the image.
ImageComponent()
Default constructor. Initializes the ImageComponent with default values.
Represents a texture component used in an entity component system.
void setFilePath(const std::string &filePath)
Sets the file path for the texture.
Represents a rectangular component that can detect collisions and mouse interactions,...
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 ...
A class for representing and manipulating colors using RGBA components. Inherits from EntityNode to a...
A generic 2D rectangle class that holds position and size as pairs.
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.