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