diff --git a/PanoPainter.rc b/PanoPainter.rc index 3136fd9..39b6731 100644 Binary files a/PanoPainter.rc and b/PanoPainter.rc differ diff --git a/PanoPainter.sln b/PanoPainter.sln index 0bc5e76..53e579d 100644 --- a/PanoPainter.sln +++ b/PanoPainter.sln @@ -20,11 +20,13 @@ Global {6D5028CE-4D76-4B6A-A7C2-DE5A3268D433}.Debug|Any CPU.ActiveCfg = Debug|Win32 {6D5028CE-4D76-4B6A-A7C2-DE5A3268D433}.Debug|x64.ActiveCfg = Debug|x64 {6D5028CE-4D76-4B6A-A7C2-DE5A3268D433}.Debug|x64.Build.0 = Debug|x64 + {6D5028CE-4D76-4B6A-A7C2-DE5A3268D433}.Debug|x64.Deploy.0 = Debug|x64 {6D5028CE-4D76-4B6A-A7C2-DE5A3268D433}.Debug|x86.ActiveCfg = Debug|Win32 {6D5028CE-4D76-4B6A-A7C2-DE5A3268D433}.Debug|x86.Build.0 = Debug|Win32 {6D5028CE-4D76-4B6A-A7C2-DE5A3268D433}.Release|Any CPU.ActiveCfg = Release|Win32 {6D5028CE-4D76-4B6A-A7C2-DE5A3268D433}.Release|x64.ActiveCfg = Release|x64 {6D5028CE-4D76-4B6A-A7C2-DE5A3268D433}.Release|x64.Build.0 = Release|x64 + {6D5028CE-4D76-4B6A-A7C2-DE5A3268D433}.Release|x64.Deploy.0 = Release|x64 {6D5028CE-4D76-4B6A-A7C2-DE5A3268D433}.Release|x86.ActiveCfg = Release|Win32 {6D5028CE-4D76-4B6A-A7C2-DE5A3268D433}.Release|x86.Build.0 = Release|Win32 {3A716FB6-DE62-439F-83B6-3C40915D6678}.Debug|Any CPU.ActiveCfg = Debug|Any CPU diff --git a/PanoPainter.vcxproj b/PanoPainter.vcxproj index e375345..077ce91 100644 --- a/PanoPainter.vcxproj +++ b/PanoPainter.vcxproj @@ -428,6 +428,7 @@ + @@ -510,6 +511,8 @@ Designer + + @@ -543,6 +546,9 @@ + + + diff --git a/PanoPainter.vcxproj.filters b/PanoPainter.vcxproj.filters index 60e0da6..df16511 100644 --- a/PanoPainter.vcxproj.filters +++ b/PanoPainter.vcxproj.filters @@ -578,6 +578,9 @@ Header Files + + Header Files + @@ -683,4 +686,9 @@ shaders + + + Resource Files + + \ No newline at end of file diff --git a/data/splash.bmp b/data/splash.bmp new file mode 100644 index 0000000..575919b Binary files /dev/null and b/data/splash.bmp differ diff --git a/resource.h b/resource.h index 42e2961..7c5d90a 100644 Binary files a/resource.h and b/resource.h differ diff --git a/src/log.cpp b/src/log.cpp index 420b341..e5a2ccd 100644 --- a/src/log.cpp +++ b/src/log.cpp @@ -96,6 +96,10 @@ void LogRemote::log(const char* format, ...) m_logfile.write(line.data(), line.size()); m_logfile.flush(); } +#if _WIN32 + auto line = "DBG: " + std::string(buffer, n) + "\n"; + OutputDebugStringA(line.c_str()); +#endif } void LogRemote::log(const wchar_t* format, ...) { @@ -127,6 +131,10 @@ void LogRemote::log(const wchar_t* format, ...) m_logfile.write(line.data(), line.size()); m_logfile.flush(); } +#if _WIN32 + auto line = L"DBG: " + std::wstring(buffer, n) + L"\n"; + OutputDebugStringW(line.c_str()); +#endif } LogRemote::~LogRemote() { diff --git a/src/main.cpp b/src/main.cpp index 9ed97c9..04fb99c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -578,6 +578,77 @@ void win32_save_window_state() p.rcNormalPosition.top, p.rcNormalPosition.right, p.rcNormalPosition.bottom })); } +LRESULT CALLBACK splash_proc(HWND hWndDlg, UINT Msg, WPARAM wParam, LPARAM lParam) +{ + switch (Msg) + { + case WM_INITDIALOG: + { + static char base_path[MAX_PATH]; + GetCurrentDirectoryA(MAX_PATH, base_path); + std::string path = std::string(base_path) + "\\data\\splash.bmp"; + auto hbitmap = (HBITMAP)LoadImageA(NULL, path.c_str(), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); + SendMessage(GetDlgItem(hWndDlg, IDC_STATIC_IMAGE), STM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)hbitmap); + SetDlgItemText(hWndDlg, IDC_STATIC_VERSION, g_version_number_w); + + auto monitor = MonitorFromWindow(0, MONITOR_DEFAULTTOPRIMARY); + auto x = unsigned{}; + auto y = unsigned{}; + GetDpiForMonitor(monitor, MDT_EFFECTIVE_DPI, &x, &y); + float z = (float)x / 96.f; + + RECT r; + GetClientRect(hWndDlg, &r); + MoveWindow(GetDlgItem(hWndDlg, IDC_STATIC_IMAGE), 0, 0, 512 * z, 200 * z, TRUE); + SetWindowPos(hWndDlg, HWND_TOP, 0, 0, 512 * z, 200 * z, SWP_NOMOVE); + + HWND hWndVersion = GetDlgItem(hWndDlg, IDC_STATIC_VERSION); + RECT rv; + GetClientRect(hWndVersion, &rv); + MoveWindow(hWndVersion, 0, 200 * z - (rv.bottom - rv.top), r.right - r.left, rv.bottom - rv.top, TRUE); + + return TRUE; + } + case WM_USER + 1: + PostQuitMessage(0); + return TRUE; + } + + return DefWindowProc(hWndDlg, Msg, wParam, lParam);; +} + +HWND splash_dialog; +void splash_thread_loop() +{ + splash_dialog = CreateDialog(hInst, MAKEINTRESOURCE(IDD_SPLASH), NULL, reinterpret_cast(splash_proc)); + + MSG msg; + while (GetMessage(&msg, 0, 0, 0) > 0) + { + if (IsDialogMessage(splash_dialog, &msg)) + { + DispatchMessage(&msg); + TranslateMessage(&msg); + } + } + + DestroyWindow(splash_dialog); +} + +BOOL UnadjustWindowRectEx(LPRECT prc, DWORD dwStyle, BOOL fMenu, DWORD dwExStyle) +{ + RECT rc; + SetRectEmpty(&rc); + BOOL fRc = AdjustWindowRectEx(&rc, dwStyle, fMenu, dwExStyle); + if (fRc) { + prc->left -= rc.left; + prc->top -= rc.top; + prc->right -= rc.right; + prc->bottom -= rc.bottom; + } + return fRc; +} + int main(int argc, char** argv) { WNDCLASS wc; @@ -587,17 +658,6 @@ int main(int argc, char** argv) App::I.initLog(); - init_vk_map(); -/* - if (!App::I.check_license()) - { - MessageBoxA(NULL, "Unable to verify this demo license, please make sure you are connected to Internet.", - "PanoPainter - License Error", MB_ICONERROR | MB_OK); - return -1; - } -*/ - - FILE* fp_check = fopen("data\\layout.xml", "rb"); if (!fp_check) { @@ -615,6 +675,9 @@ int main(int argc, char** argv) LOG("data files ok"); } + std::thread dialog_thread(splash_thread_loop); + + init_vk_map(); SetupExceptionHandler(); BT_SetTerminate(); @@ -647,6 +710,12 @@ int main(int argc, char** argv) GetDpiForMonitor(monitor, MDT_EFFECTIVE_DPI, &x, &y); App::I.zoom *= (float)x / 96.f; + int show_cmd = SW_NORMAL; + Settings::value("window-show-cmd", show_cmd); + DWORD wnd_style = WS_OVERLAPPEDWINDOW; + //if (show_cmd == SW_MAXIMIZE) + // wnd_style != WS_MAXIMIZE; + RECT clientRect = { 0, 0, (int)App::I.width * App::I.zoom, (int)App::I.height * App::I.zoom }; POINT clientPos = { CW_USEDEFAULT, CW_USEDEFAULT }; if (Settings::has("window-rect")) @@ -659,9 +728,9 @@ int main(int argc, char** argv) } else { - AdjustWindowRect(&clientRect, WS_OVERLAPPEDWINDOW, false); + AdjustWindowRect(&clientRect, wnd_style, false); } - hWnd = CreateWindow(wc.lpszClassName, L"PanoPainter", WS_OVERLAPPEDWINDOW, clientPos.x, clientPos.y, + hWnd = CreateWindow(wc.lpszClassName, L"PanoPainter", wnd_style, clientPos.x, clientPos.y, (float)(clientRect.right - clientRect.left), (float)(clientRect.bottom - clientRect.top), 0, 0, hInst, 0); @@ -723,7 +792,7 @@ int main(int argc, char** argv) wglDeleteContext(hRC); DestroyWindow(hWnd); - hWnd = CreateWindow(wc.lpszClassName, window_title, WS_OVERLAPPEDWINDOW, clientPos.x, clientPos.y, + hWnd = CreateWindow(wc.lpszClassName, window_title, wnd_style, clientPos.x, clientPos.y, (float)(clientRect.right - clientRect.left), (float)(clientRect.bottom - clientRect.top), 0, 0, hInst, 0); @@ -767,12 +836,6 @@ int main(int argc, char** argv) LOG("init app"); App::I.init(); - int show_cmd = SW_NORMAL; - Settings::value("window-show-cmd", show_cmd); - - LOG("show main window"); - ShowWindow(hWnd, show_cmd); - if (!sandboxed) { LOG("init WinTab"); @@ -798,6 +861,7 @@ int main(int argc, char** argv) const float target_tick_rate = 60; unsigned long t0 = GetTickCount(); unsigned long t1; + bool first_frame = true; int frames = 0; float one_sec = 0; float render_timer = 0; @@ -850,6 +914,18 @@ int main(int argc, char** argv) } } + if (first_frame) + { + first_frame = false; + WINDOWPLACEMENT wp; + GetWindowPlacement(hWnd, &wp); + wp.showCmd = show_cmd; + SetWindowPlacement(hWnd, &wp); +// GetClientRect(hWnd, &clientRect); +// App::I.width = clientRect.right - clientRect.left; +// App::I.height = clientRect.bottom - clientRect.top; + } + App::I.tick(dt); std::unique_lock lock(render_mutex); @@ -901,6 +977,14 @@ int main(int argc, char** argv) if (start_in_vr) App::I.vr_start(); + LOG("show main window"); + SetForegroundWindow(hWnd); + //ShowWindow(hWnd, show_cmd); + + SendMessage(splash_dialog, WM_USER + 1, 0, 0); + if (dialog_thread.joinable()) + dialog_thread.join(); + MSG msg; LOG("start main loop"); while (running == 1) @@ -941,7 +1025,7 @@ int main(int argc, char** argv) } // Clean up WacomTablet::I.terminate(); - DestroyWindow(hWnd); + UnregisterClass(className, hInst); LogRemote::I.stop(); } @@ -958,21 +1042,16 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) switch (msg) { - case WM_DESTROY: - if (running != -1) - { - running = 0; - render_cv.notify_all(); - if (renderer.joinable()) - renderer.join(); - if (hmd_renderer.joinable()) - hmd_renderer.join(); - App::I.terminate(); - } - break; case WM_USER_CLOSE: + running = 0; + render_cv.notify_all(); + if (renderer.joinable()) + renderer.join(); + if (hmd_renderer.joinable()) + hmd_renderer.join(); + App::I.terminate(); PostQuitMessage(0); - break; + return 0; case WM_PAINT: App::I.redraw = true; break; @@ -981,15 +1060,27 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) break; case WM_CLOSE: if (App::I.request_close()) + { + running = 0; + render_cv.notify_all(); + if (renderer.joinable()) + renderer.join(); + if (hmd_renderer.joinable()) + hmd_renderer.join(); + App::I.terminate(); PostQuitMessage(0); + return 0; + } else + { return true; + } break; case WM_SIZE: { auto w = (float)LOWORD(lp); auto h = (float)HIWORD(lp); - if (h != 0) + if (h != 0 && running == 1) { async_locker lock; App::I.resize(w, h);