X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fui%2FTextInput.hpp;fp=src%2Fui%2FTextInput.hpp;h=44999faac002259ecdca9c1cbdb21821abb2aec0;hb=54f3f1260b95a924fcb40d9d6de3fa2e2c382f6f;hp=0000000000000000000000000000000000000000;hpb=b49cc8c88caf7d69b35b50e23a40528e71306ade;p=blank.git diff --git a/src/ui/TextInput.hpp b/src/ui/TextInput.hpp new file mode 100644 index 0000000..44999fa --- /dev/null +++ b/src/ui/TextInput.hpp @@ -0,0 +1,78 @@ +#ifndef BLANK_UI_TEXTINPUT_HPP_ +#define BLANK_UI_TEXTINPUT_HPP_ + +#include "Text.hpp" +#include "../graphics/PrimitiveMesh.hpp" + +#include +#include + + +namespace blank { + +class Viewport; + +class TextInput { + +public: + explicit TextInput(const Font &); + + const std::string &GetInput() const noexcept { return input; } + + void Focus(Viewport &) noexcept; + void Blur() noexcept; + + void Clear() noexcept; + void Backspace() noexcept; + void Delete() noexcept; + + void MoveBegin() noexcept; + void MoveBackward() noexcept; + void MoveForward() noexcept; + void MoveEnd() noexcept; + + void Insert(const char *); + + bool AtBegin() const noexcept; + bool AtEnd() const noexcept; + + void Position(const glm::vec3 &p, Gravity g, Gravity pv) noexcept; + void Width(float) noexcept; + + void Foreground(const glm::vec4 &col) noexcept { fg = col; dirty_cursor = true; } + void Background(const glm::vec4 &col) noexcept { bg = col; dirty_box = true; } + + void Handle(const SDL_TextInputEvent &); + void Handle(const SDL_TextEditingEvent &); + + void Render(Viewport &); + +private: + void Refresh(); + +private: + const Font &font; + std::string input; + std::string::size_type cursor; + Text text; + + PrimitiveMesh bg_mesh; + PrimitiveMesh cursor_mesh; + + glm::vec4 bg; + glm::vec4 fg; + + glm::vec3 position; + glm::vec2 size; + Gravity gravity; + + bool active; + bool dirty_box; + bool dirty_cursor; + bool dirty_text; + +}; + +} + +#endif