r-type  0.0.0
R-Type main
Loading...
Searching...
No Matches
Text.hpp
Go to the documentation of this file.
1///
2/// @file Systems.hpp
3/// @brief This file contains the TextSystem definitions
4/// @namespace ecs
5///
6
7#pragma once
8
9#include "ECS/Component.hpp"
10#include "ECS/Registry.hpp"
12
13namespace ecs
14{
15
16 ///
17 /// @class TextSystem
18 /// @brief Class for text system
19 /// @namespace ecs
20 ///
21 class TextSystem final : public ASystem
22 {
23 public:
24 explicit TextSystem(const std::shared_ptr<eng::IRenderer> &renderer) : m_renderer(renderer) {}
25 ~TextSystem() override = default;
26
27 TextSystem(const TextSystem &) = delete;
28 TextSystem &operator=(const TextSystem &) = delete;
29 TextSystem(TextSystem &&) = delete;
31
32 void update(Registry &registry, float /* dt */) override
33 {
34
35 for (auto &[entity, text] : registry.getAll<Text>())
36 {
37 const auto *transform = registry.getComponent<Transform>(entity);
38 const auto *color = registry.getComponent<Color>(entity);
39
40 const float x = (transform != nullptr) ? transform->x : 0.F;
41 const float y = (transform != nullptr) ? transform->y : 0.F;
42
43 const std::uint8_t r = color ? color->r : 255u;
44 const std::uint8_t g = color ? color->g : 255u;
45 const std::uint8_t b = color ? color->b : 255u;
46 const std::uint8_t a = color ? color->a : 255u;
47
48 m_renderer->setTextContent(text.id, text.content);
49 m_renderer->setTextPosition(text.id, x, y);
50 m_renderer->setTextColor(text.id, {.r = r, .g = g, .b = b, .a = a});
51 m_renderer->drawText(text.id);
52 }
53 }
54
55 private:
56 const std::shared_ptr<eng::IRenderer> &m_renderer;
57 }; // class TextSystem
58} // namespace ecs
This file contains the component definitions.
This file contains the IRenderer class declaration.
This file contains the Registry class declaration.
Abstract class for system.
Definition ISystems.hpp:34
Class for managing entities and their components.
Definition Registry.hpp:25
std::unordered_map< Entity, T > & getAll()
Definition Registry.hpp:77
T * getComponent(Entity e)
Definition Registry.hpp:71
Class for text system.
Definition Text.hpp:22
TextSystem(TextSystem &&)=delete
TextSystem(const std::shared_ptr< eng::IRenderer > &renderer)
Definition Text.hpp:24
void update(Registry &registry, float) override
Definition Text.hpp:32
~TextSystem() override=default
TextSystem(const TextSystem &)=delete
TextSystem & operator=(TextSystem &&)=delete
const std::shared_ptr< eng::IRenderer > & m_renderer
Definition Text.hpp:56
TextSystem & operator=(const TextSystem &)=delete
virtual void setTextPosition(const std::string &name, float x, float y)=0
virtual void drawText(const std::string &name)=0
virtual void setTextContent(const std::string &name, const std::string &content)=0
virtual void setTextColor(const std::string &name, Color color)=0