2019-01-24 08:43:03 +00:00
|
|
|
// 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 09:19:50 +00:00
|
|
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Graphics.Cursor;
|
|
|
|
using osu.Framework.Input;
|
2020-09-07 06:18:15 +00:00
|
|
|
using osu.Framework.Input.StateChanges;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
namespace osu.Game.Graphics.Cursor
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// A container which provides a <see cref="MenuCursor"/> which can be overridden by hovered <see cref="Drawable"/>s.
|
|
|
|
/// </summary>
|
2018-05-25 19:13:40 +00:00
|
|
|
public class MenuCursorContainer : Container, IProvideCursor
|
2018-04-13 09:19:50 +00:00
|
|
|
{
|
|
|
|
protected override Container<Drawable> Content => content;
|
|
|
|
private readonly Container content;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Whether any cursors can be displayed.
|
|
|
|
/// </summary>
|
2018-04-13 12:13:09 +00:00
|
|
|
internal bool CanShowCursor = true;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
public CursorContainer Cursor { get; }
|
|
|
|
public bool ProvidingUserCursor => true;
|
|
|
|
|
2018-05-25 19:13:40 +00:00
|
|
|
public MenuCursorContainer()
|
2018-04-13 09:19:50 +00:00
|
|
|
{
|
|
|
|
AddRangeInternal(new Drawable[]
|
|
|
|
{
|
2019-06-11 05:28:52 +00:00
|
|
|
Cursor = new MenuCursor { State = { Value = Visibility.Hidden } },
|
2018-04-13 09:19:50 +00:00
|
|
|
content = new Container { RelativeSizeAxes = Axes.Both }
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
private InputManager inputManager;
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
inputManager = GetContainingInputManager();
|
|
|
|
}
|
|
|
|
|
|
|
|
private IProvideCursor currentTarget;
|
2019-02-28 04:31:40 +00:00
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
protected override void Update()
|
|
|
|
{
|
|
|
|
base.Update();
|
|
|
|
|
2020-09-07 06:31:05 +00:00
|
|
|
var lastMouseSource = inputManager.CurrentState.Mouse.LastSource;
|
2020-09-07 06:18:15 +00:00
|
|
|
bool hasValidInput = lastMouseSource != null && !(lastMouseSource is ISourcedFromTouch);
|
|
|
|
|
|
|
|
if (!hasValidInput || !CanShowCursor)
|
2018-04-13 09:19:50 +00:00
|
|
|
{
|
|
|
|
currentTarget?.Cursor?.Hide();
|
2019-01-23 11:52:00 +00:00
|
|
|
currentTarget = null;
|
2018-04-13 09:19:50 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-07-19 02:37:10 +00:00
|
|
|
IProvideCursor newTarget = this;
|
|
|
|
|
|
|
|
foreach (var d in inputManager.HoveredDrawables)
|
|
|
|
{
|
2020-07-24 01:41:09 +00:00
|
|
|
if (d is IProvideCursor p && p.ProvidingUserCursor)
|
|
|
|
{
|
|
|
|
newTarget = p;
|
|
|
|
break;
|
|
|
|
}
|
2020-07-19 02:37:10 +00:00
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
if (currentTarget == newTarget)
|
|
|
|
return;
|
|
|
|
|
|
|
|
currentTarget?.Cursor?.Hide();
|
|
|
|
newTarget.Cursor?.Show();
|
|
|
|
|
|
|
|
currentTarget = newTarget;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|