1
0
mirror of https://github.com/ppy/osu.git synced 2026-06-08 02:53:40 +08:00

Migrate test to SelectionRotationHandler

This commit is contained in:
Bartłomiej Dach
2023-07-23 19:57:31 +02:00
Unverified
parent f8047d6ab6
commit 21df0e2d60
@@ -3,7 +3,9 @@
#nullable disable
using System;
using System.Linq;
using JetBrains.Annotations;
using NUnit.Framework;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
@@ -34,13 +36,12 @@ namespace osu.Game.Tests.Visual.Editing
{
RelativeSizeAxes = Axes.Both,
CanRotate = true,
CanScaleX = true,
CanScaleY = true,
CanFlipX = true,
CanFlipY = true,
OnRotation = handleRotation,
RotationHandler = new TestSelectionRotationHandler(() => selectionArea),
OnScale = handleScale
}
}
@@ -71,11 +72,48 @@ namespace osu.Game.Tests.Visual.Editing
return true;
}
private bool handleRotation(float angle)
private class TestSelectionRotationHandler : SelectionRotationHandler
{
// kinda silly and wrong, but just showing that the drag handles work.
selectionArea.Rotation += angle;
return true;
private readonly Func<Container> getTargetContainer;
public TestSelectionRotationHandler(Func<Container> getTargetContainer)
{
this.getTargetContainer = getTargetContainer;
CanRotate.Value = true;
}
[CanBeNull]
private Container targetContainer;
private float? initialRotation;
public override void Begin()
{
if (targetContainer != null)
throw new InvalidOperationException($"Cannot {nameof(Begin)} a rotate operation while another is in progress!");
targetContainer = getTargetContainer();
initialRotation = targetContainer!.Rotation;
}
public override void Update(float rotation, Vector2? origin = null)
{
if (targetContainer == null)
throw new InvalidOperationException($"Cannot {nameof(Update)} a rotate operation without calling {nameof(Begin)} first!");
// kinda silly and wrong, but just showing that the drag handles work.
targetContainer.Rotation = initialRotation!.Value + rotation;
}
public override void Commit()
{
if (targetContainer == null)
throw new InvalidOperationException($"Cannot {nameof(Commit)} a rotate operation without calling {nameof(Begin)} first!");
targetContainer = null;
initialRotation = null;
}
}
[Test]