Add window position information
This commit is contained in:
25
src/window.c
25
src/window.c
@@ -5,10 +5,13 @@
|
||||
#include <SDL2/SDL_video.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user