text has colour
This commit is contained in:
@@ -21,14 +21,14 @@ namespace OpenRA.Graphics
|
|||||||
throw new InvalidOperationException("FT_New_Face failed");
|
throw new InvalidOperationException("FT_New_Face failed");
|
||||||
|
|
||||||
FT.FT_Set_Pixel_Sizes(face, 0, (uint)size);
|
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
|
// setup a 1-channel SheetBuilder for our private use
|
||||||
if (builder == null) builder = new SheetBuilder(r, TextureChannel.Alpha);
|
if (builder == null) builder = new SheetBuilder(r, TextureChannel.Alpha);
|
||||||
|
|
||||||
// precache glyphs for U+0020 - U+007f
|
// precache glyphs for U+0020 - U+007f
|
||||||
for (var n = (char)0x20; n < (char)0x7f; n++)
|
for (var n = (char)0x20; n < (char)0x7f; n++)
|
||||||
if (glyphs[n] == null)
|
if (glyphs[Pair.New(n, Color.White)] == null)
|
||||||
throw new InvalidOperationException();
|
throw new InvalidOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,8 +45,8 @@ namespace OpenRA.Graphics
|
|||||||
p = location;
|
p = location;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
var g = glyphs[s];
|
var g = glyphs[Pair.New(s, c)];
|
||||||
renderer.RgbaSpriteRenderer.DrawSprite(g.Sprite,
|
renderer.RgbaSpriteRenderer.DrawSprite(g.Sprite,
|
||||||
new float2(
|
new float2(
|
||||||
(int)Math.Round(p.X + g.Offset.X, 0),
|
(int)Math.Round(p.X + g.Offset.X, 0),
|
||||||
@@ -60,15 +60,15 @@ namespace OpenRA.Graphics
|
|||||||
|
|
||||||
public int2 Measure(string text)
|
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;
|
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);
|
FT.FT_Load_Glyph(face, index, FT.FT_LOAD_RENDER);
|
||||||
|
|
||||||
var _face = (FT_FaceRec)Marshal.PtrToStructure(face, typeof(FT_FaceRec));
|
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++)
|
for (var i = 0; i < s.size.X; i++)
|
||||||
if (p[i] != 0)
|
if (p[i] != 0)
|
||||||
s.sheet.Bitmap.SetPixel(i + s.bounds.Left, j + s.bounds.Top,
|
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;
|
p += _glyph.bitmap.pitch;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -474,19 +474,20 @@ namespace OpenRA.Widgets
|
|||||||
if (!canBuildThis) longDescSize += 8;
|
if (!canBuildThis) longDescSize += 8;
|
||||||
|
|
||||||
WidgetUtils.DrawPanel("dialog4", new Rectangle(Game.viewport.Width - 300, pos.Y, 300, longDescSize + 50));
|
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);
|
Game.chrome.renderer.BoldFont.DrawText(
|
||||||
|
buildable.Description + ((buildable.Hotkey != null)? " ({0})".F(buildable.Hotkey.ToUpper()) : ""),
|
||||||
DrawRightAligned("${0}".F(buildable.Cost), pos + new int2(-5, 5), Color.White);
|
p.ToInt2() + new int2(5, 5), Color.White);
|
||||||
|
|
||||||
if (buildable.Hotkey != null)
|
DrawRightAligned("${0}".F(buildable.Cost), pos + new int2(-5, 5),
|
||||||
DrawRightAligned("{0}".F(buildable.Hotkey.ToUpper()), pos + new int2(-5, 35),Color.White);
|
(world.LocalPlayer.PlayerActor.traits.Get<PlayerResources>().DisplayCash >= buildable.Cost)? Color.White: Color.Red);
|
||||||
|
|
||||||
var bi = info.Traits.GetOrDefault<BuildingInfo>();
|
var bi = info.Traits.GetOrDefault<BuildingInfo>();
|
||||||
|
var playerres = world.LocalPlayer.PlayerActor.traits.Get<PlayerResources>();
|
||||||
if (bi != null)
|
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);
|
p += new int2(5, 20);
|
||||||
if (!canBuildThis)
|
if (!canBuildThis)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user