diff --git a/src/BizHawk.Bizware.Graphics/Renderers/StringRenderer.cs b/src/BizHawk.Bizware.Graphics/Renderers/StringRenderer.cs index eb9701c632..aa1cf29428 100644 --- a/src/BizHawk.Bizware.Graphics/Renderers/StringRenderer.cs +++ b/src/BizHawk.Bizware.Graphics/Renderers/StringRenderer.cs @@ -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; } } diff --git a/src/BizHawk.Client.Common/DisplayManager/DisplayManagerBase.cs b/src/BizHawk.Client.Common/DisplayManager/DisplayManagerBase.cs index 01927e2522..1f24ba3e82 100644 --- a/src/BizHawk.Client.Common/DisplayManager/DisplayManagerBase.cs +++ b/src/BizHawk.Client.Common/DisplayManager/DisplayManagerBase.cs @@ -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; diff --git a/src/BizHawk.Client.Common/DisplayManager/FilterManager.cs b/src/BizHawk.Client.Common/DisplayManager/FilterManager.cs index f1e533f095..a358175e18 100644 --- a/src/BizHawk.Client.Common/DisplayManager/FilterManager.cs +++ b/src/BizHawk.Client.Common/DisplayManager/FilterManager.cs @@ -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)); diff --git a/src/BizHawk.Client.Common/DisplayManager/Filters/Gui.cs b/src/BizHawk.Client.Common/DisplayManager/Filters/Gui.cs index 1d7d080218..a9b7cca904 100644 --- a/src/BizHawk.Client.Common/DisplayManager/Filters/Gui.cs +++ b/src/BizHawk.Client.Common/DisplayManager/Filters/Gui.cs @@ -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; } diff --git a/src/BizHawk.Client.Common/DisplayManager/IBlitter.cs b/src/BizHawk.Client.Common/DisplayManager/IBlitter.cs index 5f23f8ce0f..8ae5c6e8ce 100644 --- a/src/BizHawk.Client.Common/DisplayManager/IBlitter.cs +++ b/src/BizHawk.Client.Common/DisplayManager/IBlitter.cs @@ -9,7 +9,7 @@ namespace BizHawk.Client.Common /// 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); diff --git a/src/BizHawk.Client.Common/DisplayManager/OSDManager.cs b/src/BizHawk.Client.Common/DisplayManager/OSDManager.cs index 8ba0bba9c1..580edf6acf 100644 --- a/src/BizHawk.Client.Common/DisplayManager/OSDManager.cs +++ b/src/BizHawk.Client.Common/DisplayManager/OSDManager.cs @@ -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); /// diff --git a/src/BizHawk.Client.Common/Resources/courier16px.fnt b/src/BizHawk.Client.Common/Resources/courier16px.fnt index baa19f91e1..ae3321a195 100644 Binary files a/src/BizHawk.Client.Common/Resources/courier16px.fnt and b/src/BizHawk.Client.Common/Resources/courier16px.fnt differ diff --git a/src/BizHawk.Client.Common/Resources/courier16px_0.png b/src/BizHawk.Client.Common/Resources/courier16px_0.png index 9abf51f69c..a60612705e 100644 Binary files a/src/BizHawk.Client.Common/Resources/courier16px_0.png and b/src/BizHawk.Client.Common/Resources/courier16px_0.png differ diff --git a/src/BizHawk.Client.Common/Resources/courier20px.fnt b/src/BizHawk.Client.Common/Resources/courier20px.fnt new file mode 100644 index 0000000000..03704515d8 Binary files /dev/null and b/src/BizHawk.Client.Common/Resources/courier20px.fnt differ diff --git a/src/BizHawk.Client.Common/Resources/courier20px_0.png b/src/BizHawk.Client.Common/Resources/courier20px_0.png new file mode 100644 index 0000000000..04a3e24b42 Binary files /dev/null and b/src/BizHawk.Client.Common/Resources/courier20px_0.png differ diff --git a/src/BizHawk.Client.Common/Resources/courier25px.fnt b/src/BizHawk.Client.Common/Resources/courier25px.fnt new file mode 100644 index 0000000000..ff5961b16f Binary files /dev/null and b/src/BizHawk.Client.Common/Resources/courier25px.fnt differ diff --git a/src/BizHawk.Client.Common/Resources/courier25px_0.png b/src/BizHawk.Client.Common/Resources/courier25px_0.png new file mode 100644 index 0000000000..226e4512b3 Binary files /dev/null and b/src/BizHawk.Client.Common/Resources/courier25px_0.png differ diff --git a/src/BizHawk.Client.Common/Resources/courier32px.fnt b/src/BizHawk.Client.Common/Resources/courier32px.fnt new file mode 100644 index 0000000000..dc1305925f Binary files /dev/null and b/src/BizHawk.Client.Common/Resources/courier32px.fnt differ diff --git a/src/BizHawk.Client.Common/Resources/courier32px_0.png b/src/BizHawk.Client.Common/Resources/courier32px_0.png new file mode 100644 index 0000000000..44e49adbfd Binary files /dev/null and b/src/BizHawk.Client.Common/Resources/courier32px_0.png differ