Make dragbox stateful to fix blueprint movement

This commit is contained in:
Dean Herbert 2020-01-22 17:54:11 +09:00
parent f0d810fe20
commit cb6e7425ae
3 changed files with 45 additions and 18 deletions

View File

@ -152,15 +152,16 @@ protected override bool OnDragStart(DragStartEvent e)
if (e.Button == MouseButton.Right)
return false;
if (!beginSelectionMovement())
{
if (!DragBox.UpdateDrag(e))
return false;
if (beginSelectionMovement())
return true;
DragBox.FadeIn(250, Easing.OutQuint);
if (DragBox.HandleDrag(e))
{
DragBox.Show();
return true;
}
return true;
return false;
}
protected override bool OnDrag(DragEvent e)
@ -168,13 +169,10 @@ protected override bool OnDrag(DragEvent e)
if (e.Button == MouseButton.Right)
return false;
if (!moveCurrentSelection(e))
{
if (!DragBox.UpdateDrag(e))
return false;
}
if (DragBox.State == Visibility.Visible)
return DragBox.HandleDrag(e);
return true;
return moveCurrentSelection(e);
}
protected override bool OnDragEnd(DragEndEvent e)
@ -182,13 +180,14 @@ protected override bool OnDragEnd(DragEndEvent e)
if (e.Button == MouseButton.Right)
return false;
if (!finishSelectionMovement())
if (DragBox.State == Visibility.Visible)
{
DragBox.FadeOut(250, Easing.OutQuint);
DragBox.Hide();
selectionHandler.UpdateVisibility();
return true;
}
return true;
return finishSelectionMovement();
}
protected override bool OnKeyDown(KeyDownEvent e)

View File

@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text.
using System;
using osu.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
@ -15,7 +16,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
/// <summary>
/// A box that displays the drag selection and provides selection events for users to handle.
/// </summary>
public class DragBox : CompositeDrawable
public class DragBox : CompositeDrawable, IStateful<Visibility>
{
protected readonly Action<RectangleF> PerformSelection;
@ -57,7 +58,7 @@ private void load()
/// </summary>
/// <param name="e">The mouse event.</param>
/// <returns>Whether the event should be handled and blocking.</returns>
public virtual bool UpdateDrag(MouseButtonEvent e)
public virtual bool HandleDrag(MouseButtonEvent e)
{
var dragPosition = e.ScreenSpaceMousePosition;
var dragStartPosition = e.ScreenSpaceMouseDownPosition;
@ -76,5 +77,26 @@ public virtual bool UpdateDrag(MouseButtonEvent e)
PerformSelection?.Invoke(dragRectangle);
return true;
}
private Visibility state;
public Visibility State
{
get => state;
set
{
if (value == state) return;
state = value;
this.FadeTo(state == Visibility.Hidden ? 0 : 1, 250, Easing.OutQuint);
StateChanged?.Invoke(state);
}
}
public override void Hide() => State = Visibility.Hidden;
public override void Show() => State = Visibility.Visible;
public event Action<Visibility> StateChanged;
}
}

View File

@ -52,6 +52,12 @@ protected override bool OnDrag(DragEvent e)
return base.OnDrag(e);
}
protected override bool OnDragEnd(DragEndEvent e)
{
lastDragEvent = null;
return base.OnDragEnd(e);
}
protected override void Update()
{
// trigger every frame so drags continue to update selection while playback is scrolling the timeline.
@ -81,7 +87,7 @@ public TimelineDragBox(Action<RectangleF> performSelect)
Alpha = 0.3f
};
public override bool UpdateDrag(MouseButtonEvent e)
public override bool HandleDrag(MouseButtonEvent e)
{
// store the original position of the mouse down, as we may be scrolled during selection.
if (lastMouseDown != e.ScreenSpaceMouseDownPosition)