Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated Hex Editor for High-DPI mode #519

Open
wants to merge 3 commits into
base: 51X
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions Source/Plugins/HexEditor/HexEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ namespace RTCV.Plugins.HexEditor
using RTCV.CorruptCore;
using RTCV.CorruptCore.Extensions;
using NLog;
using System.Runtime.InteropServices;

#pragma warning disable CA2213 //Component designer classes generate their own Dispose method
#pragma warning disable CA2213 //Component designer classes generate their own Dispose method
//Based on the Hex Editor from Bizhawk, available under MIT.
//https://github.com/tasvideos/bizhawk
public partial class HexEditor : Form
Expand Down Expand Up @@ -66,7 +67,7 @@ public HexEditor()
{
DataSize = 1;

var font = new Font("Courier New", 8);
var font = new Font("Courier New", (float)8.5);

// 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.
Expand All @@ -82,6 +83,7 @@ public HexEditor()
AddressesLabel.BackColor = Color.Transparent;
//LoadConfigSettings();
SetHeader();
Header.BackColor = Color.Transparent;
//Closing += (o, e) => SaveConfigSettings();

Header.Font = font;
Expand Down Expand Up @@ -179,6 +181,9 @@ await Task.Run(() => SyncObjectSingleton.FormExecute(() =>
{
AddressesLabel.Text = GenerateMemoryViewString(true);
AddressLabel.Text = GenerateAddressString();
AddressLabel.BringToFront();
AddressesLabel.BringToFront();
Header.Location = new Point(28, 39);
}
catch (Exception e)
{
Expand Down Expand Up @@ -624,6 +629,7 @@ private void UpdateGroupBoxTitle()
{
var addressesString = "0x" + $"{_domain.Size / DataSize:X8}".TrimStart('0');
MemoryViewerBox.Text = $"{AllSpec.VanguardSpec?[VSPEC.NAME] ?? "UNKNOWN"} {_domain} - {addressesString} addresses";
MemoryViewerBox.SendToBack();
}

private void ClearNibbles()
Expand Down Expand Up @@ -742,7 +748,7 @@ private void ResetScrollBar()

private void SetUpScrollBar()
{
_rowsVisible = (MemoryViewerBox.Height - (_fontHeight * 2) - (_fontHeight / 2)) / _fontHeight;
_rowsVisible = (MemoryViewerBox.Height + 15 - (_fontHeight * 2) - (_fontHeight / 2)) / _fontHeight;
var totalRows = (int)((_domain.Size + 15) / 16);

if (totalRows < _rowsVisible)
Expand All @@ -763,7 +769,7 @@ private long GetPointedAddress(int x, int y)

// Scroll value determines the first row
long i = HexScrollBar.Value;
var rowoffset = y / _fontHeight;
var rowoffset = y / (_fontHeight - 2);
i += rowoffset;
var colWidth = (DataSize * 2) + 1;

Expand Down Expand Up @@ -830,12 +836,13 @@ private void ClearHighlighted()

private Point GetAddressCoordinates(long address)
{
var extra = (address % DataSize) * _fontWidth * 2;
var xExtra = (address % DataSize) * _fontWidth * 2;
var yExtra = (address % DataSize);
var xOffset = AddressesLabel.Location.X + (_fontWidth / 2) - 2;
var yOffset = AddressesLabel.Location.Y;
var yOffset = AddressesLabel.Location.Y - 2 - ((address / 16) - HexScrollBar.Value) * 2.1;

return new Point(
(int)((((address % 16) / DataSize) * (_fontWidth * ((DataSize * 2) + 1))) + xOffset + extra),
(int)((((address % 16) / DataSize) * (_fontWidth * ((DataSize * 2) + 1))) + xOffset + xExtra),
(int)((((address / 16) - HexScrollBar.Value) * _fontHeight) + yOffset)
);
}
Expand Down Expand Up @@ -1897,5 +1904,10 @@ private bool IsFrozen(long address)
private void OptionsSubMenu_Click(object sender, EventArgs e)
{
}

private void AddressLabel_Click(object sender, EventArgs e)
{

}
}
}
Loading