R-Type  2
Doom but in better
Loading...
Searching...
No Matches
ImageComponent.hpp
Go to the documentation of this file.
1/*
2** EPITECH PROJECT, 2024
3** rtype (Workspace)
4** File description:
5** ImageComponent.hpp
6*/
7
13#pragma once
14
15#include <any>
16#include <utility>
17#include <cstdint>
18#include <optional>
19#include <SFML/Graphics/Sprite.hpp>
20
21#include "Log.hpp"
22#include "LogMacros.hpp"
23#include "Utilities.hpp"
24#include "Recoded/Rect.hpp"
29
30namespace GUI
31{
32 namespace ECS
33 {
34 namespace Components
35 {
43 class ImageComponent : public EntityNode {
44 public:
45
56 ImageComponent(const std::uint32_t entityId);
57
66 ImageComponent(const std::uint32_t entityId, const GUI::ECS::Components::TextureComponent &imageTexture, const std::string &name = "", const std::string &application = "");
76 ImageComponent(const std::uint32_t entityId, const GUI::ECS::Components::TextureComponent &imageTexture, std::pair<unsigned int, unsigned int> dimensions, const std::string &name = "", const std::string &application = "");
89 ImageComponent(const std::uint32_t entityId, const GUI::ECS::Components::TextureComponent &imageTexture, std::pair<unsigned int, unsigned int> dimensions, const GUI::ECS::Systems::Colour &normalColor, const GUI::ECS::Systems::Colour &hoverColor = GUI::ECS::Systems::Colour::White, const GUI::ECS::Systems::Colour &clickedColor = GUI::ECS::Systems::Colour::White, const std::string &name = "", const std::string &application = "");
103 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 = GUI::ECS::Systems::Colour::White, const GUI::ECS::Systems::Colour &hoverColor = GUI::ECS::Systems::Colour::White, const GUI::ECS::Systems::Colour &clickedColor = GUI::ECS::Systems::Colour::White, const std::string &name = "", const std::string &application = "");
104
113 ImageComponent(const std::uint32_t entityId, const std::string &imagePath, const std::string &name = "", const std::string &application = "");
123 ImageComponent(const std::uint32_t entityId, const std::string &imagePath, std::pair<unsigned int, unsigned int> dimensions, const std::string &name = "", const std::string &application = "");
136 ImageComponent(const std::uint32_t entityId, const std::string &imagePath, std::pair<unsigned int, unsigned int> dimensions, const GUI::ECS::Systems::Colour &normalColor, const GUI::ECS::Systems::Colour &hoverColor = GUI::ECS::Systems::Colour::White, const GUI::ECS::Systems::Colour &clickedColor = GUI::ECS::Systems::Colour::White, const std::string &name = "", const std::string &application = "");
150 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 = GUI::ECS::Systems::Colour::White, const GUI::ECS::Systems::Colour &hoverColor = GUI::ECS::Systems::Colour::White, const GUI::ECS::Systems::Colour &clickedColor = GUI::ECS::Systems::Colour::White, const std::string &name = "", const std::string &application = "");
151
156
162 void setName(const std::string &name);
163
169 void setApplication(const std::string &application);
170
176 void setNormalColor(const GUI::ECS::Systems::Colour &color);
182 void setHoverColor(const GUI::ECS::Systems::Colour &color);
189
196 void setImage(const GUI::ECS::Components::TextureComponent &image, const std::string &name = "");
203 void setImage(const std::string &path, const std::string &name = "");
204
210 void setDimension(const std::pair<float, float> &dimension);
211
217 void setPosition(const std::pair<int, int> &position);
218
226 void setVisible(const bool visible);
227
233 void setLevelBackgroundCompatible(const bool levelBackground);
234
238 void toggleVisibility();
239
246 const bool isVisible() const;
247
254 const bool isLevelBackgroundCompatible() const;
255
261 const std::string getName() const;
262
268 const std::string getApplication() const;
269
276
295
301 const std::pair<float, float> getDimension() const;
302
308 const std::pair<int, int> getPosition() const;
309
316 const bool getVisible() const;
317
326
336 const std::string getInfo(const unsigned int indent = 0) const;
337
348 const bool getLevelBackgroundCompatibility() const;
349
355 std::any render() const;
356
362 void update(const GUI::ECS::Systems::MouseInfo &mouse);
363
370
379
380 private:
385 void _initialiseImage();
386
391 void _processColour();
392
397 void _processImageComponent();
398
399
400 bool _visible = true;
401 bool _levelBackground = false;
402 bool _sizeAltered = false;
403 bool _inConstructor = true;
404 bool _textureAltered = false;
405 bool _positionAltered = false;
406 std::string _name = "";
407 std::string _application = "";
408 std::optional<sf::Sprite> _sfImage;
411 GUI::ECS::Systems::Colour _hoverColor;
412 GUI::ECS::Systems::Colour _normalColor;
413 GUI::ECS::Systems::Colour _clickedColor;
414 };
415
422 std::ostream &operator<<(std::ostream &os, const GUI::ECS::Components::ImageComponent &item);
423
424 }
425 }
426}
427
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...
Defines a rectangle class (Rect) mimicking sf::Rect without relying on SFML.
This file contains the declaration of the TextureComponent class which manages textures.
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 &copy)
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.
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 White
Definition Colour.hpp:757
std::ostream & operator<<(std::ostream &os, const AnimationComponent &item)
Outputs the animation's info to a stream.