settings file and save/restore ui state

This commit is contained in:
2019-04-14 18:03:41 +02:00
parent ada1afbac2
commit a8d475fbfb
15 changed files with 596 additions and 38 deletions

View File

@@ -16,6 +16,7 @@
#include <deque>
#include <chrono>
#include "abr.h"
#include "settings.h"
#define WM_USER_CLOSE (WM_USER + 1)
@@ -517,6 +518,15 @@ void win32_vr_stop()
}
}
void win32_save_window_state()
{
WINDOWPLACEMENT p;
GetWindowPlacement(hWnd, &p);
Settings::set("window-show-cmd", Serializer::Integer(p.showCmd));
Settings::set("window-rect", Serializer::IVec4({ p.rcNormalPosition.left,
p.rcNormalPosition.top, p.rcNormalPosition.right, p.rcNormalPosition.bottom }));
}
int main(int argc, char** argv)
{
WNDCLASS wc;
@@ -562,7 +572,6 @@ int main(int argc, char** argv)
read_WMI_info();
App::I.create();
RECT clientRect = { 0, 0, (int)App::I.width, (int)App::I.height };
// Inizialize data structures to zero
memset(&wc, 0, sizeof(wc));
@@ -588,8 +597,21 @@ int main(int argc, char** argv)
GetDpiForMonitor(monitor, MDT_EFFECTIVE_DPI, &x, &y);
App::I.zoom *= (float)x / 96.f;
AdjustWindowRect(&clientRect, WS_OVERLAPPEDWINDOW, false);
hWnd = CreateWindow(wc.lpszClassName, L"PanoPainter", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT,
RECT clientRect = { 0, 0, (int)App::I.width, (int)App::I.height };
POINT clientPos = { CW_USEDEFAULT, CW_USEDEFAULT };
if (Settings::has("window-rect"))
{
auto wnd_rect = Settings::value<Serializer::IVec4>("window-rect");
App::I.width = wnd_rect.z - wnd_rect.x;
App::I.height = wnd_rect.w - wnd_rect.y;
clientRect = { wnd_rect.x, wnd_rect.y, wnd_rect.z, wnd_rect.w };
clientPos = { wnd_rect.x, wnd_rect.y };
}
else
{
AdjustWindowRect(&clientRect, WS_OVERLAPPEDWINDOW, false);
}
hWnd = CreateWindow(wc.lpszClassName, L"PanoPainter", WS_OVERLAPPEDWINDOW, clientPos.x, clientPos.y,
(float)(clientRect.right - clientRect.left) * App::I.zoom,
(float)(clientRect.bottom - clientRect.top) * App::I.zoom, 0, 0, hInst, 0);
@@ -651,7 +673,7 @@ int main(int argc, char** argv)
wglDeleteContext(hRC);
DestroyWindow(hWnd);
hWnd = CreateWindow(wc.lpszClassName, window_title, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT,
hWnd = CreateWindow(wc.lpszClassName, window_title, WS_OVERLAPPEDWINDOW, clientPos.x, clientPos.y,
(float)(clientRect.right - clientRect.left) * App::I.zoom,
(float)(clientRect.bottom - clientRect.top) * App::I.zoom, 0, 0, hInst, 0);
@@ -691,8 +713,11 @@ int main(int argc, char** argv)
LOG("init app");
App::I.init();
int show_cmd = SW_NORMAL;
Settings::value<Serializer::Integer>("window-show-cmd", show_cmd);
LOG("show main window");
ShowWindow(hWnd, SW_NORMAL);
ShowWindow(hWnd, show_cmd);
if (!sandboxed)
{