]> git.localhorst.tv Git - blank.git/blob - src/ui/TextInput.hpp
glm backwards compatibility
[blank.git] / src / ui / TextInput.hpp
1 #ifndef BLANK_UI_TEXTINPUT_HPP_
2 #define BLANK_UI_TEXTINPUT_HPP_
3
4 #include "Text.hpp"
5 #include "../graphics/PrimitiveMesh.hpp"
6
7 #include <string>
8 #include <SDL.h>
9
10
11 namespace blank {
12
13 class Viewport;
14
15 class TextInput {
16
17 public:
18         explicit TextInput(const Font &);
19
20         const std::string &GetInput() const noexcept { return input; }
21
22         void Focus(Viewport &) noexcept;
23         void Blur() noexcept;
24
25         void Clear() noexcept;
26         void Backspace() noexcept;
27         void Delete() noexcept;
28
29         void MoveBegin() noexcept;
30         void MoveBackward() noexcept;
31         void MoveForward() noexcept;
32         void MoveEnd() noexcept;
33
34         void Insert(const char *);
35
36         bool AtBegin() const noexcept;
37         bool AtEnd() const noexcept;
38
39         void Position(const glm::vec3 &p, Gravity g, Gravity pv) noexcept;
40         void Width(float) noexcept;
41
42         void Foreground(const PrimitiveMesh::Color &col) noexcept { fg = col; dirty_cursor = true; }
43         void Background(const PrimitiveMesh::Color &col) noexcept { bg = col; dirty_box = true; }
44
45         void Handle(const SDL_TextInputEvent &);
46         void Handle(const SDL_TextEditingEvent &);
47
48         void Render(Viewport &);
49
50 private:
51         void Refresh();
52
53 private:
54         const Font &font;
55         std::string input;
56         std::string::size_type cursor;
57         Text text;
58
59         PrimitiveMesh bg_mesh;
60         PrimitiveMesh cursor_mesh;
61
62         PrimitiveMesh::Color bg;
63         PrimitiveMesh::Color fg;
64
65         glm::vec3 position;
66         glm::vec2 size;
67         Gravity gravity;
68
69         bool active;
70         bool dirty_box;
71         bool dirty_cursor;
72         bool dirty_text;
73
74 };
75
76 }
77
78 #endif