2021-05-28 01:45:04 +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.
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
#nullable disable
|
|
|
|
|
2022-10-11 21:21:50 +08:00
|
|
|
using osu.Framework.Bindables;
|
2021-05-28 01:45:04 +08:00
|
|
|
using osu.Framework.Input;
|
2022-10-11 21:21:50 +08:00
|
|
|
using osu.Framework.Input.StateChanges.Events;
|
2021-05-28 01:45:04 +08:00
|
|
|
using osuTK.Input;
|
|
|
|
|
|
|
|
namespace osu.Game.Input
|
|
|
|
{
|
|
|
|
public class OsuUserInputManager : UserInputManager
|
|
|
|
{
|
2022-10-11 21:21:50 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Whether the last input applied to the game is sourced from mouse.
|
|
|
|
/// </summary>
|
|
|
|
public IBindable<bool> IsMouseInputSource => isMouseInputSource;
|
|
|
|
|
|
|
|
private readonly Bindable<bool> isMouseInputSource = new Bindable<bool>();
|
|
|
|
|
2021-05-28 01:45:04 +08:00
|
|
|
internal OsuUserInputManager()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-10-11 21:21:50 +08:00
|
|
|
public override void HandleInputStateChange(InputStateChangeEvent inputStateChange)
|
|
|
|
{
|
|
|
|
switch (inputStateChange)
|
|
|
|
{
|
|
|
|
case ButtonStateChangeEvent<MouseButton>:
|
|
|
|
case MousePositionChangeEvent:
|
|
|
|
isMouseInputSource.Value = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
isMouseInputSource.Value = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
base.HandleInputStateChange(inputStateChange);
|
|
|
|
}
|
|
|
|
|
2021-05-28 01:45:04 +08:00
|
|
|
protected override MouseButtonEventManager CreateButtonEventManagerFor(MouseButton button)
|
|
|
|
{
|
|
|
|
switch (button)
|
|
|
|
{
|
|
|
|
case MouseButton.Right:
|
|
|
|
return new RightMouseManager(button);
|
|
|
|
}
|
|
|
|
|
|
|
|
return base.CreateButtonEventManagerFor(button);
|
|
|
|
}
|
|
|
|
|
|
|
|
private class RightMouseManager : MouseButtonEventManager
|
|
|
|
{
|
|
|
|
public RightMouseManager(MouseButton button)
|
|
|
|
: base(button)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public override bool EnableDrag => true; // allow right-mouse dragging for absolute scroll in scroll containers.
|
|
|
|
public override bool EnableClick => false;
|
|
|
|
public override bool ChangeFocusOnClick => false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|