galaxy 1.0.0
Real-Time C++23 Game Programming Framework. Built on data-driven design principles and agile software engineering.
Loading...
Searching...
No Matches
Text.hpp
Go to the documentation of this file.
1
7
8#ifndef GALAXY_GRAPHICS_TEXT_TEXT_HPP_
9#define GALAXY_GRAPHICS_TEXT_TEXT_HPP_
10
14
15namespace galaxy
16{
17 namespace graphics
18 {
22 class Text final
23 {
24 public:
28 enum class Alignment : int
29 {
30 LEFT = 0,
31 CENTER = 1,
32 RIGHT = 2
33 };
34
38 Text();
39
43 Text(Text&&);
44
49
53 ~Text();
54
64 void create(std::string_view text, const float size, const std::string& font, const graphics::Colour& colour, Alignment alignment = Alignment::LEFT);
65
71 void set_font(std::string_view font);
72
78 void update(std::string_view text);
79
85 void update(const float size);
86
92 void update(const Alignment alignment);
93
101 [[nodiscard]]
102 float width() const;
103
111 [[nodiscard]]
112 float height() const;
113
121 [[nodiscard]]
122 const std::string& get_text() const;
123
131 [[nodiscard]]
132 float get_size() const;
133
139 [[nodiscard]]
140 Alignment get_alignment() const;
141
147 [[nodiscard]]
148 const std::string& get_font() const;
149
156
163
164 private:
168 Text(const Text&) = delete;
169
173 Text& operator=(const Text&) = delete;
174
178 void update();
179
180 public:
185
186 private:
191
196
200 std::string m_font_name;
201
206
210 std::string m_text;
211
215 float m_size;
216
221 };
222 } // namespace graphics
223} // namespace galaxy
224
225#endif
Represents an RGBA colour.
Definition Colour.hpp:27
A font is a MSDF atlas of glyphs.
Definition Font.hpp:25
Draw to an opengl texture instead of the screen.
String of glyphs rendered with a font.
Definition Text.hpp:23
const std::string & get_font() const
Get font ID.
Definition Text.cpp:205
const std::string & get_text() const
Get text.
Definition Text.cpp:190
Alignment get_alignment() const
Get the text alignment.
Definition Text.cpp:200
void create(std::string_view text, const float size, const std::string &font, const graphics::Colour &colour, Alignment alignment=Alignment::LEFT)
Creates the rendered text.
Definition Text.cpp:71
float m_size
EM size.
Definition Text.hpp:215
Text & operator=(Text &&)
Move assignment operator.
Definition Text.cpp:47
Alignment
Text alignment.
Definition Text.hpp:29
~Text()
Destructor.
Definition Text.cpp:66
std::string m_font_name
Font Name.
Definition Text.hpp:200
void set_font(std::string_view font)
Update the font used.
Definition Text.cpp:84
graphics::Colour m_colour
Text colour.
Definition Text.hpp:184
graphics::RenderTexture & render_texture()
Get render texture.
Definition Text.cpp:215
graphics::Font * m_font
Pointer to font resource.
Definition Text.hpp:205
float height() const
Get text height.
Definition Text.cpp:185
graphics::VertexArray m_vao
Vertex Array Object.
Definition Text.hpp:190
Alignment m_alignment
Alignment.
Definition Text.hpp:220
void update()
Update the rendered text.
Definition Text.cpp:89
std::string m_text
Text.
Definition Text.hpp:210
Text & operator=(const Text &)=delete
Copy assignment operator.
float get_size() const
Get text em size.
Definition Text.cpp:195
float width() const
Get text width.
Definition Text.cpp:180
Text()
Constructor.
Definition Text.cpp:22
graphics::VertexArray & vao()
Get vertex array.
Definition Text.cpp:210
graphics::RenderTexture m_rt
Font render texture.
Definition Text.hpp:195
Text(const Text &)=delete
Copy constructor.
Abstraction for OpenGL vertex array objects.
Animated.cpp galaxy.
Definition Animated.cpp:16