2019-01-24 08:43:03 +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.
2018-05-18 08:53:19 +00:00
using NUnit.Framework ;
using osu.Framework.Graphics ;
using osu.Framework.Graphics.Colour ;
using osu.Framework.Graphics.Containers ;
using osu.Framework.Graphics.Primitives ;
using osu.Framework.Graphics.Shapes ;
2019-05-08 04:37:03 +00:00
using osu.Framework.Testing ;
2020-11-03 08:06:33 +00:00
using osu.Framework.Utils ;
2018-05-18 08:53:19 +00:00
using osu.Game.Graphics ;
using osu.Game.Graphics.Cursor ;
2018-11-06 09:28:22 +00:00
using osu.Game.Screens.Edit.Compose.Components.Timeline ;
2018-11-20 07:51:59 +00:00
using osuTK ;
using osuTK.Graphics ;
2020-11-03 08:06:33 +00:00
using osuTK.Input ;
2018-05-18 08:53:19 +00:00
2020-04-23 08:07:55 +00:00
namespace osu.Game.Tests.Visual.Editing
2018-05-18 08:53:19 +00:00
{
2020-03-23 01:01:33 +00:00
public class TestSceneZoomableScrollContainer : OsuManualInputManagerTestScene
2018-05-18 08:53:19 +00:00
{
2019-05-08 04:37:03 +00:00
private ZoomableScrollContainer scrollContainer ;
private Drawable innerBox ;
2018-05-18 08:53:19 +00:00
2019-05-08 04:37:03 +00:00
[SetUpSteps]
public void SetUpSteps ( )
2018-05-18 08:53:19 +00:00
{
2019-05-08 04:37:03 +00:00
AddStep ( "Add new scroll container" , ( ) = >
2018-05-18 08:53:19 +00:00
{
2019-05-08 04:37:03 +00:00
Children = new Drawable [ ]
2018-05-18 08:53:19 +00:00
{
2019-05-08 04:37:03 +00:00
new Container
2018-05-18 08:53:19 +00:00
{
2019-05-08 04:37:03 +00:00
Anchor = Anchor . Centre ,
Origin = Anchor . Centre ,
RelativeSizeAxes = Axes . X ,
Height = 250 ,
Width = 0.75f ,
Children = new Drawable [ ]
2018-05-18 08:53:19 +00:00
{
2019-05-08 04:37:03 +00:00
new Box
{
RelativeSizeAxes = Axes . Both ,
Colour = OsuColour . Gray ( 30 )
} ,
scrollContainer = new ZoomableScrollContainer { RelativeSizeAxes = Axes . Both }
}
} ,
new MenuCursor ( )
} ;
2018-05-18 08:53:19 +00:00
2019-05-08 04:37:03 +00:00
scrollContainer . Add ( innerBox = new Box
{
RelativeSizeAxes = Axes . Both ,
Colour = ColourInfo . GradientHorizontal ( new Color4 ( 0.8f , 0.6f , 0.4f , 1f ) , new Color4 ( 0.4f , 0.6f , 0.8f , 1f ) )
} ) ;
2018-05-18 08:53:19 +00:00
} ) ;
2019-05-08 04:37:03 +00:00
AddUntilStep ( "Scroll container is loaded" , ( ) = > scrollContainer . LoadState > = LoadState . Loaded ) ;
}
[Test]
public void TestWidthInitialization ( )
{
AddAssert ( "Inner container width was initialized" , ( ) = > innerBox . DrawWidth > 0 ) ;
2018-05-18 08:53:19 +00:00
}
[Test]
public void TestZoom0 ( )
{
reset ( ) ;
AddAssert ( "Box at 0" , ( ) = > Precision . AlmostEquals ( boxQuad . TopLeft , scrollQuad . TopLeft ) ) ;
AddAssert ( "Box width = 1x" , ( ) = > Precision . AlmostEquals ( boxQuad . Size , scrollQuad . Size ) ) ;
}
[Test]
public void TestZoom10 ( )
{
reset ( ) ;
AddStep ( "Set zoom = 10" , ( ) = > scrollContainer . Zoom = 10 ) ;
2018-06-12 07:20:38 +00:00
AddAssert ( "Box at 1/2" , ( ) = > Precision . AlmostEquals ( boxQuad . Centre , scrollQuad . Centre , 1 ) ) ;
2018-05-18 08:53:19 +00:00
AddAssert ( "Box width = 10x" , ( ) = > Precision . AlmostEquals ( boxQuad . Size . X , 10 * scrollQuad . Size . X ) ) ;
}
[Test]
public void TestMouseZoomInOnceOutOnce ( )
{
reset ( ) ;
// Scroll in at 0.25
AddStep ( "Move mouse to 0.25x" , ( ) = > InputManager . MoveMouseTo ( new Vector2 ( scrollQuad . TopLeft . X + 0.25f * scrollQuad . Size . X , scrollQuad . Centre . Y ) ) ) ;
2020-11-03 08:06:33 +00:00
AddStep ( "Press alt down" , ( ) = > InputManager . PressKey ( Key . AltLeft ) ) ;
2018-06-12 07:20:31 +00:00
AddStep ( "Scroll by 3" , ( ) = > InputManager . ScrollBy ( new Vector2 ( 0 , 3 ) ) ) ;
2018-05-18 08:53:19 +00:00
AddAssert ( "Box not at 0" , ( ) = > ! Precision . AlmostEquals ( boxQuad . TopLeft , scrollQuad . TopLeft ) ) ;
AddAssert ( "Box 1/4 at 1/4" , ( ) = > Precision . AlmostEquals ( boxQuad . TopLeft . X + 0.25f * boxQuad . Size . X , scrollQuad . TopLeft . X + 0.25f * scrollQuad . Size . X ) ) ;
// Scroll out at 0.25
2018-06-12 07:20:31 +00:00
AddStep ( "Scroll by -3" , ( ) = > InputManager . ScrollBy ( new Vector2 ( 0 , - 3 ) ) ) ;
2018-05-18 08:53:19 +00:00
AddAssert ( "Box at 0" , ( ) = > Precision . AlmostEquals ( boxQuad . TopLeft , scrollQuad . TopLeft ) ) ;
AddAssert ( "Box 1/4 at 1/4" , ( ) = > Precision . AlmostEquals ( boxQuad . TopLeft . X + 0.25f * boxQuad . Size . X , scrollQuad . TopLeft . X + 0.25f * scrollQuad . Size . X ) ) ;
2020-11-03 08:06:33 +00:00
AddStep ( "Release alt" , ( ) = > InputManager . ReleaseKey ( Key . AltLeft ) ) ;
2018-05-18 08:53:19 +00:00
}
[Test]
public void TestMouseZoomInTwiceOutTwice ( )
{
reset ( ) ;
2020-11-03 08:06:33 +00:00
AddStep ( "Press alt down" , ( ) = > InputManager . PressKey ( Key . AltLeft ) ) ;
2018-05-18 08:53:19 +00:00
// Scroll in at 0.25
AddStep ( "Move mouse to 0.25x" , ( ) = > InputManager . MoveMouseTo ( new Vector2 ( scrollQuad . TopLeft . X + 0.25f * scrollQuad . Size . X , scrollQuad . Centre . Y ) ) ) ;
2018-06-12 07:20:31 +00:00
AddStep ( "Scroll by 1" , ( ) = > InputManager . ScrollBy ( new Vector2 ( 0 , 1 ) ) ) ;
2018-05-18 08:53:19 +00:00
// Scroll in at 0.6
AddStep ( "Move mouse to 0.75x" , ( ) = > InputManager . MoveMouseTo ( new Vector2 ( scrollQuad . TopLeft . X + 0.75f * scrollQuad . Size . X , scrollQuad . Centre . Y ) ) ) ;
2018-06-12 07:20:31 +00:00
AddStep ( "Scroll by 1" , ( ) = > InputManager . ScrollBy ( new Vector2 ( 0 , 1 ) ) ) ;
2018-05-18 08:53:19 +00:00
AddAssert ( "Box not at 0" , ( ) = > ! Precision . AlmostEquals ( boxQuad . TopLeft , scrollQuad . TopLeft ) ) ;
// Very hard to determine actual position, so approximate
AddAssert ( "Box at correct position (1)" , ( ) = > Precision . DefinitelyBigger ( scrollQuad . TopLeft . X + 0.25f * scrollQuad . Size . X , boxQuad . TopLeft . X + 0.25f * boxQuad . Size . X ) ) ;
AddAssert ( "Box at correct position (2)" , ( ) = > Precision . DefinitelyBigger ( scrollQuad . TopLeft . X + 0.6f * scrollQuad . Size . X , boxQuad . TopLeft . X + 0.3f * boxQuad . Size . X ) ) ;
AddAssert ( "Box at correct position (3)" , ( ) = > Precision . DefinitelyBigger ( boxQuad . TopLeft . X + 0.6f * boxQuad . Size . X , scrollQuad . TopLeft . X + 0.6f * scrollQuad . Size . X ) ) ;
// Scroll out at 0.6
2018-06-12 07:20:31 +00:00
AddStep ( "Scroll by -1" , ( ) = > InputManager . ScrollBy ( new Vector2 ( 0 , - 1 ) ) ) ;
2018-05-18 08:53:19 +00:00
// Scroll out at 0.25
AddStep ( "Move mouse to 0.25x" , ( ) = > InputManager . MoveMouseTo ( new Vector2 ( scrollQuad . TopLeft . X + 0.25f * scrollQuad . Size . X , scrollQuad . Centre . Y ) ) ) ;
2018-06-12 07:20:31 +00:00
AddStep ( "Scroll by -1" , ( ) = > InputManager . ScrollBy ( new Vector2 ( 0 , - 1 ) ) ) ;
2018-05-18 08:53:19 +00:00
AddAssert ( "Box at 0" , ( ) = > Precision . AlmostEquals ( boxQuad . TopLeft , scrollQuad . TopLeft ) ) ;
2020-11-03 08:06:33 +00:00
AddStep ( "Release alt" , ( ) = > InputManager . ReleaseKey ( Key . AltLeft ) ) ;
2018-05-18 08:53:19 +00:00
}
private void reset ( )
{
AddStep ( "Reset" , ( ) = >
{
scrollContainer . Zoom = 0 ;
scrollContainer . ScrollTo ( 0 , false ) ;
} ) ;
}
private Quad scrollQuad = > scrollContainer . ScreenSpaceDrawQuad ;
private Quad boxQuad = > innerBox . ScreenSpaceDrawQuad ;
}
}