Zen 0.3.0
Loading...
Searching...
No Matches
ZEN_Event.h
1#pragma once
2
3#include <zen/zen_pch.h>
4
5#include <zen/inputs/ZEN_KeyCodes.h>
6#include <zen/inputs/ZEN_MouseCodes.h>
7
8namespace Zen {
9 enum class EventType : uint8_t {
10 None = 0,
11 WindowClose,
13 WindowFocus,
14 WindowLostFocus,
16 KeyPressed,
17 KeyReleased,
18 MouseButtonPressed,
19 MouseButtonReleased,
20 MouseMoved,
21 MouseScrolled,
22 TextInput,
23 Quit
24 };
25
26 enum class EventCategory : uint32_t {
27 None = 0,
28 Application = 1 << 0,
29 Input = 1 << 1,
30 Keyboard = 1 << 2,
31 Mouse = 1 << 3,
32 Text = 1 << 4
33 };
34
35 constexpr EventCategory operator|(EventCategory a, EventCategory b) {
36 return EventCategory((uint32_t)a | (uint32_t)b);
37 }
38
39 constexpr EventCategory operator&(EventCategory a, EventCategory b) {
40 return EventCategory((uint32_t)a & (uint32_t)b);
41 }
42
43 constexpr bool any(EventCategory c, EventCategory mask) {
44 return ((uint32_t)c & (uint32_t)mask) != 0;
45 }
46
47 // FOR EVENT TYPE PAYLOAD STUFF
48 struct EventHeader {
49 EventType type;
50 EventCategory category;
51 };
52
53 struct WindowResize {
54 int width, height;
55 };
56
57 struct WindowMoved {
58 int x, y;
59 };
60
61 struct KeyPayload {
62 ScanCode scancode;
63 bool repeat;
64 KeyModifier mods;
65 };
66
68 float x, y, dx, dy;
69 MouseButtonState state;
70 };
71
73 MouseButton button;
74 uint8_t clicks;
75 float x, y;
76 };
77
79 float x, y, pos_x, pos_y;
80 int scrl_length, scrl_height;
81 };
82
84 char32_t codepoint;
85 };
86
87 struct ZenEvent {
88 EventHeader header;
89 union {
90 WindowResize windowResize;
91 WindowMoved windowMoved;
92 KeyPayload key;
93 MouseMovePayload mouseMove;
94 MouseButtonPayload mouseButton;
95 MouseWheelPayload mouseWheel;
96 TextInputPayload textInput;
97 };
98 };
99
100 ZenEvent TranslateEvent(const SDL_Event &e);
101} // namespace Zen