2022-06-10 15:22:34 +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.
|
|
|
|
|
|
|
|
#nullable enable
|
2022-06-17 00:46:04 +08:00
|
|
|
|
2022-06-10 15:22:34 +08:00
|
|
|
using osu.Framework.Graphics;
|
2022-06-17 00:46:04 +08:00
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Graphics.Cursor;
|
2022-06-10 15:22:34 +08:00
|
|
|
using osu.Framework.Graphics.Shapes;
|
|
|
|
using osu.Framework.Input.Events;
|
2022-06-10 18:33:01 +08:00
|
|
|
using osu.Framework.Input.States;
|
2022-06-10 15:22:34 +08:00
|
|
|
using osuTK;
|
|
|
|
using osuTK.Input;
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Utility.SampleComponents
|
|
|
|
{
|
2022-06-17 00:46:04 +08:00
|
|
|
public class LatencyCursorContainer : CursorContainer
|
2022-06-10 15:22:34 +08:00
|
|
|
{
|
2022-06-17 00:46:04 +08:00
|
|
|
protected override Drawable CreateCursor() => new LatencyCursor();
|
2022-06-10 15:22:34 +08:00
|
|
|
|
2022-06-17 00:46:04 +08:00
|
|
|
public override bool IsPresent => base.IsPresent || Scheduler.HasPendingTasks;
|
2022-06-10 15:22:34 +08:00
|
|
|
|
2022-06-10 18:33:01 +08:00
|
|
|
public LatencyCursorContainer()
|
2022-06-10 15:22:34 +08:00
|
|
|
{
|
2022-06-17 00:46:04 +08:00
|
|
|
State.Value = Visibility.Hidden;
|
2022-06-10 15:22:34 +08:00
|
|
|
}
|
|
|
|
|
2022-06-17 00:46:04 +08:00
|
|
|
protected override bool OnMouseMove(MouseMoveEvent e)
|
2022-06-10 15:22:34 +08:00
|
|
|
{
|
2022-06-17 01:09:10 +08:00
|
|
|
// Scheduling is required to ensure updating of cursor position happens in limited rate.
|
2022-06-17 00:46:04 +08:00
|
|
|
// We can alternatively solve this by a PassThroughInputManager layer inside LatencyArea,
|
|
|
|
// but that would mean including input lag to this test, which may not be desired.
|
|
|
|
Schedule(() => base.OnMouseMove(e));
|
|
|
|
return false;
|
2022-06-10 15:22:34 +08:00
|
|
|
}
|
|
|
|
|
2022-06-17 00:46:04 +08:00
|
|
|
private class LatencyCursor : LatencySampleComponent
|
2022-06-10 15:22:34 +08:00
|
|
|
{
|
2022-06-17 00:46:04 +08:00
|
|
|
public LatencyCursor()
|
2022-06-10 15:22:34 +08:00
|
|
|
{
|
2022-06-17 00:46:04 +08:00
|
|
|
AutoSizeAxes = Axes.Both;
|
|
|
|
Origin = Anchor.Centre;
|
|
|
|
|
|
|
|
InternalChild = new Circle { Size = new Vector2(40) };
|
2022-06-10 15:22:34 +08:00
|
|
|
}
|
2022-06-17 00:46:04 +08:00
|
|
|
|
|
|
|
protected override void UpdateAtLimitedRate(InputState inputState)
|
2022-06-10 15:22:34 +08:00
|
|
|
{
|
2022-06-17 00:46:04 +08:00
|
|
|
Colour = inputState.Mouse.IsPressed(MouseButton.Left) ? OverlayColourProvider.Content1 : OverlayColourProvider.Colour2;
|
2022-06-10 15:22:34 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|