2018-11-22 16:22:39 -05:00
|
|
|
|
using OpenDiablo2.Common.Interfaces;
|
|
|
|
|
using OpenDiablo2.Common.Models;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2018-11-23 20:51:32 -05:00
|
|
|
|
using System.Drawing;
|
2018-11-22 16:22:39 -05:00
|
|
|
|
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();
|
|
|
|
|
}
|
2018-11-23 20:51:32 -05:00
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
2018-11-22 16:22:39 -05:00
|
|
|
|
}
|
|
|
|
|
}
|