Aurore
A Switch-like interface for your app, on every screen
Loading...
Searching...
No Matches
input.hpp
Go to the documentation of this file.
1/*
2 Copyright 2021 natinusala
3 Copyright 2021 XITRIX
4
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
8
9 http://www.apache.org/licenses/LICENSE-2.0
10
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
16*/
17
18#pragma once
19
20#include <nanovg.h>
21
22#include <vector>
23#include <aurore/core/event.hpp>
25#include <aurore/core/time.hpp>
26
27#define GAMEPADS_MAX 5
28
29namespace aurore
30{
31
40
43typedef enum
44{
45 /* The unknown key */
47
48 /* Printable keys */
97 AURORE_KBD_KEY_WORLD_1 = 161, /* non-US #1 */
98 AURORE_KBD_KEY_WORLD_2 = 162, /* non-US #2 */
99
100 /* Function keys */
171
174
175// Abstract buttons enum - names correspond to a generic Xbox controller
176// LT and RT should not be buttons but for the sake of simplicity we'll assume they are.
177// Similarly, DPAD (also called HAT) is assumed to be buttons here.
211
212// Abstract axis enum - names correspond to a generic Xbox controller
214{
217
218 RIGHT_X, // also called 5th axis
219 RIGHT_Y, // also called 4th axis
220
221 LEFT_Z, // LT
222 RIGHT_Z, // RT
223
225};
226
233
235{
236 GYRO,
237 ACCEL
238};
239
240// Represents the state of the controller's sensor
248
249// Represents the state of the controller (a gamepad or a keyboard) in the current frame
251{
252 bool buttons[_BUTTON_MAX]; // true: pressed
253 float axes[_AXES_MAX]; // from 0.0f to 1.0f
254 Time repeatingButtonStop[_BUTTON_MAX]; // When the pressing time is greater than this value, trigger long press or repeat
255};
256
257// Represents a touch phase in the current frame
258enum class TouchPhase
259{
260 START,
261 STAY,
262 END,
263 NONE,
264};
265
266// Contains raw touch data, filled in by platform driver
268{
269 int fingerId = 0;
270 bool pressed = false;
272};
273
274// Contains touch data automatically filled with current phase by the library
275class View;
283
284// Contains raw touch data, filled in by platform driver
286{
290 bool leftButton = false;
291 bool middleButton = false;
292 bool rightButton = false;
293};
294
295// A button read once a frame from its press and release events: a press
296// let go before the frame reads it still counts, for that one frame
298{
299 public:
300 void press()
301 {
302 down = true;
303 pressed = true;
304 }
305 void release() { down = false; }
306
307 // Its state for the frame starting
308 bool frame()
309 {
310 bool state = down || pressed;
311 pressed = false;
312 return state;
313 }
314
315 private:
316 bool down = false;
317 bool pressed = false;
318};
319
330
331// Interface responsible for reporting input state to the application - button presses,
332// axis position and touch screen state
334{
335 public:
336 virtual ~InputManager() { }
337
338 virtual short getControllersConnectedCount() = 0;
339
344 virtual void updateControllerState(ControllerState* state, int controller) = 0;
345
347
351 virtual void updateTouchStates(std::vector<RawTouchState>* states) = 0;
352
356 virtual void updateMouseStates(RawMouseState* state) = 0;
357
361 virtual void sendRumble(unsigned short controller, unsigned short lowFreqMotor, unsigned short highFreqMotor) = 0;
362
367 virtual void runloopStart() {};
368
369 virtual void drawCursor(NVGcontext* vg) {};
370
371 virtual void setPointerLock(bool lock) {};
372
374 {
375 return &mouseCusorEntered;
376 }
377
379 {
380 return &mouseCusorOffsetChanged;
381 }
382
384 {
385 return &mouseScrollOffsetChanged;
386 }
387
389 {
390 return &controllerSensorStateChanged;
391 }
392
394 {
395 return &keyboardKeyStateChanged;
396 }
397
401 static TouchState computeTouchState(RawTouchState currentTouch, TouchState lastFrameState);
402
406 static MouseState computeMouseState(RawMouseState currentTouch, MouseState lastFrameState);
407
409
410 private:
411 Event<bool> mouseCusorEntered;
412 Event<Point> mouseCusorOffsetChanged;
413 Event<Point> mouseScrollOffsetChanged;
414 Event<KeyState> keyboardKeyStateChanged;
415 Event<SensorEvent> controllerSensorStateChanged;
416};
417
418}; // namespace aurore
Definition input.hpp:298
void release()
Definition input.hpp:305
bool frame()
Definition input.hpp:308
void press()
Definition input.hpp:300
Definition event.hpp:41
Definition input.hpp:334
Event< bool > * getMouseCusorEntered()
Definition input.hpp:373
static TouchState computeTouchState(RawTouchState currentTouch, TouchState lastFrameState)
virtual void setPointerLock(bool lock)
Definition input.hpp:371
Event< KeyState > * getKeyboardKeyStateChanged()
Definition input.hpp:393
virtual void drawCursor(NVGcontext *vg)
Definition input.hpp:369
virtual void updateTouchStates(std::vector< RawTouchState > *states)=0
Event< SensorEvent > * getControllerSensorStateChanged()
Definition input.hpp:388
virtual void updateUnifiedControllerState(ControllerState *state)=0
Event< Point > * getMouseScrollOffsetChanged()
Definition input.hpp:383
Event< Point > * getMouseCusorOffsetChanged()
Definition input.hpp:378
virtual ~InputManager()
Definition input.hpp:336
static ControllerButton mapControllerState(ControllerButton button)
virtual short getControllersConnectedCount()=0
virtual void sendRumble(unsigned short controller, unsigned short lowFreqMotor, unsigned short highFreqMotor)=0
virtual void runloopStart()
Definition input.hpp:367
virtual bool getKeyboardKeyState(AuroreKeyboardScancode state)=0
virtual void updateControllerState(ControllerState *state, int controller)=0
static MouseState computeMouseState(RawMouseState currentTouch, MouseState lastFrameState)
virtual void updateMouseStates(RawMouseState *state)=0
Definition view.hpp:232
Definition actions.hpp:25
AuroreKeyboardScancode
Definition input.hpp:44
@ AURORE_KBD_KEY_UNKNOWN
Definition input.hpp:46
@ AURORE_KBD_KEY_KP_7
Definition input.hpp:152
@ AURORE_KBD_KEY_B
Definition input.hpp:68
@ AURORE_KBD_KEY_F10
Definition input.hpp:129
@ AURORE_KBD_KEY_KP_ENTER
Definition input.hpp:160
@ AURORE_KBD_KEY_V
Definition input.hpp:88
@ AURORE_KBD_KEY_LEFT_ALT
Definition input.hpp:164
@ AURORE_KBD_KEY_F17
Definition input.hpp:136
@ AURORE_KBD_KEY_5
Definition input.hpp:60
@ AURORE_KBD_KEY_TAB
Definition input.hpp:103
@ AURORE_KBD_KEY_F16
Definition input.hpp:135
@ AURORE_KBD_KEY_KP_9
Definition input.hpp:154
@ AURORE_KBD_KEY_F8
Definition input.hpp:127
@ AURORE_KBD_KEY_MENU
Definition input.hpp:170
@ AURORE_KBD_KEY_KP_2
Definition input.hpp:147
@ AURORE_KBD_KEY_Q
Definition input.hpp:83
@ AURORE_KBD_KEY_KP_DECIMAL
Definition input.hpp:155
@ AURORE_KBD_KEY_W
Definition input.hpp:89
@ AURORE_KBD_KEY_KP_5
Definition input.hpp:150
@ AURORE_KBD_KEY_F18
Definition input.hpp:137
@ AURORE_KBD_KEY_PAUSE
Definition input.hpp:119
@ AURORE_KBD_KEY_A
Definition input.hpp:67
@ AURORE_KBD_KEY_6
Definition input.hpp:61
@ AURORE_KBD_KEY_M
Definition input.hpp:79
@ AURORE_KBD_KEY_D
Definition input.hpp:70
@ AURORE_KBD_KEY_F3
Definition input.hpp:122
@ AURORE_KBD_KEY_COMMA
Definition input.hpp:51
@ AURORE_KBD_KEY_BACKSLASH
Definition input.hpp:94
@ AURORE_KBD_KEY_E
Definition input.hpp:71
@ AURORE_KBD_KEY_4
Definition input.hpp:59
@ AURORE_KBD_KEY_ENTER
Definition input.hpp:102
@ AURORE_KBD_KEY_F1
Definition input.hpp:120
@ AURORE_KBD_KEY_J
Definition input.hpp:76
@ AURORE_KBD_KEY_G
Definition input.hpp:73
@ AURORE_KBD_KEY_RIGHT_CONTROL
Definition input.hpp:167
@ AURORE_KBD_KEY_GRAVE_ACCENT
Definition input.hpp:96
@ AURORE_KBD_KEY_F24
Definition input.hpp:143
@ AURORE_KBD_KEY_F19
Definition input.hpp:138
@ AURORE_KBD_KEY_1
Definition input.hpp:56
@ AURORE_KBD_KEY_APOSTROPHE
Definition input.hpp:50
@ AURORE_KBD_KEY_WORLD_2
Definition input.hpp:98
@ AURORE_KBD_KEY_RIGHT_ALT
Definition input.hpp:168
@ AURORE_KBD_KEY_F23
Definition input.hpp:142
@ AURORE_KBD_KEY_SPACE
Definition input.hpp:49
@ AURORE_KBD_KEY_KP_4
Definition input.hpp:149
@ AURORE_KBD_KEY_F11
Definition input.hpp:130
@ AURORE_KBD_KEY_K
Definition input.hpp:77
@ AURORE_KBD_KEY_F6
Definition input.hpp:125
@ AURORE_KBD_KEY_SLASH
Definition input.hpp:54
@ AURORE_KBD_KEY_RIGHT_BRACKET
Definition input.hpp:95
@ AURORE_KBD_KEY_LAST
Definition input.hpp:172
@ AURORE_KBD_KEY_DOWN
Definition input.hpp:109
@ AURORE_KBD_KEY_2
Definition input.hpp:57
@ AURORE_KBD_KEY_H
Definition input.hpp:74
@ AURORE_KBD_KEY_KP_8
Definition input.hpp:153
@ AURORE_KBD_KEY_KP_EQUAL
Definition input.hpp:161
@ AURORE_KBD_KEY_T
Definition input.hpp:86
@ AURORE_KBD_KEY_KP_SUBTRACT
Definition input.hpp:158
@ AURORE_KBD_KEY_EQUAL
Definition input.hpp:66
@ AURORE_KBD_KEY_NUM_LOCK
Definition input.hpp:117
@ AURORE_KBD_KEY_F9
Definition input.hpp:128
@ AURORE_KBD_KEY_ESCAPE
Definition input.hpp:101
@ AURORE_KBD_KEY_F13
Definition input.hpp:132
@ AURORE_KBD_KEY_0
Definition input.hpp:55
@ AURORE_KBD_KEY_INSERT
Definition input.hpp:105
@ AURORE_KBD_KEY_F15
Definition input.hpp:134
@ AURORE_KBD_KEY_DELETE
Definition input.hpp:106
@ AURORE_KBD_KEY_BACKSPACE
Definition input.hpp:104
@ AURORE_KBD_KEY_PERIOD
Definition input.hpp:53
@ AURORE_KBD_KEY_F21
Definition input.hpp:140
@ AURORE_KBD_KEY_7
Definition input.hpp:62
@ AURORE_KBD_KEY_KP_1
Definition input.hpp:146
@ AURORE_KBD_KEY_9
Definition input.hpp:64
@ AURORE_KBD_KEY_N
Definition input.hpp:80
@ AURORE_KBD_KEY_F12
Definition input.hpp:131
@ AURORE_KBD_KEY_Y
Definition input.hpp:91
@ AURORE_KBD_KEY_LEFT
Definition input.hpp:108
@ AURORE_KBD_KEY_PAGE_DOWN
Definition input.hpp:112
@ AURORE_KBD_KEY_F22
Definition input.hpp:141
@ AURORE_KBD_KEY_F20
Definition input.hpp:139
@ AURORE_KBD_KEY_8
Definition input.hpp:63
@ AURORE_KBD_KEY_PAGE_UP
Definition input.hpp:111
@ AURORE_KBD_KEY_RIGHT_SHIFT
Definition input.hpp:166
@ AURORE_KBD_KEY_END
Definition input.hpp:114
@ AURORE_KBD_KEY_LEFT_SHIFT
Definition input.hpp:162
@ AURORE_KBD_KEY_RIGHT
Definition input.hpp:107
@ AURORE_KBD_KEY_LEFT_CONTROL
Definition input.hpp:163
@ AURORE_KBD_KEY_P
Definition input.hpp:82
@ AURORE_KBD_KEY_I
Definition input.hpp:75
@ AURORE_KBD_KEY_F2
Definition input.hpp:121
@ AURORE_KBD_KEY_MINUS
Definition input.hpp:52
@ AURORE_KBD_KEY_O
Definition input.hpp:81
@ AURORE_KBD_KEY_Z
Definition input.hpp:92
@ AURORE_KBD_KEY_RIGHT_SUPER
Definition input.hpp:169
@ AURORE_KBD_KEY_F14
Definition input.hpp:133
@ AURORE_KBD_KEY_F5
Definition input.hpp:124
@ AURORE_KBD_KEY_L
Definition input.hpp:78
@ AURORE_KBD_KEY_UP
Definition input.hpp:110
@ AURORE_KBD_KEY_KP_6
Definition input.hpp:151
@ AURORE_KBD_KEY_KP_ADD
Definition input.hpp:159
@ AURORE_KBD_KEY_C
Definition input.hpp:69
@ AURORE_KBD_KEY_SCROLL_LOCK
Definition input.hpp:116
@ AURORE_KBD_KEY_R
Definition input.hpp:84
@ AURORE_KBD_KEY_X
Definition input.hpp:90
@ AURORE_KBD_KEY_KP_3
Definition input.hpp:148
@ AURORE_KBD_KEY_U
Definition input.hpp:87
@ AURORE_KBD_KEY_WORLD_1
Definition input.hpp:97
@ AURORE_KBD_KEY_F4
Definition input.hpp:123
@ AURORE_KBD_KEY_3
Definition input.hpp:58
@ AURORE_KBD_KEY_F7
Definition input.hpp:126
@ AURORE_KBD_KEY_KP_DIVIDE
Definition input.hpp:156
@ AURORE_KBD_KEY_KP_MULTIPLY
Definition input.hpp:157
@ AURORE_KBD_KEY_KP_0
Definition input.hpp:145
@ AURORE_KBD_KEY_LEFT_BRACKET
Definition input.hpp:93
@ AURORE_KBD_KEY_S
Definition input.hpp:85
@ AURORE_KBD_KEY_HOME
Definition input.hpp:113
@ AURORE_KBD_KEY_F
Definition input.hpp:72
@ AURORE_KBD_KEY_SEMICOLON
Definition input.hpp:65
@ AURORE_KBD_KEY_F25
Definition input.hpp:144
@ AURORE_KBD_KEY_PRINT_SCREEN
Definition input.hpp:118
@ AURORE_KBD_KEY_LEFT_SUPER
Definition input.hpp:165
@ AURORE_KBD_KEY_CAPS_LOCK
Definition input.hpp:115
AuroreKeyboardModifiers
Definition input.hpp:33
@ AURORE_KBD_MODIFIER_SHIFT
Definition input.hpp:35
@ AURORE_KBD_MODIFIER_META
Definition input.hpp:38
@ AURORE_KBD_MODIFIER_CTRL
Definition input.hpp:36
@ AURORE_KBD_MODIFIER_NONE
Definition input.hpp:34
@ AURORE_KBD_MODIFIER_ALT
Definition input.hpp:37
ControllerButton
Definition input.hpp:179
@ BUTTON_RSB
Definition input.hpp:194
@ BUTTON_LT
Definition input.hpp:180
@ BUTTON_BACK
Definition input.hpp:190
@ BUTTON_A
Definition input.hpp:198
@ BUTTON_LSB
Definition input.hpp:183
@ BUTTON_RB
Definition input.hpp:201
@ _BUTTON_MAX
Definition input.hpp:209
@ BUTTON_GUIDE
Definition input.hpp:191
@ BUTTON_NAV_RIGHT
Definition input.hpp:205
@ BUTTON_NAV_DOWN
Definition input.hpp:206
@ BUTTON_LEFT
Definition input.hpp:188
@ BUTTON_X
Definition input.hpp:199
@ BUTTON_Y
Definition input.hpp:196
@ BUTTON_UP
Definition input.hpp:185
@ BUTTON_LB
Definition input.hpp:181
@ BUTTON_NAV_LEFT
Definition input.hpp:207
@ BUTTON_RT
Definition input.hpp:202
@ BUTTON_DOWN
Definition input.hpp:187
@ BUTTON_NAV_UP
Definition input.hpp:204
@ BUTTON_RIGHT
Definition input.hpp:186
@ BUTTON_START
Definition input.hpp:192
@ BUTTON_B
Definition input.hpp:197
TouchPhase
Definition input.hpp:259
SensorEventType
Definition input.hpp:235
retro_time_t Time
Definition time.hpp:31
ControllerAxis
Definition input.hpp:214
@ RIGHT_Z
Definition input.hpp:222
@ RIGHT_X
Definition input.hpp:218
@ LEFT_X
Definition input.hpp:215
@ RIGHT_Y
Definition input.hpp:219
@ LEFT_Z
Definition input.hpp:221
@ _AXES_MAX
Definition input.hpp:224
@ LEFT_Y
Definition input.hpp:216
Definition input.hpp:251
Time repeatingButtonStop[_BUTTON_MAX]
Definition input.hpp:254
float axes[_AXES_MAX]
Definition input.hpp:253
bool buttons[_BUTTON_MAX]
Definition input.hpp:252
Definition input.hpp:228
AuroreKeyboardScancode key
Definition input.hpp:229
short mods
Definition input.hpp:230
bool pressed
Definition input.hpp:231
Definition input.hpp:321
Point offset
Definition input.hpp:323
Point position
Definition input.hpp:322
TouchPhase middleButton
Definition input.hpp:326
Point scroll
Definition input.hpp:324
TouchPhase rightButton
Definition input.hpp:327
TouchPhase leftButton
Definition input.hpp:325
View * view
Definition input.hpp:328
Definition geometry.hpp:26
Definition input.hpp:286
bool rightButton
Definition input.hpp:292
Point scroll
Definition input.hpp:289
Point offset
Definition input.hpp:288
bool middleButton
Definition input.hpp:291
Point position
Definition input.hpp:287
bool leftButton
Definition input.hpp:290
Definition input.hpp:268
Point position
Definition input.hpp:271
int fingerId
Definition input.hpp:269
bool pressed
Definition input.hpp:270
Definition input.hpp:242
SensorEventType type
Definition input.hpp:244
uint32_t timestamp
Definition input.hpp:246
float data[3]
Definition input.hpp:245
int controllerIndex
Definition input.hpp:243
Definition input.hpp:277
View * view
Definition input.hpp:281
Point position
Definition input.hpp:280
TouchPhase phase
Definition input.hpp:279
int fingerId
Definition input.hpp:278