From 32fbee5613406cd11bcdead69453550f090b0b09 Mon Sep 17 00:00:00 2001 From: Stanislav Denisov Date: Wed, 26 Nov 2025 16:16:30 +0100 Subject: [PATCH] Implement persistence for the editor window's size (#1336) Implement persistence for the window size --- Editor/Editor.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ Editor/Editor.h | 2 ++ Editor/main_SDL2.cpp | 1 + Editor/main_Windows.cpp | 3 +++ 4 files changed, 47 insertions(+) diff --git a/Editor/Editor.cpp b/Editor/Editor.cpp index 531017d96..79ee99def 100644 --- a/Editor/Editor.cpp +++ b/Editor/Editor.cpp @@ -372,6 +372,43 @@ bool Editor::KeepRunning() { return !exit_requested || renderComponent.save_in_progress; } +void Editor::SaveWindowSize() +{ + if (window != nullptr) + { +#ifdef _WIN32 + WINDOWPLACEMENT placement = {}; + placement.length = sizeof(WINDOWPLACEMENT); + if (GetWindowPlacement(window, &placement) && placement.showCmd != SW_SHOWMAXIMIZED) + { + RECT rect; + GetWindowRect(window, &rect); + int width = rect.right - rect.left; + int height = rect.bottom - rect.top; + if (width > 0 && height > 0) + { + config.Set("width", width); + config.Set("height", height); + config.Commit(); + } + } +#elif defined(SDL2) + if (!(SDL_GetWindowFlags(window) & SDL_WINDOW_MAXIMIZED)) + { + int width = 0; + int height = 0; + SDL_GetWindowSize(window, &width, &height); + if (width > 0 && height > 0) + { + config.Set("width", width); + config.Set("height", height); + config.Commit(); + } + } +#endif + } +} + void Editor::Exit() { // Check all scenes for unsaved changes @@ -382,6 +419,10 @@ void Editor::Exit() return; } } + + // Save window size to config + SaveWindowSize(); + // main loop will need to quit for us exit_requested = true; } diff --git a/Editor/Editor.h b/Editor/Editor.h index 7310ab160..9e50e45b3 100644 --- a/Editor/Editor.h +++ b/Editor/Editor.h @@ -266,6 +266,8 @@ public: bool KeepRunning(); + void SaveWindowSize(); + void Exit() override; ~Editor() override diff --git a/Editor/main_SDL2.cpp b/Editor/main_SDL2.cpp index e52737c8e..373e056ec 100644 --- a/Editor/main_SDL2.cpp +++ b/Editor/main_SDL2.cpp @@ -46,6 +46,7 @@ int sdl_loop() case SDL_WINDOWEVENT_RESIZED: // Tells the engine to reload window configuration (size and dpi) editor.SetWindow(editor.window); + editor.SaveWindowSize(); break; case SDL_WINDOWEVENT_FOCUS_LOST: editor.is_window_active = false; diff --git a/Editor/main_Windows.cpp b/Editor/main_Windows.cpp index 6810ef60f..9d202bdcb 100644 --- a/Editor/main_Windows.cpp +++ b/Editor/main_Windows.cpp @@ -23,7 +23,10 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance, case WM_SIZE: case WM_DPICHANGED: if (editor.is_window_active && LOWORD(lParam) > 0 && HIWORD(lParam) > 0) + { editor.SetWindow(hWnd); + editor.SaveWindowSize(); + } break; case WM_CHAR: switch (wParam)