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