1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-12 05:27:40 +08:00
osu-lazer/osu.Game.Tests/Visual/Editing/TestSceneComposeSelectBox.cs

68 lines
2.3 KiB
C#
Raw Normal View History

// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
2020-09-29 18:19:48 +08:00
using osu.Framework.Input.Events;
using osu.Game.Screens.Edit.Compose.Components;
using osuTK;
namespace osu.Game.Tests.Visual.Editing
{
public class TestSceneComposeSelectBox : OsuTestScene
{
2020-09-29 18:19:48 +08:00
private Container selectionArea;
public TestSceneComposeSelectBox()
{
ComposeSelectionBox selectionBox = null;
AddStep("create box", () =>
2020-09-29 18:19:48 +08:00
Child = selectionArea = new Container
{
Size = new Vector2(300),
2020-09-29 18:19:48 +08:00
Position = -new Vector2(150),
Anchor = Anchor.Centre,
Children = new Drawable[]
{
selectionBox = new ComposeSelectionBox
{
CanRotate = true,
CanScaleX = true,
2020-09-29 18:19:48 +08:00
CanScaleY = true,
OnRotation = handleRotation,
OnScaleX = handleScaleX,
OnScaleY = handleScaleY,
}
}
});
AddToggleStep("toggle rotation", state => selectionBox.CanRotate = state);
AddToggleStep("toggle x", state => selectionBox.CanScaleX = state);
AddToggleStep("toggle y", state => selectionBox.CanScaleY = state);
}
2020-09-29 18:19:48 +08:00
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;
}
}
}