-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInput.h
184 lines (161 loc) · 4.24 KB
/
Input.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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#ifndef HOMEWORK_INPUT_H
#define HOMEWORK_INPUT_H
/**
* @file Input.h
* @brief Structures and functions related to input
* @version 0.1
* @date 2019-11-05
*
* @copyright Copyright (c) 2019
*
*/
#include <SDL.h>
#include <stdbool.h>
#include "Graphics.h"
/**
* @brief State of a button
*
*/
typedef struct ButtonState {
bool isPressed; /**< Was button just pressed */
bool isHeld; /**< Is button held */
bool isReleased; /**< Was button just released */
} ButtonState;
/**
* @brief Enum containing the different modifier buttons
*/
typedef enum ModifierButton {
MOD_CTRL = 0, /**< Ctrl key */
MOD_SHIFT = 1, /**< Shift key */
MOD_ALT = 2 /**< Alt key */
} ModifierButton;
/**
* @brief Struct holding input information
*/
typedef struct Input {
ButtonState buttons[SDL_NUM_SCANCODES]; /**< Button states */
ButtonState mouseButtons[5]; /**< Mouse states */
uint8_t mouseClicks[5]; /**< Number of clicks on each button */
ButtonState modifierButtons[3]; /**< Modifier button states */
int mouseDeltaX, /**< Mouse delta in the X direction */
mouseDeltaY; /**< Mouse delta in the Y direction */
int mouseX, /**< Mouse X position */
mouseY; /**< Mouse Y position */
int mouseWheelX, /**< Mouse wheel X movement */
mouseWheelY; /**< Mouse wheel Y movement */
} Input;
/**
* @brief Initialize input struct
*
* @param input Input to initialize
*/
void input_init(Input *input);
/**
* @brief Start a new event handling
*
* @param input Input struct to reset
*/
void input_reset_events(Input *input);
/**
* @brief Handle event
*
* @param input Input struct to write information to
* @param e Event to handle
*/
void input_handle_event(Input *input, SDL_Event *e);
/**
* @brief Get the state of the given key
*
* @param input Input struct to get information from
* @param code Scancode of the key
* @return Resulting state
*/
ButtonState input_get_key(Input *input, SDL_Scancode code);
/**
* @brief Get the state of the given modifier button
*
* @param input Input struct to get information from
* @param btn Code of the button
* @return Resulting state
*/
ButtonState input_get_mod(Input *input, ModifierButton btn);
/**
* @brief Get the state of the given mouse button
*
* @param input Input struct to get information from
* @param id Id of the mouse button
* @return Resulting state
*/
ButtonState input_get_mouse_button(Input *input, int id);
/**
* @brief Get mouse X position
*
* @param input Input struct to get information from
* @return int Mouse X position
*/
int input_get_mouse_x(Input *input);
/**
* @brief Get mouse Y position
*
* @param input Input struct to get information from
* @return int Mouse Y position
*/
int input_get_mouse_y(Input *input);
/**
* @brief Get the mouse position as a point
*
* @param input Input struct to get information from
* @return Mouse position
*/
Point input_get_mouse_pos(Input *input);
/**
* @brief Get the mouse delta X between this and the last frame
*
* @param input Input struct to get information from
* @return int Mouse dleta X
*/
int input_get_mouse_delta_x(Input *input);
/**
* @brief Get the mouse delta Y between this and the last frame
*
* @param input Input struct to get information from
* @return int Mouse delta Y
*/
int input_get_mouse_delta_y(Input *input);
/**
* @brief Get the mouse delta as a vector
*
* @param input Input struct to get information from
* @return Vec Mouse delta
*/
Vec input_get_mouse_delta(Input *input);
/**
* @brief Get the mouse wheel movement in the horizontal direction
*
* @param input Input struct to get information from
* @return int Mouse wheel X
*/
int input_get_mouse_wheel_x(Input *input);
/**
* @brief Get the mouse wheel movement in the vertical direction
*
* @param input Input struct to get information from
* @return int Mouse wheel Y
*/
int input_get_mouse_wheel_y(Input *input);
/**
* @brief Get the mouse wheel as a vector
*
* @param input Input struct to get information from
* @return Vec Mouse wheel delta
*/
Vec input_get_mouse_wheel(Input *input);
/**
* @brief Check, if the mouse is over a rect in screen space
*
* @param input Input to get t
* @param r Rect to check
* @return If the mouse is over the rect or not
*/
bool input_mouse_over(Input *input, SDL_Rect r);
#endif //HOMEWORK_INPUT_H