OrbitCamera: a second press during a drag is ignored, as Blender's modal operator ignores it
A drag whose own button is no longer held (a lost release) still ends, so the next press starts a new one. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
21ed762d35
commit
b7305edd04
1 changed files with 11 additions and 3 deletions
|
|
@ -77,7 +77,7 @@ public partial class OrbitCamera : Camera3D
|
|||
Distance = wheel.ButtonIndex == MouseButton.WheelUp ? _distance / MathF.Pow(ZoomStep, wheel.Factor) : _distance * MathF.Pow(ZoomStep, wheel.Factor);
|
||||
Handle();
|
||||
break;
|
||||
case InputEventMouseButton { Pressed: true } press:
|
||||
case InputEventMouseButton { Pressed: true } press when _drag is null || StaleDrag(press.ButtonMask):
|
||||
foreach (var row in Bindings)
|
||||
{
|
||||
if (row.Button != press.ButtonIndex || row.Alt != press.AltPressed || row.Shift != press.ShiftPressed || row.Ctrl != press.CtrlPressed) continue;
|
||||
|
|
@ -93,14 +93,22 @@ public partial class OrbitCamera : Camera3D
|
|||
Handle();
|
||||
break;
|
||||
case InputEventMouseMotion motion when _drag is { } drag:
|
||||
var held = drag.Button == MouseButton.Left ? MouseButtonMask.Left : MouseButtonMask.Middle;
|
||||
if ((motion.ButtonMask & held) == 0) { _drag = null; return; } // the release was lost, to a focus change say
|
||||
if ((motion.ButtonMask & Held(drag.Button)) == 0) { _drag = null; return; } // the release was lost, to a focus change say
|
||||
Apply(drag, motion.Relative);
|
||||
Handle();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private static MouseButtonMask Held(MouseButton button) => button == MouseButton.Left ? MouseButtonMask.Left : MouseButtonMask.Middle;
|
||||
|
||||
/// <summary>A drag is under way, so a second press is ignored as Blender's modal operator ignores it, unless the drag's own button is no longer held (its release was lost): then the drag ends and the press is new.</summary>
|
||||
private bool StaleDrag(MouseButtonMask held)
|
||||
{
|
||||
if (_drag is { } drag && (held & Held(drag.Button)) == 0) _drag = null;
|
||||
return _drag is null;
|
||||
}
|
||||
|
||||
private void Handle() => GetViewport().SetInputAsHandled();
|
||||
|
||||
private void Apply(Drag drag, Vector2 move)
|
||||
|
|
|
|||
Loading…
Reference in a new issue