Bind Win32 tablet state in runtime shell

This commit is contained in:
2026-06-17 08:52:02 +02:00
parent 3930e70817
commit e9723276be
6 changed files with 107 additions and 80 deletions

View File

@@ -8,6 +8,7 @@
#include "wacom.h"
namespace pp::platform::windows {
namespace {
struct StylusInputState final
@@ -28,6 +29,13 @@ StylusInputState& stylus_input_state()
return state;
}
[[nodiscard]] WacomTablet& active_wacom_tablet()
{
auto* tablet = bound_wacom_tablet();
assert(tablet);
return *tablet;
}
}
void initialize_stylus_input()
@@ -55,24 +63,25 @@ void update_stylus_state(float dt)
{
auto& state = stylus_input_state();
auto* app = bound_app();
auto& tablet = active_wacom_tablet();
state.timer_stylus += dt;
state.timer_ink_touch += dt;
state.timer_ink_pen += dt;
if (state.timer_stylus > 0.1f && (WacomTablet::I.m_stylus || WacomTablet::I.m_eraser))
if (state.timer_stylus > 0.1f && (tablet.m_stylus || tablet.m_eraser))
{
WacomTablet::I.m_stylus = false;
WacomTablet::I.m_eraser = false;
tablet.m_stylus = false;
tablet.m_eraser = false;
app->redraw = true;
}
if (state.timer_ink_pen > 0.1f && WacomTablet::I.m_ink_pen)
if (state.timer_ink_pen > 0.1f && tablet.m_ink_pen)
{
WacomTablet::I.m_ink_pen = false;
tablet.m_ink_pen = false;
app->redraw = true;
}
if (state.timer_ink_touch > 0.1f && WacomTablet::I.m_ink_touch)
if (state.timer_ink_touch > 0.1f && tablet.m_ink_touch)
{
WacomTablet::I.m_ink_touch = false;
tablet.m_ink_touch = false;
app->redraw = true;
}
}
@@ -87,6 +96,7 @@ void note_wintab_packet()
void handle_pointer_update_message(WPARAM wp)
{
auto& state = stylus_input_state();
auto& tablet = active_wacom_tablet();
if (!state.get_pointer_info)
return;
@@ -109,8 +119,8 @@ void handle_pointer_update_message(WPARAM wp)
return;
state.timer_ink_touch = 0.0f;
WacomTablet::I.m_ink_touch = true;
WacomTablet::I.m_pen_pres = 1.0f;
tablet.m_ink_touch = true;
tablet.m_pen_pres = 1.0f;
return;
case PT_PEN:
@@ -118,8 +128,8 @@ void handle_pointer_update_message(WPARAM wp)
return;
state.timer_ink_pen = 0.0f;
WacomTablet::I.m_ink_pen = true;
WacomTablet::I.m_pen_pres = static_cast<float>(pen_info.pressure) / 1024.0f;
tablet.m_ink_pen = true;
tablet.m_pen_pres = static_cast<float>(pen_info.pressure) / 1024.0f;
bound_app()->set_stylus();
return;