Get window position accounts for borders now.
This commit is contained in:
+9
-3
@@ -143,8 +143,15 @@ static sdl_window_size SDLGetWindowSize(SDL_Window *Window)
|
||||
|
||||
static sdl_window_position SDLGetWindowPosition(SDL_Window *Window)
|
||||
{
|
||||
// NOTE: SDL_GetWindowPosition returns the client area position.
|
||||
S32 top, left;
|
||||
SDL_GetWindowBordersSize(Window, &top, &left, 0, 0);
|
||||
|
||||
sdl_window_position Position;
|
||||
SDL_GetWindowPosition(Window, &Position.X, &Position.Y);
|
||||
Position.X -= left;
|
||||
Position.Y -= top;
|
||||
|
||||
return Position;
|
||||
}
|
||||
|
||||
@@ -300,15 +307,13 @@ static void HandleEvent(SDL_Event *Event)
|
||||
}
|
||||
}
|
||||
|
||||
// NOTE: On XFCE4 (tested on X11), the window moves slightly lower than the set position, for whatever reason.
|
||||
// Maybe, we need to redraw inside of the window atleast once before repositioning?
|
||||
// This issue does not happen on MacOS.
|
||||
static void SDLToggleFullscreen(SDL_Window *Window)
|
||||
{
|
||||
if(IsFullscreen) {
|
||||
if(SDL_SetWindowFullscreen(Window, 0) == 0) {
|
||||
SDL_SetWindowSize(Window, WindowSize.Width, WindowSize.Height);
|
||||
SDL_SetWindowPosition(Window, WindowPosition.X, WindowPosition.Y);
|
||||
|
||||
IsFullscreen = FALSE;
|
||||
} else {
|
||||
/* TODO: This didn't work . . . SDL_GetError() */
|
||||
@@ -602,6 +607,7 @@ S32 main(S32 argc, char *argv[])
|
||||
/* NOTE: We create the window hidden at first. This is so that we do not get a window outline
|
||||
* that shows up whilst it is waiting for the rendered to be created. We want to display
|
||||
* the window once everything is ready. */
|
||||
// TODO: SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, in non-debug build
|
||||
SDL_Window *Window = SDL_CreateWindow("Handmade Hero", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, RESOLUTION_WIDTH+20, RESOLUTION_HEIGHT+20, SDL_WINDOW_HIDDEN | SDL_WINDOW_RESIZABLE/* | SDL_WINDOW_ALWAYS_ON_TOP*/);
|
||||
|
||||
if(Window) {
|
||||
|
||||
Reference in New Issue
Block a user