From fc4069f794e91e6ea1eb4a4b28c334b12e301a85 Mon Sep 17 00:00:00 2001 From: Wleter Date: Fri, 1 Sep 2023 13:01:51 +0200 Subject: [PATCH] let SelectionBox perform flip with scale handles --- .../SkinEditor/SkinSelectionHandler.cs | 14 ++++--------- .../Edit/Compose/Components/SelectionBox.cs | 20 ++++++++++++++++++- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/osu.Game/Overlays/SkinEditor/SkinSelectionHandler.cs b/osu.Game/Overlays/SkinEditor/SkinSelectionHandler.cs index ff53095e22..b30351f61b 100644 --- a/osu.Game/Overlays/SkinEditor/SkinSelectionHandler.cs +++ b/osu.Game/Overlays/SkinEditor/SkinSelectionHandler.cs @@ -81,18 +81,12 @@ namespace osu.Game.Overlays.SkinEditor if (adjustedRect.Width <= 0 || adjustedRect.Height <= 0) { - if (adjustedRect.Width <= 0) - { - SelectionBox.FlipScaleHandles(Direction.Horizontal); - HandleFlip(Direction.Horizontal, false); - } + Axes toFlip = Axes.None; - if (adjustedRect.Height <= 0) - { - SelectionBox.FlipScaleHandles(Direction.Vertical); - HandleFlip(Direction.Vertical, false); - } + if (adjustedRect.Width <= 0) toFlip |= Axes.X; + if (adjustedRect.Height <= 0) toFlip |= Axes.Y; + SelectionBox.PerformFlipFromScaleHandles(toFlip); return true; } diff --git a/osu.Game/Screens/Edit/Compose/Components/SelectionBox.cs b/osu.Game/Screens/Edit/Compose/Components/SelectionBox.cs index bbf9ea8c3c..0c19f6c62e 100644 --- a/osu.Game/Screens/Edit/Compose/Components/SelectionBox.cs +++ b/osu.Game/Screens/Edit/Compose/Components/SelectionBox.cs @@ -4,6 +4,7 @@ using System; using osu.Framework.Allocation; using osu.Framework.Bindables; +using osu.Framework.Extensions.EnumExtensions; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; @@ -307,7 +308,24 @@ namespace osu.Game.Screens.Edit.Compose.Components return button; } - public void FlipScaleHandles(Direction direction) => dragHandles.FlipScaleHandles(direction); + /// + /// This method should be called when a selection needs to be flipped + /// because of an ongoing scale handle drag that would otherwise cause width or height to go negative. + /// + public void PerformFlipFromScaleHandles(Axes axes) + { + if (axes.HasFlagFast(Axes.X)) + { + dragHandles.FlipScaleHandles(Direction.Horizontal); + OnFlip?.Invoke(Direction.Horizontal, false); + } + + if (axes.HasFlagFast(Axes.Y)) + { + dragHandles.FlipScaleHandles(Direction.Vertical); + OnFlip?.Invoke(Direction.Vertical, false); + } + } private void addScaleHandle(Anchor anchor) {