Inject platform dependency in SpriteFont.

This avoids needing to access the global Game.Renderer.
This commit is contained in:
RoosterDragon
2024-04-05 18:45:59 +01:00
committed by Gustas
parent 377bb4b6cc
commit 2c96f6ec8b
3 changed files with 26 additions and 25 deletions

View File

@@ -27,7 +27,7 @@ namespace OpenRA.Graphics
float deviceScale;
public SpriteFont(string name, byte[] data, int size, int ascender, float scale, SheetBuilder builder)
public SpriteFont(IPlatform platform, string name, byte[] data, int size, int ascender, float scale, SheetBuilder builder)
{
if (builder.Type != SheetType.BGRA)
throw new ArgumentException("The sheet builder must create BGRA sheets.", nameof(builder));
@@ -36,7 +36,7 @@ namespace OpenRA.Graphics
this.size = size;
this.builder = builder;
font = Game.Renderer.CreateFont(data);
font = platform.CreateFont(data);
glyphs = new Cache<char, GlyphInfo>(CreateGlyph);
contrastGlyphs = new Cache<(char, int), Sprite>(CreateContrastGlyph);
dilationElements = new Cache<int, float[]>(CreateCircularWeightMap);