Expose ManualInputManager for TestCases to use

This commit is contained in:
smoogipoo
2018-01-16 15:23:14 +09:00
parent 3e008c504f
commit b7798d7d94
4 changed files with 82 additions and 61 deletions

View File

@@ -9,13 +9,10 @@ using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input;
using osu.Framework.Input.Handlers;
using osu.Framework.Platform;
using osu.Framework.Testing;
using osu.Framework.Testing.Input;
using OpenTK;
using OpenTK.Input;
using MouseState = osu.Framework.Input.MouseState;
namespace osu.Framework.Tests.Visual
{
@@ -416,63 +413,6 @@ namespace osu.Framework.Tests.Visual
return item;
}
private class ManualInputManager : PassThroughInputManager
{
private readonly ManualInputHandler handler;
public ManualInputManager()
{
UseParentState = true;
AddHandler(handler = new ManualInputHandler());
}
public void MoveMouseTo(Drawable drawable)
{
UseParentState = false;
MoveMouseTo(drawable.ToScreenSpace(drawable.LayoutRectangle.Centre));
}
public void MoveMouseTo(Vector2 position)
{
UseParentState = false;
handler.MoveMouseTo(position);
}
public void Click(MouseButton button)
{
UseParentState = false;
handler.Click(button);
}
}
private class ManualInputHandler : InputHandler
{
private Vector2 lastMousePosition;
public void MoveMouseTo(Vector2 position)
{
PendingStates.Enqueue(new InputState { Mouse = new MouseState { Position = position } });
lastMousePosition = position;
}
public void Click(MouseButton button)
{
var mouseState = new MouseState { Position = lastMousePosition };
mouseState.SetPressed(button, true);
PendingStates.Enqueue(new InputState { Mouse = mouseState });
mouseState = (MouseState)mouseState.Clone();
mouseState.SetPressed(button, false);
PendingStates.Enqueue(new InputState { Mouse = mouseState });
}
public override bool Initialize(GameHost host) => true;
public override bool IsActive => true;
public override int Priority => 0;
}
/// <summary>
/// Helper class used to retrieve various internal properties/items from a <see cref="Menu"/>.
/// </summary>

View File

@@ -0,0 +1,40 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu-framework/master/LICENCE
using osu.Framework.Input;
using osu.Framework.Input.Handlers;
using osu.Framework.Platform;
using OpenTK;
using OpenTK.Input;
using MouseState = osu.Framework.Input.MouseState;
namespace osu.Framework.Testing.Input
{
public class ManualInputHandler : InputHandler
{
private Vector2 lastMousePosition;
public void MoveMouseTo(Vector2 position)
{
PendingStates.Enqueue(new InputState { Mouse = new MouseState { Position = position } });
lastMousePosition = position;
}
public void Click(MouseButton button)
{
var mouseState = new MouseState { Position = lastMousePosition };
mouseState.SetPressed(button, true);
PendingStates.Enqueue(new InputState { Mouse = mouseState });
mouseState = (MouseState)mouseState.Clone();
mouseState.SetPressed(button, false);
PendingStates.Enqueue(new InputState { Mouse = mouseState });
}
public override bool Initialize(GameHost host) => true;
public override bool IsActive => true;
public override int Priority => 0;
}
}

View File

@@ -0,0 +1,39 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu-framework/master/LICENCE
using osu.Framework.Graphics;
using osu.Framework.Input;
using OpenTK;
using OpenTK.Input;
namespace osu.Framework.Testing.Input
{
public class ManualInputManager : PassThroughInputManager
{
private readonly ManualInputHandler handler;
public ManualInputManager()
{
UseParentState = true;
AddHandler(handler = new ManualInputHandler());
}
public void MoveMouseTo(Drawable drawable)
{
UseParentState = false;
MoveMouseTo(drawable.ToScreenSpace(drawable.LayoutRectangle.Centre));
}
public void MoveMouseTo(Vector2 position)
{
UseParentState = false;
handler.MoveMouseTo(position);
}
public void Click(MouseButton button)
{
UseParentState = false;
handler.Click(button);
}
}
}

View File

@@ -456,6 +456,8 @@
<Compile Include="Testing\DynamicClassCompiler.cs" />
<Compile Include="Testing\GridTestCase.cs" />
<Compile Include="Testing\IDynamicallyCompile.cs" />
<Compile Include="Testing\Input\ManualInputHandler.cs" />
<Compile Include="Testing\Input\ManualInputManager.cs" />
<Compile Include="Testing\TestBrowser.cs" />
<Compile Include="Testing\TestBrowserConfig.cs" />
<Compile Include="Testing\TestBrowserTestRunner.cs" />