From 9806a5c708bc639daec4e3664a672779b38ab2b5 Mon Sep 17 00:00:00 2001 From: Abdelrahman Date: Mon, 15 Jan 2024 20:48:21 +0000 Subject: [PATCH] Add window position information --- include/window.h | 5 ++++- src/window.c | 25 ++++++++++++++++++++----- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/include/window.h b/include/window.h index 7818c05..63ebb16 100644 --- a/include/window.h +++ b/include/window.h @@ -37,6 +37,8 @@ struct rect { struct window { u32 id; + u64 x; + u64 y; u64 width; u64 height; const char *title; @@ -52,7 +54,8 @@ struct colour { }; }; -bool init_window(window_t *wnd, const char *title, u64 width, u64 height); +bool init_window(window_t *wnd, const char *title, u32 width, u32 height, i32 x, + i32 y); void cleanup_window(window_t *wnd); void clear_window(const window_t *wnd, colour_t colour); void swap_buffers(const window_t *wnd); diff --git a/src/window.c b/src/window.c index f265dd3..5602fb0 100644 --- a/src/window.c +++ b/src/window.c @@ -5,10 +5,13 @@ #include #include -bool init_window(window_t *wnd, const char *title, u64 width, u64 height) { +bool init_window(window_t *wnd, const char *title, u32 width, u32 height, i32 x, + i32 y) { + i32 pos_x = x >= 0 ? x : SDL_WINDOWPOS_CENTERED; + i32 pos_y = y >= 0 ? y : SDL_WINDOWPOS_CENTERED; + wnd->window = - SDL_CreateWindow(title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, - width, height, SDL_WINDOW_SHOWN); + SDL_CreateWindow(title, pos_x, pos_y, width, height, SDL_WINDOW_SHOWN); if (!(wnd->window)) { return false; } @@ -22,8 +25,20 @@ bool init_window(window_t *wnd, const char *title, u64 width, u64 height) { wnd->id = SDL_GetWindowID(wnd->window); wnd->title = title; - wnd->width = width; - wnd->height = height; + + i32 x_tmp = -1; + i32 y_tmp = -1; + SDL_GetWindowPosition(wnd->window, &x_tmp, &y_tmp); + + wnd->x = x_tmp; + wnd->y = y_tmp; + + i32 w_tmp = -1; + i32 h_tmp = -1; + SDL_GetWindowSize(wnd->window, &w_tmp, &h_tmp); + + wnd->width = w_tmp; + wnd->height = h_tmp; return true; }