-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinput.h
More file actions
74 lines (50 loc) · 1.67 KB
/
input.h
File metadata and controls
74 lines (50 loc) · 1.67 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#ifndef INPUT_H_INCLUDED
#define INPUT_H_INCLUDED
#include <SDL.h>
#include "vec2d.h"
typedef enum {
INPUT_NULL,
INPUT_KEYBOARD,
INPUT_MOUSE_MOTION,
INPUT_MOUSE_BUTTON,
INPUT_MOUSE_WHEEL,
INPUT_GAMEPAD_BUTTON,
INPUT_GAMEPAD_AXIS,
} Input_Type;
typedef struct Input {
Input_Type type;
SDL_JoystickID which_gamepad;
union {
SDL_Keycode key;
Uint8 mouse_motion; // 1: X axis, 2: Y axis
Uint8 mouse_pos; // 1: X axis, 2: Y axis
Uint8 mouse_button; // SDL_BUTTON_LEFT, SDL_BUTTON_MIDDLE, SDL_BUTTON_RIGHT, SDL_BUTTON_X1, SDL_BUTTON_X2
Uint8 mouse_wheel; // 1: X axis, 2: Y axis
SDL_GamepadButton gamepad_button;
SDL_GamepadAxis gamepad_axis;
} detail;
int current;
float factor;
/* gamepad axis : factor = 1 / 32767.0f;
mouse_pos : factor = window height
mouse_rel : factor = some "sensitivity" constant
*/
} Input;
bool Event_Input_cmp( SDL_Event *E, Input *I );
// Returns 1 if event matches binding and fills *output, otherwise 0.
// cx, cy are the center for mouse-absolute-position directional controls.
int HandleEvent( SDL_Event *event, Input *binding, int cx, int cy );
typedef struct DirInput {
int mode; // 4 (4 buttons), 2 (2 axis)
Input bindings [4];
/* mode 4: R L U D
mode 2: X Y
*/
} DirInput;
int Dir_HandleEvent( SDL_Event *event, DirInput *dir, int cx, int cy );
vec2d DirInput_compute( DirInput *D );
DirInput Directional_Yawer_gamepad( SDL_JoystickID which );
// str shall be in "wasd" order, lower-case
DirInput Directional_from_String( char *str );
DirInput Directional_arrows();
#endif