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

add settings tab to change various font/icon sizing parameters #252

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion ReClass.NET/Controls/MemoryViewControl.Designer.cs

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

8 changes: 7 additions & 1 deletion ReClass.NET/Controls/MemoryViewControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ public SelectedNodeInfo(BaseNode node, RemoteProcess process, MemoryBuffer memor
private HotSpot selectionCaret;
private HotSpot selectionAnchor;

private readonly FontEx font;
public FontEx font;

public int IconScale { get; set; }

public ContextMenuStrip NodeContextMenuStrip { get; set; }

Expand Down Expand Up @@ -86,6 +88,8 @@ public MemoryViewControl()
hotSpotEditBox.Font = font;

memoryPreviewPopUp = new MemoryPreviewPopUp(font);

IconScale = Program.Settings.MemoryViewIconSize;
}

protected override void OnPaint(PaintEventArgs e)
Expand Down Expand Up @@ -137,6 +141,8 @@ protected override void OnPaint(PaintEventArgs e)
MultipleNodesSelected = selectedNodes.Count > 1
};

view.IconProvider.Dimensions = DpiUtil.ScaleIntX(IconScale);

var scrollPosition = AutoScrollPosition;

var drawnSize = args.Node.Draw(
Expand Down
2 changes: 1 addition & 1 deletion ReClass.NET/Controls/ProjectView.Designer.cs

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

2 changes: 1 addition & 1 deletion ReClass.NET/Controls/ProjectView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,8 @@ public ProjectView()

InitializeComponent();

DoubleBuffered = true;

DoubleBuffered = true;
projectTreeView.TreeViewNodeSorter = new NodeSorter();
projectTreeView.ImageList = new ImageList();
projectTreeView.ImageList.Images.Add(Properties.Resources.B16x16_Text_List_Bullets);
Expand Down
2,511 changes: 1,264 additions & 1,247 deletions ReClass.NET/Forms/MainForm.Designer.cs

Large diffs are not rendered by default.

17 changes: 16 additions & 1 deletion ReClass.NET/Forms/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,20 @@ public MainForm()
InitializeComponent();
UpdateWindowTitle();

// This is done here to set the ImageSize value from the stored user settings
// I know it's ugly.
var sz = Program.Settings.ProjectViewIconSize;
projectView.projectTreeView.ImageList = new ImageList();
projectView.projectTreeView.ImageList.ImageSize = new System.Drawing.Size(sz, sz);
projectView.projectTreeView.ImageList.Images.Add(Properties.Resources.B16x16_Text_List_Bullets);
projectView.projectTreeView.ImageList.Images.Add(Properties.Resources.B16x16_Class_Type);
projectView.projectTreeView.ImageList.Images.Add(Properties.Resources.B16x16_Category);
projectView.projectTreeView.ImageList.Images.Add(Properties.Resources.B16x16_Enum_Type);

// Same here.
sz = Program.Settings.ToolStripSize;
toolStrip.ImageScalingSize = new System.Drawing.Size(sz, sz);

mainMenuStrip.Renderer = new CustomToolStripProfessionalRenderer(true, true);
toolStrip.Renderer = new CustomToolStripProfessionalRenderer(true, false);
isLittleEndianToolStripMenuItem.Checked = BitConverter.IsLittleEndian;
Expand Down Expand Up @@ -321,7 +335,8 @@ private void saveAsToolStripMenuItem_Click(object sender, EventArgs e)

private void settingsToolStripMenuItem_Click(object sender, EventArgs e)
{
using var sd = new SettingsForm(Program.Settings, CurrentProject.TypeMapping);
using var sd = new SettingsForm(Program.Settings, CurrentProject.TypeMapping,
memoryViewControl, projectView, toolStrip);

sd.ShowDialog();
}
Expand Down
825 changes: 619 additions & 206 deletions ReClass.NET/Forms/SettingsForm.Designer.cs

Large diffs are not rendered by default.

87 changes: 86 additions & 1 deletion ReClass.NET/Forms/SettingsForm.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Diagnostics.Contracts;
using System.Drawing;
using System.Windows.Forms;
using ReClassNET.Controls;
using ReClassNET.Extensions;
Expand All @@ -14,16 +15,23 @@ public partial class SettingsForm : IconForm
{
private readonly Settings settings;
private readonly CppTypeMapping typeMapping;
public MemoryViewControl memoryViewControl;
public ProjectView projectView;
public ToolStrip toolStrip;

public TabControl SettingsTabControl => settingsTabControl;

public SettingsForm(Settings settings, CppTypeMapping typeMapping)
public SettingsForm(Settings settings, CppTypeMapping typeMapping,
MemoryViewControl memoryViewControl, ProjectView projectView, ToolStrip toolStrip)
{
Contract.Requires(settings != null);
Contract.Requires(typeMapping != null);

this.settings = settings;
this.typeMapping = typeMapping;
this.memoryViewControl = memoryViewControl;
this.projectView = projectView;
this.toolStrip = toolStrip;

InitializeComponent();

Expand Down Expand Up @@ -106,6 +114,11 @@ 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));
SetBinding(memoryViewfontUpDown, nameof(NumericUpDown.Value), settings, nameof(Settings.MemoryViewFont));
SetBinding(memoryViewPadXUpDown, nameof(NumericUpDown.Value), settings, nameof(Settings.MemoryViewFontPadX));
SetBinding(memoryViewPadYUpDown, nameof(NumericUpDown.Value), settings, nameof(Settings.MemoryViewFontPadY));
SetBinding(projectViewFontUpDown, nameof(NumericUpDown.Value), settings, nameof(Settings.ProjectViewFont));
SetBinding(toolStripSizeUpDown, nameof(NumericUpDown.Value), settings, nameof(Settings.ToolStripSize));
}

private void SetColorBindings()
Expand Down Expand Up @@ -153,5 +166,77 @@ private void SetTypeDefinitionBindings()
SetBinding(utf32TextTypeTextBox, nameof(TextBox.Text), typeMapping, nameof(CppTypeMapping.TypeUtf32Text));
SetBinding(functionPtrTypeTextBox, nameof(TextBox.Text), typeMapping, nameof(CppTypeMapping.TypeFunctionPtr));
}

private void fontSizeUpDown_ValueChanged(object sender, EventArgs e)
{
var val = (int)(sender as NumericUpDown).Value;

memoryViewControl.font = new FontEx
{
Font = new Font("Courier New", DpiUtil.ScaleIntX(val), GraphicsUnit.Pixel),
Width = memoryViewControl.font.Width,
Height = memoryViewControl.font.Height
};

// Difference between default icon scale and default font size.
val += 3;

memoryViewControl.hotSpotEditBox.Font = memoryViewControl.font;
memoryViewControl.IconScale = val;
settings.MemoryViewIconSize = memoryViewControl.IconScale;
}

private void paddingXUpDown_ValueChanged(object sender, EventArgs e)
{
var val = (int)(sender as NumericUpDown).Value;

memoryViewControl.font = new FontEx
{
Font = memoryViewControl.font.Font,
Width = DpiUtil.ScaleIntX(val),
Height = memoryViewControl.font.Height
};

memoryViewControl.hotSpotEditBox.Font = memoryViewControl.font;
}

private void paddingYUpDown_ValueChanged(object sender, EventArgs e)
{
var val = (int)(sender as NumericUpDown).Value;

memoryViewControl.font = new FontEx
{
Font = memoryViewControl.font.Font,
Width = memoryViewControl.font.Width,
Height = DpiUtil.ScaleIntY(val)
};

memoryViewControl.hotSpotEditBox.Font = memoryViewControl.font;
}

private void projectViewFontUpDown_ValueChanged(object sender, EventArgs e)
{
var val = (int)(sender as NumericUpDown).Value;

projectView.Font = new System.Drawing.Font("Microsoft Sans Serif", val, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));

// Difference between default icon Size and default font size.
val = val + 8;

projectView.projectTreeView.ImageList = new ImageList();
projectView.projectTreeView.ImageList.ImageSize = new System.Drawing.Size(val, val);
projectView.projectTreeView.ImageList.Images.Add(Properties.Resources.B16x16_Text_List_Bullets);
projectView.projectTreeView.ImageList.Images.Add(Properties.Resources.B16x16_Class_Type);
projectView.projectTreeView.ImageList.Images.Add(Properties.Resources.B16x16_Category);
projectView.projectTreeView.ImageList.Images.Add(Properties.Resources.B16x16_Enum_Type);

settings.ProjectViewIconSize = val;
}

private void toolStripSizeUpDown_ValueChanged(object sender, EventArgs e)
{
var val = (int)(sender as NumericUpDown).Value;
toolStrip.ImageScalingSize = new System.Drawing.Size(val, val);
}
}
}
11 changes: 6 additions & 5 deletions ReClass.NET/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static class Program
{
public static CommandLineArgs CommandLineArgs { get; private set; }

public static Settings Settings { get; private set; }
public static Settings Settings { get; set; }

public static ILogger Logger { get; private set; }

Expand Down Expand Up @@ -51,11 +51,13 @@ static void Main(string[] args)
// ignored
}

Settings = SettingsSerializer.Load();

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

NativeMethods.EnableDebugPrivileges();
Expand All @@ -65,7 +67,6 @@ static void Main(string[] args)

CultureInfo.DefaultThreadCurrentCulture = CultureInfo.InvariantCulture;

Settings = SettingsSerializer.Load();
Logger = new GuiLogger();

if (!NativeMethods.IsUnix() && Settings.RunAsAdmin && !WinUtil.IsAdministrator)
Expand Down
17 changes: 16 additions & 1 deletion ReClass.NET/Settings.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Drawing;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ReClassNET.Util;

namespace ReClassNET
Expand Down Expand Up @@ -76,6 +77,20 @@ public class Settings

public CustomDataMap CustomData { get; } = new CustomDataMap();

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

public int MemoryViewFontPadX { get; set; } = 8;

public int MemoryViewFontPadY { get; set; } = 16;

public int MemoryViewIconSize { get; set; } = 16;

public int ProjectViewFont { get; set; } = 8;

public int ProjectViewIconSize { get; set; } = 16;

public int ToolStripSize { get; set; } = 24;

public Settings Clone() => MemberwiseClone() as Settings;
}
}
2 changes: 1 addition & 1 deletion ReClass.NET/UI/IconProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace ReClassNET.UI
{
public class IconProvider
{
public int Dimensions { get; } = DpiUtil.ScaleIntX(16);
public int Dimensions { get; set; } = DpiUtil.ScaleIntX(Program.Settings.MemoryViewFont);

public Image OpenCloseOpen { get; } = DpiUtil.ScaleImage(Properties.Resources.B16x16_Open_Icon);
public Image OpenCloseClosed { get; } = DpiUtil.ScaleImage(Properties.Resources.B16x16_Closed_Icon);
Expand Down
22 changes: 22 additions & 0 deletions ReClass.NET/Util/SettingsSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ internal sealed class SettingsSerializer
private const string XmlDisplayElement = "Display";
private const string XmlColorsElement = "Colors";
private const string XmlCustomDataElement = "CustomData";
private const string XmlFontElement = "Font";

#region Read Settings

Expand Down Expand Up @@ -74,6 +75,17 @@ public static Settings Load()
{
settings.CustomData.Deserialize(customData);
}
var font = root?.Element(XmlFontElement);
if (font != null)
{
XElementSerializer.TryRead(font, nameof(settings.MemoryViewFont), e => settings.MemoryViewFont = XElementSerializer.ToInt(e));
XElementSerializer.TryRead(font, nameof(settings.MemoryViewFontPadX), e => settings.MemoryViewFontPadX = XElementSerializer.ToInt(e));
XElementSerializer.TryRead(font, nameof(settings.MemoryViewFontPadY), e => settings.MemoryViewFontPadY = XElementSerializer.ToInt(e));
XElementSerializer.TryRead(font, nameof(settings.MemoryViewIconSize), e => settings.MemoryViewIconSize = XElementSerializer.ToInt(e));
XElementSerializer.TryRead(font, nameof(settings.ProjectViewFont), e => settings.ProjectViewFont = XElementSerializer.ToInt(e));
XElementSerializer.TryRead(font, nameof(settings.ProjectViewIconSize), e => settings.ProjectViewIconSize = XElementSerializer.ToInt(e));
XElementSerializer.TryRead(font, nameof(settings.ToolStripSize), e => settings.ToolStripSize = XElementSerializer.ToInt(e));
}
}
catch
{
Expand Down Expand Up @@ -139,6 +151,16 @@ public static void Save(Settings settings)
XElementSerializer.ToXml(nameof(settings.TextColor), settings.TextColor),
XElementSerializer.ToXml(nameof(settings.VTableColor), settings.VTableColor)
),
new XElement(
XmlFontElement,
XElementSerializer.ToXml(nameof(settings.MemoryViewFont), settings.MemoryViewFont),
XElementSerializer.ToXml(nameof(settings.MemoryViewFontPadX), settings.MemoryViewFontPadX),
XElementSerializer.ToXml(nameof(settings.MemoryViewFontPadY), settings.MemoryViewFontPadY),
XElementSerializer.ToXml(nameof(settings.MemoryViewIconSize), settings.MemoryViewIconSize),
XElementSerializer.ToXml(nameof(settings.ProjectViewFont), settings.ProjectViewFont),
XElementSerializer.ToXml(nameof(settings.ProjectViewIconSize), settings.ProjectViewIconSize),
XElementSerializer.ToXml(nameof(settings.ToolStripSize), settings.ToolStripSize)
),
settings.CustomData.Serialize(XmlCustomDataElement)
)
);
Expand Down