1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-04 23:43:00 +08:00

Refactor LatencyCursorContainer to become a cursor container

This commit is contained in:
Salman Ahmed 2022-06-16 19:46:04 +03:00
parent c7287556e5
commit 52538dc708

View File

@ -2,55 +2,51 @@
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
#nullable enable #nullable enable
using osu.Framework.Allocation;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
using osu.Framework.Input.Events; using osu.Framework.Input.Events;
using osu.Framework.Input.States; using osu.Framework.Input.States;
using osu.Game.Overlays;
using osuTK; using osuTK;
using osuTK.Input; using osuTK.Input;
namespace osu.Game.Screens.Utility.SampleComponents namespace osu.Game.Screens.Utility.SampleComponents
{ {
public class LatencyCursorContainer : LatencySampleComponent public class LatencyCursorContainer : CursorContainer
{ {
private Circle cursor = null!; protected override Drawable CreateCursor() => new LatencyCursor();
[Resolved] public override bool IsPresent => base.IsPresent || Scheduler.HasPendingTasks;
private OverlayColourProvider overlayColourProvider { get; set; } = null!;
public LatencyCursorContainer() public LatencyCursorContainer()
{ {
Masking = true; State.Value = Visibility.Hidden;
} }
protected override void LoadComplete() protected override bool OnMouseMove(MouseMoveEvent e)
{ {
base.LoadComplete(); // CursorContainer implements IRequireHighFrequencyMousePosition, which bypasses limited rate updating, therefore scheduling is required.
// We can alternatively solve this by a PassThroughInputManager layer inside LatencyArea,
InternalChild = cursor = new Circle // but that would mean including input lag to this test, which may not be desired.
{ Schedule(() => base.OnMouseMove(e));
Size = new Vector2(40), return false;
Origin = Anchor.Centre,
Colour = overlayColourProvider.Colour2,
};
} }
protected override bool OnHover(HoverEvent e) => false; private class LatencyCursor : LatencySampleComponent
protected override void UpdateAtLimitedRate(InputState inputState)
{ {
cursor.Colour = inputState.Mouse.IsPressed(MouseButton.Left) ? overlayColourProvider.Content1 : overlayColourProvider.Colour2; public LatencyCursor()
if (IsActive.Value)
{ {
cursor.Position = ToLocalSpace(inputState.Mouse.Position); AutoSizeAxes = Axes.Both;
cursor.Alpha = 1; Origin = Anchor.Centre;
InternalChild = new Circle { Size = new Vector2(40) };
} }
else
protected override void UpdateAtLimitedRate(InputState inputState)
{ {
cursor.Alpha = 0; Colour = inputState.Mouse.IsPressed(MouseButton.Left) ? OverlayColourProvider.Content1 : OverlayColourProvider.Colour2;
} }
} }
} }