tgrekov-fdf
HIVE fdf May 2024
Loading...
Searching...
No Matches
MLX42.h
1/* ************************************************************************** */
2/* */
3/* :::::::: */
4/* MLX42.h :+: :+: */
5/* +:+ */
6/* By: W2Wizard <main@w2wizard.dev> +#+ */
7/* +#+ */
8/* Created: 2021/12/28 02:29:06 by W2Wizard #+# #+# */
9/* Updated: 2023/03/30 16:23:19 by ntamayo- ######## odam.nl */
10/* */
11/* ************************************************************************** */
12
30#ifndef MLX42_H
31# define MLX42_H
32# include <stddef.h>
33# include <stdint.h>
34# include <stdbool.h>
35# ifdef __cplusplus
36extern "C" {
37# endif
38
39//= Types =//
40
53typedef enum action
54{
55 MLX_RELEASE = 0,
56 MLX_PRESS = 1,
57 MLX_REPEAT = 2,
58} action_t;
59
72typedef enum modifier_key
73{
74 MLX_SHIFT = 0x0001,
75 MLX_CONTROL = 0x0002,
76 MLX_ALT = 0x0004,
77 MLX_SUPERKEY = 0x0008,
78 MLX_CAPSLOCK = 0x0010,
79 MLX_NUMLOCK = 0x0020,
80} modifier_key_t;
81
88typedef enum mouse_key
89{
90 MLX_MOUSE_BUTTON_LEFT = 0,
91 MLX_MOUSE_BUTTON_RIGHT = 1,
92 MLX_MOUSE_BUTTON_MIDDLE = 2,
93} mouse_key_t;
94
101typedef enum mouse_mode
102{
103 MLX_MOUSE_NORMAL = 0x00034001,
104 MLX_MOUSE_HIDDEN = 0x00034002,
105 MLX_MOUSE_DISABLED = 0x00034003,
106} mouse_mode_t;
107
117typedef enum cursor
118{
119 MLX_CURSOR_ARROW = 0x00036001,
120 MLX_CURSOR_IBEAM = 0x00036002,
121 MLX_CURSOR_CROSSHAIR = 0x00036003,
122 MLX_CURSOR_HAND = 0x00036004,
123 MLX_CURSOR_HRESIZE = 0x00036005,
124 MLX_CURSOR_VRESIZE = 0x00036006,
125} cursor_t;
126
132typedef enum keys
133{
134 MLX_KEY_SPACE = 32,
135 MLX_KEY_APOSTROPHE = 39,
136 MLX_KEY_COMMA = 44,
137 MLX_KEY_MINUS = 45,
138 MLX_KEY_PERIOD = 46,
139 MLX_KEY_SLASH = 47,
140 MLX_KEY_0 = 48,
141 MLX_KEY_1 = 49,
142 MLX_KEY_2 = 50,
143 MLX_KEY_3 = 51,
144 MLX_KEY_4 = 52,
145 MLX_KEY_5 = 53,
146 MLX_KEY_6 = 54,
147 MLX_KEY_7 = 55,
148 MLX_KEY_8 = 56,
149 MLX_KEY_9 = 57,
150 MLX_KEY_SEMICOLON = 59,
151 MLX_KEY_EQUAL = 61,
152 MLX_KEY_A = 65,
153 MLX_KEY_B = 66,
154 MLX_KEY_C = 67,
155 MLX_KEY_D = 68,
156 MLX_KEY_E = 69,
157 MLX_KEY_F = 70,
158 MLX_KEY_G = 71,
159 MLX_KEY_H = 72,
160 MLX_KEY_I = 73,
161 MLX_KEY_J = 74,
162 MLX_KEY_K = 75,
163 MLX_KEY_L = 76,
164 MLX_KEY_M = 77,
165 MLX_KEY_N = 78,
166 MLX_KEY_O = 79,
167 MLX_KEY_P = 80,
168 MLX_KEY_Q = 81,
169 MLX_KEY_R = 82,
170 MLX_KEY_S = 83,
171 MLX_KEY_T = 84,
172 MLX_KEY_U = 85,
173 MLX_KEY_V = 86,
174 MLX_KEY_W = 87,
175 MLX_KEY_X = 88,
176 MLX_KEY_Y = 89,
177 MLX_KEY_Z = 90,
178 MLX_KEY_LEFT_BRACKET = 91,
179 MLX_KEY_BACKSLASH = 92,
180 MLX_KEY_RIGHT_BRACKET = 93,
181 MLX_KEY_GRAVE_ACCENT = 96,
182 MLX_KEY_ESCAPE = 256,
183 MLX_KEY_ENTER = 257,
184 MLX_KEY_TAB = 258,
185 MLX_KEY_BACKSPACE = 259,
186 MLX_KEY_INSERT = 260,
187 MLX_KEY_DELETE = 261,
188 MLX_KEY_RIGHT = 262,
189 MLX_KEY_LEFT = 263,
190 MLX_KEY_DOWN = 264,
191 MLX_KEY_UP = 265,
192 MLX_KEY_PAGE_UP = 266,
193 MLX_KEY_PAGE_DOWN = 267,
194 MLX_KEY_HOME = 268,
195 MLX_KEY_END = 269,
196 MLX_KEY_CAPS_LOCK = 280,
197 MLX_KEY_SCROLL_LOCK = 281,
198 MLX_KEY_NUM_LOCK = 282,
199 MLX_KEY_PRINT_SCREEN = 283,
200 MLX_KEY_PAUSE = 284,
201 MLX_KEY_F1 = 290,
202 MLX_KEY_F2 = 291,
203 MLX_KEY_F3 = 292,
204 MLX_KEY_F4 = 293,
205 MLX_KEY_F5 = 294,
206 MLX_KEY_F6 = 295,
207 MLX_KEY_F7 = 296,
208 MLX_KEY_F8 = 297,
209 MLX_KEY_F9 = 298,
210 MLX_KEY_F10 = 299,
211 MLX_KEY_F11 = 300,
212 MLX_KEY_F12 = 301,
213 MLX_KEY_F13 = 302,
214 MLX_KEY_F14 = 303,
215 MLX_KEY_F15 = 304,
216 MLX_KEY_F16 = 305,
217 MLX_KEY_F17 = 306,
218 MLX_KEY_F18 = 307,
219 MLX_KEY_F19 = 308,
220 MLX_KEY_F20 = 309,
221 MLX_KEY_F21 = 310,
222 MLX_KEY_F22 = 311,
223 MLX_KEY_F23 = 312,
224 MLX_KEY_F24 = 313,
225 MLX_KEY_F25 = 314,
226 MLX_KEY_KP_0 = 320,
227 MLX_KEY_KP_1 = 321,
228 MLX_KEY_KP_2 = 322,
229 MLX_KEY_KP_3 = 323,
230 MLX_KEY_KP_4 = 324,
231 MLX_KEY_KP_5 = 325,
232 MLX_KEY_KP_6 = 326,
233 MLX_KEY_KP_7 = 327,
234 MLX_KEY_KP_8 = 328,
235 MLX_KEY_KP_9 = 329,
236 MLX_KEY_KP_DECIMAL = 330,
237 MLX_KEY_KP_DIVIDE = 331,
238 MLX_KEY_KP_MULTIPLY = 332,
239 MLX_KEY_KP_SUBTRACT = 333,
240 MLX_KEY_KP_ADD = 334,
241 MLX_KEY_KP_ENTER = 335,
242 MLX_KEY_KP_EQUAL = 336,
243 MLX_KEY_LEFT_SHIFT = 340,
244 MLX_KEY_LEFT_CONTROL = 341,
245 MLX_KEY_LEFT_ALT = 342,
246 MLX_KEY_LEFT_SUPER = 343,
247 MLX_KEY_RIGHT_SHIFT = 344,
248 MLX_KEY_RIGHT_CONTROL = 345,
249 MLX_KEY_RIGHT_ALT = 346,
250 MLX_KEY_RIGHT_SUPER = 347,
251 MLX_KEY_MENU = 348,
252} keys_t;
253
263typedef struct mlx_texture
264{
265 uint32_t width;
266 uint32_t height;
267 uint8_t bytes_per_pixel;
268 uint8_t* pixels;
270
279typedef struct xpm
280{
281 mlx_texture_t texture;
282 int32_t color_count;
283 int32_t cpp;
284 char mode;
285} xpm_t;
286
301typedef struct mlx_instance
302{
303 int32_t x;
304 int32_t y;
305 int32_t z;
306 bool enabled;
308
320typedef struct mlx_key_data
321{
322 keys_t key;
323 action_t action;
324 int32_t os_key;
325 modifier_key_t modifier;
327
340typedef struct mlx_image
341{
342 const uint32_t width;
343 const uint32_t height;
344 uint8_t* pixels;
345 mlx_instance_t* instances;
346 size_t count;
347 bool enabled;
348 void* context;
350
360typedef struct mlx
361{
362 void* window;
363 void* context;
364 int32_t width;
365 int32_t height;
366 double delta_time;
367} mlx_t;
368
369// The error codes used to identify the correct error message.
370typedef enum mlx_errno
371{
372 MLX_SUCCESS = 0, // No Errors
373 MLX_INVEXT, // File has an invalid extension
374 MLX_INVFILE, // File was invalid / does not exist.
375 MLX_INVPNG, // Something is wrong with the given PNG file.
376 MLX_INVXPM, // Something is wrong with the given XPM file.
377 MLX_INVPOS, // The specified X/Y positions are out of bounds.
378 MLX_INVDIM, // The specified W/H dimensions are out of bounds.
379 MLX_INVIMG, // The provided image is invalid, might indicate mismanagement of images.
380 MLX_VERTFAIL, // Failed to compile the vertex shader.
381 MLX_FRAGFAIL, // Failed to compile the fragment shader.
382 MLX_SHDRFAIL, // Failed to compile the shaders.
383 MLX_MEMFAIL, // Dynamic memory allocation has failed.
384 MLX_GLADFAIL, // OpenGL loader has failed.
385 MLX_GLFWFAIL, // GLFW failed to initialize.
386 MLX_WINFAIL, // Failed to create a window.
387 MLX_STRTOOBIG, // The string is too big to be drawn.
388 MLX_ERRMAX, // Error count
389} mlx_errno_t;
390
391// Global error code from the MLX42 library, 0 on no error.
392extern mlx_errno_t mlx_errno;
393
394//= Global Settings =//
395
396// Set these values, if necessary, before calling `mlx_init` as they define the behaviour of MLX42.
397typedef enum mlx_settings
398{
399 MLX_STRETCH_IMAGE = 0, // Should images resize with the window as it's being resized or not. Default: false
400 MLX_FULLSCREEN, // Should the window be in Fullscreen, note it will fullscreen at the given resolution. Default: false
401 MLX_MAXIMIZED, // Start the window in a maximized state, overwrites the fullscreen state if this is true. Default: false
402 MLX_DECORATED, // Have the window be decorated with a window bar. Default: true
403 MLX_HEADLESS, // Run in headless mode, no window is created. (NOTE: Still requires some form of window manager such as xvfb)
404 MLX_SETTINGS_MAX, // Setting count.
405} mlx_settings_t;
406
414typedef void (*mlx_scrollfunc)(double xdelta, double ydelta, void* param);
415
424typedef void (*mlx_mousefunc)(mouse_key_t button, action_t action, modifier_key_t mods, void* param);
425
433typedef void (*mlx_cursorfunc)(double xpos, double ypos, void* param);
434
441typedef void (*mlx_keyfunc)(mlx_key_data_t keydata, void* param);
442
453typedef void (*mlx_resizefunc)(int32_t width, int32_t height, void* param);
454
462typedef void (*mlx_closefunc)(void* param);
463
471typedef void mlx_win_cursor_t;
472
473//= Error Functions =//
474
481const char* mlx_strerror(mlx_errno_t val);
482
483//= Generic Functions =//
484
494mlx_t* mlx_init(int32_t width, int32_t height, const char* title, bool resize);
495
503void mlx_set_setting(mlx_settings_t setting, int32_t value);
504
511void mlx_close_window(mlx_t* mlx);
512
520void mlx_loop(mlx_t* mlx);
521
532void mlx_set_icon(mlx_t* mlx, mlx_texture_t* image);
533
541void mlx_terminate(mlx_t* mlx);
542
548double mlx_get_time(void);
549
550//= Window/Monitor Functions =//
551
561void mlx_focus(mlx_t* mlx);
562
570void mlx_get_monitor_size(int32_t index, int32_t* width, int32_t* height);
571
582void mlx_set_window_pos(mlx_t* mlx, int32_t xpos, int32_t ypos);
583
591void mlx_get_window_pos(mlx_t* mlx, int32_t* xpos, int32_t* ypos);
592
601void mlx_set_window_size(mlx_t* mlx, int32_t new_width, int32_t new_height);
602
616void mlx_set_window_limit(mlx_t* mlx, int32_t min_w, int32_t min_h, int32_t max_w, int32_t max_h);
617
624void mlx_set_window_title(mlx_t* mlx, const char* title);
625
626//= Input Functions =//
627
635bool mlx_is_key_down(mlx_t* mlx, keys_t key);
636
644bool mlx_is_mouse_down(mlx_t* mlx, mouse_key_t key);
645
657void mlx_get_mouse_pos(mlx_t* mlx, int32_t* x, int32_t* y);
658
665void mlx_set_mouse_pos(mlx_t* mlx, int32_t x, int32_t y);
666
673void mlx_set_cursor_mode(mlx_t* mlx, mouse_mode_t mode);
674
681mlx_win_cursor_t* mlx_create_std_cursor(cursor_t type);
682
692mlx_win_cursor_t* mlx_create_cursor(mlx_texture_t* texture);
693
699void mlx_destroy_cursor(mlx_win_cursor_t* cursor);
700
707void mlx_set_cursor(mlx_t* mlx, mlx_win_cursor_t* cursor);
708
709//= Hooks =//
710
719void mlx_scroll_hook(mlx_t* mlx, mlx_scrollfunc func, void* param);
720
729void mlx_mouse_hook(mlx_t* mlx, mlx_mousefunc func, void* param);
730
739void mlx_cursor_hook(mlx_t* mlx, mlx_cursorfunc func, void* param);
740
749void mlx_key_hook(mlx_t* mlx, mlx_keyfunc func, void* param);
750
759void mlx_close_hook(mlx_t* mlx, mlx_closefunc func, void* param);
760
769void mlx_resize_hook(mlx_t* mlx, mlx_resizefunc func, void* param);
770
780bool mlx_loop_hook(mlx_t* mlx, void (*f)(void*), void* param);
781
782//= Texture Functions =//
783
790mlx_texture_t* mlx_load_png(const char* path);
791
798xpm_t* mlx_load_xpm42(const char* path);
799
805void mlx_delete_texture(mlx_texture_t* texture);
806
815void mlx_delete_xpm42(xpm_t* xpm);
816
824mlx_image_t* mlx_texture_to_image(mlx_t* mlx, mlx_texture_t* texture);
825
826//= Image Functions =//
827
839void mlx_put_pixel(mlx_image_t* image, uint32_t x, uint32_t y, uint32_t color);
840
849mlx_image_t* mlx_new_image(mlx_t* mlx, uint32_t width, uint32_t height);
850
868int32_t mlx_image_to_window(mlx_t* mlx, mlx_image_t* img, int32_t x, int32_t y);
869
881void mlx_delete_image(mlx_t* mlx, mlx_image_t* image);
882
892bool mlx_resize_image(mlx_image_t* img, uint32_t nwidth, uint32_t nheight);
893
904void mlx_set_instance_depth(mlx_instance_t* instance, int32_t zdepth);
905
906//= String Functions =//
907
917mlx_image_t* mlx_put_string(mlx_t* mlx, const char* str, int32_t x, int32_t y);
918
924const mlx_texture_t* mlx_get_font(void);
925
935int32_t mlx_get_texoffset(char c);
936
937# ifdef __cplusplus
938}
939# endif
940#endif
Definition MLX42.h:361
Definition MLX42.h:280