Refactor font code out of LabelWidget
This commit is contained in:
@@ -42,6 +42,9 @@ namespace OpenRA.Graphics
|
|||||||
|
|
||||||
Queue<IVertexBuffer<Vertex>> tempBuffersV = new Queue<IVertexBuffer<Vertex>>();
|
Queue<IVertexBuffer<Vertex>> tempBuffersV = new Queue<IVertexBuffer<Vertex>>();
|
||||||
|
|
||||||
|
public enum FontType { Regular, Bold, Title, Tiny, TinyBold, BigBold }
|
||||||
|
public Dictionary<FontType, SpriteFont> Fonts;
|
||||||
|
|
||||||
public Renderer()
|
public Renderer()
|
||||||
{
|
{
|
||||||
SpriteShader = device.CreateShader("world-shp");
|
SpriteShader = device.CreateShader("world-shp");
|
||||||
@@ -61,6 +64,16 @@ namespace OpenRA.Graphics
|
|||||||
TinyFont = new SpriteFont("FreeSans.ttf", 10);
|
TinyFont = new SpriteFont("FreeSans.ttf", 10);
|
||||||
TinyBoldFont = new SpriteFont("FreeSansBold.ttf", 10);
|
TinyBoldFont = new SpriteFont("FreeSansBold.ttf", 10);
|
||||||
|
|
||||||
|
Fonts = new Dictionary<FontType, SpriteFont>()
|
||||||
|
{
|
||||||
|
{FontType.Regular, RegularFont},
|
||||||
|
{FontType.Bold, BoldFont},
|
||||||
|
{FontType.Title, TitleFont},
|
||||||
|
{FontType.Tiny, TinyFont},
|
||||||
|
{FontType.TinyBold, TinyBoldFont},
|
||||||
|
{FontType.BigBold, BigBoldFont}
|
||||||
|
};
|
||||||
|
|
||||||
for( int i = 0 ; i < TempBufferCount ; i++ )
|
for( int i = 0 ; i < TempBufferCount ; i++ )
|
||||||
tempBuffersV.Enqueue( device.CreateVertexBuffer( TempBufferSize ) );
|
tempBuffersV.Enqueue( device.CreateVertexBuffer( TempBufferSize ) );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,12 +19,11 @@ 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 Renderer.FontType Font = Renderer.FontType.Regular;
|
||||||
public Color Color = Color.White;
|
public Color Color = Color.White;
|
||||||
public bool Bold = false; // Legacy flag. TODO: Remove
|
public bool Bold = false; // Legacy flag. TODO: Remove
|
||||||
public bool Contrast = false;
|
public bool Contrast = false;
|
||||||
@@ -62,29 +61,10 @@ namespace OpenRA.Widgets
|
|||||||
if (bg != null)
|
if (bg != null)
|
||||||
WidgetUtils.DrawPanel(bg, RenderBounds );
|
WidgetUtils.DrawPanel(bg, RenderBounds );
|
||||||
|
|
||||||
if (Font == LabelFont.Regular && Bold)
|
if (Font == Renderer.FontType.Regular && Bold)
|
||||||
Font = LabelFont.Bold;
|
Font = Renderer.FontType.Bold;
|
||||||
|
|
||||||
// TODO: Hardcoded font types are stupid
|
SpriteFont font = Game.Renderer.Fonts[Font];
|
||||||
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;
|
||||||
|
|||||||
Reference in New Issue
Block a user