-
Notifications
You must be signed in to change notification settings - Fork 2
/
inp.h
78 lines (62 loc) · 1.92 KB
/
inp.h
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
75
76
77
78
#ifndef INP_H
#define INP_H
#define GLFW_INCLUDE_NONE
#include <GLFW/glfw3.h>
#include "alg/alg.h"
/*
* Public API
*/
#define KEY(K) GLFW_KEY_ ## K
#define KEY_DOWN(K) (inp_data.key.states[KEY(K)] == 1)
#define KEY_UP(K) (inp_data.key.states[KEY(K)] == 2)
#define KEY_HELD(K) (inp_data.key.states[KEY(K)] == 3)
#define BTN(B) GLFW_MOUSE_BUTTON_ ## B
#define BTN_DOWN(B) (inp_data.btn.states[BTN(B)] == 1)
#define BTN_UP(B) (inp_data.btn.states[BTN(B)] == 2)
#define BTN_HELD(B) (inp_data.btn.states[BTN(B)] == 3)
#define MOUSE_POS (inp_data.mouse.pos)
#define MOUSE_D (inp_data.mouse.delta)
#define PAD(B) GLFW_GAMEPAD_BUTTON_ ## B
#define PAD_DOWN(B) (inp_data.pad.states[PAD(B)] == 1)
#define PAD_UP(B) (inp_data.pad.states[PAD(B)] == 2)
#define PAD_HELD(B) (inp_data.pad.states[PAD(B)] == 3)
#define JOY_STICK_L (inp_data.joy.stick_l)
#define JOY_STICK_R (inp_data.joy.stick_r)
#define JOY_TRIGG_L (inp_data.joy.trigg_l)
#define JOY_TRIGG_R (inp_data.joy.trigg_r)
void inp_key_init(const int *key_handles, size_t key_count);
void inp_btn_init(const int *btn_handles, size_t btn_count);
void inp_pad_init(const int *pad_handles, size_t pad_count);
/*
* User callback; must be implemented by consumer (you)
* if txtquad was compiled with INP_TEXT
*/
__attribute__((weak))
void inp_ev_text(unsigned unicode);
/*
* Internal
*/
#define INP_DATA_STRUCT(T) \
struct { \
const int *handles; \
size_t count; \
unsigned char states[GLFW_ ## T ## _LAST + 1]; \
}
extern struct Input {
struct {
v2 pos;
v2 delta;
} mouse;
struct {
v2 stick_l;
v2 stick_r;
float trigg_l;
float trigg_r;
} joy;
INP_DATA_STRUCT(KEY) key;
INP_DATA_STRUCT(MOUSE_BUTTON) btn;
INP_DATA_STRUCT(GAMEPAD_BUTTON) pad;
} inp_data;
#undef INP_DATA_STRUCT
void inp_update(GLFWwindow *win);
#endif