Free, open-source 3D sculpting for Linux, macOS and Windows: dense meshes, remeshing, painting, built-in AI (image/text to 3D), Send to Unreal, game-ready LODs, Gaussian splats and OpenUSD.
C++ 3d3d-sculptingcppdear-imguidigital-sculptingfbxgame-developmentgaussian-splattinggltfimage-to-3dmcpopenglopenusdsculptingtext-to-3dunreal-engine
Tablet: stray mouse events no longer move the brush ring while the pen is in range
islandmed47165811475a
diff --git a/src/app/App.cpp b/src/app/App.cppindex b562c6fa..8cb6a554 100644--- a/src/app/App.cpp+++ b/src/app/App.cpp@@ -700,10 +700,20 @@ void App::onMouseDown(float x, float y, Uint8 button) {}void App::onMouseMove(float x, float y, float dx, float dy, bool fromPen) {+ if (!fromPen) {+ // Windows Ink and some tablet drivers send mouse events of their own beside the pen's, often at an old+ // position (where the pen last touched). Taking those made the brush ring flick between two places, so+ // while the pen is in range only the pen moves the cursor. A pen that went quiet without saying it left+ // (some drivers never do) hands the cursor back to the mouse.+ if (dragFromPen_ && drag_ != Drag::None) return;+ if (penInProximity_) {+ if (SDL_GetTicksNS() - lastPenNs_ < 1000000000ull) return;+ penLeft();+ }+ }mouseX_ = x;mouseY_ = y;lastInputPen_ = fromPen;- if (!fromPen && dragFromPen_ && drag_ != Drag::None) return; // a pen drag ignores a stray mouse// ZBrush: start a pan with Alt, then let go of Alt while still dragging to zoom.if (drag_ == Drag::Pan && panFromAlt_ && !(inputMods() & SDL_KMOD_ALT)) drag_ = Drag::Zoom;switch (drag_) {diff --git a/src/app/App.h b/src/app/App.hindex 58b15c11..7b409e66 100644--- a/src/app/App.h+++ b/src/app/App.h@@ -656,6 +656,7 @@ private:void detectPenName();PenPressureTracker penTracker_;bool penInProximity_ = false, penTouching_ = false, penEraser_ = false;+ Uint64 lastPenNs_ = 0; // when the last pen event arrived (see onMouseMove)uint32_t penButtons_ = 0; // bit N: pen button N is heldint penNavButton_ = 0; // the pen button driving a view drag (0: none)bool dragFromPen_ = false;diff --git a/src/app/Tablet.cpp b/src/app/Tablet.cppindex 3a5892be..b1785fa5 100644--- a/src/app/Tablet.cpp+++ b/src/app/Tablet.cpp@@ -39,6 +39,7 @@ bool App::dropPenMouseEvent(const SDL_Event& e) const {}void App::handlePenEvent(const SDL_Event& e) {+ lastPenNs_ = SDL_GetTicksNS();switch (e.type) {case SDL_EVENT_PEN_PROXIMITY_IN:penSeen_ = penInProximity_ = true;diff --git a/src/app/UiTest.cpp b/src/app/UiTest.cppindex a9db17ad..b4c51991 100644--- a/src/app/UiTest.cpp+++ b/src/app/UiTest.cpp@@ -44,7 +44,8 @@// moved (vertices moved since `snapshot`), moved_max / moved_sum (distance),// moved_out (summed movement along the snapshot's normals: > 0 out, < 0 in),// pen_pressure (raw), brush_pressure (after the curve; 1 for the mouse),-// stroking (1 while a stroke is open), camera_yaw / camera_pitch / camera_roll (degrees),+// stroking (1 while a stroke is open), cursor_x / cursor_y (the brush cursor, pixels),+// camera_yaw / camera_pitch / camera_roll (degrees),// camera_up (the view's up vector . world Y), camera_aligned (1 when looking along a world// axis), camera_distance, camera_pan (target offset);// N may be $NAME or $NAME*K for a value kept by `remember`@@ -69,6 +70,8 @@// button mapped to rotate / pan / right-click is held)// pen_pressure P a pressure sample from the hovering pen (e.g. a stale value before a stroke)// pen_out the pen leaves proximity+// mouse_move U V a plain mouse (not the pen) moves to a point on the model, e.g. the stray mouse+// events Windows Ink sends beside the pen's#include "app/App.h"#ifndef SDL_PEN_INPUT_IN_PROXIMITY@@ -281,6 +284,8 @@ double Demo::query(const std::string& name, bool& known) const {if (name == "pen_pressure") return app_.penTracker_.raw();if (name == "brush_pressure") return app_.strokePressure();if (name == "stroking") return app_.drag_ == App::Drag::Stroke ? 1.0 : 0.0;+ if (name == "cursor_x") return app_.mouseX_;+ if (name == "cursor_y") return app_.mouseY_;if (name == "camera_yaw") return glm::degrees(app_.camera_.yaw);if (name == "camera_pitch") return glm::degrees(app_.camera_.pitch);if (name == "camera_roll") return glm::degrees(app_.camera_.roll);@@ -854,6 +859,13 @@ bool Demo::parseStep(int line, const std::vector<std::string>& w, std::string& eif (!penIn_) penProximity(true);penPressure(p);});+ } else if (verb == "mouse_move") {+ if (!need(2)) return false;+ run([this, u = num(1, 0.5f), v = num(2, 0.5f)] {+ const ImVec2 p = onModel(u, v);+ mouseMotion(p.x, p.y);+ });+ wait(0.05f);} else if (verb == "pen_out") {run([this] { penProximity(false); });wait(0.05f);diff --git a/tests/ui/tablet.sfui b/tests/ui/tablet.sfuiindex 574f08bb..dce88ecb 100644--- a/tests/ui/tablet.sfui+++ b/tests/ui/tablet.sfui@@ -34,6 +34,7 @@ key ctrl+z# The mouse always presses fully, whatever the pen did last.+pen_outstroke 0.3 0.45 0.7 0.55expect_value brush_pressure == 1expect_value moved_out > $heavy@@ -116,3 +117,18 @@ remember masked mask_beforepen_stroke 0.2 0.5 0.8 0.5 1 1 eraserexpect_value masked < $mask_before*0.5expect_value moved == 0++# Stray mouse events beside the pen's (Windows Ink sends them, often at an old position) must not move+# the brush ring: it used to flick between the two places, like a second brush blinking on the model.+pen_hover 0.5 0.5+remember cursor_x pen_x+remember cursor_y pen_y+mouse_move 0.1 0.9+expect_value cursor_x == $pen_x+expect_value cursor_y == $pen_y+pen_hover 0.6 0.5+expect_value cursor_x > $pen_x+# Once the pen has left, the mouse moves the cursor again.+pen_out+mouse_move 0.1 0.9+expect_value cursor_x < $pen_x