Add a Shadow option to LabelWidget and ButtonWidget
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -48,7 +48,8 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
var font = Game.Renderer.Fonts[Font];
|
||||
var color = GetColor();
|
||||
var colordisabled = GetColorDisabled();
|
||||
var contrast = GetContrastColor();
|
||||
var bgDark = GetContrastColorDark();
|
||||
var bgLight = GetContrastColorLight();
|
||||
var rect = RenderBounds;
|
||||
var text = GetText();
|
||||
var textSize = font.Measure(text);
|
||||
@@ -64,7 +65,7 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
|
||||
if (Contrast)
|
||||
font.DrawTextWithContrast(text, position,
|
||||
disabled ? colordisabled : color, contrast, 2);
|
||||
disabled ? colordisabled : color, bgDark, bgLight, 2);
|
||||
else
|
||||
font.DrawText(text, position,
|
||||
disabled ? colordisabled : color);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user