Consider drag handles active using mouse down instead of when dragged

This commit is contained in:
Salman Ahmed
2021-05-04 06:40:43 +03:00
parent 5f33c3514e
commit b2a0c2b563
5 changed files with 29 additions and 27 deletions

View File

@ -55,7 +55,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
protected override void UpdateHoverState() protected override void UpdateHoverState()
{ {
base.UpdateHoverState(); base.UpdateHoverState();
icon.FadeColour(!HandlingMouse && IsHovered ? Color4.White : Color4.Black, TRANSFORM_DURATION, Easing.OutQuint); icon.FadeColour(!IsHeld && IsHovered ? Color4.White : Color4.Black, TRANSFORM_DURATION, Easing.OutQuint);
} }
public string TooltipText { get; } public string TooltipText { get; }

View File

@ -25,9 +25,9 @@ namespace osu.Game.Screens.Edit.Compose.Components
private Circle circle; private Circle circle;
/// <summary> /// <summary>
/// Whether this control is currently being operated on by the user. /// Whether the user is currently holding the control with mouse.
/// </summary> /// </summary>
public bool InOperation { get; private set; } public bool IsHeld { get; private set; }
[Resolved] [Resolved]
protected OsuColour Colours { get; private set; } protected OsuColour Colours { get; private set; }
@ -67,44 +67,31 @@ namespace osu.Game.Screens.Edit.Compose.Components
UpdateHoverState(); UpdateHoverState();
} }
/// <summary>
/// Whether this control is currently handling mouse down input.
/// </summary>
protected bool HandlingMouse { get; private set; }
protected override bool OnMouseDown(MouseDownEvent e) protected override bool OnMouseDown(MouseDownEvent e)
{ {
HandlingMouse = true; IsHeld = true;
UpdateHoverState(); UpdateHoverState();
return true; return true;
} }
protected override void OnMouseUp(MouseUpEvent e) protected override void OnMouseUp(MouseUpEvent e)
{ {
HandlingMouse = false; IsHeld = false;
UpdateHoverState(); UpdateHoverState();
} }
protected virtual void UpdateHoverState() protected virtual void UpdateHoverState()
{ {
if (HandlingMouse) if (IsHeld)
circle.FadeColour(Colours.GrayF, TRANSFORM_DURATION, Easing.OutQuint); circle.FadeColour(Colours.GrayF, TRANSFORM_DURATION, Easing.OutQuint);
else else
circle.FadeColour(IsHovered ? Colours.Red : Colours.YellowDark, TRANSFORM_DURATION, Easing.OutQuint); circle.FadeColour(IsHovered ? Colours.Red : Colours.YellowDark, TRANSFORM_DURATION, Easing.OutQuint);
this.ScaleTo(HandlingMouse || IsHovered ? 1.5f : 1, TRANSFORM_DURATION, Easing.OutQuint); this.ScaleTo(IsHeld || IsHovered ? 1.5f : 1, TRANSFORM_DURATION, Easing.OutQuint);
} }
protected void OnOperationStarted() protected void OnOperationStarted() => OperationStarted?.Invoke();
{
InOperation = true;
OperationStarted?.Invoke();
}
protected void OnOperationEnded() protected void OnOperationEnded() => OperationEnded?.Invoke();
{
InOperation = false;
OperationEnded?.Invoke();
}
} }
} }

View File

@ -34,6 +34,8 @@ namespace osu.Game.Screens.Edit.Compose.Components
internal event Action HoverGained; internal event Action HoverGained;
internal event Action HoverLost; internal event Action HoverLost;
internal event Action MouseDown;
internal event Action MouseUp;
protected override bool OnHover(HoverEvent e) protected override bool OnHover(HoverEvent e)
{ {
@ -48,6 +50,19 @@ namespace osu.Game.Screens.Edit.Compose.Components
HoverLost?.Invoke(); HoverLost?.Invoke();
} }
protected override bool OnMouseDown(MouseDownEvent e)
{
bool result = base.OnMouseDown(e);
MouseDown?.Invoke();
return result;
}
protected override void OnMouseUp(MouseUpEvent e)
{
base.OnMouseUp(e);
MouseUp?.Invoke();
}
#endregion #endregion
} }
} }

View File

@ -62,8 +62,8 @@ namespace osu.Game.Screens.Edit.Compose.Components
{ {
handle.HoverGained += updateRotationHandlesVisibility; handle.HoverGained += updateRotationHandlesVisibility;
handle.HoverLost += updateRotationHandlesVisibility; handle.HoverLost += updateRotationHandlesVisibility;
handle.OperationStarted += updateRotationHandlesVisibility; handle.MouseDown += updateRotationHandlesVisibility;
handle.OperationEnded += updateRotationHandlesVisibility; handle.MouseUp += updateRotationHandlesVisibility;
allDragHandles.Add(handle); allDragHandles.Add(handle);
} }
@ -72,13 +72,13 @@ namespace osu.Game.Screens.Edit.Compose.Components
private void updateRotationHandlesVisibility() private void updateRotationHandlesVisibility()
{ {
if (activeHandle?.InOperation == true || activeHandle?.IsHovered == true) if (activeHandle?.IsHeld == true || activeHandle?.IsHovered == true)
return; return;
displayedRotationHandle?.FadeOut(SelectionBoxControl.TRANSFORM_DURATION, Easing.OutQuint); displayedRotationHandle?.FadeOut(SelectionBoxControl.TRANSFORM_DURATION, Easing.OutQuint);
displayedRotationHandle = null; displayedRotationHandle = null;
activeHandle = allDragHandles.SingleOrDefault(h => h.InOperation); activeHandle = allDragHandles.SingleOrDefault(h => h.IsHeld);
activeHandle ??= allDragHandles.SingleOrDefault(h => h.IsHovered); activeHandle ??= allDragHandles.SingleOrDefault(h => h.IsHovered);
if (activeHandle != null) if (activeHandle != null)

View File

@ -36,7 +36,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
protected override void UpdateHoverState() protected override void UpdateHoverState()
{ {
base.UpdateHoverState(); base.UpdateHoverState();
icon.FadeColour(!HandlingMouse && IsHovered ? Color4.White : Color4.Black, TRANSFORM_DURATION, Easing.OutQuint); icon.FadeColour(!IsHeld && IsHovered ? Color4.White : Color4.Black, TRANSFORM_DURATION, Easing.OutQuint);
} }
} }
} }