From a01ed1827a481fb8ac87aef1a1fda89ed5b33f4e Mon Sep 17 00:00:00 2001 From: Graham Johnson Date: Thu, 17 Dec 2020 19:34:16 -0500 Subject: [PATCH] Align the drag circles on the selction box in the editor to be on the center of the border --- .../Edit/Compose/Components/SelectionBox.cs | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/osu.Game/Screens/Edit/Compose/Components/SelectionBox.cs b/osu.Game/Screens/Edit/Compose/Components/SelectionBox.cs index 347d9e3ba7..e4feceb987 100644 --- a/osu.Game/Screens/Edit/Compose/Components/SelectionBox.cs +++ b/osu.Game/Screens/Edit/Compose/Components/SelectionBox.cs @@ -235,6 +235,8 @@ namespace osu.Game.Screens.Edit.Compose.Components private void addDragHandle(Anchor anchor) => AddInternal(new SelectionBoxDragHandle { Anchor = anchor, + Y = getAdjustmentToCenterCircleOnBorder(anchor).Y, + X = getAdjustmentToCenterCircleOnBorder(anchor).X, HandleDrag = e => OnScale?.Invoke(e.Delta, anchor), OperationStarted = operationStarted, OperationEnded = operationEnded @@ -251,6 +253,45 @@ 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. + 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)