Skip to content

Commit

Permalink
Fix Hex Editor font/highlight alignment under Mono
Browse files Browse the repository at this point in the history
  • Loading branch information
YoshiRulz committed Nov 18, 2021
1 parent b1b06cc commit 625c657
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/BizHawk.Client.EmuHawk/tools/HexEditor/HexEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,18 @@ 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.
var fontSize1 = TextRenderer.MeasureText("0", font);
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;
Expand Down Expand Up @@ -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),
Expand All @@ -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;
}

Expand Down

0 comments on commit 625c657

Please sign in to comment.