forked from cocos/cocos-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEngineEvents.h
More file actions
359 lines (329 loc) · 8.59 KB
/
Copy pathEngineEvents.h
File metadata and controls
359 lines (329 loc) · 8.59 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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
/****************************************************************************
Copyright (c) 2022-2023 Xiamen Yaji Software Co., Ltd.
http://www.cocos.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#pragma once
#include <memory>
#include "base/std/container/string.h"
#include "base/std/container/unordered_map.h"
#include "base/std/container/vector.h"
#include "core/event/EventBus.h"
namespace cc {
class ISystemWindow;
enum class OSEventType {
KEYBOARD_OSEVENT = 0,
TOUCH_OSEVENT = 1,
MOUSE_OSEVENT = 2,
CUSTOM_OSEVENT = 3,
DEVICE_OSEVENT = 4,
WINDOW_OSEVENT = 5,
APP_OSEVENT = 6,
CONTROLLER_OSEVENT = 7,
UNKNOWN_OSEVENT = 8
};
class WindowEvent {
public:
WindowEvent() = default;
enum class Type {
QUIT = 0,
SHOW,
RESTORED,
SIZE_CHANGED,
RESIZED,
HIDDEN,
MINIMIZED,
CLOSE,
ENTER,
LEAVE,
UNKNOWN,
};
Type type = Type::UNKNOWN;
int width = 0;
int height = 0;
uint32_t windowId = 0;
};
// Touch event related
class TouchInfo {
public:
float x = 0;
float y = 0;
int index = 0;
TouchInfo(float x, float y, int index)
: x(x),
y(y),
index(index) {}
};
class TouchEvent {
public:
TouchEvent() = default;
enum class Type {
BEGAN,
MOVED,
ENDED,
CANCELLED,
UNKNOWN
};
ccstd::vector<TouchInfo> touches;
Type type = Type::UNKNOWN;
uint32_t windowId = 0;
};
enum class StickKeyCode {
UNDEFINE = 0,
A,
B,
X,
Y,
L1,
R1,
MINUS,
PLUS,
L3,
R3,
MENU,
START,
TRIGGER_LEFT,
TRIGGER_RIGHT,
};
enum class StickAxisCode {
UNDEFINE = 0,
X,
Y,
LEFT_STICK_X,
LEFT_STICK_Y,
RIGHT_STICK_X,
RIGHT_STICK_Y,
L2,
R2,
LEFT_GRIP,
RIGHT_GRIP,
};
enum class StickTouchCode {
UNDEFINE = 0,
A,
B,
X,
Y,
LEFT_TRIGGER,
RIGHT_TRIGGER,
LEFT_THUMBSTICK,
RIGHT_THUMBSTICK,
};
struct ControllerInfo {
struct AxisInfo {
StickAxisCode axis{StickAxisCode::UNDEFINE};
float value{0.F};
AxisInfo(StickAxisCode axis, float value) : axis(axis), value(value) {}
};
struct ButtonInfo {
StickKeyCode key{StickKeyCode::UNDEFINE};
bool isPress{false};
ButtonInfo(StickKeyCode key, bool isPress) : key(key), isPress(isPress) {}
};
struct TouchInfo {
StickTouchCode key{StickTouchCode::UNDEFINE};
float value{0.F};
TouchInfo(StickTouchCode key, float value) : key(key), value(value) {}
};
int napdId{0};
std::vector<AxisInfo> axisInfos;
std::vector<ButtonInfo> buttonInfos;
std::vector<TouchInfo> touchInfos;
};
struct ControllerEvent {
ControllerEvent() = default;
enum class Type {
GAMEPAD,
HANDLE,
UNKNOWN
};
Type type = Type::UNKNOWN;
ccstd::vector<std::unique_ptr<ControllerInfo>> controllerInfos;
};
struct ControllerChangeEvent {
ccstd::vector<uint32_t> controllerIds;
};
class MouseEvent {
public:
MouseEvent() = default;
enum class Type {
DOWN,
UP,
MOVE,
WHEEL,
UNKNOWN
};
float x = 0.0F;
float y = 0.0F;
float xDelta = 0.0F;
float yDelta = 0.0F;
// The button number that was pressed when the mouse event was fired: Left button=0, middle button=1 (if present), right button=2.
// For mice configured for left handed use in which the button actions are reversed the values are instead read from right to left.
uint16_t button = 0;
Type type = Type::UNKNOWN;
uint32_t windowId = 0;
};
enum class KeyCode {
/**
* @en The back key on mobile phone
* @zh 移动端返回键
*/
MOBILE_BACK = 6,
BACKSPACE = 8,
TAB = 9,
NUM_LOCK = 12,
NUMPAD_ENTER = 20013,
ENTER = 13,
SHIFT_RIGHT = 20016,
SHIFT_LEFT = 16,
CONTROL_LEFT = 17,
CONTROL_RIGHT = 20017,
ALT_RIGHT = 20018,
ALT_LEFT = 18,
PAUSE = 19,
CAPS_LOCK = 20,
ESCAPE = 27,
SPACE = 32,
PAGE_UP = 33,
PAGE_DOWN = 34,
END = 35,
HOME = 36,
ARROW_LEFT = 37,
ARROW_UP = 38,
ARROW_RIGHT = 39,
ARROW_DOWN = 40,
INSERT = 45,
DELETE_KEY = 46, // DELETE has conflict
META_LEFT = 91,
CONTEXT_MENU = 20093,
PRINT_SCREEN = 20094,
META_RIGHT = 93,
NUMPAD_MULTIPLY = 106,
NUMPAD_PLUS = 107,
NUMPAD_MINUS = 109,
NUMPAD_DECIMAL = 110,
NUMPAD_DIVIDE = 111,
SCROLLLOCK = 145,
SEMICOLON = 186,
EQUAL = 187,
COMMA = 188,
MINUS = 189,
PERIOD = 190,
SLASH = 191,
BACKQUOTE = 192,
BRACKET_LEFT = 219,
BACKSLASH = 220,
BRACKET_RIGHT = 221,
QUOTE = 222,
NUMPAD_0 = 10048,
NUMPAD_1 = 10049,
NUMPAD_2 = 10050,
NUMPAD_3 = 10051,
NUMPAD_4 = 10052,
NUMPAD_5 = 10053,
NUMPAD_6 = 10054,
NUMPAD_7 = 10055,
NUMPAD_8 = 10056,
NUMPAD_9 = 10057,
DPAD_UP = 1003,
DPAD_LEFT = 1000,
DPAD_DOWN = 1004,
DPAD_RIGHT = 1001,
DPAD_CENTER = 1005,
// WIN/Command按钮
LGUI = 20300,
RGUI = 20301,
};
class KeyboardEvent {
public:
KeyboardEvent() = default;
enum class Action {
PRESS,
RELEASE,
REPEAT,
UNKNOWN
};
uint32_t windowId = 0;
int key = -1;
Action action = Action::UNKNOWN;
bool altKeyActive = false;
bool ctrlKeyActive = false;
bool metaKeyActive = false;
bool shiftKeyActive = false;
ccstd::string code;
// TODO(mingo): support caps lock?
};
union EventParameterType {
void *ptrVal;
int32_t longVal;
int intVal;
int16_t shortVal;
char charVal;
bool boolVal;
};
class CustomEvent {
public:
CustomEvent() = default;
ccstd::string name;
EventParameterType args[10];
virtual ~CustomEvent() = default; // NOLINT(modernize-use-nullptr)
};
class DeviceEvent {
public:
DeviceEvent() = default;
enum class Type {
MEMORY,
ORIENTATION,
UNKNOWN
};
EventParameterType args[3];
Type type{Type::UNKNOWN}; // NOLINT(modernize-use-nullptr)
};
enum class ScriptEngineEvent {
BEFORE_INIT,
AFTER_INIT,
BEFORE_CLEANUP,
AFTER_CLEANUP,
};
namespace events {
DECLARE_EVENT_BUS(Engine)
DECLARE_BUS_EVENT_ARG0(EnterForeground, Engine)
DECLARE_BUS_EVENT_ARG0(EnterBackground, Engine)
DECLARE_BUS_EVENT_ARG0(WindowEnter, Engine)
DECLARE_BUS_EVENT_ARG0(WindowLeave, Engine)
DECLARE_BUS_EVENT_ARG1(WindowRecreated, Engine, uint32_t /* windowId*/)
DECLARE_BUS_EVENT_ARG1(WindowDestroy, Engine, uint32_t /*windowId*/)
DECLARE_BUS_EVENT_ARG1(WindowEvent, Engine, const cc::WindowEvent &)
DECLARE_BUS_EVENT_ARG1(WindowChanged, Engine, cc::WindowEvent::Type)
DECLARE_BUS_EVENT_ARG0(LowMemory, Engine)
DECLARE_BUS_EVENT_ARG1(Touch, Engine, const cc::TouchEvent &)
DECLARE_BUS_EVENT_ARG1(Mouse, Engine, const cc::MouseEvent &)
DECLARE_BUS_EVENT_ARG1(Keyboard, Engine, const cc::KeyboardEvent &)
DECLARE_BUS_EVENT_ARG1(Controller, Engine, const cc::ControllerEvent &)
DECLARE_BUS_EVENT_ARG1(ControllerChange, Engine, const cc::ControllerChangeEvent &)
DECLARE_BUS_EVENT_ARG1(Tick, Engine, float)
DECLARE_BUS_EVENT_ARG0(BeforeTick, Engine)
DECLARE_BUS_EVENT_ARG0(AfterTick, Engine)
DECLARE_BUS_EVENT_ARG3(Resize, Engine, int, int, uint32_t /* windowId*/)
DECLARE_BUS_EVENT_ARG1(Orientation, Engine, int)
DECLARE_BUS_EVENT_ARG1(PointerLock, Engine, bool)
DECLARE_BUS_EVENT_ARG0(RestartVM, Engine)
DECLARE_BUS_EVENT_ARG0(Close, Engine)
DECLARE_BUS_EVENT_ARG0(SceneLoad, Engine)
DECLARE_BUS_EVENT_ARG1(ScriptEngine, Engine, ScriptEngineEvent)
} // namespace events
} // namespace cc