mirror of
https://github.com/ppy/osu.git
synced 2025-02-21 03:53:21 +08:00
Add rotation support
This commit is contained in:
parent
33b24b6f46
commit
934db14e03
@ -6,6 +6,7 @@ using System.Linq;
|
|||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Primitives;
|
using osu.Framework.Graphics.Primitives;
|
||||||
using osu.Framework.Input.Events;
|
using osu.Framework.Input.Events;
|
||||||
|
using osu.Game.Rulesets.Objects.Types;
|
||||||
using osu.Game.Rulesets.Osu.Objects;
|
using osu.Game.Rulesets.Osu.Objects;
|
||||||
using osu.Game.Screens.Edit.Compose.Components;
|
using osu.Game.Screens.Edit.Compose.Components;
|
||||||
using osuTK;
|
using osuTK;
|
||||||
@ -21,7 +22,7 @@ namespace osu.Game.Rulesets.Osu.Edit
|
|||||||
CanScaleX = true,
|
CanScaleX = true,
|
||||||
CanScaleY = true,
|
CanScaleY = true,
|
||||||
|
|
||||||
// OnRotation = handleRotation,
|
OnRotation = handleRotation,
|
||||||
OnScaleX = handleScaleX,
|
OnScaleX = handleScaleX,
|
||||||
OnScaleY = handleScaleY,
|
OnScaleY = handleScaleY,
|
||||||
};
|
};
|
||||||
@ -54,13 +55,45 @@ namespace osu.Game.Rulesets.Osu.Edit
|
|||||||
scaleSelection(new Vector2(direction * e.Delta.X, 0));
|
scaleSelection(new Vector2(direction * e.Delta.X, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Vector2? centre;
|
||||||
|
|
||||||
private void handleRotation(DragEvent e)
|
private void handleRotation(DragEvent e)
|
||||||
{
|
{
|
||||||
|
rotateSelection(e.Delta.X);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool HandleMovement(MoveSelectionEvent moveEvent) =>
|
public override bool HandleMovement(MoveSelectionEvent moveEvent) =>
|
||||||
moveSelection(moveEvent.InstantDelta);
|
moveSelection(moveEvent.InstantDelta);
|
||||||
|
|
||||||
|
private bool rotateSelection(in float delta)
|
||||||
|
{
|
||||||
|
Quad quad = getSelectionQuad();
|
||||||
|
|
||||||
|
if (!centre.HasValue)
|
||||||
|
centre = quad.Centre;
|
||||||
|
|
||||||
|
foreach (var h in SelectedHitObjects.OfType<OsuHitObject>())
|
||||||
|
{
|
||||||
|
if (h is Spinner)
|
||||||
|
{
|
||||||
|
// Spinners don't support position adjustments
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
h.Position = Rotate(h.Position, centre.Value, delta);
|
||||||
|
|
||||||
|
if (h is IHasPath path)
|
||||||
|
{
|
||||||
|
foreach (var point in path.Path.ControlPoints)
|
||||||
|
{
|
||||||
|
point.Position.Value = Rotate(point.Position.Value, Vector2.Zero, delta);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
private bool scaleSelection(Vector2 scale)
|
private bool scaleSelection(Vector2 scale)
|
||||||
{
|
{
|
||||||
Quad quad = getSelectionQuad();
|
Quad quad = getSelectionQuad();
|
||||||
@ -153,7 +186,7 @@ namespace osu.Game.Rulesets.Osu.Edit
|
|||||||
/// <param name="p">The point.</param>
|
/// <param name="p">The point.</param>
|
||||||
/// <param name="center">The center to rotate around.</param>
|
/// <param name="center">The center to rotate around.</param>
|
||||||
/// <param name="angle">The angle to rotate (in degrees).</param>
|
/// <param name="angle">The angle to rotate (in degrees).</param>
|
||||||
internal static Vector2 Rotate(Vector2 p, Vector2 center, int angle)
|
internal static Vector2 Rotate(Vector2 p, Vector2 center, float angle)
|
||||||
{
|
{
|
||||||
angle = -angle;
|
angle = -angle;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user