From ea67b41683ac256327c95764ce07f6bf217a37e6 Mon Sep 17 00:00:00 2001 From: Jorolf Date: Thu, 20 Apr 2017 00:42:40 +0200 Subject: [PATCH] move tooltip outside of the cursor --- .../Tests/TestCaseTooltip.cs | 1 - osu.Game/Graphics/Cursor/MenuCursor.cs | 2 +- osu.Game/Graphics/Cursor/TooltipContainer.cs | 50 ++++++++++--------- osu.Game/OsuGameBase.cs | 5 +- 4 files changed, 30 insertions(+), 28 deletions(-) diff --git a/osu.Desktop.VisualTests/Tests/TestCaseTooltip.cs b/osu.Desktop.VisualTests/Tests/TestCaseTooltip.cs index 7ea36e2ad8..e7615e63bf 100644 --- a/osu.Desktop.VisualTests/Tests/TestCaseTooltip.cs +++ b/osu.Desktop.VisualTests/Tests/TestCaseTooltip.cs @@ -1,7 +1,6 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE -using System; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Testing; diff --git a/osu.Game/Graphics/Cursor/MenuCursor.cs b/osu.Game/Graphics/Cursor/MenuCursor.cs index ceb3296bdf..8d5f95aad5 100644 --- a/osu.Game/Graphics/Cursor/MenuCursor.cs +++ b/osu.Game/Graphics/Cursor/MenuCursor.cs @@ -98,7 +98,7 @@ namespace osu.Game.Graphics.Cursor public Cursor() { - Size = new Vector2(42); + AutoSizeAxes = Axes.Both; } [BackgroundDependencyLoader] diff --git a/osu.Game/Graphics/Cursor/TooltipContainer.cs b/osu.Game/Graphics/Cursor/TooltipContainer.cs index f7221326d4..562f604fca 100644 --- a/osu.Game/Graphics/Cursor/TooltipContainer.cs +++ b/osu.Game/Graphics/Cursor/TooltipContainer.cs @@ -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().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().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() { diff --git a/osu.Game/OsuGameBase.cs b/osu.Game/OsuGameBase.cs index 371699eab3..b42f8591e4 100644 --- a/osu.Game/OsuGameBase.cs +++ b/osu.Game/OsuGameBase.cs @@ -144,9 +144,10 @@ namespace osu.Game AddInternal(ratioContainer = new RatioAdjust { - Children = new[] + Children = new Drawable[] { - Cursor = new MenuCursor { Depth = float.MinValue } + Cursor = new MenuCursor { Depth = float.MinValue }, + new TooltipContainer(Cursor) { Depth = float.MinValue } } }); }