mirror of
https://github.com/SK-la/osu-framework.git
synced 2026-03-15 03:20:30 +00:00
Expose ManualInputManager for TestCases to use
This commit is contained in:
@@ -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>
|
||||
|
||||
40
osu.Framework/Testing/Input/ManualInputHandler.cs
Normal file
40
osu.Framework/Testing/Input/ManualInputHandler.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
39
osu.Framework/Testing/Input/ManualInputManager.cs
Normal file
39
osu.Framework/Testing/Input/ManualInputManager.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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" />
|
||||
|
||||
Reference in New Issue
Block a user