Extract menu, stylus, and canvas draw helpers

This commit is contained in:
2026-06-16 11:25:09 +02:00
parent d135835787
commit 18665bdffc
10 changed files with 510 additions and 361 deletions

View File

@@ -13,6 +13,7 @@
#include "renderer_gl/opengl_capabilities.h"
#include "platform_windows/windows_platform_services.h"
#include "platform_windows/windows_splash.h"
#include "platform_windows/windows_stylus_input.h"
#include "../resource.h"
#include <shellscalingapi.h>
@@ -55,9 +56,6 @@ struct RetainedState
std::map<kKey, int> vkey_map;
wchar_t window_title[512]{};
std::jthread hmd_renderer;
float timer_stylus = 0;
float timer_ink_touch = 0;
float timer_ink_pen = 0;
bool sandboxed = false;
std::mutex hmd_render_mutex;
std::condition_variable hmd_render_cv;
@@ -176,25 +174,6 @@ void init_shcore_API()
SetProcessDpiAwareness_fn = (decltype(SetProcessDpiAwareness_fn))GetProcAddress(dll, "SetProcessDpiAwareness");
}
BOOL(*GetPointerInfo_fn)(UINT32 pointerId, POINTER_INFO* pointerInfo);
BOOL(*GetPointerType_fn)(UINT32 pointerId, POINTER_INPUT_TYPE* pointerType);
BOOL(*GetPointerTouchInfo_fn)(UINT32 pointerId, POINTER_TOUCH_INFO* touchInfo);
BOOL(*GetPointerPenInfo_fn)(UINT32 pointerId, POINTER_PEN_INFO* penInfo);
void init_ink_API()
{
HMODULE dll = LoadLibrary(L"User32.dll");
if (!dll)
{
LOG("cannot load User32.dll");
return;
}
LOG("loaded User32.dll");
GetPointerInfo_fn = (decltype(GetPointerInfo_fn))GetProcAddress(dll, "GetPointerInfo");
GetPointerType_fn = (decltype(GetPointerType_fn))GetProcAddress(dll, "GetPointerType");
GetPointerTouchInfo_fn = (decltype(GetPointerTouchInfo_fn))GetProcAddress(dll, "GetPointerTouchInfo");
GetPointerPenInfo_fn = (decltype(GetPointerPenInfo_fn))GetProcAddress(dll, "GetPointerPenInfo");
}
//Returns the last Win32 error, in string format. Returns an empty string if there is no error.
std::string GetLastErrorAsString()
{
@@ -245,27 +224,7 @@ void async_unlock()
void win32_update_stylus(float dt)
{
auto& state = retained_state();
state.timer_stylus += dt;
state.timer_ink_touch += dt;
state.timer_ink_pen += dt;
if (state.timer_stylus > 0.1 && (WacomTablet::I.m_stylus || WacomTablet::I.m_eraser))
{
WacomTablet::I.m_stylus = false;
WacomTablet::I.m_eraser = false;
App::I->redraw = true;
}
if (state.timer_ink_pen > 0.1 && WacomTablet::I.m_ink_pen)
{
WacomTablet::I.m_ink_pen = false;
App::I->redraw = true;
}
if (state.timer_ink_touch > 0.1 && WacomTablet::I.m_ink_touch)
{
WacomTablet::I.m_ink_touch = false;
App::I->redraw = true;
}
pp::platform::windows::update_stylus_state(dt);
}
void win32_update_fps(int frames)
@@ -710,7 +669,7 @@ int main(int argc, char** argv)
App::I->initLog();
init_shcore_API();
init_ink_API();
pp::platform::windows::initialize_stylus_input();
if(SetProcessDpiAwareness_fn)
SetProcessDpiAwareness_fn(PROCESS_PER_MONITOR_DPI_AWARE);
@@ -1064,8 +1023,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
// }
case WT_PACKET:
{
App::I->set_stylus();
state.timer_stylus = 0;
pp::platform::windows::note_wintab_packet();
App::I->ui_task_async([=] {
WacomTablet::I.handle_message(hWnd, msg, wp, lp);
});
@@ -1229,79 +1187,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
}
case WM_POINTERUPDATE:
{
POINTER_TOUCH_INFO touchInfo;
POINTER_PEN_INFO penInfo;
POINTER_INFO pointerInfo;
UINT32 pointerId = GET_POINTERID_WPARAM(wp);
POINTER_INPUT_TYPE pointerType = PT_POINTER;
if(!GetPointerInfo_fn)
break;
// Retrieve common pointer information
if (!GetPointerInfo_fn(pointerId, &pointerInfo))
{
// failure, call GetLastError()
}
else
{
// success, process pointerInfo
if (!GetPointerType_fn(pointerId, &pointerType))
{
// failure, call GetLastError()
// set PT_POINTER to fall to default case below
pointerType = PT_POINTER;
}
switch (pointerType)
{
case PT_TOUCH:
// Retrieve touch information
if (!GetPointerTouchInfo_fn(pointerId, &touchInfo))
{
// failure, call GetLastError()
}
else
{
// success, process touchInfo
// mark as handled to skip call to DefWindowProc
//fHandled = TRUE;
state.timer_ink_touch = 0;
WacomTablet::I.m_ink_touch = true;
WacomTablet::I.m_pen_pres = 1;
}
break;
case PT_PEN:
// Retrieve pen information
if (!GetPointerPenInfo_fn(pointerId, &penInfo))
{
// failure, call GetLastError()
}
else
{
// success, process penInfo
// mark as handled to skip call to DefWindowProc
//fHandled = TRUE;
//penInfo.pressure
state.timer_ink_pen = 0;
WacomTablet::I.m_ink_pen = true;
WacomTablet::I.m_pen_pres = (float)penInfo.pressure / 1024.f;
App::I->set_stylus();
}
break;
default:
if (!GetPointerInfo_fn(pointerId, &pointerInfo))
{
// failure.
}
else
{
// success, proceed with pointerInfo.
//fHandled = HandleGenericPointerInfo(&pointerInfo);
}
break;
}
}
pp::platform::windows::handle_pointer_update_message(wp);
break;
}
}