From 533b2f9ad778f72ac18f9fa22e245202278d54f7 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sat, 3 Jun 2017 14:29:20 +0000 Subject: [PATCH] Flip tooltips above the cursor at the bottom of the screen. --- OpenRA.Mods.Common/Widgets/TooltipContainerWidget.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/OpenRA.Mods.Common/Widgets/TooltipContainerWidget.cs b/OpenRA.Mods.Common/Widgets/TooltipContainerWidget.cs index b3cbb96614..c76ac2772d 100644 --- a/OpenRA.Mods.Common/Widgets/TooltipContainerWidget.cs +++ b/OpenRA.Mods.Common/Widgets/TooltipContainerWidget.cs @@ -19,7 +19,10 @@ namespace OpenRA.Mods.Common.Widgets public class TooltipContainerWidget : Widget { static readonly Action Nothing = () => { }; + public int2 CursorOffset = new int2(0, 20); + public int BottomEdgeYOffset = -5; + public Action BeforeRender = Nothing; public int TooltipDelay = 5; Widget tooltip; @@ -52,8 +55,13 @@ namespace OpenRA.Mods.Common.Widgets var pos = Viewport.LastMousePos + (CursorProvider.CursorViewportZoomed ? CursorOffset * 2 : CursorOffset); if (tooltip != null) { + // If the tooltip overlaps the right edge of the screen, move it left until it fits if (pos.X + tooltip.Bounds.Right > Game.Renderer.Resolution.Width) pos = pos.WithX(Game.Renderer.Resolution.Width - tooltip.Bounds.Right); + + // If the tooltip overlaps the bottom edge of the screen, switch tooltip above cursor + if (pos.Y + tooltip.Bounds.Bottom > Game.Renderer.Resolution.Height) + pos = pos.WithY(Viewport.LastMousePos.Y + (CursorProvider.CursorViewportZoomed ? 2 : 1) * BottomEdgeYOffset - tooltip.Bounds.Height); } return pos;