aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/api/Event.h
blob: 7d4df213a4e4e0a197746fe534b3772161adef5a (plain)
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
#pragma once
// TODO discussing the location of these events

#include <string>

#include "types.h"

#include "KeyCodes.h"

namespace crepe {

/**
 * \brief Base struct for all event types in the system.
 */
struct Event {};

/**
 * \brief Event triggered when a key is pressed.
 */
struct KeyPressEvent : public Event {
	//! false if first time press, true if key is repeated
	bool repeat = false;

	//! The key that was pressed.
	Keycode key = Keycode::NONE;
};

/**
 * \brief Event triggered when a key is released.
 */
struct KeyReleaseEvent : public Event {
	//! The key that was released.
	Keycode key = Keycode::NONE;
};

/**
 * \brief Event triggered when a mouse button is pressed.
 */
struct MousePressEvent : public Event {
	//! mouse position in world coordinates (game units).
	vec2 mouse_pos = {0, 0};

	//! The mouse button that was pressed.
	MouseButton button = MouseButton::NONE;
};

/**
 * \brief Event triggered when a mouse button is clicked (press and release).
 */
struct MouseClickEvent : public Event {
	//! mouse position in world coordinates (game units).
	vec2 mouse_pos = {0, 0};

	//! The mouse button that was clicked.
	MouseButton button = MouseButton::NONE;
};

/**
 * \brief Event triggered when a mouse button is released.
 */
struct MouseReleaseEvent : public Event {
	//! mouse position in world coordinates (game units).
	vec2 mouse_pos = {0, 0};

	//! The mouse button that was released.
	MouseButton button = MouseButton::NONE;
};

/**
 * \brief Event triggered when the mouse is moved.
 */
struct MouseMoveEvent : public Event {
	//! mouse position in world coordinates (game units).
	vec2 mouse_pos = {0, 0};
	//! The change in mouse position relative to the last position (in pixels).
	ivec2 mouse_delta = {0, 0};
};

/**
 * \brief Event triggered when the mouse is moved.
 */
struct MouseScrollEvent : public Event {
	//! mouse position in world coordinates (game units) when the scroll happened.
	vec2 mouse_pos = {0, 0};
	//! scroll direction (-1 = down, 1 = up)
	int scroll_direction = 0;
	//! scroll amount in y axis (from and away from the person).
	float scroll_delta = 0;
};

/**
 * \brief Event triggered to indicate the application is shutting down.
 */
struct ShutDownEvent : public Event {};

/**
 * \brief Event triggered to indicate the window is overlapped by another window.
 * 
 * When two windows overlap the bottom window gets distorted and that window has to be redrawn.
 */
struct WindowExposeEvent : public Event {};

/**
 * \brief Event triggered to indicate the window is resized.
 */
struct WindowResizeEvent : public Event {
	//! new window dimensions
	ivec2 dimensions = {0, 0};
};

/**
 * \brief Event triggered to indicate the window is moved.
 */
struct WindowMoveEvent : public Event {
	//! The change in position relative to the last position (in pixels).
	ivec2 delta_move = {0, 0};
};

/**
 * \brief Event triggered to indicate the window is minimized.
 */
struct WindowMinimizeEvent : public Event {};

/**
 * \brief Event triggered to indicate the window is maximized
 */
struct WindowMaximizeEvent : public Event {};

/**
 * \brief Event triggered to indicate the window gained focus
 * 
 * This event is triggered when the window receives focus, meaning it becomes the active window
 * for user interaction.
 */
struct WindowFocusGainEvent : public Event {};

/**
 * \brief Event triggered to indicate the window lost focus
 * 
 * This event is triggered when the window loses focus, meaning it is no longer the active window
 * for user interaction.
 */
struct WindowFocusLostEvent : public Event {};

} // namespace crepe