forked from jeff-1amstudios/OpenC1
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFontRenderer.cs
72 lines (64 loc) · 2.31 KB
/
FontRenderer.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using OneAmEngine;
using Microsoft.Xna.Framework;
using OpenC1.Gfx;
using OpenC1.Parsers;
namespace OpenC1
{
enum Fonts
{
Blue,
Text,
Timer,
White,
Gears,
Speedo
}
class FontRenderer
{
static SpriteFont _default;
static bool _useDefaultFont;
static PixMapFont[] _fonts;
static FontRenderer()
{
_default = GameEngine.ContentManager.Load<SpriteFont>("content\\fonts\\Arial_14");
PixMapFont font = new PixMapFont("BLUEHEAD");
if (font.Exists)
{
_fonts = new PixMapFont[6];
_fonts[0] = font;
_fonts[1] = new PixMapFont("MEDIUMHD");
_fonts[2] = new PixMapFont("TIMER");
_fonts[3] = new PixMapFont("NEWHITE");
_fonts[4] = new PixMapFont("GEARS", new FontDescriptionFile() { Height = 16, FirstChar=0 });
_fonts[5] = new PixMapFont("SPEEDO0", new FontDescriptionFile() { Height = 16, FirstChar = 48 });
}
else
_useDefaultFont = true;
}
public static void Render(Fonts font, string text, Vector2 position, Color color)
{
if (_useDefaultFont)
GameEngine.SpriteBatch.DrawString(_default, text, position, Color.Black);
else
_fonts[(int)font].DrawString(text, position, color, 1);
}
public static void Render(Fonts font, string text, Vector2 position, Color color, float scale)
{
if (_useDefaultFont)
GameEngine.SpriteBatch.DrawString(_default, text, position, Color.Black, 0, Vector2.Zero, scale, SpriteEffects.None, 0);
else
_fonts[(int)font].DrawString(text, position, color, scale);
}
public static void RenderGear(int gear, Vector2 position, Color color, float scale)
{
if (_useDefaultFont)
GameEngine.SpriteBatch.DrawString(_default, gear.ToString(), position, color, 0, Vector2.Zero, scale, SpriteEffects.None, 0);
else
_fonts[(int)Fonts.Gears].DrawChar(gear, position, color, scale);
}
}
}