Antkeeper  0.0.1
text.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2023 Christopher J. Howard
3  *
4  * This file is part of Antkeeper source code.
5  *
6  * Antkeeper source code is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * Antkeeper source code is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef ANTKEEPER_SCENE_TEXT_HPP
21 #define ANTKEEPER_SCENE_TEXT_HPP
22 
23 #include <engine/scene/object.hpp>
24 #include <engine/math/vector.hpp>
30 
31 namespace scene {
32 
36 class text: public object<text>
37 {
38 public:
40  text();
41 
42  void render(render::context& ctx) const override;
43 
47  void refresh();
48 
54  void set_material(std::shared_ptr<render::material> material);
55 
61  void set_font(const type::bitmap_font* font);
62 
68  void set_direction(type::text_direction direction);
69 
75  void set_content(const std::string& content);
76 
84  void set_color(const math::fvec4& color);
85 
87  [[nodiscard]] inline const std::shared_ptr<render::material>& get_material() const noexcept
88  {
89  return m_render_op.material;
90  }
91 
93  [[nodiscard]] inline const type::bitmap_font* get_font() const noexcept
94  {
95  return m_font;
96  }
97 
99  [[nodiscard]] inline const type::text_direction& get_direction() const noexcept
100  {
101  return m_direction;
102  }
103 
105  [[nodiscard]] inline const std::string& get_content() const noexcept
106  {
107  return m_content_u8;
108  }
109 
111  [[nodiscard]] inline const math::fvec4& get_color() const noexcept
112  {
113  return m_color;
114  }
115 
116  [[nodiscard]] inline const aabb_type& get_bounds() const noexcept override
117  {
118  return m_world_bounds;
119  }
120 
121 private:
122  void update_content();
123  void update_color();
124  void transformed() override;
125 
126  mutable render::operation m_render_op;
127  aabb_type m_local_bounds{{0.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 0.0f}};
128  aabb_type m_world_bounds{{0.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 0.0f}};
129  const type::bitmap_font* m_font{nullptr};
131  std::string m_content_u8;
132  std::u32string m_content_u32;
133  math::fvec4 m_color{1.0f, 0.0f, 1.0f, 1.0f};
134  std::vector<std::byte> m_vertex_data;
135  std::unique_ptr<gl::vertex_array> m_vertex_array;
136  std::unique_ptr<gl::vertex_buffer> m_vertex_buffer;
137 };
138 
139 } // namespace scene
140 
141 #endif // ANTKEEPER_SCENE_TEXT_HPP
geom::box< float > aabb_type
Definition: object.hpp:42
Abstract base class for lights, cameras, model instances, and other scene objects.
Definition: object.hpp:172
Text scene object.
Definition: text.hpp:37
void set_content(const std::string &content)
Sets the text content.
Definition: text.cpp:116
void render(render::context &ctx) const override
Adds render operations to a render context.
Definition: text.cpp:78
void set_direction(type::text_direction direction)
Sets the direction of the text.
Definition: text.cpp:107
void set_color(const math::fvec4 &color)
Sets the text color.
Definition: text.cpp:126
const type::text_direction & get_direction() const noexcept
Returns the text direction.
Definition: text.hpp:99
const type::bitmap_font * get_font() const noexcept
Returns the text font.
Definition: text.hpp:93
void refresh()
Manually updates the text object if its font has been updated or altered in any way.
Definition: text.cpp:88
const math::fvec4 & get_color() const noexcept
Returns the text color.
Definition: text.hpp:111
const std::shared_ptr< render::material > & get_material() const noexcept
Returns the text material.
Definition: text.hpp:87
const aabb_type & get_bounds() const noexcept override
Returns the bounds of the object.
Definition: text.hpp:116
void set_material(std::shared_ptr< render::material > material)
Sets the text material.
Definition: text.cpp:93
text()
Constructs a text object.
Definition: text.cpp:58
void set_font(const type::bitmap_font *font)
Sets the text font.
Definition: text.cpp:98
const std::string & get_content() const noexcept
Returns the text content.
Definition: text.hpp:105
Raster font in which glyphs are stored as arrays of pixels.
Definition: bitmap-font.hpp:39
Color science.
Definition: aces.hpp:27
3D scene.
Definition: context.hpp:28
text_direction
Text writing direction.
@ ltr
Text is written from left to right.
n-dimensional axis-aligned rectangle.
n-dimensional vector.
Definition: vector.hpp:44
Context of a renderer.
Definition: context.hpp:40
Atomic render operation.
Definition: operation.hpp:38
std::shared_ptr< render::material > material
Definition: operation.hpp:49