-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevents.h
162 lines (136 loc) · 3 KB
/
events.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
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
#pragma once
#include "common.h"
#include "opengl.h"
#include <GLFW/glfw3.h>
enum Event_Type : u32
{
EVENT_UNINITIALIZED = 0,
EVENT_KEYBOARD = 1,
EVENT_TEXT_INPUT = 2,
EVENT_MOUSE_V_WHEEL = 3,
EVENT_MOUSE_H_WHEEL = 4,
};
enum Key_Current_State : u32
{
KSTATE_NONE = 0x0,
KSTATE_DOWN = 0x1,
KSTATE_START = 0x4,
KSTATE_END = 0x8,
};
// @Important: Not Unicode's compliant
enum Key_Code : u32
{
CODE_UNKNOWN = 0,
CODE_BACKSPACE ,// = 8,
CODE_TAB ,// = 9,
CODE_ENTER ,// = 13,
CODE_ESCAPE ,// = 27,
CODE_SPACEBAR ,// = 32,
// The letters A-Z live in here as well and may be returned by keyboard events.
// The ASCII characters are currently not mapped to value
CODE_0,
CODE_1,
CODE_2,
CODE_3,
CODE_4,
CODE_5,
CODE_6,
CODE_7,
CODE_8,
CODE_9,
CODE_A,
CODE_B,
CODE_C,
CODE_D,
CODE_E,
CODE_F,
CODE_G,
CODE_H,
CODE_I,
CODE_J,
CODE_K,
CODE_L,
CODE_M,
CODE_N,
CODE_O,
CODE_P,
CODE_Q,
CODE_R,
CODE_S,
CODE_T,
CODE_U,
CODE_V,
CODE_W,
CODE_X,
CODE_Y,
CODE_Z,
CODE_DELETE ,// = 127,
//
CODE_ARROW_UP ,// = 128,
CODE_ARROW_DOWN ,// = 129,
CODE_ARROW_LEFT ,// = 130,
CODE_ARROW_RIGHT ,// = 131,
//
CODE_PAGE_UP ,// = 132,
CODE_PAGE_DOWN ,// = 133,
//
CODE_HOME ,// = 134,
CODE_END ,// = 135,
//
CODE_INSERT ,// = 136,
//
CODE_PAUSE ,// = 137,
CODE_SCROLL_LOCK ,// = 138,
CODE_ALT,
CODE_CTRL,
CODE_SHIFT,
CODE_F1,
CODE_F2,
CODE_F3,
CODE_F4,
CODE_F5,
CODE_F6,
CODE_F7,
CODE_F8,
CODE_F9,
CODE_F10,
CODE_F11,
CODE_F12,
CODE_MOUSE_RIGHT,
CODE_MOUSE_LEFT,
CODE_TOTAL_COUNT
};
struct Event
{
bool shift_pressed = false;
bool ctrl_pressed = false;
bool alt_pressed = false;
Event_Type type = EVENT_UNINITIALIZED;
// If EVENT_KEYBOARD:
u32 key_pressed;
Key_Code key_code = CODE_UNKNOWN;
bool repeat = false;
// If EVENT_TEXT_INPUT:
u32 utf32;
// If KEYBOARD event that also generated TEXT_INPUT events, this will tell
// you how many TEXT_INPUT events after this KEYBOARD event were generated.
u16 text_input_count;
// Mouse events
i32 typical_wheel_delta;
i32 wheel_delta;
};
struct Wheel_Delta
{
i32 vertical = 0;
i32 horizontal = 0;
};
// Per-frame mouse deltas:
extern i32 mouse_delta_x;
extern i32 mouse_delta_y;
extern Wheel_Delta mouse_wheel_delta;
extern RArr<Event> events_this_frame;
// extern SArr<Key_Current_State, CODE_TOTAL_COUNT> input_button_states;
void input_per_frame_event_and_flag_update();
void hook_our_input_event_system_to_glfw(GLFWwindow *window);
void update_linux_events();
void toggle_fullscreen();