Fix fullscreen exit resulting in a slightly lower Y position
This commit is contained in:
parent
aeb4d4e204
commit
b91a717a7b
|
@ -41,7 +41,9 @@ ConfigWindow configWindow = {
|
||||||
.y = SDL_WINDOWPOS_CENTERED,
|
.y = SDL_WINDOWPOS_CENTERED,
|
||||||
.w = DESIRED_SCREEN_WIDTH,
|
.w = DESIRED_SCREEN_WIDTH,
|
||||||
.h = DESIRED_SCREEN_HEIGHT,
|
.h = DESIRED_SCREEN_HEIGHT,
|
||||||
.reset = false
|
.reset = false,
|
||||||
|
.vsync = false,
|
||||||
|
.exiting_fullscreen = false,
|
||||||
};
|
};
|
||||||
unsigned int configFiltering = 1; // 0=force nearest, 1=linear, (TODO) 2=three-point
|
unsigned int configFiltering = 1; // 0=force nearest, 1=linear, (TODO) 2=three-point
|
||||||
unsigned int configMasterVolume = MAX_VOLUME; // 0 - MAX_VOLUME
|
unsigned int configMasterVolume = MAX_VOLUME; // 0 - MAX_VOLUME
|
||||||
|
|
|
@ -10,6 +10,8 @@
|
||||||
typedef struct {
|
typedef struct {
|
||||||
unsigned int x, y, w, h;
|
unsigned int x, y, w, h;
|
||||||
bool reset;
|
bool reset;
|
||||||
|
bool vsync;
|
||||||
|
bool exiting_fullscreen;
|
||||||
} ConfigWindow;
|
} ConfigWindow;
|
||||||
|
|
||||||
extern bool configFullscreen;
|
extern bool configFullscreen;
|
||||||
|
|
|
@ -22,6 +22,8 @@
|
||||||
|
|
||||||
#endif // End of OS-Specific GL defines
|
#endif // End of OS-Specific GL defines
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "gfx_window_manager_api.h"
|
#include "gfx_window_manager_api.h"
|
||||||
#include "gfx_screen_config.h"
|
#include "gfx_screen_config.h"
|
||||||
#include "../pc_main.h"
|
#include "../pc_main.h"
|
||||||
|
@ -40,7 +42,6 @@
|
||||||
static SDL_Window *wnd;
|
static SDL_Window *wnd;
|
||||||
static SDL_GLContext ctx = NULL;
|
static SDL_GLContext ctx = NULL;
|
||||||
static int inverted_scancode_table[512];
|
static int inverted_scancode_table[512];
|
||||||
static bool window_vsync;
|
|
||||||
|
|
||||||
const SDL_Scancode windows_scancode_table[] =
|
const SDL_Scancode windows_scancode_table[] =
|
||||||
{
|
{
|
||||||
|
@ -104,23 +105,26 @@ static void gfx_sdl_set_fullscreen() {
|
||||||
} else {
|
} else {
|
||||||
SDL_SetWindowFullscreen(wnd, 0);
|
SDL_SetWindowFullscreen(wnd, 0);
|
||||||
SDL_ShowCursor(SDL_ENABLE);
|
SDL_ShowCursor(SDL_ENABLE);
|
||||||
SDL_SetWindowSize(wnd, configWindow.w, configWindow.h);
|
configWindow.exiting_fullscreen = true;
|
||||||
SDL_SetWindowPosition(wnd, configWindow.x, configWindow.y);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void gfx_sdl_reset_dimension_and_pos() {
|
static void gfx_sdl_reset_dimension_and_pos() {
|
||||||
if (!configWindow.reset) return;
|
if (configWindow.exiting_fullscreen)
|
||||||
|
configWindow.exiting_fullscreen = false;
|
||||||
|
else if (configWindow.reset) {
|
||||||
configWindow.x = SDL_WINDOWPOS_CENTERED;
|
configWindow.x = SDL_WINDOWPOS_CENTERED;
|
||||||
configWindow.y = SDL_WINDOWPOS_CENTERED;
|
configWindow.y = SDL_WINDOWPOS_CENTERED;
|
||||||
configWindow.w = DESIRED_SCREEN_WIDTH;
|
configWindow.w = DESIRED_SCREEN_WIDTH;
|
||||||
configWindow.h = DESIRED_SCREEN_HEIGHT;
|
configWindow.h = DESIRED_SCREEN_HEIGHT;
|
||||||
configWindow.reset = false;
|
configWindow.reset = false;
|
||||||
|
|
||||||
if (!IS_FULLSCREEN) {
|
if (IS_FULLSCREEN) return;
|
||||||
|
} else
|
||||||
|
return;
|
||||||
|
|
||||||
SDL_SetWindowSize(wnd, configWindow.w, configWindow.h);
|
SDL_SetWindowSize(wnd, configWindow.w, configWindow.h);
|
||||||
SDL_SetWindowPosition(wnd, configWindow.x, configWindow.y);
|
SDL_SetWindowPosition(wnd, configWindow.x, configWindow.y);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool test_vsync(void) {
|
static bool test_vsync(void) {
|
||||||
|
@ -176,8 +180,8 @@ static void gfx_sdl_init(void) {
|
||||||
|
|
||||||
gfx_sdl_set_fullscreen();
|
gfx_sdl_set_fullscreen();
|
||||||
|
|
||||||
window_vsync = test_vsync();
|
configWindow.vsync = test_vsync();
|
||||||
if (!window_vsync)
|
if (!configWindow.vsync)
|
||||||
printf("Warning: VSync is not enabled or not working. Falling back to timer for synchronization\n");
|
printf("Warning: VSync is not enabled or not working. Falling back to timer for synchronization\n");
|
||||||
|
|
||||||
for (size_t i = 0; i < sizeof(windows_scancode_table) / sizeof(SDL_Scancode); i++) {
|
for (size_t i = 0; i < sizeof(windows_scancode_table) / sizeof(SDL_Scancode); i++) {
|
||||||
|
@ -239,8 +243,8 @@ static void gfx_sdl_handle_events(void) {
|
||||||
gfx_sdl_onkeyup(event.key.keysym.scancode);
|
gfx_sdl_onkeyup(event.key.keysym.scancode);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
case SDL_WINDOWEVENT: // FIX-ME: Check if this makes sense to be include in Web build
|
case SDL_WINDOWEVENT: // TODO: Check if this makes sense to be included in the Web build
|
||||||
if (!IS_FULLSCREEN) {
|
if (!(IS_FULLSCREEN || configWindow.exiting_fullscreen)) {
|
||||||
switch (event.window.event) {
|
switch (event.window.event) {
|
||||||
case SDL_WINDOWEVENT_MOVED:
|
case SDL_WINDOWEVENT_MOVED:
|
||||||
configWindow.x = event.window.data1;
|
configWindow.x = event.window.data1;
|
||||||
|
@ -280,7 +284,7 @@ static void sync_framerate_with_timer(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void gfx_sdl_swap_buffers_begin(void) {
|
static void gfx_sdl_swap_buffers_begin(void) {
|
||||||
if (!window_vsync)
|
if (!configWindow.vsync)
|
||||||
sync_framerate_with_timer();
|
sync_framerate_with_timer();
|
||||||
SDL_GL_SwapWindow(wnd);
|
SDL_GL_SwapWindow(wnd);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue