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

@@ -99,6 +99,19 @@ namespace OpenRA.Graphics
DrawTextWithContrast(text, location, fg, WidgetUtils.GetContrastColor(fg, bgDark, bgLight), offset); 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) public int2 Measure(string text)
{ {
if (string.IsNullOrEmpty(text)) if (string.IsNullOrEmpty(text))

View File

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

View File

@@ -48,7 +48,8 @@ namespace OpenRA.Mods.Common.Widgets
var font = Game.Renderer.Fonts[Font]; var font = Game.Renderer.Fonts[Font];
var color = GetColor(); var color = GetColor();
var colordisabled = GetColorDisabled(); var colordisabled = GetColorDisabled();
var contrast = GetContrastColor(); var bgDark = GetContrastColorDark();
var bgLight = GetContrastColorLight();
var rect = RenderBounds; var rect = RenderBounds;
var text = GetText(); var text = GetText();
var textSize = font.Measure(text); var textSize = font.Measure(text);
@@ -64,7 +65,7 @@ namespace OpenRA.Mods.Common.Widgets
if (Contrast) if (Contrast)
font.DrawTextWithContrast(text, position, font.DrawTextWithContrast(text, position,
disabled ? colordisabled : color, contrast, 2); disabled ? colordisabled : color, bgDark, bgLight, 2);
else else
font.DrawText(text, position, font.DrawText(text, position,
disabled ? colordisabled : color); disabled ? colordisabled : color);

View File

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

View File

@@ -6,6 +6,7 @@ Metrics:
ButtonTextColor: FFFFFF ButtonTextColor: FFFFFF
ButtonTextColorDisabled: 808080 ButtonTextColorDisabled: 808080
ButtonTextContrast: false ButtonTextContrast: false
ButtonTextShadow: false
ButtonTextContrastColorDark: 000000 ButtonTextContrastColorDark: 000000
ButtonTextContrastColorLight: 7F7F7F ButtonTextContrastColorLight: 7F7F7F
ButtonBaseLine: 0 ButtonBaseLine: 0
@@ -20,6 +21,7 @@ Metrics:
TextFont: Regular TextFont: Regular
TextColor: FFFFFF TextColor: FFFFFF
TextContrast: false TextContrast: false
TextShadow: false
TextContrastColorDark: 000000 TextContrastColorDark: 000000
TextContrastColorLight: 7F7F7F TextContrastColorLight: 7F7F7F
ColorPickerRemapIndices: 176, 178, 180, 182, 184, 186, 189, 191, 177, 179, 181, 183, 185, 187, 188, 190 ColorPickerRemapIndices: 176, 178, 180, 182, 184, 186, 189, 191, 177, 179, 181, 183, 185, 187, 188, 190

View File

@@ -5,6 +5,7 @@ Metrics:
ButtonTextColor: FFFFFF ButtonTextColor: FFFFFF
ButtonTextColorDisabled: 808080 ButtonTextColorDisabled: 808080
ButtonTextContrast: false ButtonTextContrast: false
ButtonTextShadow: false
ButtonTextContrastColorDark: 000000 ButtonTextContrastColorDark: 000000
ButtonTextContrastColorLight: 7F7F7F ButtonTextContrastColorLight: 7F7F7F
ButtonBaseLine: 0 ButtonBaseLine: 0
@@ -19,6 +20,7 @@ Metrics:
TextFont: Regular TextFont: Regular
TextColor: FFFFFF TextColor: FFFFFF
TextContrast: false TextContrast: false
TextShadow: false
TextContrastColorDark: 000000 TextContrastColorDark: 000000
TextContrastColorLight: 7F7F7F TextContrastColorLight: 7F7F7F
ColorPickerRemapIndices: 255, 254, 253, 252, 251, 250, 249, 248, 247, 246, 245, 244, 243, 242, 241, 240 ColorPickerRemapIndices: 255, 254, 253, 252, 251, 250, 249, 248, 247, 246, 245, 244, 243, 242, 241, 240

View File

@@ -6,6 +6,7 @@ Metrics:
ButtonTextColor: FFFFFF ButtonTextColor: FFFFFF
ButtonTextColorDisabled: 808080 ButtonTextColorDisabled: 808080
ButtonTextContrast: false ButtonTextContrast: false
ButtonTextShadow: false
ButtonTextContrastColorDark: 000000 ButtonTextContrastColorDark: 000000
ButtonTextContrastColorLight: 7F7F7F ButtonTextContrastColorLight: 7F7F7F
ButtonBaseLine: 2 ButtonBaseLine: 2
@@ -20,6 +21,7 @@ Metrics:
TextFont: Regular TextFont: Regular
TextColor: FFFFFF TextColor: FFFFFF
TextContrast: false TextContrast: false
TextShadow: false
TextContrastColorDark: 000000 TextContrastColorDark: 000000
TextContrastColorLight: 7F7F7F TextContrastColorLight: 7F7F7F
ColorPickerRemapIndices: 176, 178, 180, 182, 184, 186, 189, 191, 177, 179, 181, 183, 185, 187, 188, 190 ColorPickerRemapIndices: 176, 178, 180, 182, 184, 186, 189, 191, 177, 179, 181, 183, 185, 187, 188, 190

View File

@@ -6,6 +6,7 @@ Metrics:
ButtonTextColor: FFFFFF ButtonTextColor: FFFFFF
ButtonTextColorDisabled: 808080 ButtonTextColorDisabled: 808080
ButtonTextContrast: false ButtonTextContrast: false
ButtonTextShadow: false
ButtonTextContrastColorDark: 000000 ButtonTextContrastColorDark: 000000
ButtonTextContrastColorLight: 7F7F7F ButtonTextContrastColorLight: 7F7F7F
ButtonBaseLine: 0 ButtonBaseLine: 0
@@ -20,6 +21,7 @@ Metrics:
TextFont: Regular TextFont: Regular
TextColor: FFFFFF TextColor: FFFFFF
TextContrast: false TextContrast: false
TextShadow: false
TextContrastColorDark: 000000 TextContrastColorDark: 000000
TextContrastColorLight: 7F7F7F TextContrastColorLight: 7F7F7F
ColorPickerRemapIndices: 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95 ColorPickerRemapIndices: 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95

View File

@@ -5,6 +5,7 @@ Metrics:
ButtonTextColor: FFFFFF ButtonTextColor: FFFFFF
ButtonTextColorDisabled: 808080 ButtonTextColorDisabled: 808080
ButtonTextContrast: false ButtonTextContrast: false
ButtonTextShadow: false
ButtonTextContrastColorDark: 000000 ButtonTextContrastColorDark: 000000
ButtonTextContrastColorLight: 7F7F7F ButtonTextContrastColorLight: 7F7F7F
ButtonBaseLine: 0 ButtonBaseLine: 0
@@ -19,6 +20,7 @@ Metrics:
TextFont: Regular TextFont: Regular
TextColor: FFFFFF TextColor: FFFFFF
TextContrast: false TextContrast: false
TextShadow: false
TextContrastColorDark: 000000 TextContrastColorDark: 000000
TextContrastColorLight: 7F7F7F TextContrastColorLight: 7F7F7F
ColorPickerRemapIndices: 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31 ColorPickerRemapIndices: 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31