-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinput.h
More file actions
269 lines (238 loc) · 9.07 KB
/
Copy pathinput.h
File metadata and controls
269 lines (238 loc) · 9.07 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
#ifndef INPUT_H
#define INPUT_H
#include <GLFW/glfw3.h>
#include <stdbool.h>
#include "common.h"
typedef struct {
double x;
double y;
} Vec2f;
/// CALLBACKS
typedef void (*TextCallback)(unsigned int codepoint);
typedef void (*KeyInputCallback)(int key, int action, int mods);
typedef void (*MouseButtonCallback)(int button, int action, int mods);
typedef void (*CursorPosCallback)(double xpos, double ypos);
typedef void (*ScrollCallback)(double xOffset, double deltaY);
typedef void (*WindowResizeCallback)(int width, int height);
typedef void (*WindowFocusCallback)(int focused);
typedef void (*WindowPosCallback)(int xpos, int ypos);
typedef void (*DropCallback)(int count, const char** paths);
extern TextCallback currentTextCallback;
extern KeyInputCallback currentKeyCallback;
extern MouseButtonCallback currentMouseButtonCallback;
extern CursorPosCallback currentCursorPosCallback;
extern ScrollCallback currentScrollCallback;
extern WindowResizeCallback currentResizeCallback;
extern WindowFocusCallback currentFocusCallback;
extern WindowPosCallback currentWindowPosCallback;
void registerTextCallback(TextCallback callback);
void registerKeyCallback(KeyInputCallback callback);
void registerMouseButtonCallback(MouseButtonCallback callback);
void registerCursorPosCallback(CursorPosCallback callback);
void registerScrollCallback(ScrollCallback callback);
void registerWindowResizeCallback(WindowResizeCallback callback);
void registerWindowFocusCallback(WindowFocusCallback callback);
void registerWindowPosCallback(WindowPosCallback callback);
void registerDropCallback(DropCallback callback);
void internal_char_callback(GLFWwindow* window, unsigned int codepoint);
void internal_key_callback(GLFWwindow* window, int key, int scancode, int action, int mods);
void internal_mouse_button_callback(GLFWwindow* window, int button, int action, int mods);
void internal_cursor_position_callback(GLFWwindow* window, double xpos, double ypos);
void internal_scroll_callback(GLFWwindow* window, double xOffset, double yOffset);
void internal_window_resize_callback(GLFWwindow* window, int width, int height);
void internal_window_focus_callback(GLFWwindow* window, int focused);
void internal_window_pos_callback(GLFWwindow* window, int xpos, int ypos);
void internal_drop_callback(GLFWwindow* window, int count, const char** paths);
void init_input();
void update_input();
int isKeyDown(int key);
int isKeyPressed(int key);
int isKeyReleased(int key);
void getCursorPosition(double* x, double* y);
bool getMouseButton(int button);
Vec2f getMouseDelta();
int isMouseButtonPressed(int button);
int isMouseButtonReleased(int button);
int isMouseButtonDown(int button);
int isGamepadButtonPressed(int button);
int isGamepadButtonDown(int button);
/// Printable keys
#define KEY_SPACE 32
#define KEY_APOSTROPHE 39 /* ' */
#define KEY_COMMA 44 /* , */
#define KEY_MINUS 45 /* - */
#define KEY_PERIOD 46 /* . */
#define KEY_SLASH 47 /* / */
#define KEY_0 48
#define KEY_1 49
#define KEY_2 50
#define KEY_3 51
#define KEY_4 52
#define KEY_5 53
#define KEY_6 54
#define KEY_7 55
#define KEY_8 56
#define KEY_9 57
#define KEY_SEMICOLON 59 /* ; */
#define KEY_EQUAL 61 /* = */
#define KEY_A 65
#define KEY_B 66
#define KEY_C 67
#define KEY_D 68
#define KEY_E 69
#define KEY_F 70
#define KEY_G 71
#define KEY_H 72
#define KEY_I 73
#define KEY_J 74
#define KEY_K 75
#define KEY_L 76
#define KEY_M 77
#define KEY_N 78
#define KEY_O 79
#define KEY_P 80
#define KEY_Q 81
#define KEY_R 82
#define KEY_S 83
#define KEY_T 84
#define KEY_U 85
#define KEY_V 86
#define KEY_W 87
#define KEY_X 88
#define KEY_Y 89
#define KEY_Z 90
#define KEY_LEFT_BRACKET 91 /* [ */
#define KEY_BACKSLASH 92 /* \ */
#define KEY_RIGHT_BRACKET 93 /* ] */
#define KEY_GRAVE_ACCENT 96 /* ` */
#define KEY_WORLD_1 161 /* non-US #1 */
#define KEY_WORLD_2 162 /* non-US #2 */
/// Function keys
#define KEY_ESCAPE 256
#define KEY_ENTER 257
#define KEY_TAB 258
#define KEY_BACKSPACE 259
#define KEY_INSERT 260
#define KEY_DELETE 261
#define KEY_RIGHT 262
#define KEY_LEFT 263
#define KEY_DOWN 264
#define KEY_UP 265
#define KEY_PAGE_UP 266
#define KEY_PAGE_DOWN 267
#define KEY_HOME 268
#define KEY_END 269
#define KEY_CAPS_LOCK 280
#define KEY_SCROLL_LOCK 281
#define KEY_NUM_LOCK 282
#define KEY_PRINT_SCREEN 283
#define KEY_PAUSE 284
#define KEY_F1 290
#define KEY_F2 291
#define KEY_F3 292
#define KEY_F4 293
#define KEY_F5 294
#define KEY_F6 295
#define KEY_F7 296
#define KEY_F8 297
#define KEY_F9 298
#define KEY_F10 299
#define KEY_F11 300
#define KEY_F12 301
#define KEY_F13 302
#define KEY_F14 303
#define KEY_F15 304
#define KEY_F16 305
#define KEY_F17 306
#define KEY_F18 307
#define KEY_F19 308
#define KEY_F20 309
#define KEY_F21 310
#define KEY_F22 311
#define KEY_F23 312
#define KEY_F24 313
#define KEY_F25 314
#define KEY_KP_0 320
#define KEY_KP_1 321
#define KEY_KP_2 322
#define KEY_KP_3 323
#define KEY_KP_4 324
#define KEY_KP_5 325
#define KEY_KP_6 326
#define KEY_KP_7 327
#define KEY_KP_8 328
#define KEY_KP_9 329
#define KEY_KP_DECIMAL 330
#define KEY_KP_DIVIDE 331
#define KEY_KP_MULTIPLY 332
#define KEY_KP_SUBTRACT 333
#define KEY_KP_ADD 334
#define KEY_KP_ENTER 335
#define KEY_KP_EQUAL 336
#define KEY_LEFT_SHIFT 340
#define KEY_LEFT_CONTROL 341
#define KEY_LEFT_ALT 342
#define KEY_LEFT_SUPER 343
#define KEY_RIGHT_SHIFT 344
#define KEY_RIGHT_CONTROL 345
#define KEY_RIGHT_ALT 346
#define KEY_RIGHT_SUPER 347
#define KEY_MENU 348
#define KEY_LAST KEY_MENU
#define KEY_UNKNOWN GLFW_KEY_UNKNOWN
/// MODIFIERS
#define MOD_SHIFT GLFW_MOD_SHIFT
#define MOD_CONTROL GLFW_MOD_CONTROL
#define MOD_ALT GLFW_MOD_ALT
#define MOD_SUPER GLFW_MOD_SUPER
#define MOD_CAPS_LOCK GLFW_MOD_CAPS_LOCK
#define MOD_NUM_LOCK GLFW_MOD_NUM_LOCK
/// KEY STATES
#define RELEASE GLFW_RELEASE
#define PRESS GLFW_PRESS
#define REPEAT GLFW_REPEAT
/// CURSOR
#define CURSOR GLFW_CURSOR
#define CURSOR_NORMAL GLFW_CURSOR_NORMAL
#define CURSOR_DISABLED GLFW_CURSOR_DISABLED
/// GAMEPAD
#define MOUSE_BUTTON_1 0
#define MOUSE_BUTTON_2 1
#define MOUSE_BUTTON_3 2
#define MOUSE_BUTTON_4 3
#define MOUSE_BUTTON_5 4
#define MOUSE_BUTTON_6 5
#define MOUSE_BUTTON_7 6
#define MOUSE_BUTTON_8 7
#define MOUSE_BUTTON_LAST MOUSE_BUTTON_8
#define MOUSE_BUTTON_LEFT MOUSE_BUTTON_1
#define MOUSE_BUTTON_RIGHT MOUSE_BUTTON_2
#define MOUSE_BUTTON_MIDDLE MOUSE_BUTTON_3
#define GAMEPAD_BUTTON_A 0
#define GAMEPAD_BUTTON_B 1
#define GAMEPAD_BUTTON_X 2
#define GAMEPAD_BUTTON_Y 3
#define GAMEPAD_BUTTON_LEFT_BUMPER 4
#define GAMEPAD_BUTTON_RIGHT_BUMPER 5
#define GAMEPAD_BUTTON_BACK 6
#define GAMEPAD_BUTTON_START 7
#define GAMEPAD_BUTTON_GUIDE 8
#define GAMEPAD_BUTTON_LEFT_THUMB 9
#define GAMEPAD_BUTTON_RIGHT_THUMB 10
#define GAMEPAD_BUTTON_DPAD_UP 11
#define GAMEPAD_BUTTON_DPAD_RIGHT 12
#define GAMEPAD_BUTTON_DPAD_DOWN 13
#define GAMEPAD_BUTTON_DPAD_LEFT 14
#define GAMEPAD_BUTTON_LAST GAMEPAD_BUTTON_DPAD_LEFT
#define GAMEPAD_BUTTON_CROSS GAMEPAD_BUTTON_A
#define GAMEPAD_BUTTON_CIRCLE GAMEPAD_BUTTON_B
#define GAMEPAD_BUTTON_SQUARE GAMEPAD_BUTTON_X
#define GAMEPAD_BUTTON_TRIANGLE GAMEPAD_BUTTON_Y
#define GAMEPAD_AXIS_LEFT_X 0
#define GAMEPAD_AXIS_LEFT_Y 1
#define GAMEPAD_AXIS_RIGHT_X 2
#define GAMEPAD_AXIS_RIGHT_Y 3
#define GAMEPAD_AXIS_LEFT_TRIGGER 4
#define GAMEPAD_AXIS_RIGHT_TRIGGER 5
#define GAMEPAD_AXIS_LAST GAMEPAD_AXIS_RIGHT_TRIGGER
#endif