mirror of
https://github.com/hedge-dev/UnleashedRecomp.git
synced 2025-10-30 07:11:05 +00:00
window: save config on close with window dimensions
This commit is contained in:
parent
f1a82ac97e
commit
78cba0e78d
2 changed files with 30 additions and 8 deletions
|
|
@ -11,6 +11,7 @@ int Window_OnSDLEvent(void*, SDL_Event* event)
|
|||
switch (event->type)
|
||||
{
|
||||
case SDL_QUIT:
|
||||
Config::Save();
|
||||
ExitProcess(0);
|
||||
break;
|
||||
|
||||
|
|
@ -31,6 +32,14 @@ int Window_OnSDLEvent(void*, SDL_Event* event)
|
|||
|
||||
break;
|
||||
}
|
||||
|
||||
// Restore original window dimensions on F2.
|
||||
case SDLK_F2:
|
||||
{
|
||||
Window::SetFullscreen(Config::Fullscreen);
|
||||
Window::SetWindowDimensions(-1, -1, true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
|
@ -66,6 +75,11 @@ int Window_OnSDLEvent(void*, SDL_Event* event)
|
|||
Window::s_height = event->window.data2;
|
||||
Window::RaiseResizeEvents();
|
||||
break;
|
||||
|
||||
case SDL_WINDOWEVENT_MOVED:
|
||||
Config::WindowX = event->window.data1;
|
||||
Config::WindowY = event->window.data2;
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
|
|
@ -89,12 +103,17 @@ void Window::Init()
|
|||
|
||||
SetProcessDPIAware();
|
||||
|
||||
s_window = SDL_CreateWindow(title,
|
||||
SDL_WINDOWPOS_CENTERED,
|
||||
SDL_WINDOWPOS_CENTERED,
|
||||
Config::WindowWidth,
|
||||
Config::WindowHeight,
|
||||
SDL_WINDOW_RESIZABLE);
|
||||
int32_t x = Config::WindowX < 0 ? SDL_WINDOWPOS_CENTERED : Config::WindowX;
|
||||
int32_t y = Config::WindowY < 0 ? SDL_WINDOWPOS_CENTERED : Config::WindowY;
|
||||
int32_t width = Config::WindowWidth;
|
||||
int32_t height = Config::WindowHeight;
|
||||
|
||||
s_window = SDL_CreateWindow(title, x, y, width, height, SDL_WINDOW_RESIZABLE);
|
||||
|
||||
SDL_GetWindowPosition(s_window, &x, &y);
|
||||
|
||||
Config::WindowX = x;
|
||||
Config::WindowY = y;
|
||||
|
||||
if (auto icon = GetIconSurface())
|
||||
{
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
static void SetWindowDimensions(int w = -1, int h = -1)
|
||||
static void SetWindowDimensions(int w = -1, int h = -1, bool recenter = false)
|
||||
{
|
||||
auto width = w <= 0 ? Config::WindowWidth : w;
|
||||
auto height = h <= 0 ? Config::WindowHeight : h;
|
||||
|
|
@ -94,9 +94,12 @@ public:
|
|||
isPendingMaximise = true;
|
||||
}
|
||||
|
||||
int32_t x = recenter ? SDL_WINDOWPOS_CENTERED : Config::WindowX;
|
||||
int32_t y = recenter ? SDL_WINDOWPOS_CENTERED : Config::WindowY;
|
||||
|
||||
SDL_SetWindowSize(s_window, width, height);
|
||||
SDL_SetWindowMinimumSize(s_window, 640, 480);
|
||||
SDL_SetWindowPosition(s_window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
|
||||
SDL_SetWindowPosition(s_window, x, y);
|
||||
|
||||
s_width = width;
|
||||
s_height = height;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue