add contrast surround to timer & chat which are displayed straight over the world

This commit is contained in:
Chris Forbes
2011-01-08 12:10:29 +13:00
parent 303525a5ba
commit db63724aeb
6 changed files with 30 additions and 6 deletions

View File

@@ -69,6 +69,19 @@ namespace OpenRA.Graphics
}
}
public void DrawTextWithContrast(string text, float2 location, Color fg, Color bg, int offset)
{
if (offset > 0)
{
DrawText(text, location + new float2(-offset, 0), bg);
DrawText(text, location + new float2(offset, 0), bg);
DrawText(text, location + new float2(0, -offset), bg);
DrawText(text, location + new float2(0, offset), bg);
}
DrawText(text, location, fg);
}
public int2 Measure(string text)
{
return new int2((int)text.Split( '\n' ).Max( s => s.Sum(a => glyphs[Pair.New(a, Color.White)].Advance)), text.Split('\n').Count()*size);

View File

@@ -18,6 +18,7 @@ namespace OpenRA.Widgets
public class ChatDisplayWidget : Widget
{
public readonly int RemoveTime = 0;
public readonly bool UseContrast = false;
const int logLength = 9;
public string Notification = "";
@@ -52,10 +53,13 @@ namespace OpenRA.Widgets
{
var owner = line.Owner + ":";
inset = Game.Renderer.RegularFont.Measure(owner).X + 10;
Game.Renderer.RegularFont.DrawText(owner, chatpos, line.Color);
Game.Renderer.RegularFont.DrawTextWithContrast(owner, chatpos,
line.Color, Color.Black, UseContrast ? 1 : 0);
}
Game.Renderer.RegularFont.DrawText(line.Text, chatpos + new int2(inset, 0), Color.White);
Game.Renderer.RegularFont.DrawTextWithContrast(line.Text, chatpos + new int2(inset, 0),
Color.White, Color.Black, UseContrast ? 1 : 0);
}
Game.Renderer.DisableScissor();

View File

@@ -25,6 +25,7 @@ namespace OpenRA.Widgets
string content = "";
bool composing = false;
bool teamChat = false;
public readonly bool UseContrast = false;
readonly OrderManager orderManager;
[ObjectCreator.UseCtor]
@@ -40,8 +41,8 @@ namespace OpenRA.Widgets
var text = teamChat ? "Chat (Team): " : "Chat (All): ";
var w = Game.Renderer.BoldFont.Measure(text).X;
Game.Renderer.BoldFont.DrawText(text, RenderOrigin + new float2(3, 7), Color.White);
Game.Renderer.RegularFont.DrawText(content, RenderOrigin + new float2(3 + w, 7), Color.White);
Game.Renderer.BoldFont.DrawTextWithContrast(text, RenderOrigin + new float2(3, 7), Color.White, Color.Black, UseContrast ? 1 : 0);
Game.Renderer.RegularFont.DrawTextWithContrast(content, RenderOrigin + new float2(3 + w, 7), Color.White, Color.Black, UseContrast ? 1 : 0);
}
}

View File

@@ -27,7 +27,9 @@ namespace OpenRA.Widgets
{
var s = WidgetUtils.FormatTime(Game.LocalTick);
var size = Game.Renderer.TitleFont.Measure(s);
Game.Renderer.TitleFont.DrawText(s, new float2(RenderBounds.Left - size.X / 2, RenderBounds.Top - 20), Color.White);
var pos = new float2(RenderBounds.Left - size.X / 2, RenderBounds.Top - 20);
Game.Renderer.TitleFont.DrawTextWithContrast(s, pos, Color.White, Color.Black, 1);
}
}
}

View File

@@ -206,12 +206,14 @@ Container@INGAME_ROOT:
Height: 200
DrawBackground: False
RemoveTime:250
UseContrast: yes
ChatEntry@CHAT_ENTRY:
Id:CHAT_ENTRY
X:250
Y:WINDOW_BOTTOM - HEIGHT
Width: 760
Height: 30
UseContrast: yes
Background@DEVELOPERMODE_BG:
Id:DEVELOPERMODE_BG
Delegate:DeveloperModeDelegate

View File

@@ -213,12 +213,14 @@ Container@INGAME_ROOT:
Height: 200
DrawBackground: False
RemoveTime:250
UseContrast: yes
ChatEntry@CHAT_ENTRY:
Id:CHAT_ENTRY
X:250
Y:WINDOW_BOTTOM - HEIGHT
Width: 760
Height: 30
UseContrast: yes
Background@DEVELOPERMODE_BG:
Id:DEVELOPERMODE_BG
Delegate:DeveloperModeDelegate