diff --git a/OpenRA.Game/Graphics/SpriteFont.cs b/OpenRA.Game/Graphics/SpriteFont.cs index ccc3a5f9e6..cb492d5755 100644 --- a/OpenRA.Game/Graphics/SpriteFont.cs +++ b/OpenRA.Game/Graphics/SpriteFont.cs @@ -99,6 +99,19 @@ namespace OpenRA.Graphics DrawTextWithContrast(text, location, fg, WidgetUtils.GetContrastColor(fg, bgDark, bgLight), offset); } + public void DrawTextWithShadow(string text, float2 location, Color fg, Color bg, int offset) + { + if (offset != 0) + DrawText(text, location + new float2(offset, offset), bg); + + DrawText(text, location, fg); + } + + 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); + } + public int2 Measure(string text) { if (string.IsNullOrEmpty(text)) diff --git a/OpenRA.Mods.Common/Widgets/ButtonWidget.cs b/OpenRA.Mods.Common/Widgets/ButtonWidget.cs index c3dbd36b51..140d947449 100644 --- a/OpenRA.Mods.Common/Widgets/ButtonWidget.cs +++ b/OpenRA.Mods.Common/Widgets/ButtonWidget.cs @@ -36,13 +36,16 @@ namespace OpenRA.Mods.Common.Widgets public Color TextColor = ChromeMetrics.Get("ButtonTextColor"); public Color TextColorDisabled = ChromeMetrics.Get("ButtonTextColorDisabled"); public bool Contrast = ChromeMetrics.Get("ButtonTextContrast"); - public Color ContrastColor = ChromeMetrics.Get("ButtonTextContrastColorDark"); + public bool Shadow = ChromeMetrics.Get("ButtonTextShadow"); + public Color ContrastColorDark = ChromeMetrics.Get("ButtonTextContrastColorDark"); + public Color ContrastColorLight = ChromeMetrics.Get("ButtonTextContrastColorLight"); public bool Disabled = false; public bool Highlighted = false; public Func GetText; public Func GetColor; public Func GetColorDisabled; - public Func GetContrastColor; + public Func GetContrastColorDark; + public Func GetContrastColorLight; public Func IsDisabled; public Func IsHighlighted; public Action 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); diff --git a/OpenRA.Mods.Common/Widgets/CheckboxWidget.cs b/OpenRA.Mods.Common/Widgets/CheckboxWidget.cs index 7d1261097d..67f4802f1c 100644 --- a/OpenRA.Mods.Common/Widgets/CheckboxWidget.cs +++ b/OpenRA.Mods.Common/Widgets/CheckboxWidget.cs @@ -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); diff --git a/OpenRA.Mods.Common/Widgets/LabelWidget.cs b/OpenRA.Mods.Common/Widgets/LabelWidget.cs index 27e1e80e73..d842b516a9 100644 --- a/OpenRA.Mods.Common/Widgets/LabelWidget.cs +++ b/OpenRA.Mods.Common/Widgets/LabelWidget.cs @@ -27,17 +27,21 @@ namespace OpenRA.Mods.Common.Widgets public string Font = ChromeMetrics.Get("TextFont"); public Color TextColor = ChromeMetrics.Get("TextColor"); public bool Contrast = ChromeMetrics.Get("TextContrast"); - public Color ContrastColor = ChromeMetrics.Get("TextContrastColorDark"); + public bool Shadow = ChromeMetrics.Get("TextShadow"); + public Color ContrastColorDark = ChromeMetrics.Get("TextContrastColorDark"); + public Color ContrastColorLight = ChromeMetrics.Get("TextContrastColorLight"); public bool WordWrap = false; public Func GetText; public Func GetColor; - public Func GetContrastColor; + public Func GetContrastColorDark; + public Func 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); } diff --git a/mods/cnc/metrics.yaml b/mods/cnc/metrics.yaml index 1d10f5eb78..6a8fa357da 100644 --- a/mods/cnc/metrics.yaml +++ b/mods/cnc/metrics.yaml @@ -6,6 +6,7 @@ Metrics: ButtonTextColor: FFFFFF ButtonTextColorDisabled: 808080 ButtonTextContrast: false + ButtonTextShadow: false ButtonTextContrastColorDark: 000000 ButtonTextContrastColorLight: 7F7F7F ButtonBaseLine: 0 @@ -20,6 +21,7 @@ Metrics: TextFont: Regular TextColor: FFFFFF TextContrast: false + TextShadow: false TextContrastColorDark: 000000 TextContrastColorLight: 7F7F7F ColorPickerRemapIndices: 176, 178, 180, 182, 184, 186, 189, 191, 177, 179, 181, 183, 185, 187, 188, 190 diff --git a/mods/d2k/metrics.yaml b/mods/d2k/metrics.yaml index 3f91d3bd12..4df566c1c4 100644 --- a/mods/d2k/metrics.yaml +++ b/mods/d2k/metrics.yaml @@ -5,6 +5,7 @@ Metrics: ButtonTextColor: FFFFFF ButtonTextColorDisabled: 808080 ButtonTextContrast: false + ButtonTextShadow: false ButtonTextContrastColorDark: 000000 ButtonTextContrastColorLight: 7F7F7F ButtonBaseLine: 0 @@ -19,6 +20,7 @@ Metrics: TextFont: Regular TextColor: FFFFFF TextContrast: false + TextShadow: false TextContrastColorDark: 000000 TextContrastColorLight: 7F7F7F ColorPickerRemapIndices: 255, 254, 253, 252, 251, 250, 249, 248, 247, 246, 245, 244, 243, 242, 241, 240 diff --git a/mods/modchooser/metrics.yaml b/mods/modchooser/metrics.yaml index 4e71fb732e..d5cd4dc133 100644 --- a/mods/modchooser/metrics.yaml +++ b/mods/modchooser/metrics.yaml @@ -6,6 +6,7 @@ Metrics: ButtonTextColor: FFFFFF ButtonTextColorDisabled: 808080 ButtonTextContrast: false + ButtonTextShadow: false ButtonTextContrastColorDark: 000000 ButtonTextContrastColorLight: 7F7F7F ButtonBaseLine: 2 @@ -20,6 +21,7 @@ Metrics: TextFont: Regular TextColor: FFFFFF TextContrast: false + TextShadow: false TextContrastColorDark: 000000 TextContrastColorLight: 7F7F7F ColorPickerRemapIndices: 176, 178, 180, 182, 184, 186, 189, 191, 177, 179, 181, 183, 185, 187, 188, 190 diff --git a/mods/ra/metrics.yaml b/mods/ra/metrics.yaml index 5e29223461..7e67598172 100644 --- a/mods/ra/metrics.yaml +++ b/mods/ra/metrics.yaml @@ -6,6 +6,7 @@ Metrics: ButtonTextColor: FFFFFF ButtonTextColorDisabled: 808080 ButtonTextContrast: false + ButtonTextShadow: false ButtonTextContrastColorDark: 000000 ButtonTextContrastColorLight: 7F7F7F ButtonBaseLine: 0 @@ -20,6 +21,7 @@ Metrics: TextFont: Regular TextColor: FFFFFF TextContrast: false + TextShadow: false TextContrastColorDark: 000000 TextContrastColorLight: 7F7F7F ColorPickerRemapIndices: 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95 diff --git a/mods/ts/metrics.yaml b/mods/ts/metrics.yaml index 7072ac1913..6a243757e0 100644 --- a/mods/ts/metrics.yaml +++ b/mods/ts/metrics.yaml @@ -5,6 +5,7 @@ Metrics: ButtonTextColor: FFFFFF ButtonTextColorDisabled: 808080 ButtonTextContrast: false + ButtonTextShadow: false ButtonTextContrastColorDark: 000000 ButtonTextContrastColorLight: 7F7F7F ButtonBaseLine: 0 @@ -19,6 +20,7 @@ Metrics: TextFont: Regular TextColor: FFFFFF TextContrast: false + TextShadow: false TextContrastColorDark: 000000 TextContrastColorLight: 7F7F7F ColorPickerRemapIndices: 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31