]> git.localhorst.tv Git - blank.git/blob - src/graphics/Text.hpp
combine text handling stuff into a class
[blank.git] / src / graphics / Text.hpp
1 #ifndef BLANK_GRAPHICS_TEXT_HPP_
2 #define BLANK_GRAPHICS_TEXT_HPP_
3
4 #include "align.hpp"
5 #include "Texture.hpp"
6 #include "../model/SpriteModel.hpp"
7
8 #include <string>
9 #include <glm/glm.hpp>
10
11
12 namespace blank {
13
14 class Font;
15 class Viewport;
16
17 class Text {
18
19 public:
20         Text() noexcept;
21
22         void Set(const Font &, const char *);
23         void Set(const Font &f, const std::string &s) {
24                 Set(f, s.c_str());
25         }
26
27         void Position(const glm::vec3 &p) noexcept {
28                 pos = p;
29         }
30         void Position(
31                 const glm::vec3 &p,
32                 Gravity g
33         ) noexcept {
34                 pos = p;
35                 grav = g;
36                 pivot = g;
37                 dirty = true;
38         }
39         void Position(
40                 const glm::vec3 &p,
41                 Gravity g,
42                 Gravity pv
43         ) noexcept {
44                 pos = p;
45                 grav = g;
46                 pivot = pv;
47                 dirty = true;
48         }
49
50         void Foreground(const glm::vec4 &col) noexcept { fg = col; }
51         void Background(const glm::vec4 &col) noexcept { bg = col; }
52
53         void Render(Viewport &) noexcept;
54
55         void Show() noexcept { visible = true; }
56         void Hide() noexcept { visible = false; }
57         void Toggle() noexcept { visible = !visible; }
58         bool Visible() const noexcept { return visible; }
59
60 private:
61         void Update();
62
63 private:
64         Texture tex;
65         SpriteModel sprite;
66         glm::vec4 bg;
67         glm::vec4 fg;
68         glm::vec2 size;
69         glm::vec3 pos;
70         Gravity grav;
71         Gravity pivot;
72         bool dirty;
73         bool visible;
74
75 };
76
77 }
78
79 #endif