1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-08 13:57:29 +08:00
osu-lazer/osu.Game/Graphics/Cursor/OsuCursorContainer.cs

65 lines
1.9 KiB
C#
Raw Normal View History

// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System.Linq;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Input;
namespace osu.Game.Graphics.Cursor
{
public class OsuCursorContainer : Container, IProvideLocalCursor
{
protected override Container<Drawable> Content => content;
private readonly Container content;
/// <summary>
/// Whether any cursors can be displayed.
/// </summary>
public bool CanShowCursor;
public CursorContainer LocalCursor { get; }
public bool ProvidesUserCursor => true;
public OsuCursorContainer()
{
AddRangeInternal(new Drawable[]
{
LocalCursor = new MenuCursor { State = Visibility.Hidden },
content = new Container { RelativeSizeAxes = Axes.Both }
});
}
private InputManager inputManager;
protected override void LoadComplete()
{
base.LoadComplete();
inputManager = GetContainingInputManager();
}
private IProvideLocalCursor currentTarget;
protected override void Update()
{
base.Update();
if (!CanShowCursor)
{
currentTarget?.LocalCursor?.Hide();
return;
}
var newTarget = inputManager.HoveredDrawables.OfType<IProvideLocalCursor>().FirstOrDefault(t => t.ProvidesUserCursor) ?? this;
if (currentTarget == newTarget)
return;
currentTarget?.LocalCursor?.Hide();
newTarget.LocalCursor?.Show();
currentTarget = newTarget;
}
}
}