diff --git a/osu.Desktop.VisualTests/Tests/TestCaseTooltip.cs b/osu.Desktop.VisualTests/Tests/TestCaseTooltip.cs index 30e486d2b1..7ea36e2ad8 100644 --- a/osu.Desktop.VisualTests/Tests/TestCaseTooltip.cs +++ b/osu.Desktop.VisualTests/Tests/TestCaseTooltip.cs @@ -32,8 +32,8 @@ namespace osu.Desktop.VisualTests.Tests Spacing = new Vector2(0,10), Children = new Drawable[] { - new TooltipContainer("Text with some tooltip"), - new TooltipContainer("and another one with a custom delay") + new TooltipTextContainer("Text with some tooltip"), + new TooltipTextContainer("and another one with a custom delay") { TooltipDelay = 1000, }, @@ -57,15 +57,15 @@ namespace osu.Desktop.VisualTests.Tests }); } - private class TooltipContainer : Container, IHasTooltipWithCustomDelay + private class TooltipTextContainer : Container, IHasTooltipWithCustomDelay { private readonly OsuSpriteText text; public string TooltipText => text.Text; - public int TooltipDelay { get; set; } = Tooltip.DEFAULT_APPEAR_DELAY; + public int TooltipDelay { get; set; } = TooltipContainer.DEFAULT_APPEAR_DELAY; - public TooltipContainer(string tooltipText) + public TooltipTextContainer(string tooltipText) { AutoSizeAxes = Axes.Both; Children = new[] diff --git a/osu.Game/Graphics/Cursor/MenuCursor.cs b/osu.Game/Graphics/Cursor/MenuCursor.cs index da89571b36..ceb3296bdf 100644 --- a/osu.Game/Graphics/Cursor/MenuCursor.cs +++ b/osu.Game/Graphics/Cursor/MenuCursor.cs @@ -20,12 +20,6 @@ namespace osu.Game.Graphics.Cursor protected override Drawable CreateCursor() => new Cursor(); private bool dragging; - private readonly Tooltip tooltip; - - public MenuCursor() - { - Add(tooltip = new Tooltip()); - } protected override bool OnMouseMove(InputState state) { @@ -43,9 +37,6 @@ namespace osu.Game.Graphics.Cursor ActiveCursor.RotateTo(degrees, 600, EasingTypes.OutQuint); } - tooltip.Position = new Vector2(state.Mouse.Position.X,Math.Min(ActiveCursor.BoundingBox.Bottom, state.Mouse.Position.Y + ActiveCursor.DrawHeight)); - tooltip.MouseState = state.Mouse; - return base.OnMouseMove(state); } @@ -107,7 +98,7 @@ namespace osu.Game.Graphics.Cursor public Cursor() { - AutoSizeAxes = Axes.Both; + Size = new Vector2(42); } [BackgroundDependencyLoader] diff --git a/osu.Game/Graphics/Cursor/Tooltip.cs b/osu.Game/Graphics/Cursor/Tooltip.cs deleted file mode 100644 index 1efbdf6ba8..0000000000 --- a/osu.Game/Graphics/Cursor/Tooltip.cs +++ /dev/null @@ -1,113 +0,0 @@ -// Copyright (c) 2007-2017 ppy Pty Ltd . -// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE - -using OpenTK.Graphics; -using osu.Framework.Allocation; -using osu.Framework.Extensions.Color4Extensions; -using osu.Framework.Graphics; -using osu.Framework.Graphics.Containers; -using osu.Framework.Graphics.Primitives; -using osu.Framework.Graphics.Sprites; -using osu.Framework.Input; -using osu.Framework.Threading; -using osu.Game.Graphics.Sprites; -using System.Linq; - -namespace osu.Game.Graphics.Cursor -{ - public class Tooltip : Container - { - private readonly Box tooltipBackground; - private readonly OsuSpriteText text; - - private ScheduledDelegate show; - private UserInputManager input; - private IHasDisappearingTooltip disappearingTooltip; - - public const int DEFAULT_APPEAR_DELAY = 250; - - public string TooltipText { - get - { - return text.Text; - } - set - { - text.Text = value; - if (string.IsNullOrEmpty(value)) - Hide(); - else - Show(); - } - } - - public IMouseState MouseState - { - set - { - if (value.Position != value.LastPosition && disappearingTooltip?.Disappear != false) - { - show?.Cancel(); - TooltipText = string.Empty; - IHasTooltip hasTooltip = input.HoveredDrawables.OfType().FirstOrDefault(); - if (hasTooltip != null) - { - IHasTooltipWithCustomDelay delayedTooltip = hasTooltip as IHasTooltipWithCustomDelay; - disappearingTooltip = hasTooltip as IHasDisappearingTooltip; - show = Scheduler.AddDelayed(() => TooltipText = hasTooltip.TooltipText, delayedTooltip?.TooltipDelay ?? DEFAULT_APPEAR_DELAY); - } - } - } - } - - public Tooltip() - { - AlwaysPresent = true; - Children = new[] - { - new Container - { - AutoSizeAxes = Axes.Both, - CornerRadius = 5, - Masking = true, - EdgeEffect = new EdgeEffect - { - Type = EdgeEffectType.Shadow, - Colour = Color4.Black.Opacity(40), - Radius = 5, - }, - Children = new Drawable[] - { - tooltipBackground = new Box - { - RelativeSizeAxes = Axes.Both - }, - text = new OsuSpriteText - { - Padding = new MarginPadding(3), - Font = @"Exo2.0-Regular", - } - } - } - }; - } - - [BackgroundDependencyLoader] - private void load(OsuColour colour, UserInputManager input) - { - this.input = input; - tooltipBackground.Colour = colour.Gray3; - } - - protected override void Update() - { - if (disappearingTooltip?.Disappear == false) - TooltipText = disappearingTooltip.TooltipText; - else if (disappearingTooltip != null) - { - disappearingTooltip = null; - TooltipText = string.Empty; - } - } - } -} diff --git a/osu.Game/Graphics/Cursor/TooltipContainer.cs b/osu.Game/Graphics/Cursor/TooltipContainer.cs new file mode 100644 index 0000000000..f7221326d4 --- /dev/null +++ b/osu.Game/Graphics/Cursor/TooltipContainer.cs @@ -0,0 +1,130 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using OpenTK; +using OpenTK.Graphics; +using osu.Framework.Allocation; +using osu.Framework.Extensions.Color4Extensions; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Cursor; +using osu.Framework.Graphics.Primitives; +using osu.Framework.Graphics.Sprites; +using osu.Framework.Input; +using osu.Framework.Threading; +using osu.Game.Graphics.Sprites; +using System; +using System.Linq; + +namespace osu.Game.Graphics.Cursor +{ + public class TooltipContainer : Container + { + private readonly CursorContainer cursor; + private readonly Tooltip tooltip; + + private ScheduledDelegate show; + private UserInputManager input; + private IHasDisappearingTooltip disappearingTooltip; + + 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; + } + + [BackgroundDependencyLoader] + private void load(OsuColour colour, UserInputManager input) + { + this.input = input; + } + + protected override void Update() + { + if (disappearingTooltip?.Disappear == false) + tooltip.TooltipText = disappearingTooltip.TooltipText; + else if (disappearingTooltip != null) + { + disappearingTooltip = null; + tooltip.TooltipText = string.Empty; + } + } + + 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)); + return base.OnMouseMove(state); + } + + public class Tooltip : Container + { + private readonly Box tooltipBackground; + private readonly OsuSpriteText text; + + public string TooltipText + { + set + { + text.Text = value; + if (string.IsNullOrEmpty(value)) + Hide(); + else + Show(); + } + } + + public Tooltip() + { + + AutoSizeAxes = Axes.Both; + CornerRadius = 5; + Masking = true; + EdgeEffect = new EdgeEffect + { + Type = EdgeEffectType.Shadow, + Colour = Color4.Black.Opacity(40), + Radius = 5, + }; + Children = new Drawable[] + { + tooltipBackground = new Box + { + RelativeSizeAxes = Axes.Both + }, + text = new OsuSpriteText + { + Padding = new MarginPadding(3), + Font = @"Exo2.0-Regular", + } + }; + } + + [BackgroundDependencyLoader] + private void load(OsuColour colour) + { + tooltipBackground.Colour = colour.Gray3; + } + } + } +} diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index 58b484259b..829bc6efbc 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -98,7 +98,7 @@ - +