Skip to content
Open
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions ReClass.NET/Controls/HotSpotTextBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ public class HotSpotTextBox : TextBox
get => font;
set
{
if (font != value)
{
font = value;
font = value;

if (font?.Font != null)
{
base.Font = font.Font;
}
}
Expand Down
11 changes: 11 additions & 0 deletions ReClass.NET/Controls/MemoryViewControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,17 @@ public MemoryViewControl()
memoryPreviewPopUp = new MemoryPreviewPopUp(font);
}

public void RefreshFont()
{
if (Program.DesignMode)
{
return;
}

hotSpotEditBox.Font = font;
Invalidate();
}

protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
Expand Down
5 changes: 5 additions & 0 deletions ReClass.NET/Forms/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ public MainForm()
pluginManager = new PluginManager(new DefaultPluginHost(this, Program.RemoteProcess, Program.Logger));
}

public void RefreshMemoryViewFont()
{
memoryViewControl.RefreshFont();
}

protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
Expand Down
73 changes: 68 additions & 5 deletions ReClass.NET/Forms/SettingsForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 44 additions & 0 deletions ReClass.NET/Forms/SettingsForm.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using System.Diagnostics.Contracts;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using ReClassNET.Controls;
using ReClassNET.Extensions;
Expand Down Expand Up @@ -106,6 +108,48 @@ private void SetGeneralBindings()
SetBinding(showPluginInfoCheckBox, nameof(CheckBox.Checked), settings, nameof(Settings.ShowCommentPluginInfo));
SetBinding(runAsAdminCheckBox, nameof(CheckBox.Checked), settings, nameof(Settings.RunAsAdmin));
SetBinding(randomizeWindowTitleCheckBox, nameof(CheckBox.Checked), settings, nameof(Settings.RandomizeWindowTitle));

var fontNames = FontFamily.Families
.Where(f => f.IsStyleAvailable(FontStyle.Regular))
.Select(f => f.Name)
.OrderBy(n => n)
.ToArray();
monoSpaceFontComboBox.Items.AddRange(fontNames);
if (!string.IsNullOrEmpty(settings.MonoSpaceFontName) && monoSpaceFontComboBox.Items.Contains(settings.MonoSpaceFontName))
{
monoSpaceFontComboBox.SelectedItem = settings.MonoSpaceFontName;
}
else if (monoSpaceFontComboBox.Items.Contains("Courier New"))
{
monoSpaceFontComboBox.SelectedItem = "Courier New";
}
else if (monoSpaceFontComboBox.Items.Count > 0)
{
monoSpaceFontComboBox.SelectedIndex = 0;
}
if (monoSpaceFontComboBox.SelectedItem is string selectedFont)
{
settings.MonoSpaceFontName = selectedFont;
}
monoSpaceFontComboBox.SelectedIndexChanged += (_, __) =>
{
if (monoSpaceFontComboBox.SelectedItem is string fontName)
{
settings.MonoSpaceFontName = fontName;
Program.UpdateMonoSpaceFont();
}
};

monoSpaceFontSizeNumericUpDown.Value = Math.Min(
monoSpaceFontSizeNumericUpDown.Maximum,
Math.Max(monoSpaceFontSizeNumericUpDown.Minimum, settings.MonoSpaceFontSize)
);
settings.MonoSpaceFontSize = (int)monoSpaceFontSizeNumericUpDown.Value;
monoSpaceFontSizeNumericUpDown.ValueChanged += (_, __) =>
{
settings.MonoSpaceFontSize = (int)monoSpaceFontSizeNumericUpDown.Value;
Program.UpdateMonoSpaceFont();
};
}

private void SetColorBindings()
Expand Down
4 changes: 2 additions & 2 deletions ReClass.NET/Nodes/BaseNumericNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ protected Size DrawNumeric(DrawContext context, int x, int y, Image icon, string
x = AddIcon(context, x, y, icon, HotSpot.NoneId, HotSpotType.None);
x = AddAddressOffset(context, x, y);

x = AddText(context, x, y, context.Settings.TypeColor, HotSpot.NoneId, type) + context.Font.Width;
x = AddText(context, x, y, context.Settings.TypeColor, HotSpot.NoneId, type.PadRight(6)) + context.Font.Width;
if (!IsWrapped)
{
x = AddText(context, x, y, context.Settings.NameColor, HotSpot.NameId, Name) + context.Font.Width;
x = AddText(context, x, y, context.Settings.NameColor, HotSpot.NameId, Name.PadRight(12)) + context.Font.Width;
}
x = AddText(context, x, y, context.Settings.NameColor, HotSpot.NoneId, "=") + context.Font.Width;
x = AddText(context, x, y, context.Settings.ValueColor, 0, value) + context.Font.Width;
Expand Down
51 changes: 44 additions & 7 deletions ReClass.NET/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,6 @@ static void Main(string[] args)
// ignored
}

MonoSpaceFont = new FontEx
{
Font = new Font("Courier New", DpiUtil.ScaleIntX(13), GraphicsUnit.Pixel),
Width = DpiUtil.ScaleIntX(8),
Height = DpiUtil.ScaleIntY(16)
};

NativeMethods.EnableDebugPrivileges();

Application.EnableVisualStyles();
Expand All @@ -68,6 +61,8 @@ static void Main(string[] args)
Settings = SettingsSerializer.Load();
Logger = new GuiLogger();

UpdateMonoSpaceFont();

if (!NativeMethods.IsUnix() && Settings.RunAsAdmin && !WinUtil.IsAdministrator)
{
WinUtil.RunElevated(Process.GetCurrentProcess().MainModule?.FileName, args.Length > 0 ? string.Join(" ", args) : null);
Expand Down Expand Up @@ -99,6 +94,48 @@ static void Main(string[] args)
SettingsSerializer.Save(Settings);
}

/// <summary>Creates or updates the monospace font used by the memory view from <see cref="Settings"/>.</summary>
public static void UpdateMonoSpaceFont()
{
var fontName = string.IsNullOrWhiteSpace(Settings?.MonoSpaceFontName) ? "Courier New" : Settings.MonoSpaceFontName;
var fontSize = Settings?.MonoSpaceFontSize > 0 ? Settings.MonoSpaceFontSize : 13;

Font font;
try
{
font = new Font(fontName, DpiUtil.ScaleIntX(fontSize), GraphicsUnit.Pixel);
}
catch
{
font = new Font(FontFamily.GenericMonospace, DpiUtil.ScaleIntX(fontSize), GraphicsUnit.Pixel);
}

int width;
int height;
using (var bitmap = new Bitmap(1, 1))
using (var g = Graphics.FromImage(bitmap))
{
var charSize = g.MeasureString("X", font, int.MaxValue, StringFormat.GenericTypographic);
width = Math.Max(1, (int)Math.Ceiling(charSize.Width));
height = Math.Max(1, (int)Math.Ceiling(font.GetHeight(g)));
}

var previous = MonoSpaceFont?.Font;

if (MonoSpaceFont == null)
{
MonoSpaceFont = new FontEx();
}

MonoSpaceFont.Font = font;
MonoSpaceFont.Width = width;
MonoSpaceFont.Height = height;

previous?.Dispose();

MainForm?.RefreshMemoryViewFont();
}

/// <summary>Shows the exception in a special form.</summary>
/// <param name="ex">The exception.</param>
public static void ShowException(Exception ex)
Expand Down
4 changes: 4 additions & 0 deletions ReClass.NET/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ public class Settings

public bool HighlightChangedValues { get; set; } = true;

public string MonoSpaceFontName { get; set; } = "Courier New";

public int MonoSpaceFontSize { get; set; } = 13;

public Encoding RawDataEncoding { get; set; } = Encoding.GetEncoding(1252); /* Windows-1252 */

// Comment Drawing Settings
Expand Down
4 changes: 4 additions & 0 deletions ReClass.NET/Util/SettingsSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ public static Settings Load()
XElementSerializer.TryRead(display, nameof(settings.ShowNodeOffset), e => settings.ShowNodeOffset = XElementSerializer.ToBool(e));
XElementSerializer.TryRead(display, nameof(settings.ShowNodeText), e => settings.ShowNodeText = XElementSerializer.ToBool(e));
XElementSerializer.TryRead(display, nameof(settings.HighlightChangedValues), e => settings.HighlightChangedValues = XElementSerializer.ToBool(e));
XElementSerializer.TryRead(display, nameof(settings.MonoSpaceFontName), e => settings.MonoSpaceFontName = XElementSerializer.ToString(e));
XElementSerializer.TryRead(display, nameof(settings.MonoSpaceFontSize), e => settings.MonoSpaceFontSize = XElementSerializer.ToInt(e));
XElementSerializer.TryRead(display, nameof(settings.ShowCommentFloat), e => settings.ShowCommentFloat = XElementSerializer.ToBool(e));
XElementSerializer.TryRead(display, nameof(settings.ShowCommentInteger), e => settings.ShowCommentInteger = XElementSerializer.ToBool(e));
XElementSerializer.TryRead(display, nameof(settings.ShowCommentPointer), e => settings.ShowCommentPointer = XElementSerializer.ToBool(e));
Expand Down Expand Up @@ -115,6 +117,8 @@ public static void Save(Settings settings)
XElementSerializer.ToXml(nameof(settings.ShowNodeOffset), settings.ShowNodeOffset),
XElementSerializer.ToXml(nameof(settings.ShowNodeText), settings.ShowNodeText),
XElementSerializer.ToXml(nameof(settings.HighlightChangedValues), settings.HighlightChangedValues),
XElementSerializer.ToXml(nameof(settings.MonoSpaceFontName), settings.MonoSpaceFontName),
XElementSerializer.ToXml(nameof(settings.MonoSpaceFontSize), settings.MonoSpaceFontSize),
XElementSerializer.ToXml(nameof(settings.ShowCommentFloat), settings.ShowCommentFloat),
XElementSerializer.ToXml(nameof(settings.ShowCommentInteger), settings.ShowCommentInteger),
XElementSerializer.ToXml(nameof(settings.ShowCommentPointer), settings.ShowCommentPointer),
Expand Down