From 122250f454059d9adc231e982bd976e3795e1beb Mon Sep 17 00:00:00 2001 From: Graham Johnson Date: Fri, 18 Dec 2020 10:45:23 -0500 Subject: [PATCH] replace drag cirle function with dictionary --- .../Edit/Compose/Components/SelectionBox.cs | 61 ++++++------------- 1 file changed, 17 insertions(+), 44 deletions(-) diff --git a/osu.Game/Screens/Edit/Compose/Components/SelectionBox.cs b/osu.Game/Screens/Edit/Compose/Components/SelectionBox.cs index 8ccd4f71e9..85e86499be 100644 --- a/osu.Game/Screens/Edit/Compose/Components/SelectionBox.cs +++ b/osu.Game/Screens/Edit/Compose/Components/SelectionBox.cs @@ -2,6 +2,7 @@ // See the LICENCE file in the repository root for full licence text. using System; +using System.Collections.Generic; using osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; @@ -235,13 +236,27 @@ namespace osu.Game.Screens.Edit.Compose.Components private void addDragHandle(Anchor anchor) => AddInternal(new SelectionBoxDragHandle { Anchor = anchor, - X = getAdjustmentToCenterCircleOnBorder(anchor).X, - Y = getAdjustmentToCenterCircleOnBorder(anchor).Y, + X = dragCircleAdjustments[anchor].X, + Y = dragCircleAdjustments[anchor].Y, HandleDrag = e => OnScale?.Invoke(e.Delta, anchor), OperationStarted = operationStarted, OperationEnded = operationEnded }); + /// + /// Adjust Drag circle to be centered on the center of the border instead of on the edge. + /// + private Dictionary dragCircleAdjustments = new Dictionary(){ + {Anchor.TopLeft, new Vector2(BORDER_RADIUS / 2)}, + {Anchor.CentreLeft, new Vector2(BORDER_RADIUS / 2, 0)}, + {Anchor.BottomLeft, new Vector2(BORDER_RADIUS / 2, -BORDER_RADIUS / 2)}, + {Anchor.TopCentre, new Vector2(0, BORDER_RADIUS / 2)}, + {Anchor.BottomCentre, new Vector2(0, -BORDER_RADIUS / 2)}, + {Anchor.TopRight, new Vector2(-BORDER_RADIUS / 2, BORDER_RADIUS / 2)}, + {Anchor.CentreRight, new Vector2(-BORDER_RADIUS / 2, 0)}, + {Anchor.BottomRight, new Vector2(-BORDER_RADIUS / 2)} + }; + private int activeOperations; private float convertDragEventToAngleOfRotation(DragEvent e) @@ -253,48 +268,6 @@ namespace osu.Game.Screens.Edit.Compose.Components return (endAngle - startAngle) * 180 / MathF.PI; } - /// - /// Adjust Drag circle to be centered on the center of the border instead of on the edge. - /// - /// The part of the rectangle to be adjusted. - /// A 2d vector on how much to adjust the drag circle - private Vector2 getAdjustmentToCenterCircleOnBorder(Anchor anchor) - { - Vector2 adjustment = Vector2.Zero; - - switch (anchor) - { - case Anchor.TopLeft: - case Anchor.CentreLeft: - case Anchor.BottomLeft: - adjustment.X = BORDER_RADIUS / 2; - break; - - case Anchor.TopRight: - case Anchor.CentreRight: - case Anchor.BottomRight: - adjustment.X = -BORDER_RADIUS / 2; - break; - } - - switch (anchor) - { - case Anchor.TopLeft: - case Anchor.TopCentre: - case Anchor.TopRight: - adjustment.Y = BORDER_RADIUS / 2; - break; - - case Anchor.BottomLeft: - case Anchor.BottomCentre: - case Anchor.BottomRight: - adjustment.Y = -BORDER_RADIUS / 2; - break; - } - - return adjustment; - } - private void operationEnded() { if (--activeOperations == 0)