shengine pre-release
shengine by mrsinho
Loading...
Searching...
No Matches
shWindow.h
Go to the documentation of this file.
1/**
2 * @file shWindow.h
3 * @brief Handling window-related functionalities in the `shengine` framework.
4 *
5 * The shWindow.h file contains structures and functions related to handling windows in the `shengine` framework.
6 */
7
8#ifndef SH_WINDOW_H
9#define SH_WINDOW_H
10
11#ifdef __cplusplus
12extern "C" {
13#endif//__cplusplus
14
15#define GLFW_INCLUDE_NONE
16#define GLFW_INCLUDE_VULKAN
17#include <GLFW/glfw3.h>
18#include <stdint.h>
19
20
21
22#include "shengine/shInput.h"
23
24
25
26/**
27 * @struct ShInput
28 * @brief Structure representing input in the `shengine` framework.
29 *
30 * The ShInput structure represents input in the `shengine` framework, including properties such as cursor position,
31 * cursor position changes, mouse events, and key events.
32 */
33typedef struct ShInput {
34 float cursor_pos_x; /**< X-coordinate of the cursor position. */
35 float cursor_pos_y; /**< Y-coordinate of the cursor position. */
36 float d_cursor_pos_x; /**< Change in the X-coordinate of the cursor position. */
37 float d_cursor_pos_y; /**< Change in the Y-coordinate of the cursor position. */
38 shMouseEvents mouse_events; /**< Mouse events. */
39 shMouseEvents d_mouse_events; /**< Change in mouse events. */
40 shKeyEvents key_events; /**< Key events. */
41 shKeyEvents d_key_events; /**< Change in key events. */
43
44
45
46/**
47 * @struct ShWindow
48 * @brief Structure representing a window in the `shengine` framework.
49 *
50 * The ShWindow structure represents a window in the `shengine` framework, including properties such as the GLFW window,
51 * default cursors, cursor icons, width, height, title, instance extensions, instance extension count, input, and surface
52 * resize status.
53 */
54typedef struct ShWindow {
55 GLFWwindow* window; /**< GLFW window. */
56 GLFWcursor* default_cursors[4]; /**< Default cursors. */
57 int32_t default_cursor_icons[4]; /**< Default cursor icons. */
58 uint32_t width; /**< Width of the window. */
59 uint32_t height; /**< Height of the window. */
60 const char* title; /**< Title of the window. */
61 const char** pp_instance_extensions; /**< Instance extensions. */
62 uint32_t instance_extension_count; /**< Instance extension count. */
63 ShInput input; /**< Input structure. */
64 uint8_t surface_resize_pending; /**< Surface resize status. */
66
67
68
69typedef struct ShEngine ShEngine;
70
71
72
73/**
74 * @brief Sets up a window in the `shengine` framework.
75 *
76 * @param title Title of the window.
77 * @param p_window Valid pointer to a @ref ShWindow structure.
78 * @return 1 on success, 0 on failure.
79 */
80extern uint8_t shWindowSetup(
81 const char* title,
82 ShWindow* p_window
83);
84
85/**
86 * @def shSetCursor
87 * @brief Macro to set the cursor of a GLFW window.
88 *
89 * The shSetCursor macro sets the cursor of a GLFW window to a specified cursor.
90 *
91 * Example:
92 * @code
93 * shSetCursor(glfw_window, glfw_cursor)
94 * @endcode
95 *
96 * @param glfw_window GLFW window.
97 * @param glfw_cursor GLFW cursor.
98 */
99#define shSetCursor(glfw_window, glfw_cursor)\
100 glfwSetCursor(glfw_window, glfw_cursor)
101
102/**
103 * @def shPollEvents
104 * @brief Macro to poll events in the GLFW window.
105 *
106 * The shPollEvents macro polls events in the GLFW window.
107 */
108#define shPollEvents glfwPollEvents
109
110/**
111 * @def shWaitEvents
112 * @brief Macro to wait for events in the GLFW window.
113 *
114 * The shWaitEvents macro waits for events in the GLFW window.
115 */
116#define shWaitEvents glfwWaitEvents
117
118/**
119 * @brief Clears the contents of a window in the `shengine` framework.
120 *
121 * @param p_window Valid pointer to a @ref ShWindow structure.
122 * @return 1 on success, 0 on failure.
123 */
124extern uint8_t shClearWindow(
125 ShWindow* p_window
126);
127
128/**
129 * @def shIsWindowActive
130 * @brief Macro to check if a window is active.
131 *
132 * The shIsWindowActive macro checks if a GLFW window is active.
133 *
134 * @param _window ShWindow structure to check for activity.
135 * @return True if the window is active, false otherwise.
136 */
137#define shIsWindowActive(_window)\
138 (!glfwWindowShouldClose((_window).window))
139
140/**
141 * @brief Creates a surface for the `shengine` module using the window.
142 *
143 * The `shWindowCreateSurface` function creates a surface for the `shengine` module using the window.
144 *
145 * @param p_engine Pointer to a valid @ref ShEngine structure.
146 * @return An integer indicating the success (1) or failure (0) of creating the window surface.
147 */
148extern uint8_t shWindowCreateSurface(
149 ShEngine* p_engine
150);
151
152/**
153 * @brief Updates input for the specified window.
154 *
155 * The `shUpdateInput` function updates input for the specified ShWindow.
156 *
157 * @param p_window Pointer to the ShWindow structure to update input.
158 * @return An integer indicating the success (1) or failure (0) of updating input.
159 */
160extern uint8_t shUpdateInput(
161 ShWindow* p_window
162);
163
164/**
165 * @brief Retrieves the size of the specified window.
166 *
167 * The `shGetWindowSize` function retrieves the size of the specified ShWindow.
168 *
169 * @param p_window Pointer to the ShWindow structure to get the size.
170 * @return An integer indicating the success (1) or failure (0) of retrieving the window size.
171 */
172extern uint8_t shGetWindowSize(
173 ShWindow* p_window
174);
175
176/**
177 * @brief Updates the specified window within the `shengine` module.
178 *
179 * The `shUpdateWindow` function updates the specified ShWindow within `shengine` module.
180 *
181 * @param p_engine Pointer to a valid @ref ShEngine structure.
182 * @return An integer indicating the success (1) or failure (0) of updating the window.
183 */
184extern uint8_t shUpdateWindow(
185 ShEngine* p_engine
186);
187
188
189
190/**
191 * @brief Checks if a key is pressed in a window.
192 *
193 * @param window Valid pointer to a @ref ShWindow structure.
194 * @param key Key code to check.
195 * @return True if the key is pressed, false otherwise.
196 */
197static uint8_t shIsKeyPressed(const ShWindow window, const uint32_t key) {
198 return window.input.d_key_events[key] == GLFW_PRESS;
199}
200
201/**
202 * @brief Checks if a key is down in a window.
203 *
204 * @param window Valid pointer to a @ref ShWindow structure.
205 * @param key Key code to check.
206 * @return True if the key is down, false otherwise.
207 */
208static uint8_t shIsKeyDown(const ShWindow window, const uint32_t key) {
209 return window.input.key_events[key] == GLFW_PRESS;
210}
211
212/**
213 * @brief Checks if a key is released in a window.
214 *
215 * @param window Valid pointer to a @ref ShWindow structure.
216 * @param key Key code to check.
217 * @return True if the key is released, false otherwise.
218 */
219static uint8_t shIsKeyReleased(const ShWindow window, const uint32_t key) {
220 return window.input.key_events[key] == GLFW_RELEASE;
221}
222
223/**
224 * @brief Checks if a key is repeated in a window.
225 *
226 * @param window Valid pointer to a @ref ShWindow structure.
227 * @param key Key code to check.
228 * @return True if the key is repeated, false otherwise.
229 */
230static uint8_t shIsKeyRepeated(const ShWindow window, const uint32_t key) {
231 return window.input.key_events[key] == GLFW_REPEAT;
232}
233
234/**
235 * @brief Checks if a mouse button is pressed in a window.
236 *
237 * @param window Valid pointer to a @ref ShWindow structure.
238 * @param button Mouse button code to check.
239 * @return True if the mouse button is pressed, false otherwise.
240 */
241static uint8_t shIsMouseButtonPressed(const ShWindow window, const uint32_t button) {
242 return window.input.d_mouse_events[button] == GLFW_PRESS;
243}
244
245/**
246 * @brief Checks if a mouse button is down in a window.
247 *
248 * @param window Valid pointer to a @ref ShWindow structure.
249 * @param button Mouse button code to check.
250 * @return True if the mouse button is down, false otherwise.
251 */
252static uint8_t shIsMouseButtonDown(const ShWindow window, const uint32_t button) {
253 return window.input.mouse_events[button] == GLFW_PRESS;
254}
255
256/**
257 * @brief Checks if a mouse button is released in a window.
258 *
259 * @param window Valid pointer to a @ref ShWindow structure.
260 * @param button Mouse button code to check.
261 * @return True if the mouse button is released, false otherwise.
262 */
263static uint8_t shIsMouseButtonReleased(const ShWindow window, const uint32_t button) {
264 return window.input.mouse_events[button] == GLFW_RELEASE;
265}
266
267/**
268 * @brief Checks if a mouse button is repeated in a window.
269 *
270 * @param window Valid pointer to a @ref ShWindow structure.
271 * @param button Mouse button code to check.
272 * @return True if the mouse button is repeated, false otherwise.
273 */
274static uint8_t shIsMouseButtonRepeated(const ShWindow window, const uint32_t button) {
275 return window.input.mouse_events[button] == GLFW_REPEAT;
276}
277
278
279
280#ifdef __cplusplus
281}
282#endif//__cplusplus
283
284#endif//SH_WINDOW_H
int8_t shKeyEvents[SH_KEY_LAST+1]
Definition shInput.h:154
int8_t shMouseEvents[SH_MOUSE_BUTTON_8+1]
Definition shInput.h:169
uint8_t shWindowCreateSurface(ShEngine *p_engine)
Creates a surface for the shengine module using the window.
Definition shWindow.c:68
uint8_t shGetWindowSize(ShWindow *p_window)
Retrieves the size of the specified window.
Definition shWindow.c:98
uint8_t shWindowSetup(const char *title, ShWindow *p_window)
Sets up a window in the shengine framework.
Definition shWindow.c:13
uint8_t shUpdateWindow(ShEngine *p_engine)
Updates the specified window within the shengine module.
Definition shWindow.c:117
uint8_t shClearWindow(ShWindow *p_window)
Clears the contents of a window in the shengine framework.
Definition shWindow.c:57
uint8_t shUpdateInput(ShWindow *p_window)
Updates input for the specified window.
Definition shWindow.c:81
Represents the ShEngine structure, which is the main instance of the engine.
Definition shEngine.h:78
ShWindow window
Definition shEngine.h:80
Structure representing input in the shengine framework.
Definition shWindow.h:33
float cursor_pos_x
Definition shWindow.h:34
shMouseEvents d_mouse_events
Definition shWindow.h:39
shKeyEvents key_events
Definition shWindow.h:40
shMouseEvents mouse_events
Definition shWindow.h:38
shKeyEvents d_key_events
Definition shWindow.h:41
float d_cursor_pos_y
Definition shWindow.h:37
float cursor_pos_y
Definition shWindow.h:35
float d_cursor_pos_x
Definition shWindow.h:36
Structure representing a window in the shengine framework.
Definition shWindow.h:54
uint32_t height
Definition shWindow.h:59
const char ** pp_instance_extensions
Definition shWindow.h:61
GLFWwindow * window
Definition shWindow.h:55
uint8_t surface_resize_pending
Definition shWindow.h:64
int32_t default_cursor_icons[4]
Definition shWindow.h:57
GLFWcursor * default_cursors[4]
Definition shWindow.h:56
ShInput input
Definition shWindow.h:63
uint32_t width
Definition shWindow.h:58
const char * title
Definition shWindow.h:60
uint32_t instance_extension_count
Definition shWindow.h:62