1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-21 18:42:56 +08:00
osu-lazer/osu.Game/Graphics/Cursor/GlobalCursorDisplay.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

93 lines
2.9 KiB
C#
Raw Normal View History

// 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.
2018-04-13 17:19:50 +08:00
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.Input;
using osu.Framework.Input.StateChanges;
using osu.Game.Configuration;
2018-04-13 17:19:50 +08:00
namespace osu.Game.Graphics.Cursor
{
/// <summary>
/// A container which provides the main <see cref="Cursor.MenuCursor"/>.
/// Also handles cases where a more localised cursor is provided by another component (via <see cref="IProvideCursor"/>).
/// </summary>
public class GlobalCursorDisplay : Container, IProvideCursor
{
/// <summary>
/// Control whether any cursor should be displayed.
/// </summary>
internal bool ShowCursor = true;
public CursorContainer MenuCursor { get; }
2018-04-13 17:19:50 +08:00
public bool ProvidingUserCursor => true;
2018-04-13 17:19:50 +08:00
protected override Container<Drawable> Content { get; } = new Container { RelativeSizeAxes = Axes.Both };
private Bindable<bool> showDuringTouch = null!;
private InputManager inputManager = null!;
private IProvideCursor? currentOverrideProvider;
[Resolved]
private OsuConfigManager config { get; set; } = null!;
public GlobalCursorDisplay()
{
AddRangeInternal(new Drawable[]
{
MenuCursor = new MenuCursor { State = { Value = Visibility.Hidden } },
Content = new Container { RelativeSizeAxes = Axes.Both }
});
}
2018-04-13 17:19:50 +08:00
protected override void LoadComplete()
{
base.LoadComplete();
inputManager = GetContainingInputManager();
showDuringTouch = config.GetBindable<bool>(OsuSetting.GameplayCursorDuringTouch);
}
2018-04-13 17:19:50 +08:00
protected override void Update()
{
base.Update();
2018-04-13 17:19:50 +08:00
2020-09-07 14:31:05 +08:00
var lastMouseSource = inputManager.CurrentState.Mouse.LastSource;
bool hasValidInput = lastMouseSource != null && (showDuringTouch.Value || lastMouseSource is not ISourcedFromTouch);
if (!hasValidInput || !ShowCursor)
{
currentOverrideProvider?.MenuCursor?.Hide();
currentOverrideProvider = null;
return;
}
2018-04-13 17:19:50 +08:00
IProvideCursor newOverrideProvider = this;
foreach (var d in inputManager.HoveredDrawables)
{
2020-07-24 09:41:09 +08:00
if (d is IProvideCursor p && p.ProvidingUserCursor)
{
newOverrideProvider = p;
2020-07-24 09:41:09 +08:00
break;
}
}
2018-04-13 17:19:50 +08:00
if (currentOverrideProvider == newOverrideProvider)
return;
2018-04-13 17:19:50 +08:00
currentOverrideProvider?.MenuCursor?.Hide();
newOverrideProvider.MenuCursor?.Show();
2018-04-13 17:19:50 +08:00
currentOverrideProvider = newOverrideProvider;
}
}
}