From 4bd29bee9fc70fbe3f5460080944f82b5d59d567 Mon Sep 17 00:00:00 2001 From: omigamedev Date: Thu, 4 Jun 2026 18:26:21 +0200 Subject: [PATCH] Route canvas input policy through platform services --- docs/modernization/build-inventory.md | 8 ++-- docs/modernization/debt.md | 4 +- docs/modernization/roadmap.md | 9 +++- src/app.h | 2 + src/app_events.cpp | 13 +++++ src/canvas_modes.cpp | 24 ++-------- src/platform_api/platform_services.h | 5 ++ .../legacy_platform_services.cpp | 19 ++++++++ .../windows_platform_services.cpp | 17 +++++++ .../platform_api/platform_services_tests.cpp | 47 +++++++++++++++++++ 10 files changed, 122 insertions(+), 26 deletions(-) diff --git a/docs/modernization/build-inventory.md b/docs/modernization/build-inventory.md index deed40e..04c00e9 100644 --- a/docs/modernization/build-inventory.md +++ b/docs/modernization/build-inventory.md @@ -208,7 +208,8 @@ Known local toolchain state: - `src/legacy_canvas_tool_services.*` is the current app-shell bridge for canvas toolbar tool selection, NodeCanvas stylus/input mode switching, and canvas hotkey/touch execution. It keeps those live paths on the `pp_app_core` - contracts while legacy `Canvas` mode state, transform actions, picking, + contracts while canvas mode tip visibility and pressure remapping now ask + `PlatformServices`; legacy `Canvas` mode state, transform actions, picking, touch-lock, save/UI/cursor calls, brush-size controls, and history execution remain tracked by `DEBT-0027`. - `src/legacy_document_animation_services.*` is the current UI-shell bridge for @@ -555,8 +556,9 @@ Known local toolchain state: hooks, render debug callback hooks, per-frame platform hooks, picker callbacks, recording cleanup, exported-image publishing, persistent storage flushing, document browse roots, working-directory picker policy and - display-path formatting, native UI/window state saving, live asset/layout - reload policy, diagnostic stacktrace/crash hooks, + display-path formatting, canvas input tip visibility and pressure remapping, + native UI/window state saving, live asset/layout reload policy, diagnostic + stacktrace/crash hooks, SonarPen availability/startup, PPBR export data-directory policy, prepared-file writable target selection, network TLS verification policy, and prepared-file save/download handoff; PPBR diff --git a/docs/modernization/debt.md b/docs/modernization/debt.md index c3e9de6..62eb512 100644 --- a/docs/modernization/debt.md +++ b/docs/modernization/debt.md @@ -35,7 +35,7 @@ agent or engineer to remove them without reconstructing context from chat. | DEBT-0014 | Open | Modernization | `windows-clangcl-asan` now configures as a headless Ninja/clang-cl preset and uses the release MSVC runtime required by ASan, but local builds still fail because installed clang-cl 18.1.8 is paired with VS 2026-preview STL headers that require Clang 20 or newer | Sanitizer validation should be local and repeatable, but this machine's compiler/header pairing is incompatible | `cmake --fresh --preset windows-clangcl-asan`; `cmake --build --preset windows-clangcl-asan --target pp_foundation` | Install/use Clang 20+ with the VS 2026 STL, or point the preset at a compatible VS 2022 toolchain, then make `platform-build.ps1 -Presets windows-clangcl-asan` pass for the headless matrix | | DEBT-0015 | Open | Modernization | Cursor visibility requests now consume pure `pp_app_core` planning through `pano_cli plan-cursor-visibility`, `App::show_cursor`/`App::hide_cursor` dispatch through `PlatformServices` without platform guards, and Windows live execution uses injected `WindowsPlatformServices`, but macOS cursor execution still reaches the retained fallback adapter | Keep canvas cursor behavior stable while platform shells are extracted incrementally | `pp_app_core_document_platform_io_tests`; `pano_cli plan-cursor-visibility --visible`; `ctest --preset desktop-fast --build-config Debug` | Cursor visibility execution is owned by injected `pp_platform_*` services for every supported platform | | DEBT-0016 | Open | Modernization | Clipboard get/set requests now consume pure `pp_app_core` planning through `pano_cli plan-clipboard-read` and `pano_cli plan-clipboard-write`, and Windows live execution uses injected `WindowsPlatformServices`, but Apple/Android clipboard execution still reaches retained fallback adapter branches from `App::clipboard_get_text` and `App::clipboard_set_text` | Keep picker/color text clipboard behavior stable while platform shells are extracted incrementally | `pp_app_core_document_platform_io_tests`; `pano_cli plan-clipboard-write --text #ff00aa`; `ctest --preset desktop-fast --build-config Debug` | Clipboard execution is owned by injected `pp_platform_*` services for every supported platform | -| DEBT-0017 | Open | Modernization | Startup storage path preparation, `App::clipboard_get_text`, `App::clipboard_set_text`, `App::show_cursor`, `App::hide_cursor`, `App::showKeyboard`, `App::hideKeyboard`, `App::display_file`, `App::share_file`, native app/window close, UI-thread lifecycle hooks, render-context acquire/release/present hooks, render-target binding hooks, render platform hint hooks, render debug callback hooks, render-capture frame hooks, recording cleanup, live asset/layout reload policy, diagnostic stacktrace/crash hooks, per-frame platform hooks, `App::pick_image`, `App::pick_file`, the non-writer `App::pick_file_save`, `App::pick_dir`, working-directory picker/display-path policy, prepared-file save/download handoff, work-directory document export collection policy, app network TLS verification policy, PPBR export data-directory policy, and SonarPen availability/startup now call the SDK-free `pp::platform::PlatformServices` interface, and Windows injects `WindowsPlatformServices` from `src/platform_windows/windows_platform_services.*`; non-Windows live implementations still use `src/platform_legacy/legacy_platform_services.*`, a named fallback adapter that forwards to retained Apple/Android/Linux/Web bridge functions and retained no-op branches, including the retained macOS directory picker/display-path behavior, retained iOS SonarPen bridge, and retained macOS PPBR export directory override; `pp_platform_api` also owns the default network TLS policy helper consumed by retained curl sites that cannot yet depend on injected services | Preserve behavior while moving platform execution behind a testable service boundary before platform shell implementations are injected | `pp_platform_api_tests`; `pp_app_core_document_export_tests`; `pp_app_core_document_platform_io_tests`; `ctest --preset desktop-fast --build-config Debug`; `powershell -ExecutionPolicy Bypass -File scripts\automation\package-smoke.ps1 -Preset windows-msvc-default -Configuration Debug` | Replace `src/platform_legacy/legacy_platform_services.*` with injected `pp_platform_*` service implementations owned by each non-Windows platform shell | +| DEBT-0017 | Open | Modernization | Startup storage path preparation, `App::clipboard_get_text`, `App::clipboard_set_text`, `App::show_cursor`, `App::hide_cursor`, `App::showKeyboard`, `App::hideKeyboard`, `App::display_file`, `App::share_file`, native app/window close, UI-thread lifecycle hooks, render-context acquire/release/present hooks, render-target binding hooks, render platform hint hooks, render debug callback hooks, render-capture frame hooks, recording cleanup, live asset/layout reload policy, diagnostic stacktrace/crash hooks, per-frame platform hooks, `App::pick_image`, `App::pick_file`, the non-writer `App::pick_file_save`, `App::pick_dir`, working-directory picker/display-path policy, canvas input tip/pressure policy, prepared-file save/download handoff, work-directory document export collection policy, app network TLS verification policy, PPBR export data-directory policy, and SonarPen availability/startup now call the SDK-free `pp::platform::PlatformServices` interface, and Windows injects `WindowsPlatformServices` from `src/platform_windows/windows_platform_services.*`; non-Windows live implementations still use `src/platform_legacy/legacy_platform_services.*`, a named fallback adapter that forwards to retained Apple/Android/Linux/Web bridge functions and retained no-op branches, including retained iOS canvas tip behavior, retained macOS directory picker/display-path behavior, retained iOS SonarPen bridge, and retained macOS PPBR export directory override; `pp_platform_api` also owns the default network TLS policy helper consumed by retained curl sites that cannot yet depend on injected services | Preserve behavior while moving platform execution behind a testable service boundary before platform shell implementations are injected | `pp_platform_api_tests`; `pp_app_core_document_export_tests`; `pp_app_core_document_platform_io_tests`; `ctest --preset desktop-fast --build-config Debug`; `powershell -ExecutionPolicy Bypass -File scripts\automation\package-smoke.ps1 -Preset windows-msvc-default -Configuration Debug` | Replace `src/platform_legacy/legacy_platform_services.*` with injected `pp_platform_*` service implementations owned by each non-Windows platform shell | | DEBT-0019 | Open | Modernization | Unreferenced-parameter warnings are muted globally through `pp_project_warnings` with MSVC `/wd4100` and Clang/GCC `-Wno-unused-parameter` | Legacy callbacks, virtual hooks, serializer methods, and platform/API compatibility functions carry many intentionally unused parameters during the component split; muting this keeps stricter warning builds focused on higher-signal migration issues | `cmake --build --preset windows-msvc-default --config Debug --target PanoPainter`; `ctest --preset desktop-fast --build-config Debug`; `cmake --build --preset linux-clang --target pp_foundation` | Remove `/wd4100` and `-Wno-unused-parameter`, mark intentionally unused parameters with names/comments or `[[maybe_unused]]`, and make the Windows app plus headless Clang/GCC tests pass without unreferenced-parameter warnings | | DEBT-0020 | Open | Modernization | Document resize dialog state, selected-resolution planning, and execution dispatch now consume pure `pp_app_core` through `NodeDialogResize`, `App::dialog_resize`, `pano_cli plan-document-resize`, and the `DocumentResizeServices` boundary, and live resize shares `src/legacy_document_canvas_services.*` with canvas clear commands, but the shared live bridge still calls legacy `Canvas::resize`, updates the legacy app title, and clears legacy `ActionManager` history through the history bridge | Preserve existing layer/frame GPU resize behavior while the document model and canvas execution boundary are extracted incrementally | `pp_app_core_document_resize_tests`; `pano_cli plan-document-resize --current-resolution 2048 --selected-resolution-index 4`; `ctest --preset desktop-fast --build-config Debug` | Document resize execution is owned by injected document/app services with no legacy resize adapter, title shim, or direct `ActionManager` history clearing | | DEBT-0021 | Open | Modernization | Layer rename planning/execution dispatch and layer panel operation planning/execution dispatch now consume pure `pp_app_core` through `App::dialog_layer_rename`, `App::init_sidebar` layer callbacks, `pano_cli plan-layer-rename`, `pano_cli plan-layer-operation`, `DocumentLayerRenameServices`, and `DocumentLayerOperationServices`, and the live execution adapters are centralized in `src/legacy_document_layer_services.*`, but that shared bridge still mutates legacy `Canvas` layer state, `NodeLayer`/`NodePanelLayer`, and `ActionManager` undo entries | Preserve existing UI/canvas behavior while document layer commands and undo history are extracted incrementally | `pp_app_core_document_layer_tests`; `pano_cli plan-layer-rename --old-name Base --new-name Paint`; `pano_cli plan-layer-operation --kind add --layer-count 2 --index 1 --name Paint`; `ctest --preset desktop-fast --build-config Debug` | Layer command execution is owned by the document/app command boundary with legacy `Canvas`/UI nodes acting only as adapters or removed entirely | @@ -44,7 +44,7 @@ agent or engineer to remove them without reconstructing context from chat. | DEBT-0024 | Open | Modernization | Grid/heightmap/lightmap UI planning and execution dispatch now consume pure `pp_app_core` through `NodePanelGrid`, `pano_cli plan-grid-operation`, and the `GridUiServices` boundary; live execution is centralized in `src/legacy_grid_ui_services.*`, and retained CPU lightmap row dispatch now uses shared `parallel_for` instead of platform-specific Win32/Apple worker APIs, but the bridge still performs legacy image loading, OpenGL texture updates, nanort lightmap baking/progress, and `Canvas::draw_objects` commit execution | Preserve grid/lightmap behavior while moving renderable grid commands toward app/renderer/document boundaries | `pp_app_core_grid_ui_tests`; `pano_cli plan-grid-operation --kind render --float32 --texture-resolution 1024 --samples 32`; `ctest --preset desktop-fast --build-config Debug` | Grid heightmap/lightmap execution is owned by app/renderer/document services with `NodePanelGrid` acting only as UI adapter | | DEBT-0025 | Open | Modernization | Quick brush/color slot and mini-state planning and execution dispatch now consume pure `pp_app_core` through `NodePanelQuick`, `pano_cli plan-quick-operation`, and the `QuickUiServices` boundary; live execution is centralized in `src/legacy_quick_ui_services.*`, but the bridge still mutates legacy quick UI widgets, `Brush` previews, color picker popup state, and preset popup state | Preserve quick-panel behavior while quick brush/color commands move toward a brush/app command boundary with safer automation coverage | `pp_app_core_quick_ui_tests`; `pano_cli plan-quick-operation --kind brush --current-index 0 --slot-index 2`; `pano_cli plan-quick-operation --kind restore --brush-index 2 --color-index 1 --fire-event`; `ctest --preset desktop-fast --build-config Debug` | Quick-panel selection, popup, restore, reset, brush preview, and color execution are owned by injected app/brush/UI services with no legacy quick-panel adapter | | DEBT-0026 | Open | Modernization | Toolbar history command planning and canvas hotkey history dispatch now consume pure `pp_app_core` through `App::init_toolbar_main`, `NodeCanvas`, `pano_cli plan-history-operation`, and the `HistoryUiServices` boundary, and both live callers share `src/legacy_history_services.*` for saturated legacy history metrics and execution, but the shared live bridge still mutates legacy `ActionManager` stacks directly | Preserve undo/redo/clear behavior while moving action history toward document/app command services | `pp_app_core_history_ui_tests`; `pano_cli plan-history-operation --kind undo --undo-count 2`; `pano_cli plan-history-operation --kind clear --undo-count 2 --redo-count 1 --memory-bytes 4096`; `ctest --preset desktop-fast --build-config Debug` | Undo/redo/clear execution is owned by injected document/app history services with no legacy `ActionManager` adapter | -| DEBT-0027 | Open | Modernization | Canvas draw-tool toolbar command, canvas input mode switching, active-state planning/execution dispatch, and canvas keyboard/touch command planning now consume pure `pp_app_core` through `App::init_toolbar_draw`, `App::update`, `NodeCanvas`, `pano_cli plan-canvas-tool`, `pano_cli plan-canvas-tool-state`, `pano_cli plan-canvas-hotkey`, `CanvasToolServices`, and `CanvasHotkeyServices`, and live toolbar/input/hotkey execution is centralized in `src/legacy_canvas_tool_services.*`, but the bridge still mutates or reads legacy `Canvas` mode state, pen picking state, touch-lock state, transform copy/cut action objects, `ActionManager`, legacy save UI, legacy stroke size controls, and cursor/UI singletons | Preserve current toolbar, stylus eraser, keyboard, and touch command behavior while canvas input/tools move toward an app/document command boundary | `pp_app_core_canvas_tool_ui_tests`; `pp_app_core_canvas_hotkey_tests`; `pano_cli plan-canvas-tool --kind copy`; `pano_cli plan-canvas-tool-state --mode draw --picking --touch-lock`; `pano_cli plan-canvas-hotkey --event key-up --key z --ctrl --undo-count 2`; `pano_cli plan-canvas-hotkey --event key-up --key s --ctrl --shift`; `ctest --preset desktop-fast --build-config Debug` | Canvas tool selection, toolbar state refresh, picking, touch lock, stylus eraser/key mode switching, hotkey/touch command dispatch, save hotkeys, history hotkeys, brush-size hotkeys, and transform action execution are owned by injected app/document/canvas services with no legacy toolbar/canvas adapter | +| DEBT-0027 | Open | Modernization | Canvas draw-tool toolbar command, canvas input mode switching, active-state planning/execution dispatch, and canvas keyboard/touch command planning now consume pure `pp_app_core` through `App::init_toolbar_draw`, `App::update`, `NodeCanvas`, `pano_cli plan-canvas-tool`, `pano_cli plan-canvas-tool-state`, `pano_cli plan-canvas-hotkey`, `CanvasToolServices`, and `CanvasHotkeyServices`, live toolbar/input/hotkey execution is centralized in `src/legacy_canvas_tool_services.*`, and canvas mode tip visibility plus pressure remapping now route through `PlatformServices`, but the bridge still mutates or reads legacy `Canvas` mode state, pen picking state, touch-lock state, transform copy/cut action objects, `ActionManager`, legacy save UI, legacy stroke size controls, and cursor/UI singletons | Preserve current toolbar, stylus eraser, keyboard, and touch command behavior while canvas input/tools move toward an app/document command boundary | `pp_app_core_canvas_tool_ui_tests`; `pp_app_core_canvas_hotkey_tests`; `pp_platform_api_tests`; `pano_cli plan-canvas-tool --kind copy`; `pano_cli plan-canvas-tool-state --mode draw --picking --touch-lock`; `pano_cli plan-canvas-hotkey --event key-up --key z --ctrl --undo-count 2`; `pano_cli plan-canvas-hotkey --event key-up --key s --ctrl --shift`; `ctest --preset desktop-fast --build-config Debug` | Canvas tool selection, toolbar state refresh, picking, touch lock, stylus eraser/key mode switching, hotkey/touch command dispatch, save hotkeys, history hotkeys, brush-size hotkeys, and transform action execution are owned by injected app/document/canvas services with no legacy toolbar/canvas adapter | | DEBT-0028 | Open | Modernization | Canvas clear command planning and execution dispatch now consume pure `pp_app_core` through `App::init_toolbar_main`, Layer menu clear, `pano_cli plan-canvas-clear`, and the `DocumentCanvasClearServices` boundary, and toolbar/Layer-menu clear share `src/legacy_document_canvas_services.*`, but the shared live bridge still calls legacy `Canvas::clear`, which records `ActionLayerClear`, clears the current layer/frame, and marks legacy `Canvas::I` unsaved | Preserve clear-current-layer behavior while canvas/document commands move toward document/app command services | `pp_app_core_document_canvas_tests`; `pano_cli plan-canvas-clear --r 0 --g 0.1 --b 0.2 --a 0.3`; `pano_cli plan-canvas-clear --no-canvas`; `pano_cli plan-layer-menu --command clear --current-index 1 --current-name Paint`; `ctest --preset desktop-fast --build-config Debug` | Canvas clear execution, undo recording, dirty-state updates, and clear color handling are owned by injected document/app services with no legacy canvas-clear adapter | | DEBT-0029 | Open | Modernization | Image import route planning and execution dispatch now consume pure `pp_app_core` through the File menu, `pano_cli plan-image-import`, and the `DocumentImageImportServices` boundary, and live File-menu import execution is centralized in `src/legacy_app_shell_services.*`, but the bridge still loads images with legacy `Image`, calls legacy `Canvas::import_equirectangular`, or configures legacy import transform mode directly | Preserve current File > Import behavior while image import moves toward document/app/asset command services | `pp_app_core_document_import_tests`; `pano_cli plan-image-import --width 4096 --height 2048`; `pano_cli plan-image-import --width 1024 --height 1024`; `ctest --preset desktop-fast --build-config Debug` | Image loading, equirectangular import, transform-placement import, and failure reporting are owned by injected document/app/asset services with File-menu callbacks acting only as adapters and no legacy image-import adapter | | DEBT-0030 | Open | Modernization | File export menu action planning and execution dispatch now consume pure `pp_app_core` through the File menu, `pano_cli plan-export-menu`, and the `DocumentExportMenuServices` boundary, and live execution is centralized in `src/legacy_app_shell_services.*`, but the bridge still opens legacy export dialogs and then reaches legacy canvas/render/video export code | Preserve current export menu behavior while export command execution moves toward document/app/renderer/video services | `pp_app_core_document_export_tests`; `pano_cli plan-export-menu --kind png`; `pano_cli plan-export-menu --kind animation-mp4 --demo`; `pano_cli plan-export-menu --kind layers --no-canvas`; `ctest --preset desktop-fast --build-config Debug` | Export menu routing, license gating, target creation, image/layer/cube/depth/animation/timelapse execution, and error reporting are owned by injected document/app/renderer/video services with File-menu callbacks acting only as UI adapters and no legacy export adapter | diff --git a/docs/modernization/roadmap.md b/docs/modernization/roadmap.md index ab274a5..d5a0570 100644 --- a/docs/modernization/roadmap.md +++ b/docs/modernization/roadmap.md @@ -555,7 +555,10 @@ mode, pen picking, touch-lock, and transform state adapters continue. refresh used by `App::update` before legacy `Canvas` mode state remains the source of truth. `NodeCanvas` stylus eraser mode switching consumes the same shared bridge through its input-only path before legacy canvas mode execution -continues. `NodeCanvas` keyboard and touch command handling now consumes +continues. Canvas mode pointer-tip visibility and Windows pressure remapping +now dispatch through `PlatformServices`, preserving iOS tip behavior and the +Windows pressure curve outside `canvas_modes.cpp`. `NodeCanvas` keyboard and +touch command handling now consumes `pp_app_core` canvas-hotkey planning for E draw/erase, Ctrl+Z, Ctrl+Shift+Z, Ctrl+S, Ctrl+Shift+S, Tab UI toggle, brush-size brackets, Android back, Alt cursor reveal, and two-finger undo before the shared bridge delegates to legacy @@ -703,6 +706,9 @@ The UI loop's per-frame platform hooks now dispatch through `PlatformServices`: Windows stylus timeout polling and FPS-title updates live in `WindowsPlatformServices`, while Linux FPS-title updates remain in the legacy adapter pending Phase 6 platform shell extraction. +Canvas input tip-visibility and pressure-remap policies now also dispatch +through `PlatformServices`, removing the local iOS and Windows branches from +pen, line, and flood-fill canvas modes. The UI thread's platform attach/detach hooks now also dispatch through `PlatformServices`, preserving Android JNI attach/detach behavior in the legacy adapter while removing direct Android lifecycle calls from the main app @@ -1746,6 +1752,7 @@ Results: recording cleanup dispatch, exported-image publish dispatch, persistent storage flush dispatch, document browse-root dispatch, working-directory picker policy and display-path formatting dispatch, + canvas input tip visibility and pressure remap dispatch, native UI/window state save dispatch, prepared-file writable target dispatch, prepared-file export-dialog policy dispatch, work-directory document export collection policy dispatch, network TLS verification policy dispatch, diff --git a/src/app.h b/src/app.h index f9fedd6..4a0ccc9 100644 --- a/src/app.h +++ b/src/app.h @@ -192,6 +192,8 @@ public: [[nodiscard]] bool uses_ppbr_export_data_directory_override() const; [[nodiscard]] bool platform_supports_sonarpen() const; void start_platform_sonarpen(); + [[nodiscard]] bool draws_canvas_tip_for_input(kEventSource source, kEventType type) const; + [[nodiscard]] float adjust_canvas_input_pressure(float pressure) const; void pick_dir(std::function callback); void display_file(std::string path); void share_file(std::string path); diff --git a/src/app_events.cpp b/src/app_events.cpp index 50c2eec..43cfde0 100644 --- a/src/app_events.cpp +++ b/src/app_events.cpp @@ -211,6 +211,19 @@ void App::start_platform_sonarpen() active_platform_services().start_sonarpen(); } +bool App::draws_canvas_tip_for_input(kEventSource source, kEventType type) const +{ + return active_platform_services().draws_canvas_tip_for_pointer( + source == kEventSource::Mouse, + source == kEventSource::Stylus, + type == kEventType::MouseUpL); +} + +float App::adjust_canvas_input_pressure(float pressure) const +{ + return active_platform_services().adjust_canvas_input_pressure(pressure); +} + void App::pick_dir(std::function callback) { redraw = true; diff --git a/src/canvas_modes.cpp b/src/canvas_modes.cpp index a29ce6f..e122b4d 100644 --- a/src/canvas_modes.cpp +++ b/src/canvas_modes.cpp @@ -140,21 +140,13 @@ void CanvasModePen::on_GestureEvent(GestureEvent* ge) void CanvasModePen::on_MouseEvent(MouseEvent* me, glm::vec2& loc) { -#if defined(__IOS__) - m_draw_tip = (me->m_source == kEventSource::Mouse && me->m_type != kEventType::MouseUpL); -#else - m_draw_tip = (me->m_source == kEventSource::Mouse || me->m_source == kEventSource::Stylus); -#endif + m_draw_tip = App::I->draws_canvas_tip_for_input(me->m_source, me->m_type); m_draw_outline = true; if (Canvas::I->m_touch_lock && me->m_source == kEventSource::Touch) return; -#if _WIN32 - // curve https://www.wolframalpha.com/input/?i=plot+(1-(x-1)%5E2)%5E2+from+x%3D0+to+1 - auto curve = [](float x, float max) { return x > max ? 1.f : glm::pow(1.f - glm::pow(x / max - 1.f, 2.f), 2.f); }; - me->m_pressure = curve(me->m_pressure, 0.95f); -#endif + me->m_pressure = App::I->adjust_canvas_input_pressure(me->m_pressure); switch (me->m_type) { @@ -344,11 +336,7 @@ void CanvasModePen::enter(kCanvasMode prev) void CanvasModeLine::on_MouseEvent(MouseEvent* me, glm::vec2& loc) { -#if defined(__IOS__) - m_draw_tip = (me->m_source == kEventSource::Mouse && me->m_type != kEventType::MouseUpL); -#else - m_draw_tip = (me->m_source == kEventSource::Mouse || me->m_source == kEventSource::Stylus); -#endif + m_draw_tip = App::I->draws_canvas_tip_for_input(me->m_source, me->m_type); if (Canvas::I->m_touch_lock && me->m_source == kEventSource::Touch) return; switch (me->m_type) @@ -1636,11 +1624,7 @@ void CanvasModeTransform::on_MouseEvent(MouseEvent* me, glm::vec2& loc) void CanvasModeFloodFill::on_MouseEvent(MouseEvent* me, glm::vec2& loc) { -#if defined(__IOS__) - m_draw_tip = (me->m_source == kEventSource::Mouse && me->m_type != kEventType::MouseUpL); -#else - m_draw_tip = (me->m_source == kEventSource::Mouse || me->m_source == kEventSource::Stylus); -#endif + m_draw_tip = App::I->draws_canvas_tip_for_input(me->m_source, me->m_type); if (Canvas::I->m_touch_lock && me->m_source == kEventSource::Touch) return; diff --git a/src/platform_api/platform_services.h b/src/platform_api/platform_services.h index da5d054..9dd0c5e 100644 --- a/src/platform_api/platform_services.h +++ b/src/platform_api/platform_services.h @@ -71,6 +71,11 @@ public: [[nodiscard]] virtual bool uses_ppbr_export_data_directory_override() = 0; [[nodiscard]] virtual bool supports_sonarpen() = 0; virtual void start_sonarpen() = 0; + [[nodiscard]] virtual bool draws_canvas_tip_for_pointer( + bool is_mouse, + bool is_stylus, + bool is_left_button_release) = 0; + [[nodiscard]] virtual float adjust_canvas_input_pressure(float pressure) = 0; [[nodiscard]] virtual PreparedFileTarget prepare_writable_file( std::string_view type, std::string_view default_name, diff --git a/src/platform_legacy/legacy_platform_services.cpp b/src/platform_legacy/legacy_platform_services.cpp index ff8fcc4..d0c143e 100644 --- a/src/platform_legacy/legacy_platform_services.cpp +++ b/src/platform_legacy/legacy_platform_services.cpp @@ -499,6 +499,25 @@ public: #endif } + [[nodiscard]] bool draws_canvas_tip_for_pointer( + bool is_mouse, + bool is_stylus, + bool is_left_button_release) override + { +#if defined(__IOS__) + (void)is_stylus; + return is_mouse && !is_left_button_release; +#else + (void)is_left_button_release; + return is_mouse || is_stylus; +#endif + } + + [[nodiscard]] float adjust_canvas_input_pressure(float pressure) override + { + return pressure; + } + [[nodiscard]] pp::platform::PreparedFileTarget prepare_writable_file( std::string_view type, std::string_view default_name, diff --git a/src/platform_windows/windows_platform_services.cpp b/src/platform_windows/windows_platform_services.cpp index 18395f2..62d5e60 100644 --- a/src/platform_windows/windows_platform_services.cpp +++ b/src/platform_windows/windows_platform_services.cpp @@ -496,6 +496,23 @@ public: { } + [[nodiscard]] bool draws_canvas_tip_for_pointer( + bool is_mouse, + bool is_stylus, + bool is_left_button_release) override + { + (void)is_left_button_release; + return is_mouse || is_stylus; + } + + [[nodiscard]] float adjust_canvas_input_pressure(float pressure) override + { + const auto curve = [](float x, float max) { + return x > max ? 1.f : glm::pow(1.f - glm::pow(x / max - 1.f, 2.f), 2.f); + }; + return curve(pressure, 0.95f); + } + [[nodiscard]] pp::platform::PreparedFileTarget prepare_writable_file( std::string_view type, std::string_view default_name, diff --git a/tests/platform_api/platform_services_tests.cpp b/tests/platform_api/platform_services_tests.cpp index 80dbeba..9e6c8c9 100644 --- a/tests/platform_api/platform_services_tests.cpp +++ b/tests/platform_api/platform_services_tests.cpp @@ -260,6 +260,25 @@ public: ++sonarpen_starts; } + [[nodiscard]] bool draws_canvas_tip_for_pointer( + bool is_mouse, + bool is_stylus, + bool is_left_button_release) override + { + ++canvas_tip_policy_checks; + last_canvas_tip_mouse = is_mouse; + last_canvas_tip_stylus = is_stylus; + last_canvas_tip_left_release = is_left_button_release; + return canvas_tip_visible; + } + + [[nodiscard]] float adjust_canvas_input_pressure(float pressure) override + { + ++canvas_pressure_adjustments; + last_canvas_pressure = pressure; + return adjusted_canvas_pressure; + } + [[nodiscard]] pp::platform::PreparedFileTarget prepare_writable_file( std::string_view type, std::string_view default_name, @@ -327,6 +346,8 @@ public: int ppbr_export_data_directory_override_checks = 0; int sonarpen_support_checks = 0; int sonarpen_starts = 0; + int canvas_tip_policy_checks = 0; + int canvas_pressure_adjustments = 0; int prepare_writable_file_requests = 0; int save_prepared_file_requests = 0; bool cursor_visible = false; @@ -338,9 +359,15 @@ public: bool network_tls_verification_disabled = false; bool ppbr_export_data_directory_override = false; bool sonarpen_supported = false; + bool canvas_tip_visible = false; + bool last_canvas_tip_mouse = false; + bool last_canvas_tip_stylus = false; + bool last_canvas_tip_left_release = false; bool deletes_recorded_files = true; bool live_asset_reloading = true; float last_platform_delta = 0.0f; + float last_canvas_pressure = 0.0f; + float adjusted_canvas_pressure = 0.75f; int last_frame_report = 0; std::string displayed_path; std::string shared_path; @@ -727,6 +754,25 @@ void platform_services_dispatch_sonarpen_policy_and_start(pp::tests::Harness& ha PP_EXPECT(harness, fake.sonarpen_starts == 1); } +void platform_services_dispatch_canvas_input_policy(pp::tests::Harness& harness) +{ + FakePlatformServices fake("unused"); + pp::platform::PlatformServices& services = fake; + + PP_EXPECT(harness, !services.draws_canvas_tip_for_pointer(true, false, true)); + fake.canvas_tip_visible = true; + PP_EXPECT(harness, services.draws_canvas_tip_for_pointer(false, true, false)); + PP_EXPECT(harness, fake.canvas_tip_policy_checks == 2); + PP_EXPECT(harness, !fake.last_canvas_tip_mouse); + PP_EXPECT(harness, fake.last_canvas_tip_stylus); + PP_EXPECT(harness, !fake.last_canvas_tip_left_release); + + const auto pressure = services.adjust_canvas_input_pressure(0.5f); + PP_EXPECT(harness, pressure == 0.75f); + PP_EXPECT(harness, fake.last_canvas_pressure == 0.5f); + PP_EXPECT(harness, fake.canvas_pressure_adjustments == 1); +} + } int main() @@ -762,5 +808,6 @@ int main() "platform services dispatch ppbr export directory policy", platform_services_dispatch_ppbr_export_directory_policy); harness.run("platform services dispatch sonarpen policy and start", platform_services_dispatch_sonarpen_policy_and_start); + harness.run("platform services dispatch canvas input policy", platform_services_dispatch_canvas_input_policy); return harness.finish(); }