HIRO_DRAW
Computer Graphics Structures library
TextRenderer.h
1 /*
2  Copyright (C) Skeletex Research, s.r.o. - All Rights Reserved
3  Unauthorized copying of this file, via any medium is strictly prohibited
4  Proprietary and confidential
5 */
6 #ifndef HIRO_DRAW_TEXT_RENDERER_H
7 #define HIRO_DRAW_TEXT_RENDERER_H
8 #include <string>
9 
10 #include <glm/glm.hpp>
11 #include <Utils/NamedClass.h>
12 
13 #include <GLW/ShaderProgramList.h>
14 #include <COGS/Color.h>
15 
16 #include <HIRO_DRAW/Scene.h>
17 
18 
19 
20 namespace hiro::draw
21 {
22 
24  enum class TextAlignment : uint8_t
25  {
26  top_left,
27  top_center,
28  top_right,
29  center_left,
30  center,
31  center_right,
32  bottom_left,
33  bottom_center,
34  bottom_right
35  };
36 
37 
47  class HIRO_DRAW_API TextRenderer
48  {
49  friend class RenderSystem;
50  public:
51  TextRenderer();
52  TextRenderer(const hiro::draw::TextRenderer &) = delete;
53  ~TextRenderer();
55  size_t LoadFont(const std::string &font_file, float font_height);
57  void SetFont(const size_t font_id);
59  void SetColor(const cogs::Color4b &color);
61  void SetAlignment(hiro::draw::TextAlignment alignment);
63  void Print(glm::ivec2 pos, const std::string &text);
65  void SetSceneContext(const hiro::draw::PScene &scene);
66 
67  private:
68  struct Impl;
69  std::unique_ptr<hiro::draw::TextRenderer::Impl> m;
70 
71  glm::ivec2 AlignCoords(const std::string &text, glm::ivec2 coords) const;
72  void LoadShaderPrograms(glw::ProgramList *program_list);
73  void Render(glw::ProgramList *program_list, const glm::uvec2 &resolution);
74  };
75 
76 
77 
88  class HIRO_DRAW_API TextPrinter
89  {
90  public:
93  void PrintStr(const std::string &text);
95  void PrintBool(const std::string &text, bool state);
97  template<typename T> void PrintValue(const std::string &text, T value);
98 
99  private:
100  float current_line_y_{ 10.0f };
101  hiro::draw::TextRenderer *renderer_{ nullptr };
102  void NewLine();
103  glm::vec2 GetCurrentLineOrigin() const;
104  };
105 
106  template<typename T> void TextPrinter::PrintValue(const std::string &text, T value)
107  {
108  PrintStr(text + " : " + std::to_string(value));
109  }
110 
111 
112 }
113 
114 #endif /* !HIRO_DRAW_TEXT_RENDERER_H */
Responsible for rendering texts.
Definition: TextRenderer.h:47
Helper class for easier state printing to the top left corner of the viewport.
Definition: TextRenderer.h:88
Extensions for object visualization. Implements a higher level of OpenGL rendering.
Definition: API.h:20
void PrintValue(const std::string &text, T value)
Print text and value. Type of value parameter must be supported by any of the std::to_string overload...
Definition: TextRenderer.h:106
TextAlignment
Defined alignment origin of the text.
Definition: TextRenderer.h:24
Class responsible for rendering loop implementation and its optimization.
Definition: RenderSystem.h:42