From a18648dc45437019f04e1e4ebbd685b13b8cc6ad Mon Sep 17 00:00:00 2001 From: feos Date: Sun, 17 Apr 2016 11:47:18 +0300 Subject: [PATCH] GDIRenderer: add a method to create NormalFont using the LOGFONT features. InputRoll: make the font match what fceux uses. padding still works oddly though. --- .../CustomControls/GDIRenderer.cs | 10 ++++++++++ BizHawk.Client.EmuHawk/CustomControls/InputRoll.cs | 13 ++++++------- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/BizHawk.Client.EmuHawk/CustomControls/GDIRenderer.cs b/BizHawk.Client.EmuHawk/CustomControls/GDIRenderer.cs index 7759326ae2..5bbe8445fc 100644 --- a/BizHawk.Client.EmuHawk/CustomControls/GDIRenderer.cs +++ b/BizHawk.Client.EmuHawk/CustomControls/GDIRenderer.cs @@ -142,6 +142,16 @@ namespace BizHawk.Client.EmuHawk.CustomControls TextOut(CurrentHDC, point.X, point.Y, str, str.Length); } + public static IntPtr CreateNormalHFont(Font font, int width) + { + LOGFONT logf = new LOGFONT(); + font.ToLogFont(logf); + logf.lfWidth = width; + logf.lfOutPrecision = (byte)FontPrecision.OUT_TT_ONLY_PRECIS; + var ret = CreateFontIndirect(logf); + return ret; + } + //this returns an IntPtr HFONT because .net's Font class will erase the relevant properties when using its Font.FromLogFont() //note that whether this is rotated clockwise or CCW might affect how you have to position the text (right-aligned sometimes?, up or down by the height of the font?) public static IntPtr CreateRotatedHFont(Font font, bool CW) diff --git a/BizHawk.Client.EmuHawk/CustomControls/InputRoll.cs b/BizHawk.Client.EmuHawk/CustomControls/InputRoll.cs index cb6aedf49a..12f8744bb0 100644 --- a/BizHawk.Client.EmuHawk/CustomControls/InputRoll.cs +++ b/BizHawk.Client.EmuHawk/CustomControls/InputRoll.cs @@ -47,13 +47,12 @@ namespace BizHawk.Client.EmuHawk public bool letKeysModifySelection { get; set; } private IntPtr RotatedFont; - private readonly Font NormalFont; + private readonly IntPtr NormalFont; private Color _foreColor; private Color _backColor; public InputRoll() { - UseCustomBackground = true; GridLines = true; CellWidthPadding = 3; @@ -61,11 +60,11 @@ namespace BizHawk.Client.EmuHawk CurrentCell = null; ScrollMethod = "near"; - NormalFont = new Font("Courier New", 8); // Only support fixed width - + Font CommonFont = new Font("Arial", 8, FontStyle.Bold); + NormalFont = GDIRenderer.CreateNormalHFont(CommonFont, 6); // PrepDrawString doesn't actually set the font, so this is rather useless. // I'm leaving this stuff as-is so it will be a bit easier to fix up with another rendering method. - RotatedFont = GDIRenderer.CreateRotatedHFont(NormalFont, true); + RotatedFont = GDIRenderer.CreateRotatedHFont(CommonFont, true); SetStyle(ControlStyles.AllPaintingInWmPaint, true); SetStyle(ControlStyles.UserPaint, true); @@ -77,7 +76,7 @@ namespace BizHawk.Client.EmuHawk using (var g = CreateGraphics()) using (var LCK = Gdi.LockGraphics(g)) { - _charSize = Gdi.MeasureString("A", NormalFont); // TODO make this a property so changing it updates other values. + _charSize = Gdi.MeasureString("A", CommonFont); // TODO make this a property so changing it updates other values. } UpdateCellSize(); @@ -132,7 +131,7 @@ namespace BizHawk.Client.EmuHawk { Gdi.Dispose(); - NormalFont.Dispose(); + GDIRenderer.DestroyHFont(NormalFont); GDIRenderer.DestroyHFont(RotatedFont); base.Dispose(disposing);