Add mouse capture usage for new rubber band selection

#3151
This commit is contained in:
Wojtek Figat
2025-03-11 13:07:53 +01:00
parent a54299a560
commit f256b0670f
2 changed files with 21 additions and 6 deletions

View File

@@ -34,12 +34,15 @@ public class ViewportRubberBandSelector
/// <summary>
/// Triggers the start of a rubber band selection.
/// </summary>
public void TryStartingRubberBandSelection()
/// <returns>True if selection started, otherwise false.</returns>
public bool TryStartingRubberBandSelection()
{
if (!_isRubberBandSpanning && !_owner.Gizmos.Active.IsControllingMouse && !_owner.IsRightMouseButtonDown)
{
_tryStartRubberBand = true;
return true;
}
return false;
}
/// <summary>
@@ -248,9 +251,12 @@ public class ViewportRubberBandSelector
/// <summary>
/// Immediately stops the rubber band.
/// </summary>
public void StopRubberBand()
/// <returns>True if rubber band was active before stopping.</returns>
public bool StopRubberBand()
{
var result = _tryStartRubberBand;
_isRubberBandSpanning = false;
_tryStartRubberBand = false;
return result;
}
}

View File

@@ -493,14 +493,18 @@ namespace FlaxEditor.Viewport
public override void OnLostFocus()
{
base.OnLostFocus();
_rubberBandSelector.StopRubberBand();
if (_rubberBandSelector.StopRubberBand())
EndMouseCapture();
}
/// <inheritdoc />
public override void OnMouseLeave()
{
base.OnMouseLeave();
_rubberBandSelector.StopRubberBand();
if (_rubberBandSelector.StopRubberBand())
EndMouseCapture();
}
/// <summary>
@@ -615,8 +619,11 @@ namespace FlaxEditor.Viewport
protected override void OnLeftMouseButtonDown()
{
base.OnLeftMouseButtonDown();
_rubberBandSelector.TryStartingRubberBandSelection();
if (_rubberBandSelector.TryStartingRubberBandSelection())
{
StartMouseCapture();
}
}
/// <inheritdoc />
@@ -629,6 +636,8 @@ namespace FlaxEditor.Viewport
// Select rubberbanded rect actor nodes or pick with gizmo
if (!_rubberBandSelector.ReleaseRubberBandSelection())
{
EndMouseCapture();
// Try to pick something with the current gizmo
Gizmos.Active?.Pick();
}