sandbox
Loading...
Searching...
No Matches
input.hpp
1// SPDX-License-Identifier: MIT
2#ifndef LIBSBX_DEVICES_INPUT_HPP_
3#define LIBSBX_DEVICES_INPUT_HPP_
4
5#include <cinttypes>
6#include <unordered_map>
7
8#include <GLFW/glfw3.h>
9
10#include <libsbx/utility/bitmask.hpp>
11
12#include <libsbx/math/vector2.hpp>
13
14#include <libsbx/devices/key.hpp>
15#include <libsbx/devices/mouse_button.hpp>
16#include <libsbx/devices/input_action.hpp>
17#include <libsbx/devices/input_mod.hpp>
18
19namespace sbx::devices {
20
21struct key_state {
22 input_action action;
23 input_action last_action;
24}; // struct key_state
25
26class input {
27
28 friend class devices_module;
29 friend class window;
30
31public:
32
33 input() = delete;
34
35 static auto is_key_pressed(key key) -> bool;
36 static auto is_key_down(key key) -> bool;
37 static auto is_key_released(key key) -> bool;
38
39 static auto is_mouse_button_pressed(mouse_button button) -> bool;
40 static auto is_mouse_button_down(mouse_button button) -> bool;
41 static auto is_mouse_button_released(mouse_button button) -> bool;
42
43 static auto mouse_position() -> math::vector2;
44
45 static auto mouse_window_position() -> math::vector2;
46
47 static auto scroll_delta() -> math::vector2;
48
49 static auto set_active_viewport(const math::vector2& origin, const math::vector2& size) -> void;
50
51 static auto active_viewport_origin() -> math::vector2;
52
53 static auto active_viewport_size() -> math::vector2;
54
55 static auto set_scene_input_active(bool active) -> void;
56
57 static auto is_scene_input_active() -> bool;
58
59private:
60
61 static auto _transition_pressed_keys() -> void;
62 static auto _transition_pressed_mouse_buttons() -> void;
63 static auto _transition_scroll_delta() -> void;
64
65 static auto _update_key_state(key key, input_action action) -> void;
66 static auto _update_mouse_button_state(mouse_button button, input_action action) -> void;
67 static auto _update_mouse_position(const math::vector2& position) -> void;
68 static auto _update_scroll_delta(const math::vector2& delta) -> void;
69
70 static std::unordered_map<key, key_state> _key_states;
71 static std::unordered_map<mouse_button, key_state> _mouse_button_states;
72
73 static math::vector2 _mouse_window_position;
74 static math::vector2 _scroll_delta;
75
76 static math::vector2 _active_viewport_origin;
77 static math::vector2 _active_viewport_size;
78
79 static bool _is_active;
80 static bool _is_captured;
81
82}; // class input
83
84} // namespace sbx::devices
85
86#endif // LIBSBX_DEVICES_INPUT_HPP_
Definition: devices_module.hpp:27
Definition: input.hpp:26
Definition: window.hpp:33
A vector in two-dimensional space.
Definition: vector2.hpp:28
Definition: input.hpp:21