Skip to content

Commit

Permalink
Support drawing fonts without culture involved.
Browse files Browse the repository at this point in the history
  • Loading branch information
isadorasophia committed Jan 14, 2025
1 parent 45bf454 commit 4ab928e
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/Murder/Core/Graphics/DrawInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ public readonly struct DrawInfo

public Rectangle Clip { get; init; } = Rectangle.Empty;

/// <summary>
/// Whether this should bypass localization fonts.
/// </summary>
public bool CultureInvariant { get; init; } = false;

public DrawInfo()
{
}
Expand Down
4 changes: 2 additions & 2 deletions src/Murder/Data/GameDataManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -866,9 +866,9 @@ public ImmutableDictionary<Guid, GameAsset> FilterOutAssets(params Type[] types)
return builder.ToImmutableDictionary();
}

public PixelFont GetFont(int index)
public PixelFont GetFont(int index, bool cultureInvariant = false)
{
if (_game is not null)
if (_game is not null && !cultureInvariant)
{
index = _game.GetLocalizedFont(index);
}
Expand Down
6 changes: 6 additions & 0 deletions src/Murder/Services/MurderFonts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,10 @@ public static float GetLineWidth(this MurderFonts font, string text)
{
return GetLineWidth((int)font, text);
}

public static int GetFontHeight(this MurderFonts font)
{
PixelFont f = Game.Data.GetFont((int)font);
return f.LineHeight;
}
}
3 changes: 2 additions & 1 deletion src/Murder/Services/RenderServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -987,9 +987,10 @@ public static Point DrawText(this Batch2D uiBatch, MurderFonts font, string text
=> DrawText(uiBatch, (int)font, text, position, maxWidth, -1, drawInfo ?? DrawInfo.Default);
public static Point DrawText(this Batch2D uiBatch, MurderFonts font, string text, Vector2 position, int maxWidth, int visibleCharacters, DrawInfo? drawInfo = default)
=> DrawText(uiBatch, (int)font, text, position, maxWidth, visibleCharacters, drawInfo ?? DrawInfo.Default);

public static Point DrawText(this Batch2D uiBatch, int pixelFont, string text, Vector2 position, int maxWidth, int visibleCharacters, DrawInfo drawInfo)
{
var font = Game.Data.GetFont(pixelFont);
var font = Game.Data.GetFont(pixelFont, cultureInvariant: drawInfo.CultureInvariant);
return font.Draw(uiBatch, text, position + drawInfo.Offset, drawInfo.Origin, drawInfo.Scale, drawInfo.Sort, drawInfo.Color, drawInfo.Outline, drawInfo.Shadow, maxWidth, visibleCharacters, drawInfo.Debug);
}

Expand Down

0 comments on commit 4ab928e

Please sign in to comment.