💿🐜 Antkeeper source code https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

183 lines
3.9 KiB

  1. /*
  2. * Copyright (C) 2021 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. #ifndef ANTKEEPER_SCENE_TEXT_HPP
  20. #define ANTKEEPER_SCENE_TEXT_HPP
  21. #include "scene/object.hpp"
  22. #include "geom/aabb.hpp"
  23. #include "utility/fundamental-types.hpp"
  24. #include "gl/vertex-array.hpp"
  25. #include "gl/vertex-buffer.hpp"
  26. #include "renderer/material.hpp"
  27. #include "type/bitmap-font.hpp"
  28. #include "type/text-direction.hpp"
  29. namespace scene {
  30. /**
  31. * Text scene object.
  32. */
  33. class text: public object<text>
  34. {
  35. public:
  36. typedef geom::aabb<float> aabb_type;
  37. /// Constructs a text object.
  38. text();
  39. /// Destructs a text object.
  40. ~text();
  41. /**
  42. * Sets the text material.
  43. *
  44. * @param material Text material.
  45. */
  46. void set_material(material* material);
  47. /**
  48. * Sets the text font.
  49. *
  50. * @param font Pointer to a font.
  51. */
  52. void set_font(const type::bitmap_font* font);
  53. /**
  54. * Sets the direction of the text.
  55. *
  56. * @param direction Text direction.
  57. */
  58. void set_direction(type::text_direction direction);
  59. /**
  60. * Sets the text content.
  61. *
  62. * @param content UTF-8 string of text.
  63. */
  64. void set_content(const std::string& content);
  65. /**
  66. * Sets the text color.
  67. *
  68. * Text color is passed to the text's material shader as a vertex color.
  69. *
  70. * @param color RGBA color.
  71. */
  72. void set_color(const float4& color);
  73. /// Returns the text material.
  74. material* get_material() const;
  75. /// Returns the text font.
  76. const type::bitmap_font* get_font() const;
  77. /// Returns the text direction.
  78. const type::text_direction& get_direction() const;
  79. /// Returns the text content.
  80. const std::string& get_content() const;
  81. /// Returns the text color.
  82. const float4& get_color() const;
  83. /// Returns the text vertex array.
  84. const gl::vertex_array* get_vertex_array() const;
  85. /// Returns the text vertex buffer.
  86. const gl::vertex_buffer* get_vertex_buffer() const;
  87. /// Returns the number of vertices.
  88. std::size_t get_vertex_count() const;
  89. /// @copydoc scene::object::get_bounds() const
  90. virtual const bounding_volume_type& get_bounds() const;
  91. /// @copydoc scene::object::update_tweens()
  92. virtual void update_tweens();
  93. private:
  94. void update_content();
  95. void update_color();
  96. virtual void transformed();
  97. aabb_type local_bounds;
  98. aabb_type world_bounds;
  99. material* material;
  100. const type::bitmap_font* font;
  101. type::text_direction direction;
  102. std::string content_u8;
  103. std::u32string content_u32;
  104. float4 color;
  105. std::size_t vertex_stride;
  106. std::size_t vertex_count;
  107. std::vector<std::byte> vertex_data;
  108. gl::vertex_array* vao;
  109. gl::vertex_buffer* vbo;
  110. };
  111. inline material* text::get_material() const
  112. {
  113. return material;
  114. }
  115. inline const type::bitmap_font* text::get_font() const
  116. {
  117. return font;
  118. }
  119. inline const type::text_direction& text::get_direction() const
  120. {
  121. return direction;
  122. }
  123. inline const std::string& text::get_content() const
  124. {
  125. return content_u8;
  126. }
  127. inline const float4& text::get_color() const
  128. {
  129. return color;
  130. }
  131. inline const gl::vertex_array* text::get_vertex_array() const
  132. {
  133. return vao;
  134. }
  135. inline const gl::vertex_buffer* text::get_vertex_buffer() const
  136. {
  137. return vbo;
  138. }
  139. inline std::size_t text::get_vertex_count() const
  140. {
  141. return vertex_count;
  142. }
  143. inline const typename object_base::bounding_volume_type& text::get_bounds() const
  144. {
  145. return world_bounds;
  146. }
  147. } // namespace scene
  148. #endif // ANTKEEPER_SCENE_TEXT_HPP