aboutsummaryrefslogtreecommitdiff
path: root/src/client/input.hh
blob: d5287a76fa462c51787453a61c3908e4460b6113 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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