Merge pull request #18736 from frenzibyte/latency-certifier/hidden-cursor

Refactor `LatencyCursorContainer` to display menu cursor when inactive
This commit is contained in:
Dean Herbert 2022-06-19 01:19:37 +09:00 committed by GitHub
commit 3105e04839
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 32 deletions

View File

@ -6,8 +6,10 @@ using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Input.Events;
using osu.Game.Graphics.Cursor;
using osu.Game.Overlays;
using osu.Game.Screens.Utility.SampleComponents;
using osuTK.Input;
@ -15,7 +17,7 @@ using osuTK.Input;
namespace osu.Game.Screens.Utility
{
[Cached]
public class LatencyArea : CompositeDrawable
public class LatencyArea : CompositeDrawable, IProvideCursor
{
[Resolved]
private OverlayColourProvider overlayColourProvider { get; set; } = null!;
@ -34,6 +36,10 @@ namespace osu.Game.Screens.Utility
public readonly Bindable<LatencyVisualMode> VisualMode = new Bindable<LatencyVisualMode>();
public CursorContainer? Cursor { get; private set; }
public bool ProvidingUserCursor => IsActiveArea.Value;
public LatencyArea(Key key, int? targetFrameRate)
{
this.key = key;
@ -85,7 +91,7 @@ namespace osu.Game.Screens.Utility
{
RelativeSizeAxes = Axes.Both,
},
new LatencyCursorContainer
Cursor = new LatencyCursorContainer
{
RelativeSizeAxes = Axes.Both,
},
@ -99,7 +105,7 @@ namespace osu.Game.Screens.Utility
{
RelativeSizeAxes = Axes.Both,
},
new LatencyCursorContainer
Cursor = new LatencyCursorContainer
{
RelativeSizeAxes = Axes.Both,
},
@ -113,7 +119,7 @@ namespace osu.Game.Screens.Utility
{
RelativeSizeAxes = Axes.Both,
},
new LatencyCursorContainer
Cursor = new LatencyCursorContainer
{
RelativeSizeAxes = Axes.Both,
},

View File

@ -39,8 +39,6 @@ namespace osu.Game.Screens.Utility
public override bool HideOverlaysOnEnter => true;
public override bool CursorVisible => mainArea.Count == 0;
public override float BackgroundParallaxAmount => 0;
private readonly LinkFlowContainer explanatoryText;

View File

@ -1,55 +1,52 @@
// 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.
using osu.Framework.Allocation;
#nullable enable
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Input.Events;
using osu.Framework.Input.States;
using osu.Game.Overlays;
using osuTK;
using osuTK.Input;
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]
private OverlayColourProvider overlayColourProvider { get; set; } = null!;
public override bool IsPresent => base.IsPresent || Scheduler.HasPendingTasks;
public LatencyCursorContainer()
{
Masking = true;
State.Value = Visibility.Hidden;
}
protected override void LoadComplete()
protected override bool OnMouseMove(MouseMoveEvent e)
{
base.LoadComplete();
InternalChild = cursor = new Circle
{
Size = new Vector2(40),
Origin = Anchor.Centre,
Colour = overlayColourProvider.Colour2,
};
// Scheduling is required to ensure updating of cursor position happens in limited rate.
// 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;
}
protected override bool OnHover(HoverEvent e) => false;
protected override void UpdateAtLimitedRate(InputState inputState)
private class LatencyCursor : LatencySampleComponent
{
cursor.Colour = inputState.Mouse.IsPressed(MouseButton.Left) ? overlayColourProvider.Content1 : overlayColourProvider.Colour2;
if (IsActive.Value)
public LatencyCursor()
{
cursor.Position = ToLocalSpace(inputState.Mouse.Position);
cursor.Alpha = 1;
AutoSizeAxes = Axes.Both;
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;
}
}
}