Fri, 01 Aug 2025 18:18:57 +0200
add functions to change the window position
src/ascension/window.h | file | annotate | diff | comparison | revisions | |
src/window.c | file | annotate | diff | comparison | revisions |
--- a/src/ascension/window.h Fri Aug 01 17:58:28 2025 +0200 +++ b/src/ascension/window.h Fri Aug 01 18:18:57 2025 +0200 @@ -176,6 +176,21 @@ void asc_window_set_title(unsigned int index, const char *title); /** + * Sets the window position. + * + * @param index the window index + * @param pos the new position + */ +void asc_window_set_position(unsigned index, asc_vec2i pos); + +/** + * Centers the window on screen. + * + * @param index the window index + */ +void asc_window_center(unsigned index); + +/** * Sets the window size. * * @param index the window index
--- a/src/window.c Fri Aug 01 17:58:28 2025 +0200 +++ b/src/window.c Fri Aug 01 18:18:57 2025 +0200 @@ -222,8 +222,22 @@ SDL_SetWindowTitle(asc_context.windows[index].window, title); } +void asc_window_set_position(unsigned index, asc_vec2i pos) { + assert(asc_context.windows[index].window != NULL); + SDL_SetWindowPosition(asc_context.windows[index].window, pos.x, pos.y); +} + +void asc_window_center(unsigned index) { + // TODO: add support for multiple displays + // TODO: add support for centering just one axis + assert(asc_context.windows[index].window != NULL); + SDL_SetWindowPosition(asc_context.windows[index].window, + SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED); +} + void asc_window_set_size(unsigned index, asc_vec2u size) { assert(asc_context.windows[index].window != NULL); asc_context.windows[index].dimensions = size; + // TODO: check what needs to be changed when SDL_WINDOW_ALLOW_HIGHDPI is supported by the engine SDL_SetWindowSize(asc_context.windows[index].window, (int)size.width, (int)size.height); }