Add a shadow to text drawn in player colors

This commit is contained in:
Oliver Brakmann
2016-08-26 23:37:15 +02:00
parent 1059d5b88d
commit 38c16e4f7a
25 changed files with 140 additions and 5 deletions

View File

@@ -12,6 +12,7 @@
using System;
using System.Drawing;
using OpenRA.Graphics;
using OpenRA.Widgets;
namespace OpenRA.Mods.Common.Graphics
{
@@ -21,17 +22,27 @@ namespace OpenRA.Mods.Common.Graphics
readonly WPos pos;
readonly int zOffset;
readonly Color color;
readonly Color bgDark;
readonly Color bgLight;
readonly string text;
public TextRenderable(SpriteFont font, WPos pos, int zOffset, Color color, string text)
public TextRenderable(SpriteFont font, WPos pos, int zOffset, Color color, Color bgDark, Color bgLight, string text)
{
this.font = font;
this.pos = pos;
this.zOffset = zOffset;
this.color = color;
this.bgDark = bgDark;
this.bgLight = bgLight;
this.text = text;
}
public TextRenderable(SpriteFont font, WPos pos, int zOffset, Color color, string text)
: this(font, pos, zOffset, color,
ChromeMetrics.Get<Color>("TextContrastColorDark"),
ChromeMetrics.Get<Color>("TextContrastColorLight"),
text) { }
public WPos Pos { get { return pos; } }
public PaletteReference Palette { get { return null; } }
public int ZOffset { get { return zOffset; } }
@@ -47,7 +58,7 @@ namespace OpenRA.Mods.Common.Graphics
{
var screenPos = wr.Viewport.Zoom * (wr.ScreenPosition(pos) - wr.Viewport.TopLeft.ToFloat2()) - 0.5f * font.Measure(text).ToFloat2();
var screenPxPos = new float2((float)Math.Round(screenPos.X), (float)Math.Round(screenPos.Y));
font.DrawTextWithContrast(text, screenPxPos, color, Color.Black, 1);
font.DrawTextWithContrast(text, screenPxPos, color, bgDark, bgLight, 1);
}
public void RenderDebugGeometry(WorldRenderer wr)

View File

@@ -21,6 +21,8 @@ namespace OpenRA.Mods.Common.Widgets
{
public readonly int RemoveTime = 0;
public readonly bool UseContrast = false;
public readonly Color BackgroundColorDark = ChromeMetrics.Get<Color>("TextContrastColorDark");
public readonly Color BackgroundColorLight = ChromeMetrics.Get<Color>("TextContrastColorLight");
public string Notification = "";
const int LogLength = 9;
@@ -57,7 +59,7 @@ namespace OpenRA.Mods.Common.Widgets
if (owner != null)
{
font.DrawTextWithContrast(owner, chatpos,
line.Color, Color.Black, UseContrast ? 1 : 0);
line.Color, BackgroundColorDark, BackgroundColorLight, UseContrast ? 1 : 0);
}
font.DrawTextWithContrast(text, chatpos + new int2(inset, 0),

View File

@@ -40,6 +40,8 @@ namespace OpenRA.Mods.Common.Widgets
public bool DisplayFirstYAxisValue = false;
public string LabelFont;
public string AxisFont;
public Color BackgroundColorDark = ChromeMetrics.Get<Color>("TextContrastColorDark");
public Color BackgroundColorLight = ChromeMetrics.Get<Color>("TextContrastColorLight");
public LineGraphWidget()
{
@@ -79,6 +81,8 @@ namespace OpenRA.Mods.Common.Widgets
DisplayFirstYAxisValue = other.DisplayFirstYAxisValue;
LabelFont = other.LabelFont;
AxisFont = other.AxisFont;
BackgroundColorDark = other.BackgroundColorDark;
BackgroundColorLight = other.BackgroundColorLight;
}
public override void Draw()
@@ -131,10 +135,12 @@ namespace OpenRA.Mods.Common.Widgets
}), 1, color);
if (lastPoint != 0f)
tiny.DrawText(GetValueFormat().F(lastPoint), origin + new float2(lastX * xStep, -lastPoint * scale - 2), color);
tiny.DrawTextWithShadow(GetValueFormat().F(lastPoint), origin + new float2(lastX * xStep, -lastPoint * scale - 2),
color, BackgroundColorDark, BackgroundColorLight, 1);
}
tiny.DrawText(key, new float2(rect.Left, rect.Top) + new float2(5, 10 * keyOffset + 3), color);
tiny.DrawTextWithShadow(key, new float2(rect.Left, rect.Top) + new float2(5, 10 * keyOffset + 3),
color, BackgroundColorDark, BackgroundColorLight, 1);
keyOffset++;
}