Extract file menu binding and Win32 splash helper
This commit is contained in:
86
src/main.cpp
86
src/main.cpp
@@ -12,6 +12,7 @@
|
||||
#include "legacy_preference_storage.h"
|
||||
#include "renderer_gl/opengl_capabilities.h"
|
||||
#include "platform_windows/windows_platform_services.h"
|
||||
#include "platform_windows/windows_splash.h"
|
||||
#include "../resource.h"
|
||||
|
||||
#include <shellscalingapi.h>
|
||||
@@ -61,7 +62,6 @@ struct RetainedState
|
||||
std::mutex hmd_render_mutex;
|
||||
std::condition_variable hmd_render_cv;
|
||||
std::unique_ptr<Vive> vive;
|
||||
HWND splash_dialog{};
|
||||
};
|
||||
|
||||
RetainedState& retained_state()
|
||||
@@ -669,84 +669,6 @@ void win32_save_window_state()
|
||||
p.rcNormalPosition.right,
|
||||
p.rcNormalPosition.bottom });
|
||||
}
|
||||
|
||||
HBITMAP image_to_hbitmap(const Image& img)
|
||||
{
|
||||
BITMAPINFOHEADER bmih;
|
||||
memset(&bmih, 0, sizeof(BITMAPINFOHEADER));
|
||||
bmih.biWidth = img.width;
|
||||
bmih.biHeight = img.height;
|
||||
bmih.biBitCount = 32;
|
||||
bmih.biCompression = BI_RGB;
|
||||
bmih.biSize = sizeof(BITMAPINFOHEADER);
|
||||
bmih.biPlanes = 1;
|
||||
BITMAPINFO* bmi = (BITMAPINFO*)&bmih;
|
||||
return CreateDIBitmap(GetDC(NULL), &bmih, CBM_INIT, img.data(), bmi, DIB_RGB_COLORS);
|
||||
}
|
||||
|
||||
LRESULT CALLBACK splash_proc(HWND hWndDlg, UINT Msg, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
switch (Msg)
|
||||
{
|
||||
case WM_INITDIALOG:
|
||||
{
|
||||
auto monitor = MonitorFromWindow(0, MONITOR_DEFAULTTOPRIMARY);
|
||||
auto x = unsigned{ 96 };
|
||||
auto y = unsigned{ 96 };
|
||||
if (GetDpiForMonitor_fn)
|
||||
GetDpiForMonitor_fn(monitor, MDT_EFFECTIVE_DPI, &x, &y);
|
||||
float z = (float)x / 96.f;
|
||||
|
||||
static char base_path[MAX_PATH];
|
||||
GetCurrentDirectoryA(MAX_PATH, base_path);
|
||||
std::string path = std::string(base_path) + "\\data\\splash.jpg";
|
||||
//auto hbitmap = (HBITMAP)LoadImageA(NULL, path.c_str(), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
|
||||
Image img;
|
||||
img.load_file(path);
|
||||
img.flip();
|
||||
auto hbitmap = image_to_hbitmap(img.resize(512 * z, 200 * z));
|
||||
SendMessage(GetDlgItem(hWndDlg, IDC_STATIC_IMAGE), STM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)hbitmap);
|
||||
SetDlgItemText(hWndDlg, IDC_STATIC_VERSION, g_version_number_w);
|
||||
|
||||
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_CLOSE:
|
||||
PostQuitMessage(0);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return DefWindowProc(hWndDlg, Msg, wParam, lParam);;
|
||||
}
|
||||
|
||||
void splash_thread_loop()
|
||||
{
|
||||
auto& state = retained_state();
|
||||
BT_SetTerminate();
|
||||
state.splash_dialog = CreateDialog(state.hInst, MAKEINTRESOURCE(IDD_SPLASH), NULL, reinterpret_cast<DLGPROC>(splash_proc));
|
||||
|
||||
MSG msg;
|
||||
while (GetMessage(&msg, 0, 0, 0) > 0)
|
||||
{
|
||||
if (IsDialogMessage(state.splash_dialog, &msg))
|
||||
{
|
||||
DispatchMessage(&msg);
|
||||
TranslateMessage(&msg);
|
||||
}
|
||||
}
|
||||
|
||||
DestroyWindow(state.splash_dialog);
|
||||
}
|
||||
|
||||
BOOL UnadjustWindowRectEx(LPRECT prc, DWORD dwStyle, BOOL fMenu, DWORD dwExStyle)
|
||||
{
|
||||
RECT rc;
|
||||
@@ -811,7 +733,7 @@ int main(int argc, char** argv)
|
||||
LOG("data files ok");
|
||||
}
|
||||
|
||||
std::jthread dialog_thread(splash_thread_loop);
|
||||
pp::platform::windows::SplashScreen splash(GetModuleHandle(NULL));
|
||||
|
||||
init_vk_map();
|
||||
|
||||
@@ -1022,9 +944,7 @@ int main(int argc, char** argv)
|
||||
SetForegroundWindow(state.hWnd);
|
||||
//ShowWindow(hWnd, show_cmd);
|
||||
|
||||
SendMessage(state.splash_dialog, WM_USER_CLOSE, 0, 0);
|
||||
if (dialog_thread.joinable())
|
||||
dialog_thread.join();
|
||||
splash.dismiss();
|
||||
|
||||
MSG msg;
|
||||
LOG("start main loop");
|
||||
|
||||
Reference in New Issue
Block a user