Practical Tools for Simple Design
Loading...
Searching...
No Matches
Text.hpp
1#ifndef UTIL_TEXT_HPP
2#define UTIL_TEXT_HPP
3
4#include "pch.hpp" // IWYU pragma: export
5
6#include <functional>
7
8#include "Core/Drawable.hpp"
9#include "Core/Program.hpp"
10#include "Core/Texture.hpp"
11#include "Core/UniformBuffer.hpp"
12#include "Core/VertexArray.hpp"
13
14#include "Util/Color.hpp"
15
16namespace Util {
25class Text : public Core::Drawable {
26public:
37 Text(const std::string &font, int size, const std::string &text,
38 const Util::Color &color = Color(127, 127, 127), bool useAA = true);
39
40 glm::vec2 GetSize() const override { return m_Size; };
41
47 void SetText(const std::string &text) {
48 m_Text = text;
49 ApplyTexture();
50 }
51
57 void SetColor(const Util::Color &color) {
58 m_Color = color;
59 ApplyTexture();
60 };
61
74 void UseAntiAliasing(bool useAA);
75
85 void Draw(const Core::Matrices &data) override;
86
87private:
88 void InitProgram();
89 void InitVertexArray();
90 void InitUniformBuffer();
91
97 void ApplyTexture();
98
99 static constexpr int UNIFORM_SURFACE_LOCATION = 0;
100
101 static std::unique_ptr<Core::Program> s_Program;
102 static std::unique_ptr<Core::VertexArray> s_VertexArray;
103 std::unique_ptr<Core::UniformBuffer<Core::Matrices>> m_UniformBuffer;
104
105private:
106 std::unique_ptr<Core::Texture> m_Texture = nullptr;
107 std::unique_ptr<TTF_Font, std::function<void(TTF_Font *)>> m_Font;
108
109 std::string m_Text;
110 Util::Color m_Color;
111 glm::vec2 m_Size;
112};
113} // namespace Util
114
115#endif
Definition: Drawable.hpp:14
A class representing a color.
Definition: Color.hpp:19
A class representing a text.
Definition: Text.hpp:25
void SetText(const std::string &text)
Sets the text to the specified string.
Definition: Text.hpp:47
void Draw(const Core::Matrices &data) override
Draws the text with a given transform and z-index.
void SetColor(const Util::Color &color)
Sets the color of the text.
Definition: Text.hpp:57
void UseAntiAliasing(bool useAA)
Sets whether anti-aliasing (AA) should be enabled or disabled.
Text(const std::string &font, int size, const std::string &text, const Util::Color &color=Color(127, 127, 127), bool useAA=true)
Constructor for the Text class.
Useful tools for development.
Definition: Animation.hpp:12
Definition: Drawable.hpp:9