mirror of
https://github.com/osukey/osukey.git
synced 2025-07-01 08:20:00 +09:00
move tooltip outside of the cursor
This commit is contained in:
@ -26,32 +26,16 @@ namespace osu.Game.Graphics.Cursor
|
||||
private ScheduledDelegate show;
|
||||
private UserInputManager input;
|
||||
private IHasDisappearingTooltip disappearingTooltip;
|
||||
private IHasTooltip hasTooltip;
|
||||
|
||||
public const int DEFAULT_APPEAR_DELAY = 250;
|
||||
|
||||
public IMouseState MouseState
|
||||
{
|
||||
set
|
||||
{
|
||||
if (value.Position != value.LastPosition && disappearingTooltip?.Disappear != false)
|
||||
{
|
||||
show?.Cancel();
|
||||
tooltip.TooltipText = string.Empty;
|
||||
IHasTooltip hasTooltip = input.HoveredDrawables.OfType<IHasTooltip>().FirstOrDefault();
|
||||
if (hasTooltip != null)
|
||||
{
|
||||
IHasTooltipWithCustomDelay delayedTooltip = hasTooltip as IHasTooltipWithCustomDelay;
|
||||
disappearingTooltip = hasTooltip as IHasDisappearingTooltip;
|
||||
show = Scheduler.AddDelayed(() => tooltip.TooltipText = hasTooltip.TooltipText, delayedTooltip?.TooltipDelay ?? DEFAULT_APPEAR_DELAY);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public TooltipContainer(CursorContainer cursor)
|
||||
{
|
||||
this.cursor = cursor;
|
||||
AlwaysPresent = true;
|
||||
RelativeSizeAxes = Axes.Both;
|
||||
Add(tooltip = new Tooltip());
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
@ -62,9 +46,9 @@ namespace osu.Game.Graphics.Cursor
|
||||
|
||||
protected override void Update()
|
||||
{
|
||||
if (disappearingTooltip?.Disappear == false)
|
||||
tooltip.TooltipText = disappearingTooltip.TooltipText;
|
||||
else if (disappearingTooltip != null)
|
||||
if (tooltip?.IsPresent == true)
|
||||
tooltip.TooltipText = hasTooltip?.TooltipText;
|
||||
else if (disappearingTooltip?.Disappear == true && show?.Completed == true)
|
||||
{
|
||||
disappearingTooltip = null;
|
||||
tooltip.TooltipText = string.Empty;
|
||||
@ -73,7 +57,23 @@ namespace osu.Game.Graphics.Cursor
|
||||
|
||||
protected override bool OnMouseMove(InputState state)
|
||||
{
|
||||
Position = new Vector2(state.Mouse.Position.X, Math.Min(cursor.ActiveCursor.BoundingBox.Bottom, state.Mouse.Position.Y + cursor.ActiveCursor.DrawHeight));
|
||||
if (((hasTooltip as Drawable)?.Hovering != true && disappearingTooltip?.Disappear != false) || show?.Completed != true)
|
||||
{
|
||||
show?.Cancel();
|
||||
tooltip.TooltipText = string.Empty;
|
||||
hasTooltip = input.HoveredDrawables.OfType<IHasTooltip>().FirstOrDefault();
|
||||
if (hasTooltip != null)
|
||||
{
|
||||
IHasTooltipWithCustomDelay delayedTooltip = hasTooltip as IHasTooltipWithCustomDelay;
|
||||
disappearingTooltip = hasTooltip as IHasDisappearingTooltip;
|
||||
show = Scheduler.AddDelayed(delegate
|
||||
{
|
||||
tooltip.TooltipText = hasTooltip.TooltipText;
|
||||
tooltip.Position = new Vector2(state.Mouse.Position.X, Math.Min(cursor.ActiveCursor.BoundingBox.Bottom, state.Mouse.Position.Y + cursor.ActiveCursor.DrawHeight));
|
||||
}, delayedTooltip?.TooltipDelay ?? DEFAULT_APPEAR_DELAY);
|
||||
}
|
||||
}
|
||||
|
||||
return base.OnMouseMove(state);
|
||||
}
|
||||
|
||||
@ -87,13 +87,15 @@ namespace osu.Game.Graphics.Cursor
|
||||
set
|
||||
{
|
||||
text.Text = value;
|
||||
if (string.IsNullOrEmpty(value))
|
||||
if (string.IsNullOrEmpty(value) && !Hovering)
|
||||
Hide();
|
||||
else
|
||||
Show();
|
||||
}
|
||||
}
|
||||
|
||||
public override bool HandleInput => false;
|
||||
|
||||
public Tooltip()
|
||||
{
|
||||
|
||||
|
Reference in New Issue
Block a user