Add more courier font sizes instead of upscaling the 16px one (#4210)
* add more courier font sizes instead of upscaling the 16px one * use 25px font instead of 26px * remove now-unused property
|
@ -11,11 +11,11 @@ namespace BizHawk.Bizware.Graphics
|
|||
{
|
||||
public class StringRenderer : IDisposable
|
||||
{
|
||||
public StringRenderer(IGL owner, Stream xml, params Stream[] textures)
|
||||
public StringRenderer(IGL owner, Stream fontInfo, params Stream[] textures)
|
||||
{
|
||||
Owner = owner;
|
||||
FontInfo = new();
|
||||
FontInfo.LoadXml(xml);
|
||||
FontInfo.LoadBinary(fontInfo);
|
||||
|
||||
// load textures
|
||||
for (var i = 0; i < FontInfo.Pages.Length; i++)
|
||||
|
@ -48,10 +48,10 @@ namespace BizHawk.Bizware.Graphics
|
|||
TexturePages = null;
|
||||
}
|
||||
|
||||
public SizeF Measure(string str, float scale)
|
||||
public SizeF Measure(string str)
|
||||
{
|
||||
float x = 0;
|
||||
float y = FontInfo.LineHeight * scale;
|
||||
float y = FontInfo.LineHeight;
|
||||
var ox = x;
|
||||
var len = str.Length;
|
||||
|
||||
|
@ -80,18 +80,18 @@ namespace BizHawk.Bizware.Graphics
|
|||
}
|
||||
|
||||
x = 0;
|
||||
y += FontInfo.LineHeight * scale;
|
||||
y += FontInfo.LineHeight;
|
||||
continue;
|
||||
}
|
||||
|
||||
var bfc = FontInfo[c];
|
||||
x += bfc.XAdvance * scale;
|
||||
x += bfc.XAdvance;
|
||||
}
|
||||
|
||||
return new(Math.Max(x, ox), y);
|
||||
}
|
||||
|
||||
public void RenderString(IGuiRenderer renderer, float x, float y, string str, float scale)
|
||||
public void RenderString(IGuiRenderer renderer, float x, float y, string str)
|
||||
{
|
||||
if (Owner != renderer.Owner)
|
||||
{
|
||||
|
@ -121,19 +121,19 @@ namespace BizHawk.Bizware.Graphics
|
|||
if (c == '\n')
|
||||
{
|
||||
x = ox;
|
||||
y += FontInfo.LineHeight * scale;
|
||||
y += FontInfo.LineHeight;
|
||||
continue;
|
||||
}
|
||||
|
||||
var bfc = FontInfo[c];
|
||||
var tex = TexturePages[bfc.TexturePage];
|
||||
var gx = x + bfc.XOffset * scale;
|
||||
var gy = y + bfc.YOffset * scale;
|
||||
var gx = x + bfc.XOffset;
|
||||
var gy = y + bfc.YOffset;
|
||||
var charTexCoords = CharTexCoords[bfc.Char];
|
||||
renderer.DrawSubrect(tex, gx, gy, bfc.Width * scale, bfc.Height * scale,
|
||||
renderer.DrawSubrect(tex, gx, gy, bfc.Width, bfc.Height,
|
||||
charTexCoords.U0, charTexCoords.V0, charTexCoords.U1, charTexCoords.V1);
|
||||
|
||||
x += bfc.XAdvance * scale;
|
||||
x += bfc.XAdvance;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -73,9 +73,6 @@ namespace BizHawk.Client.Common
|
|||
}
|
||||
|
||||
{
|
||||
using var xml = ReflectionCache.EmbeddedResourceStream("Resources.courier16px.fnt");
|
||||
using var tex = ReflectionCache.EmbeddedResourceStream("Resources.courier16px_0.png");
|
||||
_theOneFont = new(_gl, xml, tex);
|
||||
using var gens = ReflectionCache.EmbeddedResourceStream("Resources.gens.ttf");
|
||||
LoadCustomFont(gens);
|
||||
using var fceux = ReflectionCache.EmbeddedResourceStream("Resources.fceux.ttf");
|
||||
|
@ -152,14 +149,38 @@ namespace BizHawk.Client.Common
|
|||
s?.Dispose();
|
||||
}
|
||||
|
||||
_theOneFont.Dispose();
|
||||
_theOneFont?.Dispose();
|
||||
_renderer.Dispose();
|
||||
}
|
||||
|
||||
// rendering resources:
|
||||
protected readonly IGL _gl;
|
||||
|
||||
private readonly StringRenderer _theOneFont;
|
||||
private float _scale = 1;
|
||||
private StringRenderer _theOneFont;
|
||||
private StringRenderer Font
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_theOneFont is not null) return _theOneFont;
|
||||
|
||||
float scale = GetGraphicsControlDpi() / 96f;
|
||||
int fontSize = scale switch
|
||||
{
|
||||
< 1.25f => 16,
|
||||
< 1.5f => 20,
|
||||
< 2 => 25,
|
||||
_ => 32,
|
||||
};
|
||||
_scale = fontSize / 16f;
|
||||
|
||||
using var fontInfo = ReflectionCache.EmbeddedResourceStream($"Resources.courier{fontSize}px.fnt");
|
||||
using var tex = ReflectionCache.EmbeddedResourceStream($"Resources.courier{fontSize}px_0.png");
|
||||
_theOneFont = new(_gl, fontInfo, tex);
|
||||
|
||||
return _theOneFont;
|
||||
}
|
||||
}
|
||||
|
||||
private readonly IGuiRenderer _renderer;
|
||||
|
||||
|
@ -276,7 +297,7 @@ namespace BizHawk.Client.Common
|
|||
|
||||
var fPresent = new FinalPresentation(chainOutSize);
|
||||
var fInput = new SourceImage(chainInSize);
|
||||
var fOSD = new OSD(includeOSD, OSD, _theOneFont);
|
||||
var fOSD = new OSD(includeOSD, OSD, Font, _scale);
|
||||
|
||||
var chain = new FilterProgram();
|
||||
|
||||
|
@ -815,8 +836,6 @@ namespace BizHawk.Client.Common
|
|||
filterProgram.GuiRenderer = _renderer;
|
||||
filterProgram.GL = _gl;
|
||||
|
||||
filterProgram.ControlDpi = GetGraphicsControlDpi();
|
||||
|
||||
//setup the source image filter
|
||||
var fInput = (SourceImage)filterProgram["input"];
|
||||
fInput.Texture = videoTexture;
|
||||
|
|
|
@ -70,10 +70,6 @@ namespace BizHawk.Client.Common.FilterManager
|
|||
|
||||
public IRenderTarget CurrRenderTarget;
|
||||
|
||||
// DPI / 96.0 indicates the display scaling
|
||||
// this is mainly relevant for OSD
|
||||
public int ControlDpi;
|
||||
|
||||
public IRenderTarget GetTempTarget(int width, int height)
|
||||
{
|
||||
return RenderTargetProvider.Get(new(width, height));
|
||||
|
|
|
@ -586,12 +586,14 @@ namespace BizHawk.Client.Common.Filters
|
|||
private readonly bool _drawOsd;
|
||||
private readonly OSDManager _manager;
|
||||
private readonly StringRenderer _font;
|
||||
private readonly float _scale;
|
||||
|
||||
public OSD(bool drawOsd, OSDManager manager, StringRenderer font)
|
||||
public OSD(bool drawOsd, OSDManager manager, StringRenderer font, float scale)
|
||||
{
|
||||
_drawOsd = drawOsd;
|
||||
_manager = manager;
|
||||
_font = font;
|
||||
_scale = scale;
|
||||
}
|
||||
|
||||
public override void Initialize()
|
||||
|
@ -614,8 +616,7 @@ namespace BizHawk.Client.Common.Filters
|
|||
var size = FindInput().SurfaceFormat.Size;
|
||||
|
||||
FilterProgram.GuiRenderer.Begin(size.Width, size.Height);
|
||||
var scale = FilterProgram.ControlDpi / 96.0F;
|
||||
var blitter = new OSDBlitter(_font, FilterProgram.GuiRenderer, new(0, 0, size.Width, size.Height), scale);
|
||||
var blitter = new OSDBlitter(_font, FilterProgram.GuiRenderer, new(0, 0, size.Width, size.Height), _scale);
|
||||
FilterProgram.GuiRenderer.EnableBlending();
|
||||
_manager.DrawScreenInfo(blitter);
|
||||
_manager.DrawMessages(blitter);
|
||||
|
@ -635,15 +636,15 @@ namespace BizHawk.Client.Common.Filters
|
|||
Scale = scale;
|
||||
}
|
||||
|
||||
public void DrawString(string s, Color color, float x, float y)
|
||||
public void DrawString(string s, Color color, int x, int y)
|
||||
{
|
||||
_renderer.SetModulateColor(color);
|
||||
_font.RenderString(_renderer, x, y, s, Scale);
|
||||
_font.RenderString(_renderer, x, y, s);
|
||||
_renderer.SetModulateColorWhite();
|
||||
}
|
||||
|
||||
public SizeF MeasureString(string s)
|
||||
=> _font.Measure(s, Scale);
|
||||
=> _font.Measure(s);
|
||||
|
||||
public Rectangle ClipBounds { get; }
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ namespace BizHawk.Client.Common
|
|||
/// </summary>
|
||||
public interface IBlitter
|
||||
{
|
||||
void DrawString(string s, Color color, float x, float y);
|
||||
void DrawString(string s, Color color, int x, int y);
|
||||
|
||||
SizeF MeasureString(string s);
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ namespace BizHawk.Client.Common
|
|||
|
||||
|
||||
|
||||
private static PointF GetCoordinates(IBlitter g, MessagePosition position, string message)
|
||||
private static Point GetCoordinates(IBlitter g, MessagePosition position, string message)
|
||||
{
|
||||
var size = g.MeasureString(message);
|
||||
var x = position.Anchor.IsLeft()
|
||||
|
@ -49,7 +49,7 @@ namespace BizHawk.Client.Common
|
|||
? position.Y * g.Scale
|
||||
: g.ClipBounds.Height - position.Y * g.Scale - size.Height;
|
||||
|
||||
return new PointF(x, y);
|
||||
return new Point((int)Math.Round(x), (int)Math.Round(y));
|
||||
}
|
||||
|
||||
private string MakeFrameCounter()
|
||||
|
@ -211,7 +211,7 @@ namespace BizHawk.Client.Common
|
|||
: "";
|
||||
}
|
||||
|
||||
private static void DrawOsdMessage(IBlitter g, string message, Color color, float x, float y)
|
||||
private static void DrawOsdMessage(IBlitter g, string message, Color color, int x, int y)
|
||||
=> g.DrawString(message, color, x, y);
|
||||
|
||||
/// <summary>
|
||||
|
|
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 2.3 KiB |
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 2.4 KiB |
After Width: | Height: | Size: 2.3 KiB |
After Width: | Height: | Size: 2.9 KiB |
After Width: | Height: | Size: 2.3 KiB |
After Width: | Height: | Size: 3.9 KiB |
After Width: | Height: | Size: 2.3 KiB |
After Width: | Height: | Size: 3.8 KiB |