diff options
| author | Nicolas James <Eele1Ephe7uZahRie@tutanota.com> | 2025-02-12 18:05:18 +1100 |
|---|---|---|
| committer | Nicolas James <Eele1Ephe7uZahRie@tutanota.com> | 2025-02-12 18:05:18 +1100 |
| commit | 1cc08c51eb4b0f95c30c0a98ad1fc5ad3459b2df (patch) | |
| tree | 222dfcd07a1e40716127a347bbfd7119ce3d0984 /src/client/input.hh | |
initial commit
Diffstat (limited to 'src/client/input.hh')
| -rw-r--r-- | src/client/input.hh | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/src/client/input.hh b/src/client/input.hh new file mode 100644 index 0000000..d5287a7 --- /dev/null +++ b/src/client/input.hh @@ -0,0 +1,48 @@ +#ifndef CLIENT_INPUT_HH_ +#define CLIENT_INPUT_HH_ + +#include <functional> +#include <optional> +#include <string> +#include <variant> + +#include <SDL2/SDL.h> +#include <glm/glm.hpp> + +#include "client/render/render.hh" + +namespace client { + +namespace input { + +// Called on every event during update, supports multiple handlers. +// using event_callback = void (*)(const SDL_Event&); +using event_callback = std::function<void(const SDL_Event&)>; +void register_event_handler(const event_callback&) noexcept; + +// Empties our event queue while updating our inlines - also calls our +// registered callback functions per event. +void update() noexcept; + +void set_text_input(const bool should_start) noexcept; +void set_mouse_relative(const bool is_relative) noexcept; +void set_mouse_position(const glm::ivec2& d) noexcept; + +bool is_key_pressed(const SDL_Keycode& key) noexcept; +bool is_key_toggled(const SDL_Keycode& key) noexcept; + +struct state { + std::string text_input; + bool quit; + bool focused = true; + bool typing; + glm::vec2 mouse_pos; +}; + +inline state state; + +} // namespace input + +} // namespace client + +#endif |
