Add window position information
This commit is contained in:
parent
81fbff96b8
commit
9806a5c708
@ -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);
|
||||
|
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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user