text has colour

This commit is contained in:
alzeih
2010-06-13 20:35:50 +12:00
committed by Chris Forbes
parent f0ea329b2c
commit 3001d58ba0
2 changed files with 20 additions and 19 deletions

View File

@@ -21,14 +21,14 @@ namespace OpenRA.Graphics
throw new InvalidOperationException("FT_New_Face failed");
FT.FT_Set_Pixel_Sizes(face, 0, (uint)size);
glyphs = new Cache<char, GlyphInfo>(CreateGlyph);
glyphs = new Cache<Pair<char, Color>, GlyphInfo>(CreateGlyph);
// setup a 1-channel SheetBuilder for our private use
if (builder == null) builder = new SheetBuilder(r, TextureChannel.Alpha);
// precache glyphs for U+0020 - U+007f
for (var n = (char)0x20; n < (char)0x7f; n++)
if (glyphs[n] == null)
if (glyphs[Pair.New(n, Color.White)] == null)
throw new InvalidOperationException();
}
@@ -45,8 +45,8 @@ namespace OpenRA.Graphics
p = location;
continue;
}
var g = glyphs[s];
var g = glyphs[Pair.New(s, c)];
renderer.RgbaSpriteRenderer.DrawSprite(g.Sprite,
new float2(
(int)Math.Round(p.X + g.Offset.X, 0),
@@ -60,15 +60,15 @@ namespace OpenRA.Graphics
public int2 Measure(string text)
{
return new int2((int)text.Split( '\n' ).Max( s => s.Sum(a => glyphs[a].Advance)), text.Split('\n').Count()*size);
return new int2((int)text.Split( '\n' ).Max( s => s.Sum(a => glyphs[Pair.New(a, Color.White)].Advance)), text.Split('\n').Count()*size);
}
Cache<char, GlyphInfo> glyphs;
Cache<Pair<char,Color>, GlyphInfo> glyphs;
IntPtr face;
GlyphInfo CreateGlyph(char c)
GlyphInfo CreateGlyph(Pair<char,Color> c)
{
var index = FT.FT_Get_Char_Index(face, (uint)c);
var index = FT.FT_Get_Char_Index(face, (uint)c.First);
FT.FT_Load_Glyph(face, index, FT.FT_LOAD_RENDER);
var _face = (FT_FaceRec)Marshal.PtrToStructure(face, typeof(FT_FaceRec));
@@ -92,7 +92,7 @@ namespace OpenRA.Graphics
for (var i = 0; i < s.size.X; i++)
if (p[i] != 0)
s.sheet.Bitmap.SetPixel(i + s.bounds.Left, j + s.bounds.Top,
Color.FromArgb(p[i], 0xff, 0xff, 0xff));
Color.FromArgb(p[i], c.Second.R, c.Second.G, c.Second.B));
p += _glyph.bitmap.pitch;
}

View File

@@ -474,19 +474,20 @@ namespace OpenRA.Widgets
if (!canBuildThis) longDescSize += 8;
WidgetUtils.DrawPanel("dialog4", new Rectangle(Game.viewport.Width - 300, pos.Y, 300, longDescSize + 50));
Game.chrome.renderer.BoldFont.DrawText(buildable.Description, p.ToInt2() + new int2(5, 5), Color.White);
DrawRightAligned("${0}".F(buildable.Cost), pos + new int2(-5, 5), Color.White);
if (buildable.Hotkey != null)
DrawRightAligned("{0}".F(buildable.Hotkey.ToUpper()), pos + new int2(-5, 35),Color.White);
Game.chrome.renderer.BoldFont.DrawText(
buildable.Description + ((buildable.Hotkey != null)? " ({0})".F(buildable.Hotkey.ToUpper()) : ""),
p.ToInt2() + new int2(5, 5), Color.White);
DrawRightAligned("${0}".F(buildable.Cost), pos + new int2(-5, 5),
(world.LocalPlayer.PlayerActor.traits.Get<PlayerResources>().DisplayCash >= buildable.Cost)? Color.White: Color.Red);
var bi = info.Traits.GetOrDefault<BuildingInfo>();
var playerres = world.LocalPlayer.PlayerActor.traits.Get<PlayerResources>();
if (bi != null)
DrawRightAligned("{1}{0}".F(bi.Power, bi.Power > 0 ? "+" : ""), pos + new int2(-5, 20), Color.White);
DrawRightAligned("{1}{0}".F(bi.Power, bi.Power > 0 ? "+" : ""), pos + new int2(-5, 20),
((playerres.PowerProvided - playerres.PowerDrained) >= -bi.Power || bi.Power > 0)? Color.White: Color.Red);
p += new int2(5, 20);
if (!canBuildThis)
{