1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-17 13:02:56 +08:00
osu-lazer/osu.Game.Tests/Visual/Editing/TestSceneComposeSelectBox.cs

73 lines
2.4 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;
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()
{
SelectionBox selectionBox = null;
AddStep("create box", () =>
2020-09-29 18:19:48 +08:00
Child = selectionArea = new Container
{
Size = new Vector2(400),
2020-09-29 18:19:48 +08:00
Position = -new Vector2(150),
Anchor = Anchor.Centre,
Children = new Drawable[]
{
selectionBox = new SelectionBox
{
CanRotate = true,
CanScaleX = true,
2020-09-29 18:19:48 +08:00
CanScaleY = true,
OnRotation = handleRotation,
OnScale = handleScale
}
}
});
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 bool handleScale(Vector2 amount, Anchor reference)
2020-09-29 18:19:48 +08:00
{
if ((reference & Anchor.y1) == 0)
{
int directionY = (reference & Anchor.y0) > 0 ? -1 : 1;
if (directionY < 0)
selectionArea.Y += amount.Y;
selectionArea.Height += directionY * amount.Y;
}
2020-09-29 18:19:48 +08:00
if ((reference & Anchor.x1) == 0)
{
int directionX = (reference & Anchor.x0) > 0 ? -1 : 1;
if (directionX < 0)
selectionArea.X += amount.X;
selectionArea.Width += directionX * amount.X;
}
return true;
2020-09-29 18:19:48 +08:00
}
private bool handleRotation(float angle)
2020-09-29 18:19:48 +08:00
{
// kinda silly and wrong, but just showing that the drag handles work.
selectionArea.Rotation += angle;
return true;
2020-09-29 18:19:48 +08:00
}
}
}