diff --git a/OpenRA.Game/Graphics/SpriteFont.cs b/OpenRA.Game/Graphics/SpriteFont.cs index be36206201..552acebd46 100644 --- a/OpenRA.Game/Graphics/SpriteFont.cs +++ b/OpenRA.Game/Graphics/SpriteFont.cs @@ -112,7 +112,7 @@ namespace OpenRA.Graphics public void DrawTextWithContrast(string text, float2 location, Color fg, Color bgDark, Color bgLight, int offset) { - DrawTextWithContrast(text, location, fg, WidgetUtils.GetContrastColor(fg, bgDark, bgLight), offset); + DrawTextWithContrast(text, location, fg, GetContrastColor(fg, bgDark, bgLight), offset); } public void DrawTextWithShadow(string text, float2 location, Color fg, Color bg, int offset) @@ -125,7 +125,7 @@ namespace OpenRA.Graphics public void DrawTextWithShadow(string text, float2 location, Color fg, Color bgDark, Color bgLight, int offset) { - DrawTextWithShadow(text, location, fg, WidgetUtils.GetContrastColor(fg, bgDark, bgLight), offset); + DrawTextWithShadow(text, location, fg, GetContrastColor(fg, bgDark, bgLight), offset); } public int2 Measure(string text) @@ -185,6 +185,11 @@ namespace OpenRA.Graphics return g; } + static Color GetContrastColor(Color fgColor, Color bgDark, Color bgLight) + { + return fgColor == Color.White || fgColor.GetBrightness() > 0.33 ? bgDark : bgLight; + } + public void Dispose() { font.Dispose(); diff --git a/OpenRA.Mods.Cnc/CncLoadScreen.cs b/OpenRA.Mods.Cnc/CncLoadScreen.cs index c973dd2145..063689821a 100644 --- a/OpenRA.Mods.Cnc/CncLoadScreen.cs +++ b/OpenRA.Mods.Cnc/CncLoadScreen.cs @@ -13,6 +13,7 @@ using System.Collections.Generic; using System.Diagnostics; using OpenRA.Graphics; using OpenRA.Mods.Common.LoadScreens; +using OpenRA.Mods.Common.Widgets; using OpenRA.Primitives; using OpenRA.Widgets; diff --git a/OpenRA.Mods.Common/LoadScreens/LogoStripeLoadScreen.cs b/OpenRA.Mods.Common/LoadScreens/LogoStripeLoadScreen.cs index 421457b80d..f8e6b382a0 100644 --- a/OpenRA.Mods.Common/LoadScreens/LogoStripeLoadScreen.cs +++ b/OpenRA.Mods.Common/LoadScreens/LogoStripeLoadScreen.cs @@ -12,6 +12,7 @@ using System.Collections.Generic; using System.Diagnostics; using OpenRA.Graphics; +using OpenRA.Mods.Common.Widgets; using OpenRA.Primitives; using OpenRA.Widgets; diff --git a/OpenRA.Mods.Common/LoadScreens/ModContentLoadScreen.cs b/OpenRA.Mods.Common/LoadScreens/ModContentLoadScreen.cs index c88d68b2d7..f80eebd0a6 100644 --- a/OpenRA.Mods.Common/LoadScreens/ModContentLoadScreen.cs +++ b/OpenRA.Mods.Common/LoadScreens/ModContentLoadScreen.cs @@ -14,6 +14,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; using OpenRA.Graphics; +using OpenRA.Mods.Common.Widgets; using OpenRA.Primitives; using OpenRA.Widgets; diff --git a/OpenRA.Mods.Common/Scripting/Global/UtilsGlobal.cs b/OpenRA.Mods.Common/Scripting/Global/UtilsGlobal.cs index 167e6f22b4..95ede5609e 100644 --- a/OpenRA.Mods.Common/Scripting/Global/UtilsGlobal.cs +++ b/OpenRA.Mods.Common/Scripting/Global/UtilsGlobal.cs @@ -11,6 +11,7 @@ using System.Linq; using Eluant; +using OpenRA.Mods.Common.Widgets; using OpenRA.Scripting; using OpenRA.Widgets; diff --git a/OpenRA.Game/Widgets/WidgetUtils.cs b/OpenRA.Mods.Common/Widgets/WidgetUtils.cs similarity index 96% rename from OpenRA.Game/Widgets/WidgetUtils.cs rename to OpenRA.Mods.Common/Widgets/WidgetUtils.cs index 2c0dbeac91..08dda8f70e 100644 --- a/OpenRA.Game/Widgets/WidgetUtils.cs +++ b/OpenRA.Mods.Common/Widgets/WidgetUtils.cs @@ -14,7 +14,7 @@ using System.Linq; using OpenRA.Graphics; using OpenRA.Primitives; -namespace OpenRA.Widgets +namespace OpenRA.Mods.Common.Widgets { public static class WidgetUtils { @@ -265,9 +265,16 @@ namespace OpenRA.Widgets return trimmed; } - public static Color GetContrastColor(Color fgColor, Color bgDark, Color bgLight) + public static void TruncateLabelToTooltip(LabelWithTooltipWidget label, string text) { - return fgColor == Color.White || fgColor.GetBrightness() > 0.33 ? bgDark : bgLight; + var truncatedText = TruncateText(text, label.Bounds.Width, Game.Renderer.Fonts[label.Font]); + + label.GetText = () => truncatedText; + + if (text != truncatedText) + label.GetTooltipText = () => text; + else + label.GetTooltipText = null; } }