1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 14:25:05 +08:00

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()
{
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; }

View File

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

View File

@ -34,6 +34,8 @@ namespace osu.Game.Screens.Edit.Compose.Components
internal event Action HoverGained;
internal event Action HoverLost;
internal event Action MouseDown;
internal event Action MouseUp;
protected override bool OnHover(HoverEvent e)
{
@ -48,6 +50,19 @@ namespace osu.Game.Screens.Edit.Compose.Components
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
}
}

View File

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

View File

@ -36,7 +36,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
protected override void 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);
}
}
}