2018-01-12 17:13:17 +08:00
|
|
|
// 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;
|
|
|
|
|
2018-01-12 18:34:55 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Whether any cursors can be displayed.
|
|
|
|
/// </summary>
|
|
|
|
public bool CanShowCursor;
|
|
|
|
|
2018-01-12 17:13:17 +08:00
|
|
|
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();
|
|
|
|
|
2018-01-12 18:34:55 +08:00
|
|
|
if (!CanShowCursor)
|
|
|
|
{
|
|
|
|
currentTarget?.LocalCursor?.Hide();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-01-12 17:13:17 +08:00
|
|
|
var newTarget = inputManager.HoveredDrawables.OfType<IProvideLocalCursor>().FirstOrDefault(t => t.ProvidesUserCursor) ?? this;
|
|
|
|
|
|
|
|
if (currentTarget == newTarget)
|
|
|
|
return;
|
|
|
|
|
|
|
|
currentTarget?.LocalCursor?.Hide();
|
|
|
|
newTarget.LocalCursor?.Show();
|
|
|
|
|
|
|
|
currentTarget = newTarget;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|