From 1d6306761476fbfc7f2ca830e9c0422a4c067877 Mon Sep 17 00:00:00 2001 From: Zode Date: Sat, 7 Jun 2025 21:04:59 +0300 Subject: [PATCH] Add ability to do additive and subtractive selections in visject surfaces using ctrl and shift during selection. --- Source/Editor/Surface/VisjectSurface.Input.cs | 68 ++++++++++++++++--- Source/Editor/Surface/VisjectSurface.cs | 12 ++++ 2 files changed, 69 insertions(+), 11 deletions(-) diff --git a/Source/Editor/Surface/VisjectSurface.Input.cs b/Source/Editor/Surface/VisjectSurface.Input.cs index a874db681..09df195eb 100644 --- a/Source/Editor/Surface/VisjectSurface.Input.cs +++ b/Source/Editor/Surface/VisjectSurface.Input.cs @@ -27,6 +27,7 @@ namespace FlaxEditor.Surface private Float2 _movingNodesDelta; private Float2 _gridRoundingDelta; private HashSet _movingNodes; + private HashSet _temporarySelectedNodes; private readonly Stack _inputBrackets = new Stack(); private class InputBracket @@ -130,13 +131,34 @@ namespace FlaxEditor.Surface if (_rootControl.Children[i] is SurfaceControl control) { var select = control.IsSelectionIntersecting(ref selectionRect); - if (select != control.IsSelected) + + if (Root.GetKey(KeyboardKeys.Shift)) { - control.IsSelected = select; - selectionChanged = true; + if (select == control.IsSelected && _temporarySelectedNodes.Contains(control)) + { + control.IsSelected = !select; + selectionChanged = true; + } + } + else if (Root.GetKey(KeyboardKeys.Control)) + { + if (select != control.IsSelected && !_temporarySelectedNodes.Contains(control)) + { + control.IsSelected = select; + selectionChanged = true; + } + } + else + { + if (select != control.IsSelected) + { + control.IsSelected = select; + selectionChanged = true; + } } } } + if (selectionChanged) SelectionChanged?.Invoke(); } @@ -461,6 +483,19 @@ namespace FlaxEditor.Surface // Cache data _isMovingSelection = false; _mousePos = location; + if(_temporarySelectedNodes == null) + _temporarySelectedNodes = new HashSet(); + else + _temporarySelectedNodes.Clear(); + + for (int i = 0; i < _rootControl.Children.Count; i++) + { + if (_rootControl.Children[i] is SurfaceNode node && node.IsSelected) + { + _temporarySelectedNodes.Add(node); + } + } + if (button == MouseButton.Left) { _leftMouseDown = true; @@ -488,9 +523,11 @@ namespace FlaxEditor.Surface // Check if user is pressing control if (Root.GetKey(KeyboardKeys.Control)) { - // Add/remove from selection - controlUnderMouse.IsSelected = !controlUnderMouse.IsSelected; - SelectionChanged?.Invoke(); + AddToSelection(controlUnderMouse); + } + else if (Root.GetKey(KeyboardKeys.Shift)) + { + RemoveFromSelection(controlUnderMouse); } // Check if node isn't selected else if (!controlUnderMouse.IsSelected) @@ -500,10 +537,14 @@ namespace FlaxEditor.Surface } // Start moving selected nodes - StartMouseCapture(); - _movingSelectionViewPos = _rootControl.Location; - _movingNodesDelta = Float2.Zero; - OnGetNodesToMove(); + if (!Root.GetKey(KeyboardKeys.Shift)) + { + StartMouseCapture(); + _movingSelectionViewPos = _rootControl.Location; + _movingNodesDelta = Float2.Zero; + OnGetNodesToMove(); + } + Focus(); return true; } @@ -515,7 +556,12 @@ namespace FlaxEditor.Surface { // Start selecting or commenting StartMouseCapture(); - ClearSelection(); + + if (!Root.GetKey(KeyboardKeys.Control) && !Root.GetKey(KeyboardKeys.Shift)) + { + ClearSelection(); + } + Focus(); return true; } diff --git a/Source/Editor/Surface/VisjectSurface.cs b/Source/Editor/Surface/VisjectSurface.cs index faecebbd3..69bd276d2 100644 --- a/Source/Editor/Surface/VisjectSurface.cs +++ b/Source/Editor/Surface/VisjectSurface.cs @@ -710,6 +710,18 @@ namespace FlaxEditor.Surface SelectionChanged?.Invoke(); } + /// + /// Removes the specified control from the selection. + /// + /// The control. + public void RemoveFromSelection(SurfaceControl control) + { + if (!control.IsSelected) + return; + control.IsSelected = false; + SelectionChanged?.Invoke(); + } + /// /// Selects the specified control. ///