From 51587ec974d532b68bb323a14d18f857ed357d74 Mon Sep 17 00:00:00 2001 From: onelin Date: Wed, 26 Nov 2025 22:07:21 +0100 Subject: Add `window_get_size` --- src/include/daw/platform_glfw.h | 2 ++ src/include/daw/window.h | 5 +++++ src/platform_glfw.c | 4 ++-- src/window.c | 4 ++++ 4 files changed, 13 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/include/daw/platform_glfw.h b/src/include/daw/platform_glfw.h index 01964c9..8311c5a 100644 --- a/src/include/daw/platform_glfw.h +++ b/src/include/daw/platform_glfw.h @@ -13,6 +13,7 @@ extern "C" { Window* window_init_glfw(const char *restrict windowtitle, ivec2 windowsize, const u32 flags); void window_destroy_glfw(Window *restrict w); void window_resize_glfw(Window *restrict window, int width, int height); +void window_size_glfw(Window *restrict w, ivec2 *restrict dst); bool window_should_close_glfw(Window *restrict window); void window_poll_glfw(void); @@ -20,6 +21,7 @@ const struct Platform Platform_GLFW = { .window_init = window_init_glfw, .window_destroy = window_destroy_glfw, .window_resize = window_resize_glfw, + .window_size = window_size_glfw, .window_should_close = window_should_close_glfw, .window_poll = window_poll_glfw, }; diff --git a/src/include/daw/window.h b/src/include/daw/window.h index 83280ec..f445860 100644 --- a/src/include/daw/window.h +++ b/src/include/daw/window.h @@ -73,6 +73,10 @@ struct Platform { */ void (*window_resize)(Window *restrict window, int width, int height); + /* Retrieve the current window size and store it in `dst`. + */ + void (*window_size)(Window *restrict window, ivec2 *restrict dst); + /* Return true if the platform has ordered the window to exit. */ bool (*window_should_close)(Window *restrict w); @@ -94,6 +98,7 @@ void window_reset_drawing(void); void render(Window* w); void get_mousepos(double *x, double *y); +void window_get_size(ivec2* dst); #ifdef __cplusplus } diff --git a/src/platform_glfw.c b/src/platform_glfw.c index 96b533c..5453258 100644 --- a/src/platform_glfw.c +++ b/src/platform_glfw.c @@ -17,7 +17,7 @@ static void window_resize_callback(GLFWwindow *restrict window, int width, int h static void framebuffer_resize_callback(GLFWwindow *restrict window, int width, int height); static void glfw_err_callback(int code, const char* description); static void render_init_opengl(Window *restrict w, const u32 flags); -static void window_size(GLFWwindow *restrict w, ivec2 *restrict dst); +void window_size_glfw(GLFWwindow *restrict w, ivec2 *restrict dst); Window* window_init_glfw(const char *restrict windowtitle, ivec2 windowsize, const u32 flags) { @@ -221,7 +221,7 @@ static void render_init_opengl(Window *restrict w, const u32 flags) { w->renderer = WINDOW_RENDERER_OPENGL; } -static void window_size(GLFWwindow *restrict w, ivec2 *restrict dst) { +void window_size_glfw(GLFWwindow *restrict w, ivec2 *restrict dst) { ivec2 wsize; vec2 wscaling; glfwGetWindowContentScale(w, &wscaling[0], &wscaling[1]); diff --git a/src/window.c b/src/window.c index ea42678..fc688b7 100644 --- a/src/window.c +++ b/src/window.c @@ -80,3 +80,7 @@ void get_mousepos(double *x, double *y) { } } + +void window_get_size(ivec2* dst) { + glm_ivec2_copy(GLOBAL_PLATFORM->window->windowsize, *dst); +} -- cgit v1.3