1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-14 00:42:55 +08:00

Add test coverage of event handling

This commit is contained in:
Dean Herbert 2020-09-29 19:19:48 +09:00
parent cd794eaa65
commit 265bba1a88

View File

@ -3,6 +3,7 @@
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Input.Events;
using osu.Game.Screens.Edit.Compose.Components; using osu.Game.Screens.Edit.Compose.Components;
using osuTK; using osuTK;
@ -10,23 +11,29 @@ namespace osu.Game.Tests.Visual.Editing
{ {
public class TestSceneComposeSelectBox : OsuTestScene public class TestSceneComposeSelectBox : OsuTestScene
{ {
private Container selectionArea;
public TestSceneComposeSelectBox() public TestSceneComposeSelectBox()
{ {
ComposeSelectionBox selectionBox = null; ComposeSelectionBox selectionBox = null;
AddStep("create box", () => AddStep("create box", () =>
Child = new Container Child = selectionArea = new Container
{ {
Size = new Vector2(300), Size = new Vector2(300),
Position = -new Vector2(150),
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Children = new Drawable[] Children = new Drawable[]
{ {
selectionBox = new ComposeSelectionBox selectionBox = new ComposeSelectionBox
{ {
CanRotate = true, CanRotate = true,
CanScaleX = true, CanScaleX = true,
CanScaleY = true CanScaleY = true,
OnRotation = handleRotation,
OnScaleX = handleScaleX,
OnScaleY = handleScaleY,
} }
} }
}); });
@ -35,5 +42,26 @@ namespace osu.Game.Tests.Visual.Editing
AddToggleStep("toggle x", state => selectionBox.CanScaleX = state); AddToggleStep("toggle x", state => selectionBox.CanScaleX = state);
AddToggleStep("toggle y", state => selectionBox.CanScaleY = state); AddToggleStep("toggle y", state => selectionBox.CanScaleY = state);
} }
private void handleScaleY(DragEvent e, Anchor reference)
{
int direction = (reference & Anchor.y0) > 0 ? -1 : 1;
if (direction < 0)
selectionArea.Y += e.Delta.Y;
selectionArea.Height += direction * e.Delta.Y;
}
private void handleScaleX(DragEvent e, Anchor reference)
{
int direction = (reference & Anchor.x0) > 0 ? -1 : 1;
if (direction < 0)
selectionArea.X += e.Delta.X;
selectionArea.Width += direction * e.Delta.X;
}
private void handleRotation(DragEvent e)
{
selectionArea.Rotation += e.Delta.X;
}
} }
} }