From b2a0c2b5631ac3a3e5d746909d141fafbf655ce3 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Tue, 4 May 2021 06:40:43 +0300 Subject: [PATCH] Consider drag handles active using mouse down instead of when dragged --- .../Compose/Components/SelectionBoxButton.cs | 2 +- .../Compose/Components/SelectionBoxControl.cs | 29 +++++-------------- .../Components/SelectionBoxDragHandle.cs | 15 ++++++++++ .../SelectionBoxDragHandleContainer.cs | 8 ++--- .../Components/SelectionBoxRotationHandle.cs | 2 +- 5 files changed, 29 insertions(+), 27 deletions(-) diff --git a/osu.Game/Screens/Edit/Compose/Components/SelectionBoxButton.cs b/osu.Game/Screens/Edit/Compose/Components/SelectionBoxButton.cs index fbbebe3288..43cbbb617b 100644 --- a/osu.Game/Screens/Edit/Compose/Components/SelectionBoxButton.cs +++ b/osu.Game/Screens/Edit/Compose/Components/SelectionBoxButton.cs @@ -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; } diff --git a/osu.Game/Screens/Edit/Compose/Components/SelectionBoxControl.cs b/osu.Game/Screens/Edit/Compose/Components/SelectionBoxControl.cs index 4406cc055d..159886648e 100644 --- a/osu.Game/Screens/Edit/Compose/Components/SelectionBoxControl.cs +++ b/osu.Game/Screens/Edit/Compose/Components/SelectionBoxControl.cs @@ -25,9 +25,9 @@ namespace osu.Game.Screens.Edit.Compose.Components private Circle circle; /// - /// Whether this control is currently being operated on by the user. + /// Whether the user is currently holding the control with mouse. /// - 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(); } - /// - /// Whether this control is currently handling mouse down input. - /// - 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(); } } diff --git a/osu.Game/Screens/Edit/Compose/Components/SelectionBoxDragHandle.cs b/osu.Game/Screens/Edit/Compose/Components/SelectionBoxDragHandle.cs index ed7c451b7e..3c1741e24d 100644 --- a/osu.Game/Screens/Edit/Compose/Components/SelectionBoxDragHandle.cs +++ b/osu.Game/Screens/Edit/Compose/Components/SelectionBoxDragHandle.cs @@ -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 } } diff --git a/osu.Game/Screens/Edit/Compose/Components/SelectionBoxDragHandleContainer.cs b/osu.Game/Screens/Edit/Compose/Components/SelectionBoxDragHandleContainer.cs index 7db2cdbbf5..c78514b7db 100644 --- a/osu.Game/Screens/Edit/Compose/Components/SelectionBoxDragHandleContainer.cs +++ b/osu.Game/Screens/Edit/Compose/Components/SelectionBoxDragHandleContainer.cs @@ -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) diff --git a/osu.Game/Screens/Edit/Compose/Components/SelectionBoxRotationHandle.cs b/osu.Game/Screens/Edit/Compose/Components/SelectionBoxRotationHandle.cs index 6303caf9ed..65a54292ab 100644 --- a/osu.Game/Screens/Edit/Compose/Components/SelectionBoxRotationHandle.cs +++ b/osu.Game/Screens/Edit/Compose/Components/SelectionBoxRotationHandle.cs @@ -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); } } }