Abstract window and rendere initialisation code
This commit is contained in:
		
							
								
								
									
										52
									
								
								include/window.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										52
									
								
								include/window.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,52 @@ | ||||
| #ifndef WINDOW_H | ||||
| #define WINDOW_H | ||||
|  | ||||
| #include "SDL_events.h" | ||||
| #include "aliases/aliases.h" | ||||
| #include "colour.h" | ||||
| #include <SDL_render.h> | ||||
| #include <SDL_video.h> | ||||
| #include <stdbool.h> | ||||
|  | ||||
| #ifndef MAX_HANDLERS_LENGTH | ||||
| #define MAX_HANDLERS_LENGTH 128 | ||||
| #endif // !MAX_HANDLERS_LENGTH | ||||
|  | ||||
| typedef struct window window_t; | ||||
|  | ||||
| typedef void (*event_listener_t)(const window_t *wnd, void *obj, | ||||
|                                  const SDL_Event *ev); | ||||
| typedef void (*render_func_t)(const window_t *wnd, void *obj); | ||||
|  | ||||
| typedef struct { | ||||
|   u64 x; | ||||
|   u64 y; | ||||
|   u64 width; | ||||
|   u64 height; | ||||
| } render_rect_t; | ||||
|  | ||||
| struct window { | ||||
|   u64 width; | ||||
|   u64 height; | ||||
|   SDL_Window *window; | ||||
|   SDL_Renderer *renderer; | ||||
|   colour_t bg_colour; | ||||
|   bool running; | ||||
|   SDL_Event event; | ||||
|   u64 count; | ||||
|   void *objects[MAX_HANDLERS_LENGTH]; | ||||
|   event_listener_t listeners[MAX_HANDLERS_LENGTH]; | ||||
|   render_func_t render_funcs[MAX_HANDLERS_LENGTH]; | ||||
| }; | ||||
|  | ||||
| bool open_window(window_t *wnd, const char *title, u64 w, u64 h, | ||||
|                  colour_t bg_colour); | ||||
| void run_window_loop(window_t *wnd); | ||||
| void close_window(window_t *wnd); | ||||
| bool add_event_listener(window_t *wnd, void *obj, event_listener_t listener); | ||||
| bool add_renderer_func(window_t *wnd, void *obj, render_func_t func); | ||||
| void fill_rect(const window_t *wnd, const render_rect_t *rect, colour_t colour); | ||||
| void draw_rect(const window_t *wnd, const render_rect_t *rect, colour_t colour); | ||||
| bool aabb(u64 x, u64 y, const render_rect_t *rect); | ||||
|  | ||||
| #endif // !WINDOW_H | ||||
		Reference in New Issue
	
	Block a user