Extract brush panel UI, app startup shell, and Win32 runtime shell

This commit is contained in:
2026-06-16 22:03:27 +02:00
parent a2a67960c8
commit 24d9d5b6e2
13 changed files with 480 additions and 332 deletions

View File

@@ -0,0 +1,131 @@
#include "pch.h"
#include "platform_windows/windows_runtime_shell.h"
#include "app.h"
#include "log.h"
#include "platform_windows/windows_bootstrap_helpers.h"
#include "platform_windows/windows_lifecycle_shell.h"
#include "platform_windows/windows_platform_services.h"
#include "platform_windows/windows_window_shell.h"
#include "wacom.h"
#include "../resource.h"
namespace pp::platform::windows {
namespace {
void register_touch_window(HWND hWnd)
{
// link: https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-registertouchwindow
if (RegisterTouchWindow(hWnd, 0) == 0)
{
LOG("RegisterTouchWindow error: %s", GetLastErrorAsString().c_str());
}
}
void initialize_runtime_threads()
{
mark_lifecycle_running();
App::I->runtime().render_thread_start(*App::I);
App::I->runtime().ui_thread_start(*App::I);
}
void install_debug_gl_callbacks()
{
#ifdef _DEBUG
glad_set_pre_callback(_pre_call_callback);
glad_set_post_callback(_post_call_callback);
#endif
}
void initialize_wintab(HWND hWnd, bool sandboxed)
{
if (!sandboxed)
{
LOG("init WinTab");
WacomTablet::I.init(hWnd);
}
else
{
LOG("SKIP init WinTab");
}
}
void set_main_window_icon(HWND hWnd)
{
LOG("change icon");
SendMessage(
hWnd,
WM_SETICON,
ICON_SMALL,
(LPARAM)LoadIcon(GetModuleHandle(0), MAKEINTRESOURCE(IDI_ICON1)));
}
void restore_window_placement(HWND hWnd, int show_command)
{
WINDOWPLACEMENT wp;
GetWindowPlacement(hWnd, &wp);
wp.showCmd = show_command;
SetWindowPlacement(hWnd, &wp);
}
void run_main_message_loop()
{
MSG msg;
LOG("start main loop");
while (lifecycle_is_running())
{
auto present = App::I->animate || App::I->redraw ?
PeekMessage(&msg, 0, 0, 0, PM_REMOVE) : GetMessage(&msg, 0, 0, 0);
if (msg.message == WM_QUIT)
mark_lifecycle_stopped();
if (present)
{
DispatchMessage(&msg);
TranslateMessage(&msg);
}
drain_main_thread_tasks();
}
}
void shutdown_main_window_runtime(const MainWindowStartupState& startup, HINSTANCE hInst)
{
WacomTablet::I.terminate();
UnregisterClass(startup.window_class.lpszClassName, hInst);
LogRemote::I.stop();
}
}
void run_main_window_runtime(const MainWindowStartupState& startup, bool start_in_vr, SplashScreen& splash)
{
auto& state = retained_state();
register_touch_window(state.hWnd);
wglMakeCurrent(NULL, NULL);
initialize_runtime_threads();
install_debug_gl_callbacks();
initialize_wintab(state.hWnd, state.sandboxed);
set_main_window_icon(state.hWnd);
App::I->ui_sync();
restore_window_placement(state.hWnd, startup.show_command);
if (start_in_vr)
App::I->vr_start();
LOG("show main window");
SetForegroundWindow(state.hWnd);
splash.dismiss();
run_main_message_loop();
shutdown_main_window_runtime(startup, state.hInst);
}
}