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

@@ -36,13 +36,16 @@ namespace OpenRA.Mods.Common.Widgets
public Color TextColor = ChromeMetrics.Get<Color>("ButtonTextColor");
public Color TextColorDisabled = ChromeMetrics.Get<Color>("ButtonTextColorDisabled");
public bool Contrast = ChromeMetrics.Get<bool>("ButtonTextContrast");
public Color ContrastColor = ChromeMetrics.Get<Color>("ButtonTextContrastColorDark");
public bool Shadow = ChromeMetrics.Get<bool>("ButtonTextShadow");
public Color ContrastColorDark = ChromeMetrics.Get<Color>("ButtonTextContrastColorDark");
public Color ContrastColorLight = ChromeMetrics.Get<Color>("ButtonTextContrastColorLight");
public bool Disabled = false;
public bool Highlighted = false;
public Func<string> GetText;
public Func<Color> GetColor;
public Func<Color> GetColorDisabled;
public Func<Color> GetContrastColor;
public Func<Color> GetContrastColorDark;
public Func<Color> GetContrastColorLight;
public Func<bool> IsDisabled;
public Func<bool> IsHighlighted;
public Action<MouseInput> OnMouseDown = _ => { };
@@ -67,7 +70,8 @@ namespace OpenRA.Mods.Common.Widgets
GetText = () => Text;
GetColor = () => TextColor;
GetColorDisabled = () => TextColorDisabled;
GetContrastColor = () => ContrastColor;
GetContrastColorDark = () => ContrastColorDark;
GetContrastColorLight = () => ContrastColorLight;
OnMouseUp = _ => OnClick();
OnKeyPress = _ => OnClick();
IsDisabled = () => Disabled;
@@ -88,14 +92,17 @@ namespace OpenRA.Mods.Common.Widgets
TextColor = other.TextColor;
TextColorDisabled = other.TextColorDisabled;
Contrast = other.Contrast;
ContrastColor = other.ContrastColor;
Shadow = other.Shadow;
Depressed = other.Depressed;
Background = other.Background;
VisualHeight = other.VisualHeight;
GetText = other.GetText;
GetColor = other.GetColor;
GetColorDisabled = other.GetColorDisabled;
GetContrastColor = other.GetContrastColor;
ContrastColorDark = other.ContrastColorDark;
ContrastColorLight = other.ContrastColorLight;
GetContrastColorDark = other.GetContrastColorDark;
GetContrastColorLight = other.GetContrastColorLight;
OnMouseDown = other.OnMouseDown;
Disabled = other.Disabled;
IsDisabled = other.IsDisabled;
@@ -213,12 +220,12 @@ namespace OpenRA.Mods.Common.Widgets
var rb = RenderBounds;
var disabled = IsDisabled();
var highlighted = IsHighlighted();
var font = Game.Renderer.Fonts[Font];
var text = GetText();
var color = GetColor();
var colordisabled = GetColorDisabled();
var contrast = GetContrastColor();
var bgDark = GetContrastColorDark();
var bgLight = GetContrastColorLight();
var s = font.Measure(text);
var stateOffset = Depressed ? new int2(VisualHeight, VisualHeight) : new int2(0, 0);
var position = new int2(rb.X + (UsableWidth - s.X) / 2, rb.Y - BaseLine + (Bounds.Height - s.Y) / 2);
@@ -226,7 +233,9 @@ namespace OpenRA.Mods.Common.Widgets
DrawBackground(rb, disabled, Depressed, Ui.MouseOverWidget == this, highlighted);
if (Contrast)
font.DrawTextWithContrast(text, position + stateOffset,
disabled ? colordisabled : color, contrast, 2);
disabled ? colordisabled : color, bgDark, bgLight, 2);
else if (Shadow)
font.DrawTextWithShadow(text, position, color, bgDark, bgLight, 1);
else
font.DrawText(text, position + stateOffset,
disabled ? colordisabled : color);