From ad29dd0c929aa76b949b0bbb1dc6281372eaee0f Mon Sep 17 00:00:00 2001 From: Luke Schneider Date: Thu, 21 Sep 2023 08:37:13 -0500 Subject: [PATCH] MMB Panning Added MMB panning to VisjectSurfaces (materials/etc). --- Source/Editor/Surface/VisjectSurface.Input.cs | 35 ++++++++++++++++++- Source/Editor/Surface/VisjectSurface.cs | 10 ++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/Source/Editor/Surface/VisjectSurface.Input.cs b/Source/Editor/Surface/VisjectSurface.Input.cs index 7264321c3..517040cb7 100644 --- a/Source/Editor/Surface/VisjectSurface.Input.cs +++ b/Source/Editor/Surface/VisjectSurface.Input.cs @@ -213,6 +213,21 @@ namespace FlaxEditor.Surface return; } + if (_middleMouseDown) { + // Calculate delta + var delta = location - _middleMouseDownPos; + if (delta.LengthSquared > 0.01f) { + // Move view + _mouseMoveAmount += delta.Length; + _rootControl.Location += delta; + _middleMouseDownPos = location; + Cursor = CursorType.SizeAll; + } + + // Handled + return; + } + // Check if user is selecting or moving node(s) if (_leftMouseDown) { @@ -269,6 +284,10 @@ namespace FlaxEditor.Surface _rightMouseDown = false; Cursor = CursorType.Default; } + if (_middleMouseDown) { + _middleMouseDown = false; + Cursor = CursorType.Default; + } _isMovingSelection = false; ConnectingEnd(null); @@ -380,6 +399,7 @@ namespace FlaxEditor.Surface _isMovingSelection = false; _rightMouseDown = false; _leftMouseDown = false; + _middleMouseDown = false; return true; } @@ -398,6 +418,12 @@ namespace FlaxEditor.Surface { _rightMouseDown = true; _rightMouseDownPos = location; + Debug.Log("The right mouse button is down in a window"); + } + if (button == MouseButton.Middle) { + _middleMouseDown = true; + _middleMouseDownPos = location; + Debug.Log("The middle mouse button is down in a window"); } // Check if any node is under the mouse @@ -444,7 +470,7 @@ namespace FlaxEditor.Surface Focus(); return true; } - if (_rightMouseDown) + if (_rightMouseDown || _middleMouseDown) { // Start navigating StartMouseCapture(); @@ -513,6 +539,12 @@ namespace FlaxEditor.Surface } _mouseMoveAmount = 0; } + if (_middleMouseDown && button == MouseButton.Middle) { + _middleMouseDown = false; + EndMouseCapture(); + Cursor = CursorType.Default; + _mouseMoveAmount = 0; + } // Base bool handled = base.OnMouseUp(location, button); @@ -523,6 +555,7 @@ namespace FlaxEditor.Surface // Clear flags _rightMouseDown = false; _leftMouseDown = false; + _middleMouseDown = false; return true; } diff --git a/Source/Editor/Surface/VisjectSurface.cs b/Source/Editor/Surface/VisjectSurface.cs index 22aba4855..29dbeb1c6 100644 --- a/Source/Editor/Surface/VisjectSurface.cs +++ b/Source/Editor/Surface/VisjectSurface.cs @@ -59,6 +59,11 @@ namespace FlaxEditor.Surface /// protected bool _rightMouseDown; + /// + /// The middle mouse down flag. + /// + protected bool _middleMouseDown; + /// /// The left mouse down position. /// @@ -69,6 +74,11 @@ namespace FlaxEditor.Surface /// protected Float2 _rightMouseDownPos = Float2.Minimum; + /// + /// The middle mouse down position. + /// + protected Float2 _middleMouseDownPos = Float2.Minimum; + /// /// The mouse position. ///