From 625c657531e757b96aded78048c72a212722f139 Mon Sep 17 00:00:00 2001 From: YoshiRulz Date: Fri, 19 Nov 2021 01:59:28 +1000 Subject: [PATCH] Fix Hex Editor font/highlight alignment under Mono --- .../tools/HexEditor/HexEditor.cs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/BizHawk.Client.EmuHawk/tools/HexEditor/HexEditor.cs b/src/BizHawk.Client.EmuHawk/tools/HexEditor/HexEditor.cs index 5b18421966d..9551ceba514 100644 --- a/src/BizHawk.Client.EmuHawk/tools/HexEditor/HexEditor.cs +++ b/src/BizHawk.Client.EmuHawk/tools/HexEditor/HexEditor.cs @@ -118,7 +118,9 @@ public HexEditor() RecentTables = new RecentFiles(8); DataSize = 1; - var font = new Font("Courier New", 8); + Font font = OSTailoredCode.IsUnixHost + ? new("Liberation Mono", 9) + : new("Courier New", 8); // Measure the font. There seems to be some extra horizontal padding on the first // character so we'll see how much the width increases on the second character. @@ -126,6 +128,8 @@ public HexEditor() var fontSize2 = TextRenderer.MeasureText("00", font); _fontWidth = fontSize2.Width - fontSize1.Width; _fontHeight = fontSize1.Height; + const int MAGIC_FIX_NUMBER_H = 4; // don't wanna know + if (OSTailoredCode.IsUnixHost) _fontHeight -= MAGIC_FIX_NUMBER_H; InitializeComponent(); Icon = Resources.PokeIcon; @@ -1049,6 +1053,14 @@ private Point GetAddressCoordinates(long address) var extra = (address % DataSize) * _fontWidth * 2; var xOffset = AddressesLabel.Location.X + _fontWidth / 2 - 2; var yOffset = AddressesLabel.Location.Y; + if (OSTailoredCode.IsUnixHost) + { + // don't wanna know + const int MAGIC_FIX_NUMBER_X = -2; + const int MAGIC_FIX_NUMBER_Y = 2; + xOffset += MAGIC_FIX_NUMBER_X; + yOffset += MAGIC_FIX_NUMBER_Y; + } return new Point( (int)((((address % 16) / DataSize) * (_fontWidth * (DataSize * 2 + 1))) + xOffset + extra), @@ -1066,6 +1078,8 @@ private int GetTextOffset() int start = (16 / DataSize) * _fontWidth * (DataSize * 2 + 1); start += AddressesLabel.Location.X + _fontWidth / 2; start += _fontWidth * 2; + const int MAGIC_FIX_NUMBER_X_ASCII = -3; // don't wanna know + if (OSTailoredCode.IsUnixHost) start += MAGIC_FIX_NUMBER_X_ASCII; return start; }