Add a Shadow option to LabelWidget and ButtonWidget

This commit is contained in:
Oliver Brakmann
2016-08-26 22:18:46 +02:00
parent 8ad18ad161
commit 1059d5b88d
9 changed files with 60 additions and 17 deletions

View File

@@ -27,17 +27,21 @@ namespace OpenRA.Mods.Common.Widgets
public string Font = ChromeMetrics.Get<string>("TextFont");
public Color TextColor = ChromeMetrics.Get<Color>("TextColor");
public bool Contrast = ChromeMetrics.Get<bool>("TextContrast");
public Color ContrastColor = ChromeMetrics.Get<Color>("TextContrastColorDark");
public bool Shadow = ChromeMetrics.Get<bool>("TextShadow");
public Color ContrastColorDark = ChromeMetrics.Get<Color>("TextContrastColorDark");
public Color ContrastColorLight = ChromeMetrics.Get<Color>("TextContrastColorLight");
public bool WordWrap = false;
public Func<string> GetText;
public Func<Color> GetColor;
public Func<Color> GetContrastColor;
public Func<Color> GetContrastColorDark;
public Func<Color> GetContrastColorLight;
public LabelWidget()
{
GetText = () => Text;
GetColor = () => TextColor;
GetContrastColor = () => ContrastColor;
GetContrastColorDark = () => ContrastColorDark;
GetContrastColorLight = () => ContrastColorLight;
}
protected LabelWidget(LabelWidget other)
@@ -48,11 +52,14 @@ namespace OpenRA.Mods.Common.Widgets
Font = other.Font;
TextColor = other.TextColor;
Contrast = other.Contrast;
ContrastColor = other.ContrastColor;
ContrastColorDark = other.ContrastColorDark;
ContrastColorLight = other.ContrastColorLight;
Shadow = other.Shadow;
WordWrap = other.WordWrap;
GetText = other.GetText;
GetColor = other.GetColor;
GetContrastColor = other.GetContrastColor;
GetContrastColorDark = other.GetContrastColorDark;
GetContrastColorLight = other.GetContrastColorLight;
}
public override void Draw()
@@ -84,9 +91,12 @@ namespace OpenRA.Mods.Common.Widgets
text = WidgetUtils.WrapText(text, Bounds.Width, font);
var color = GetColor();
var contrast = GetContrastColor();
var bgDark = GetContrastColorDark();
var bgLight = GetContrastColorLight();
if (Contrast)
font.DrawTextWithContrast(text, position, color, contrast, 2);
font.DrawTextWithContrast(text, position, color, bgDark, bgLight, 2);
else if (Shadow)
font.DrawTextWithShadow(text, position, color, bgDark, bgLight, 1);
else
font.DrawText(text, position, color);
}