2020-09-29 10:07:40 +00: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.
|
|
|
|
|
2021-04-24 06:35:02 +00:00
|
|
|
using System.Linq;
|
|
|
|
using NUnit.Framework;
|
2020-09-29 10:07:40 +00:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2021-04-24 06:35:02 +00:00
|
|
|
using osu.Framework.Testing;
|
2021-05-04 04:31:52 +00:00
|
|
|
using osu.Framework.Threading;
|
2020-09-29 10:07:40 +00:00
|
|
|
using osu.Game.Screens.Edit.Compose.Components;
|
|
|
|
using osuTK;
|
2021-04-24 06:35:02 +00:00
|
|
|
using osuTK.Input;
|
2020-09-29 10:07:40 +00:00
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual.Editing
|
|
|
|
{
|
2021-04-24 06:35:02 +00:00
|
|
|
public class TestSceneComposeSelectBox : OsuManualInputManagerTestScene
|
2020-09-29 10:07:40 +00:00
|
|
|
{
|
2020-09-29 10:19:48 +00:00
|
|
|
private Container selectionArea;
|
2021-04-24 06:35:02 +00:00
|
|
|
private SelectionBox selectionBox;
|
2020-09-29 10:19:48 +00:00
|
|
|
|
2021-04-25 16:57:16 +00:00
|
|
|
[SetUp]
|
|
|
|
public void SetUp() => Schedule(() =>
|
2020-09-29 10:07:40 +00:00
|
|
|
{
|
2021-04-25 16:57:16 +00:00
|
|
|
Child = selectionArea = new Container
|
|
|
|
{
|
|
|
|
Size = new Vector2(400),
|
|
|
|
Position = -new Vector2(150),
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Children = new Drawable[]
|
2020-09-29 10:07:40 +00:00
|
|
|
{
|
2021-04-25 16:57:16 +00:00
|
|
|
selectionBox = new SelectionBox
|
2020-09-29 10:07:40 +00:00
|
|
|
{
|
2021-05-04 21:28:49 +00:00
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
2021-04-25 16:57:16 +00:00
|
|
|
CanRotate = true,
|
|
|
|
CanScaleX = true,
|
|
|
|
CanScaleY = true,
|
2021-07-21 06:59:25 +00:00
|
|
|
CanFlipX = true,
|
|
|
|
CanFlipY = true,
|
2020-09-29 10:19:48 +00:00
|
|
|
|
2021-04-25 16:57:16 +00:00
|
|
|
OnRotation = handleRotation,
|
|
|
|
OnScale = handleScale
|
2020-09-29 10:07:40 +00:00
|
|
|
}
|
2021-04-25 16:57:16 +00:00
|
|
|
}
|
|
|
|
};
|
2020-09-29 10:07:40 +00:00
|
|
|
|
2021-04-25 16:57:16 +00:00
|
|
|
InputManager.MoveMouseTo(selectionBox);
|
2021-05-04 04:31:52 +00:00
|
|
|
InputManager.ReleaseButton(MouseButton.Left);
|
2021-04-25 16:57:16 +00:00
|
|
|
});
|
2020-09-29 10:19:48 +00:00
|
|
|
|
2020-11-03 12:23:10 +00:00
|
|
|
private bool handleScale(Vector2 amount, Anchor reference)
|
2020-09-29 10:19:48 +00:00
|
|
|
{
|
2020-09-30 06:08:56 +00:00
|
|
|
if ((reference & Anchor.y1) == 0)
|
|
|
|
{
|
|
|
|
int directionY = (reference & Anchor.y0) > 0 ? -1 : 1;
|
|
|
|
if (directionY < 0)
|
2020-10-01 07:25:29 +00:00
|
|
|
selectionArea.Y += amount.Y;
|
|
|
|
selectionArea.Height += directionY * amount.Y;
|
2020-09-30 06:08:56 +00:00
|
|
|
}
|
2020-09-29 10:19:48 +00:00
|
|
|
|
2020-09-30 06:08:56 +00:00
|
|
|
if ((reference & Anchor.x1) == 0)
|
|
|
|
{
|
|
|
|
int directionX = (reference & Anchor.x0) > 0 ? -1 : 1;
|
|
|
|
if (directionX < 0)
|
2020-10-01 07:25:29 +00:00
|
|
|
selectionArea.X += amount.X;
|
|
|
|
selectionArea.Width += directionX * amount.X;
|
2020-09-30 06:08:56 +00:00
|
|
|
}
|
2020-11-03 12:23:10 +00:00
|
|
|
|
|
|
|
return true;
|
2020-09-29 10:19:48 +00:00
|
|
|
}
|
|
|
|
|
2020-11-03 12:23:10 +00:00
|
|
|
private bool handleRotation(float angle)
|
2020-09-29 10:19:48 +00:00
|
|
|
{
|
2020-09-30 06:08:56 +00:00
|
|
|
// kinda silly and wrong, but just showing that the drag handles work.
|
2020-10-01 07:25:29 +00:00
|
|
|
selectionArea.Rotation += angle;
|
2020-11-03 12:23:10 +00:00
|
|
|
return true;
|
2020-09-29 10:19:48 +00:00
|
|
|
}
|
2021-04-24 06:35:02 +00:00
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestRotationHandleShownOnHover()
|
|
|
|
{
|
|
|
|
SelectionBoxRotationHandle rotationHandle = null;
|
|
|
|
|
|
|
|
AddStep("retrieve rotation handle", () => rotationHandle = this.ChildrenOfType<SelectionBoxRotationHandle>().First());
|
|
|
|
|
|
|
|
AddAssert("handle hidden", () => rotationHandle.Alpha == 0);
|
|
|
|
AddStep("hover over handle", () => InputManager.MoveMouseTo(rotationHandle));
|
|
|
|
AddUntilStep("rotation handle shown", () => rotationHandle.Alpha == 1);
|
|
|
|
|
|
|
|
AddStep("move mouse away", () => InputManager.MoveMouseTo(selectionBox));
|
|
|
|
AddUntilStep("handle hidden", () => rotationHandle.Alpha == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestRotationHandleShownOnHoveringClosestScaleHandler()
|
|
|
|
{
|
|
|
|
SelectionBoxRotationHandle rotationHandle = null;
|
|
|
|
|
|
|
|
AddStep("retrieve rotation handle", () => rotationHandle = this.ChildrenOfType<SelectionBoxRotationHandle>().First());
|
|
|
|
|
|
|
|
AddAssert("rotation handle hidden", () => rotationHandle.Alpha == 0);
|
|
|
|
AddStep("hover over closest scale handle", () =>
|
|
|
|
{
|
|
|
|
InputManager.MoveMouseTo(this.ChildrenOfType<SelectionBoxScaleHandle>().Single(s => s.Anchor == rotationHandle.Anchor));
|
|
|
|
});
|
|
|
|
AddUntilStep("rotation handle shown", () => rotationHandle.Alpha == 1);
|
|
|
|
|
|
|
|
AddStep("move mouse away", () => InputManager.MoveMouseTo(selectionBox));
|
|
|
|
AddUntilStep("handle hidden", () => rotationHandle.Alpha == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestHoverRotationHandleFromScaleHandle()
|
|
|
|
{
|
|
|
|
SelectionBoxRotationHandle rotationHandle = null;
|
|
|
|
|
|
|
|
AddStep("retrieve rotation handle", () => rotationHandle = this.ChildrenOfType<SelectionBoxRotationHandle>().First());
|
|
|
|
|
|
|
|
AddAssert("rotation handle hidden", () => rotationHandle.Alpha == 0);
|
|
|
|
AddStep("hover over closest scale handle", () =>
|
|
|
|
{
|
|
|
|
InputManager.MoveMouseTo(this.ChildrenOfType<SelectionBoxScaleHandle>().Single(s => s.Anchor == rotationHandle.Anchor));
|
|
|
|
});
|
|
|
|
AddUntilStep("rotation handle shown", () => rotationHandle.Alpha == 1);
|
|
|
|
AddAssert("rotation handle not hovered", () => !rotationHandle.IsHovered);
|
|
|
|
|
|
|
|
AddStep("hover over rotation handle", () => InputManager.MoveMouseTo(rotationHandle));
|
|
|
|
AddAssert("rotation handle still shown", () => rotationHandle.Alpha == 1);
|
|
|
|
AddAssert("rotation handle hovered", () => rotationHandle.IsHovered);
|
|
|
|
|
|
|
|
AddStep("move mouse away", () => InputManager.MoveMouseTo(selectionBox));
|
|
|
|
AddUntilStep("handle hidden", () => rotationHandle.Alpha == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2021-05-04 04:31:52 +00:00
|
|
|
public void TestHoldingScaleHandleHidesCorrespondingRotationHandle()
|
2021-04-24 06:35:02 +00:00
|
|
|
{
|
|
|
|
SelectionBoxRotationHandle rotationHandle = null;
|
|
|
|
|
|
|
|
AddStep("retrieve rotation handle", () => rotationHandle = this.ChildrenOfType<SelectionBoxRotationHandle>().First());
|
|
|
|
|
|
|
|
AddAssert("rotation handle hidden", () => rotationHandle.Alpha == 0);
|
2021-05-04 04:31:52 +00:00
|
|
|
AddStep("hover over closest scale handle", () =>
|
2021-04-24 06:35:02 +00:00
|
|
|
{
|
|
|
|
InputManager.MoveMouseTo(this.ChildrenOfType<SelectionBoxScaleHandle>().Single(s => s.Anchor == rotationHandle.Anchor));
|
|
|
|
});
|
|
|
|
AddUntilStep("rotation handle shown", () => rotationHandle.Alpha == 1);
|
2021-05-04 04:31:52 +00:00
|
|
|
AddStep("hold scale handle", () => InputManager.PressButton(MouseButton.Left));
|
|
|
|
AddUntilStep("rotation handle hidden", () => rotationHandle.Alpha == 0);
|
|
|
|
|
|
|
|
int i;
|
|
|
|
ScheduledDelegate mouseMove = null;
|
|
|
|
|
|
|
|
AddStep("start dragging", () =>
|
|
|
|
{
|
|
|
|
i = 0;
|
2021-04-24 06:35:02 +00:00
|
|
|
|
2021-05-04 04:31:52 +00:00
|
|
|
mouseMove = Scheduler.AddDelayed(() =>
|
|
|
|
{
|
|
|
|
InputManager.MoveMouseTo(selectionBox.ScreenSpaceDrawQuad.TopLeft + Vector2.One * (5 * ++i));
|
|
|
|
}, 100, true);
|
|
|
|
});
|
|
|
|
AddAssert("rotation handle still hidden", () => rotationHandle.Alpha == 0);
|
2021-04-24 06:35:02 +00:00
|
|
|
|
2021-05-04 04:31:52 +00:00
|
|
|
AddStep("end dragging", () => mouseMove.Cancel());
|
|
|
|
AddAssert("rotation handle still hidden", () => rotationHandle.Alpha == 0);
|
2021-04-24 06:35:02 +00:00
|
|
|
AddStep("unhold left", () => InputManager.ReleaseButton(MouseButton.Left));
|
2021-05-04 04:31:52 +00:00
|
|
|
AddUntilStep("rotation handle shown", () => rotationHandle.Alpha == 1);
|
2021-04-24 06:35:02 +00:00
|
|
|
AddStep("move mouse away", () => InputManager.MoveMouseTo(selectionBox, new Vector2(20)));
|
2021-05-04 04:31:52 +00:00
|
|
|
AddUntilStep("rotation handle hidden", () => rotationHandle.Alpha == 0);
|
2021-04-24 06:35:02 +00:00
|
|
|
}
|
2021-05-12 08:07:31 +00:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Tests that hovering over two handles instantaneously from one to another does not crash or cause issues to the visibility state.
|
|
|
|
/// </summary>
|
|
|
|
[Test]
|
|
|
|
public void TestHoverOverTwoHandlesInstantaneously()
|
|
|
|
{
|
|
|
|
AddStep("hover over top-left scale handle", () =>
|
|
|
|
InputManager.MoveMouseTo(this.ChildrenOfType<SelectionBoxScaleHandle>().Single(s => s.Anchor == Anchor.TopLeft)));
|
|
|
|
AddStep("hover over top-right scale handle", () =>
|
|
|
|
InputManager.MoveMouseTo(this.ChildrenOfType<SelectionBoxScaleHandle>().Single(s => s.Anchor == Anchor.TopRight)));
|
|
|
|
AddUntilStep("top-left rotation handle hidden", () =>
|
|
|
|
this.ChildrenOfType<SelectionBoxRotationHandle>().Single(r => r.Anchor == Anchor.TopLeft).Alpha == 0);
|
|
|
|
AddUntilStep("top-right rotation handle shown", () =>
|
|
|
|
this.ChildrenOfType<SelectionBoxRotationHandle>().Single(r => r.Anchor == Anchor.TopRight).Alpha == 1);
|
|
|
|
}
|
2020-09-29 10:07:40 +00:00
|
|
|
}
|
|
|
|
}
|