mirror of
https://github.com/hedge-dev/UnleashedRecomp.git
synced 2026-04-27 04:41:39 +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)
|
switch (event->type)
|
||||||
{
|
{
|
||||||
case SDL_QUIT:
|
case SDL_QUIT:
|
||||||
|
Config::Save();
|
||||||
ExitProcess(0);
|
ExitProcess(0);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
@ -31,6 +32,14 @@ int Window_OnSDLEvent(void*, SDL_Event* event)
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Restore original window dimensions on F2.
|
||||||
|
case SDLK_F2:
|
||||||
|
{
|
||||||
|
Window::SetFullscreen(Config::Fullscreen);
|
||||||
|
Window::SetWindowDimensions(-1, -1, true);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
@ -66,6 +75,11 @@ int Window_OnSDLEvent(void*, SDL_Event* event)
|
||||||
Window::s_height = event->window.data2;
|
Window::s_height = event->window.data2;
|
||||||
Window::RaiseResizeEvents();
|
Window::RaiseResizeEvents();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case SDL_WINDOWEVENT_MOVED:
|
||||||
|
Config::WindowX = event->window.data1;
|
||||||
|
Config::WindowY = event->window.data2;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
@ -89,12 +103,17 @@ void Window::Init()
|
||||||
|
|
||||||
SetProcessDPIAware();
|
SetProcessDPIAware();
|
||||||
|
|
||||||
s_window = SDL_CreateWindow(title,
|
int32_t x = Config::WindowX < 0 ? SDL_WINDOWPOS_CENTERED : Config::WindowX;
|
||||||
SDL_WINDOWPOS_CENTERED,
|
int32_t y = Config::WindowY < 0 ? SDL_WINDOWPOS_CENTERED : Config::WindowY;
|
||||||
SDL_WINDOWPOS_CENTERED,
|
int32_t width = Config::WindowWidth;
|
||||||
Config::WindowWidth,
|
int32_t height = Config::WindowHeight;
|
||||||
Config::WindowHeight,
|
|
||||||
SDL_WINDOW_RESIZABLE);
|
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())
|
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 width = w <= 0 ? Config::WindowWidth : w;
|
||||||
auto height = h <= 0 ? Config::WindowHeight : h;
|
auto height = h <= 0 ? Config::WindowHeight : h;
|
||||||
|
|
@ -94,9 +94,12 @@ public:
|
||||||
isPendingMaximise = true;
|
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_SetWindowSize(s_window, width, height);
|
||||||
SDL_SetWindowMinimumSize(s_window, 640, 480);
|
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_width = width;
|
||||||
s_height = height;
|
s_height = height;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue