mirror of
https://github.com/ppy/osu.git
synced 2025-01-13 19:52:55 +08:00
Add test coverage of event handling
This commit is contained in:
parent
cd794eaa65
commit
265bba1a88
@ -3,6 +3,7 @@
|
||||
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Input.Events;
|
||||
using osu.Game.Screens.Edit.Compose.Components;
|
||||
using osuTK;
|
||||
|
||||
@ -10,23 +11,29 @@ namespace osu.Game.Tests.Visual.Editing
|
||||
{
|
||||
public class TestSceneComposeSelectBox : OsuTestScene
|
||||
{
|
||||
private Container selectionArea;
|
||||
|
||||
public TestSceneComposeSelectBox()
|
||||
{
|
||||
ComposeSelectionBox selectionBox = null;
|
||||
|
||||
AddStep("create box", () =>
|
||||
Child = new Container
|
||||
Child = selectionArea = new Container
|
||||
{
|
||||
Size = new Vector2(300),
|
||||
Position = -new Vector2(150),
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
selectionBox = new ComposeSelectionBox
|
||||
{
|
||||
CanRotate = 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 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user