add IHasOverhangingTooltip

This commit is contained in:
Jorolf
2017-04-14 00:18:17 +02:00
parent f6f75fac74
commit 7f08c3c417
4 changed files with 41 additions and 19 deletions

View File

@ -12,7 +12,7 @@ namespace osu.Game.Graphics.Cursor
}
/// <summary>
/// Interface of <see cref="IHasTooltip"/> with custom appear time
/// Tooltip with custom appear time
/// </summary>
public interface IHasDelayedTooltip : IHasTooltip
{
@ -21,4 +21,15 @@ namespace osu.Game.Graphics.Cursor
/// </summary>
int Delay { get; }
}
/// <summary>
/// Tooltip which can show after hovering over the object
/// </summary>
public interface IHasOverhangingTooltip : IHasTooltip
{
/// <summary>
/// Should the tooltip still show?
/// </summary>
bool Overhanging { get; }
}
}

View File

@ -31,24 +31,33 @@ namespace osu.Game.Graphics.Cursor
private ScheduledDelegate show;
private OsuGameBase game;
private IHasOverhangingTooltip overhang;
protected override bool OnMouseMove(InputState state)
{
if (state.Mouse.Position != state.Mouse.LastPosition)
Tooltip tooltip = ((Cursor)ActiveCursor).Tooltip;
if (overhang?.Overhanging ?? false)
tooltip.TooltipText = overhang.Tooltip;
else if (state.Mouse.Position != state.Mouse.LastPosition)
{
Tooltip tooltip = ((Cursor)ActiveCursor).Tooltip;
show?.Cancel();
tooltip.TooltipText = string.Empty;
IHasTooltip hasTooltip = null;
if (game.InternalChildren.OfType<IContainer>().Any(child => (hasTooltip = searchTooltip(child as IContainerEnumerable<Drawable>)) != null))
{
IHasDelayedTooltip delayedTooltip = hasTooltip as IHasDelayedTooltip;
overhang = hasTooltip as IHasOverhangingTooltip;
show = Scheduler.AddDelayed(delegate
{
tooltip.TooltipText = hasTooltip.Tooltip;
}, delayedTooltip?.Delay ?? 250);
}
}
else if(overhang != null)
{
overhang = null;
tooltip.TooltipText = string.Empty;
}
if (dragging)
{

View File

@ -34,8 +34,6 @@ namespace osu.Game.Graphics.Cursor
public Tooltip()
{
Depth = float.MinValue;
AlwaysReceiveInput = true;
Children = new[]
{
new Container