Add TruncateLabelWithTooltip helper function
* Move GetContrastColor helper to SpriteFont * Move WidgetUtils from OpenRA.Game.Widgets to OpenRA.Mods.Common.Widgets
This commit is contained in:
committed by
abcdefg30
parent
79d1899426
commit
1fee50be2e
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
|
||||
using System.Linq;
|
||||
using Eluant;
|
||||
using OpenRA.Mods.Common.Widgets;
|
||||
using OpenRA.Scripting;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user