Wizard Engine
2D cross-platform game engine built around SDL2
 
Loading...
Searching...
No Matches
input.hpp
Go to the documentation of this file.
1/*
2 Wizard Engine
3 Copyright (C) 2023-2024 Zana Domán
4
5 This software is provided 'as-is', without any express or implied
6 warranty. In no event will the authors be held liable for any damages
7 arising from the use of this software.
8
9 Permission is granted to anyone to use this software for any purpose,
10 including commercial applications, and to alter it and redistribute it
11 freely, subject to the following restrictions:
12
13 1. The origin of this software must not be misrepresented; you must not
14 claim that you wrote the original software. If you use this software
15 in a product, an acknowledgment in the product documentation would be
16 appreciated but is not required.
17 2. Altered source versions must be plainly marked as such, and must not be
18 misrepresented as being the original software.
19 3. This notice may not be removed or altered from any source distribution.
20*/
21
22#ifndef WIZARD_ENGINE_INPUT_HPP
23#define WIZARD_ENGINE_INPUT_HPP
24
28
29namespace wze {
35struct finger {
36 float absolute_x;
37 float absolute_y;
38 float relative_x;
39 float relative_y;
40};
41
47struct gesture {
48 float x;
49 float y;
50 float length;
51 float angle;
52};
53
59class input final {
60 private:
61 static SDL_Keycode _key;
62 static std::array<bool, KEY_COUNT> _keys;
63 static std::unordered_map<std::string, std::vector<enum key>> _keymaps;
64 static float _cursor_absolute_x;
65 static float _cursor_absolute_y;
66 static float _cursor_relative_x;
67 static float _cursor_relative_y;
68 static float _mouse_sensitivity;
69 static std::unordered_map<size_t, finger> _fingers;
70 static std::optional<gesture> _gesture;
71 static std::unique_ptr<SDL_Sensor, std::function<void(SDL_Sensor*)>>
72 _accelerometer;
73 static std::array<float, 3> _accelerometer_xyz;
74
80 input() = default;
81
87 static void update_key();
88
94 static void update_keys();
95
101 static void update_cursor();
102
109 static void update_fingers();
110
116 static void update_gesture();
117
124 static void update_accelerometer();
125
126 public:
134 [[nodiscard]] static bool text_input();
135
143 static void set_text_input(bool text_input);
144
151 [[nodiscard]] static uint32_t key();
152
159 [[nodiscard]] static std::unordered_map<std::string, std::vector<enum key>>&
160 keymaps();
161
168 [[nodiscard]] static float cursor_absolute_x();
169
176 [[nodiscard]] static float cursor_absolute_y();
177
184 [[nodiscard]] static float cursor_relative_x();
185
192 [[nodiscard]] static float cursor_relative_y();
193
202 [[nodiscard]] static float mouse_sensitivity();
203
212 static void set_mouse_sensitivity(float mouse_sensitivity);
213
221 [[nodiscard]] static bool cursor_visible();
222
231 static void set_cursor_visible(bool cursor_visible);
232
240 static void
241 set_cursor_appearance(std::unique_ptr<cursor, std::function<void(cursor*)>>
242 cursor_appearance);
243
251 [[nodiscard]] static std::unordered_map<size_t, finger> const& fingers();
252
259 [[nodiscard]] static std::optional<gesture> const& gesture();
260
267 [[nodiscard]] static float accelerometer_x();
268
275 [[nodiscard]] static float accelerometer_y();
276
283 [[nodiscard]] static float accelerometer_z();
284
285#ifdef __WIZARD_ENGINE_INTERNAL__
293 static void initialize();
294#endif /* __WIZARD_ENGINE_INTERNAL__ */
295
296#ifdef __WIZARD_ENGINE_INTERNAL__
302 static void update();
303#endif /* __WIZARD_ENGINE_INTERNAL__ */
304
313 [[nodiscard]] static bool key(enum key key);
314
322 [[nodiscard]] static bool key(std::string const& name);
323
331 [[nodiscard]] static std::pair<float, float> cursor_spatial(float z);
332};
333} /* namespace wze */
334
335#endif /* WIZARD_ENGINE_INPUT_HPP */
Image file in host memory.
Enumerations.
Export header of the Wizard Engine.
Wizard Engine.
key
Keys.
Definition enums.hpp:72