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#include "Util/Transform.hpp"
16
17namespace Util {
26class Text : public Core::Drawable {
27public:
28 Text(const std::string &font, int size, const std::string &text,
29 const Util::Color &color = Color(127, 127, 127));
30
31 glm::vec2 GetSize() const override { return m_Size; };
32
38 void SetText(const std::string &text) {
39 m_Text = text;
40 ApplyTexture();
41 }
42
48 void SetColor(const Util::Color &color) {
49 m_Color = color;
50 ApplyTexture();
51 };
52
59 void Draw(const Core::Matrices &data) override;
60
61private:
62 void InitProgram();
63 void InitVertexArray();
64 void InitUniformBuffer();
65
71 void ApplyTexture();
72
73 static constexpr int UNIFORM_SURFACE_LOCATION = 0;
74
75 static std::unique_ptr<Core::Program> s_Program;
76 static std::unique_ptr<Core::VertexArray> s_VertexArray;
77 std::unique_ptr<Core::UniformBuffer<Core::Matrices>> m_UniformBuffer;
78
79private:
80 std::unique_ptr<Core::Texture> m_Texture = nullptr;
81 std::unique_ptr<TTF_Font, std::function<void(TTF_Font *)>> m_Font;
82
83 std::string m_Text;
84 Util::Color m_Color;
85 glm::vec2 m_Size;
86};
87} // namespace Util
88
89#endif
Definition Drawable.hpp:14
A class representing a color.
Definition Color.hpp:19
void SetText(const std::string &text)
Sets the text to the specified string.
Definition Text.hpp:38
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:48
Useful tools for development.
Definition Animation.hpp:12
Definition Drawable.hpp:9