mirror of
https://github.com/ppy/osu.git
synced 2025-03-28 01:37:46 +08:00
replace drag cirle function with dictionary
This commit is contained in:
parent
9079d33412
commit
122250f454
@ -2,6 +2,7 @@
|
|||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
@ -235,13 +236,27 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
|||||||
private void addDragHandle(Anchor anchor) => AddInternal(new SelectionBoxDragHandle
|
private void addDragHandle(Anchor anchor) => AddInternal(new SelectionBoxDragHandle
|
||||||
{
|
{
|
||||||
Anchor = anchor,
|
Anchor = anchor,
|
||||||
X = getAdjustmentToCenterCircleOnBorder(anchor).X,
|
X = dragCircleAdjustments[anchor].X,
|
||||||
Y = getAdjustmentToCenterCircleOnBorder(anchor).Y,
|
Y = dragCircleAdjustments[anchor].Y,
|
||||||
HandleDrag = e => OnScale?.Invoke(e.Delta, anchor),
|
HandleDrag = e => OnScale?.Invoke(e.Delta, anchor),
|
||||||
OperationStarted = operationStarted,
|
OperationStarted = operationStarted,
|
||||||
OperationEnded = operationEnded
|
OperationEnded = operationEnded
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Adjust Drag circle to be centered on the center of the border instead of on the edge.
|
||||||
|
/// </summary>
|
||||||
|
private Dictionary<Anchor, Vector2> dragCircleAdjustments = new Dictionary<Anchor, Vector2>(){
|
||||||
|
{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 int activeOperations;
|
||||||
|
|
||||||
private float convertDragEventToAngleOfRotation(DragEvent e)
|
private float convertDragEventToAngleOfRotation(DragEvent e)
|
||||||
@ -253,48 +268,6 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
|||||||
return (endAngle - startAngle) * 180 / MathF.PI;
|
return (endAngle - startAngle) * 180 / MathF.PI;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Adjust Drag circle to be centered on the center of the border instead of on the edge.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="anchor">The part of the rectangle to be adjusted.</param>
|
|
||||||
/// <returns>A 2d vector on how much to adjust the drag circle</returns>
|
|
||||||
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()
|
private void operationEnded()
|
||||||
{
|
{
|
||||||
if (--activeOperations == 0)
|
if (--activeOperations == 0)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user