All checks were successful
CI / Windows build (push) Successful in 11m34s
W1 — Custom pen width + pressure sensitivity (Saber-style):
- Root cause of "压感没用": perfect_freehand 1.0.4 IGNORES real stylus pressure
(hardcodes radius=size/2 when simulatePressure=false) — width never tracked pen
force. Upgraded perfect_freehand ^1.0.0 -> ^2.0.0 (honors real pressure); migrated
all 5 getStroke call sites to the 2.x API (PointVector / StrokeOptions / Offset).
- De-hardcoded `thinning` into `kDefaultPenThinning` (0.85), single source shared by
the on-screen painter and the PDF export path; exposed as PenConfig.pressureSensitivity
with a Pressure Sensitivity slider; live-applies via a config listener.
W3 — Native Windows pen plugin (tilt + barrel/eraser buttons):
- windows/runner/pen_channel.{h,cpp}: observe WM_POINTER at the TOP of MessageHandler
(before HandleTopLevelWindowProc, which Flutter uses to consume pen events), read
GetPointerPenInfo penFlags + tilt, stream over EventChannel('badnote/pen'); non-consuming.
- PenInputService: single latched hardware state (no Win32-pointerId<->event.pointer
correlation); graceful no-op off-Windows.
- pen_canvas maps barrel/inverted/eraser through PenConfig.sideButton/eraserEnd
(eraser/undo/toggleTool/pan) and captures tilt into PenPoint.tilt -> EditorPoint.tilt.
W2 — Zoom flicker: page raster isolated in its own RepaintBoundary (safe interim);
definitive crisp-on-zoom fix gated on the on-device root-cause probe (plan M3).
Plans: ralplan-consensus plan at docs/plans/2026-06-22-badnote-pen-polish.md
(Architect APPROVE-WITH-MUST-FIX M1-M4 + Critic ITERATE->APPROVE).
Tests: 58/58 pass incl. shared-thinning invariant + thinning-affects-outline +
tilt-adapter round-trip. flutter analyze clean; linux debug build OK.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
90 lines
2.8 KiB
C++
90 lines
2.8 KiB
C++
#include "pen_channel.h"
|
|
|
|
#include <flutter/encodable_value.h>
|
|
#include <flutter/event_channel.h>
|
|
#include <flutter/event_stream_handler_functions.h>
|
|
#include <flutter/flutter_engine.h>
|
|
#include <flutter/standard_method_codec.h>
|
|
|
|
#include <memory>
|
|
|
|
namespace {
|
|
|
|
std::unique_ptr<flutter::EventSink<flutter::EncodableValue>> g_pen_sink;
|
|
|
|
std::unique_ptr<flutter::EventChannel<flutter::EncodableValue>> g_pen_channel;
|
|
|
|
} // namespace
|
|
|
|
void RegisterPenChannel(flutter::FlutterEngine* engine) {
|
|
g_pen_channel =
|
|
std::make_unique<flutter::EventChannel<flutter::EncodableValue>>(
|
|
engine->messenger(), "badnote/pen",
|
|
&flutter::StandardMethodCodec::GetInstance());
|
|
|
|
auto handler = std::make_unique<
|
|
flutter::StreamHandlerFunctions<flutter::EncodableValue>>(
|
|
[](const flutter::EncodableValue* arguments,
|
|
std::unique_ptr<flutter::EventSink<flutter::EncodableValue>>&&
|
|
events)
|
|
-> std::unique_ptr<
|
|
flutter::StreamHandlerError<flutter::EncodableValue>> {
|
|
g_pen_sink = std::move(events);
|
|
return nullptr;
|
|
},
|
|
[](const flutter::EncodableValue* arguments)
|
|
-> std::unique_ptr<
|
|
flutter::StreamHandlerError<flutter::EncodableValue>> {
|
|
g_pen_sink = nullptr;
|
|
return nullptr;
|
|
});
|
|
|
|
g_pen_channel->SetStreamHandler(std::move(handler));
|
|
}
|
|
|
|
void ObservePenMessage(UINT message, WPARAM wparam, LPARAM lparam) {
|
|
if (message != WM_POINTERENTER && message != WM_POINTERDOWN &&
|
|
message != WM_POINTERUPDATE && message != WM_POINTERUP) {
|
|
return;
|
|
}
|
|
|
|
if (!g_pen_sink) {
|
|
return;
|
|
}
|
|
|
|
UINT32 pointerId = GET_POINTERID_WPARAM(wparam);
|
|
|
|
POINTER_INPUT_TYPE type = PT_POINTER;
|
|
if (!GetPointerType(pointerId, &type) || type != PT_PEN) {
|
|
return;
|
|
}
|
|
|
|
POINTER_PEN_INFO ppi{};
|
|
if (!GetPointerPenInfo(pointerId, &ppi)) {
|
|
return;
|
|
}
|
|
|
|
int flags = 0;
|
|
if (ppi.penFlags & PEN_FLAG_BARREL) flags |= 1;
|
|
if (ppi.penFlags & PEN_FLAG_INVERTED) flags |= 2;
|
|
if (ppi.penFlags & PEN_FLAG_ERASER) flags |= 4;
|
|
|
|
flutter::EncodableMap payload{
|
|
{flutter::EncodableValue("flags"), flutter::EncodableValue(flags)},
|
|
{flutter::EncodableValue("tiltX"), flutter::EncodableValue(static_cast<double>(ppi.tiltX))},
|
|
{flutter::EncodableValue("tiltY"), flutter::EncodableValue(static_cast<double>(ppi.tiltY))},
|
|
};
|
|
|
|
g_pen_sink->Success(flutter::EncodableValue(payload));
|
|
|
|
// On pointer up, send a cleared flags event to signal lift-off.
|
|
if (message == WM_POINTERUP) {
|
|
flutter::EncodableMap clear{
|
|
{flutter::EncodableValue("flags"), flutter::EncodableValue(0)},
|
|
{flutter::EncodableValue("tiltX"), flutter::EncodableValue(0.0)},
|
|
{flutter::EncodableValue("tiltY"), flutter::EncodableValue(0.0)},
|
|
};
|
|
g_pen_sink->Success(flutter::EncodableValue(clear));
|
|
}
|
|
}
|