1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-06-30 02:55:23 +00:00
OpenDiablo2/OpenDiablo2.SDL2/SDL2Font.cs

49 lines
1.1 KiB
C#

using OpenDiablo2.Common.Interfaces;
using OpenDiablo2.Common.Models;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OpenDiablo2.SDL2_
{
internal sealed class SDL2Font : IFont
{
internal readonly MPQFont font;
internal readonly SDL2Sprite sprite;
public Palette CurrentPalette
{
get => sprite.CurrentPalette;
set => sprite.CurrentPalette = value;
}
internal SDL2Font(MPQFont font, IntPtr renderer)
{
this.font = font;
sprite = new SDL2Sprite(font.FontImageSet, renderer);
}
public void Dispose()
{
sprite.Dispose();
}
public Size CalculateSize(string text)
{
int w = 0;
int h = 0;
foreach(byte ch in text)
{
w += font.CharacterMetric[ch].Width;
h = Math.Max(h, font.CharacterMetric[ch].Height);
}
return new Size(w, h);
}
}
}