Allow Labels to use any defined font. Add a new font type.

This commit is contained in:
Paul Chote
2011-05-06 19:21:53 +12:00
parent 4ad4c4dfb0
commit 890136d447
2 changed files with 28 additions and 3 deletions

View File

@@ -35,7 +35,7 @@ namespace OpenRA.Graphics
public ITexture PaletteTexture; public ITexture PaletteTexture;
public readonly SpriteFont RegularFont, BoldFont, TitleFont, TinyFont, TinyBoldFont; public readonly SpriteFont RegularFont, BoldFont, TitleFont, TinyFont, TinyBoldFont, BigBoldFont;
internal const int TempBufferSize = 8192; internal const int TempBufferSize = 8192;
const int TempBufferCount = 8; const int TempBufferCount = 8;
@@ -57,6 +57,7 @@ namespace OpenRA.Graphics
RegularFont = new SpriteFont("FreeSans.ttf", 14); RegularFont = new SpriteFont("FreeSans.ttf", 14);
BoldFont = new SpriteFont("FreeSansBold.ttf", 14); BoldFont = new SpriteFont("FreeSansBold.ttf", 14);
TitleFont = new SpriteFont("titles.ttf", 48); TitleFont = new SpriteFont("titles.ttf", 48);
BigBoldFont = new SpriteFont("FreeSansBold.ttf", 24);
TinyFont = new SpriteFont("FreeSans.ttf", 10); TinyFont = new SpriteFont("FreeSans.ttf", 10);
TinyBoldFont = new SpriteFont("FreeSansBold.ttf", 10); TinyBoldFont = new SpriteFont("FreeSansBold.ttf", 10);

View File

@@ -19,11 +19,13 @@ namespace OpenRA.Widgets
{ {
public enum TextAlign { Left, Center, Right } public enum TextAlign { Left, Center, Right }
public enum TextVAlign { Top, Middle, Bottom } public enum TextVAlign { Top, Middle, Bottom }
public enum LabelFont { Regular, Bold, Title, Tiny, TinyBold, BigBold }
public string Text = null; public string Text = null;
public string Background = null; public string Background = null;
public TextAlign Align = TextAlign.Left; public TextAlign Align = TextAlign.Left;
public TextVAlign VAlign = TextVAlign.Middle; public TextVAlign VAlign = TextVAlign.Middle;
public LabelFont Font = LabelFont.Regular;
public bool Bold = false; public bool Bold = false;
public bool Contrast = false; public bool Contrast = false;
public bool WordWrap = false; public bool WordWrap = false;
@@ -55,7 +57,29 @@ namespace OpenRA.Widgets
if (bg != null) if (bg != null)
WidgetUtils.DrawPanel(bg, RenderBounds ); WidgetUtils.DrawPanel(bg, RenderBounds );
var font = (Bold) ? Game.Renderer.BoldFont : Game.Renderer.RegularFont; if (Font == LabelFont.Regular && Bold)
Font = LabelFont.Bold;
// TODO: Hardcoded font types are stupid
SpriteFont font = Game.Renderer.RegularFont;
switch (Font)
{
case LabelFont.Bold:
font = Game.Renderer.BoldFont;
break;
case LabelFont.Tiny:
font = Game.Renderer.TinyFont;
break;
case LabelFont.TinyBold:
font = Game.Renderer.TinyBoldFont;
break;
case LabelFont.Title:
font = Game.Renderer.TitleFont;
break;
case LabelFont.BigBold:
font = Game.Renderer.BigBoldFont;
break;
}
var text = GetText(); var text = GetText();
if (text == null) if (text == null)
return; return;