Skip to content

Added IconProvider #173

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

Merged
merged 1 commit into from
Oct 10, 2020
Merged
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
3 changes: 3 additions & 0 deletions ReClass.NET/Controls/DrawContextRequestEventArgs.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using ReClassNET.Memory;
using ReClassNET.Nodes;
using ReClassNET.UI;

namespace ReClassNET.Controls
{
Expand All @@ -10,6 +11,8 @@ public class DrawContextRequestEventArgs : EventArgs

public Settings Settings { get; set; }

public IconProvider IconProvider { get; set; }

public RemoteProcess Process { get; set; }

public MemoryBuffer Memory { get; set; }
Expand Down
1 change: 1 addition & 0 deletions ReClass.NET/Controls/MemoryViewControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ protected override void OnPaint(PaintEventArgs e)
Settings = args.Settings,
Context = e.Graphics,
Font = font,
IconProvider = args.IconProvider,
Process = args.Process,
Memory = args.Memory,
CurrentTime = args.CurrentTime,
Expand Down
2 changes: 2 additions & 0 deletions ReClass.NET/Controls/ViewInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class ViewInfo

public Graphics Context { get; set; }
public FontEx Font { get; set; }
public IconProvider IconProvider { get; set; }

public RemoteProcess Process { get; set; }
public MemoryBuffer Memory { get; set; }
Expand All @@ -31,6 +32,7 @@ public ViewInfo Clone()
Settings = Settings,
Context = Context,
Font = Font,
IconProvider = IconProvider,
Process = Process,
Memory = Memory,
CurrentTime = CurrentTime,
Expand Down
2 changes: 2 additions & 0 deletions ReClass.NET/Forms/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ namespace ReClassNET.Forms
public partial class MainForm : IconForm
{
private readonly PluginManager pluginManager;
private readonly IconProvider iconProvider = new IconProvider();

private ReClassNetProject currentProject;
public ReClassNetProject CurrentProject => currentProject;
Expand Down Expand Up @@ -1011,6 +1012,7 @@ private void memoryViewControl_DrawContextRequested(object sender, DrawContextRe
memoryViewBuffer.UpdateFrom(process, address);

args.Settings = Program.Settings;
args.IconProvider = iconProvider;
args.Process = process;
args.Memory = memoryViewBuffer;
args.Node = classNode;
Expand Down
4 changes: 2 additions & 2 deletions ReClass.NET/Nodes/BaseFunctionPtrNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ protected Size Draw(ViewInfo view, int x, int y, string type, string name)

AddSelection(view, x, y, view.Font.Height);

x += TextPadding;
x = AddIconPadding(view, x);

x = AddIcon(view, x, y, Icons.Function, HotSpot.NoneId, HotSpotType.None);
x = AddIcon(view, x, y, view.IconProvider.Function, HotSpot.NoneId, HotSpotType.None);

var tx = x;

Expand Down
4 changes: 3 additions & 1 deletion ReClass.NET/Nodes/BaseHexNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ protected Size Draw(ViewInfo view, int x, int y, string text, int length)

AddSelection(view, x, y, view.Font.Height);

x += TextPadding + 16;
x = AddIconPadding(view, x);
x = AddIconPadding(view, x);

x = AddAddressOffset(view, x, y);

if (!string.IsNullOrEmpty(text))
Expand Down
8 changes: 4 additions & 4 deletions ReClass.NET/Nodes/BaseMatrixNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ protected Size DrawMatrixType(ViewInfo view, int x, int y, string type, DrawMatr

AddSelection(view, x, y, view.Font.Height);

x += TextPadding;
x = AddIconPadding(view, x);

x = AddIcon(view, x, y, Icons.Matrix, HotSpot.NoneId, HotSpotType.None);
x = AddIcon(view, x, y, view.IconProvider.Matrix, HotSpot.NoneId, HotSpotType.None);

var tx = x;

Expand Down Expand Up @@ -83,9 +83,9 @@ protected Size DrawVectorType(ViewInfo view, int x, int y, string type, DrawVect

AddSelection(view, x, y, view.Font.Height);

x += TextPadding;
x = AddIconPadding(view, x);

x = AddIcon(view, x, y, Icons.Vector, HotSpot.NoneId, HotSpotType.None);
x = AddIcon(view, x, y, view.IconProvider.Vector, HotSpot.NoneId, HotSpotType.None);
x = AddAddressOffset(view, x, y);

x = AddText(view, x, y, view.Settings.TypeColor, HotSpot.NoneId, type) + view.Font.Width;
Expand Down
33 changes: 20 additions & 13 deletions ReClass.NET/Nodes/BaseNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ public abstract class BaseNode

internal static readonly List<INodeInfoReader> NodeInfoReader = new List<INodeInfoReader>();

protected static readonly int TextPadding = Icons.Dimensions;
protected static readonly int HiddenHeight = 0;

private static int nodeIndex = 0;
Expand Down Expand Up @@ -383,6 +382,11 @@ protected void AddSelection(ViewInfo view, int x, int y, int height)
AddHotSpot(view, new Rectangle(0, y, view.ClientArea.Right - (IsSelected ? 16 : 0), height), string.Empty, HotSpot.NoneId, HotSpotType.Select);
}

protected int AddIconPadding(ViewInfo view, int x)
{
return x + view.IconProvider.Dimensions;
}

/// <summary>Draws an icon and adds a <see cref="HotSpot"/> if <paramref name="id"/> is not <see cref="HotSpot.NoneId"/>.</summary>
/// <param name="view">The view information.</param>
/// <param name="x">The x coordinate.</param>
Expand All @@ -397,19 +401,21 @@ protected int AddIcon(ViewInfo view, int x, int y, Image icon, int id, HotSpotTy
Contract.Requires(view.Context != null);
Contract.Requires(icon != null);

if (y > view.ClientArea.Bottom || y + Icons.Dimensions < 0)
var size = view.IconProvider.Dimensions;

if (y > view.ClientArea.Bottom || y + size < 0)
{
return x + Icons.Dimensions;
return x + size;
}

view.Context.DrawImage(icon, x + 2, y, Icons.Dimensions, Icons.Dimensions);
view.Context.DrawImage(icon, x + 2, y, size, size);

if (id != HotSpot.NoneId)
{
AddHotSpot(view, new Rectangle(x, y, Icons.Dimensions, Icons.Dimensions), string.Empty, id, type);
AddHotSpot(view, new Rectangle(x, y, size, size), string.Empty, id, type);
}

return x + Icons.Dimensions;
return x + size;
}

/// <summary>Adds a togglable Open/Close icon.</summary>
Expand All @@ -422,12 +428,13 @@ protected int AddOpenCloseIcon(ViewInfo view, int x, int y)
Contract.Requires(view != null);
Contract.Requires(view.Context != null);

if (y > view.ClientArea.Bottom || y + Icons.Dimensions < 0)
if (y > view.ClientArea.Bottom || y + view.IconProvider.Dimensions < 0)
{
return x + Icons.Dimensions;
return x + view.IconProvider.Dimensions;
}

return AddIcon(view, x, y, LevelsOpen[view.Level] ? Icons.OpenCloseOpen : Icons.OpenCloseClosed, 0, HotSpotType.OpenClose);
var icon = LevelsOpen[view.Level] ? view.IconProvider.OpenCloseOpen : view.IconProvider.OpenCloseClosed;
return AddIcon(view, x, y, icon, 0, HotSpotType.OpenClose);
}

/// <summary>Draws a context drop icon if the node is selected.</summary>
Expand All @@ -438,14 +445,14 @@ protected void AddContextDropDownIcon(ViewInfo view, int y)
Contract.Requires(view != null);
Contract.Requires(view.Context != null);

if (view.MultipleNodesSelected || y > view.ClientArea.Bottom || y + Icons.Dimensions < 0 || IsWrapped)
if (view.MultipleNodesSelected || y > view.ClientArea.Bottom || y + view.IconProvider.Dimensions < 0 || IsWrapped)
{
return;
}

if (IsSelected)
{
AddIcon(view, 0, y, Icons.DropArrow, 0, HotSpotType.Context);
AddIcon(view, 0, y, view.IconProvider.DropArrow, 0, HotSpotType.Context);
}
}

Expand All @@ -457,14 +464,14 @@ protected void AddDeleteIcon(ViewInfo view, int y)
Contract.Requires(view != null);
Contract.Requires(view.Context != null);

if (y > view.ClientArea.Bottom || y + Icons.Dimensions < 0 || IsWrapped)
if (y > view.ClientArea.Bottom || y + view.IconProvider.Dimensions < 0 || IsWrapped)
{
return;
}

if (IsSelected)
{
AddIcon(view, view.ClientArea.Right - Icons.Dimensions, y, Icons.Delete, 0, HotSpotType.Delete);
AddIcon(view, view.ClientArea.Right - view.IconProvider.Dimensions, y, view.IconProvider.Delete, 0, HotSpotType.Delete);
}
}

Expand Down
2 changes: 1 addition & 1 deletion ReClass.NET/Nodes/BaseNumericNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ protected Size DrawNumeric(ViewInfo view, int x, int y, Image icon, string type,

AddSelection(view, x, y, view.Font.Height);

x += TextPadding;
x = AddIconPadding(view, x);

x = AddIcon(view, x, y, icon, HotSpot.NoneId, HotSpotType.None);
x = AddAddressOffset(view, x, y);
Expand Down
5 changes: 3 additions & 2 deletions ReClass.NET/Nodes/BaseTextNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ protected Size DrawText(ViewInfo view, int x, int y, string type)

AddSelection(view, x, y, view.Font.Height);

x += TextPadding;
x = AddIcon(view, x, y, Icons.Text, HotSpot.NoneId, HotSpotType.None);
x = AddIconPadding(view, x);

x = AddIcon(view, x, y, view.IconProvider.Text, HotSpot.NoneId, HotSpotType.None);
x = AddAddressOffset(view, x, y);

x = AddText(view, x, y, view.Settings.TypeColor, HotSpot.NoneId, type) + view.Font.Width;
Expand Down
5 changes: 3 additions & 2 deletions ReClass.NET/Nodes/BaseTextPtrNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ public Size DrawText(ViewInfo view, int x, int y, string type)

AddSelection(view, x, y, view.Font.Height);

x += TextPadding;
x = AddIcon(view, x, y, Icons.Text, HotSpot.NoneId, HotSpotType.None);
x = AddIconPadding(view, x);

x = AddIcon(view, x, y, view.IconProvider.Text, HotSpot.NoneId, HotSpotType.None);
x = AddAddressOffset(view, x, y);

x = AddText(view, x, y, view.Settings.TypeColor, HotSpot.NoneId, type) + view.Font.Width;
Expand Down
8 changes: 4 additions & 4 deletions ReClass.NET/Nodes/BaseWrapperArrayNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ protected Size Draw(ViewInfo view, int x, int y, string type)
AddSelection(view, x, y, view.Font.Height);

x = AddOpenCloseIcon(view, x, y);
x = AddIcon(view, x, y, Icons.Array, HotSpot.NoneId, HotSpotType.None);
x = AddIcon(view, x, y, view.IconProvider.Array, HotSpot.NoneId, HotSpotType.None);

var tx = x;
x = AddAddressOffset(view, x, y);
Expand All @@ -54,14 +54,14 @@ protected Size Draw(ViewInfo view, int x, int y, string type)
x = AddText(view, x, y, view.Settings.IndexColor, IsReadOnly ? HotSpot.NoneId : 0, Count.ToString());
x = AddText(view, x, y, view.Settings.IndexColor, HotSpot.NoneId, "]");

x = AddIcon(view, x, y, Icons.LeftArrow, 2, HotSpotType.Click);
x = AddIcon(view, x, y, view.IconProvider.LeftArrow, 2, HotSpotType.Click);
x = AddText(view, x, y, view.Settings.IndexColor, HotSpot.NoneId, "(");
x = AddText(view, x, y, view.Settings.IndexColor, 1, CurrentIndex.ToString());
x = AddText(view, x, y, view.Settings.IndexColor, HotSpot.NoneId, ")");
x = AddIcon(view, x, y, Icons.RightArrow, 3, HotSpotType.Click) + view.Font.Width;
x = AddIcon(view, x, y, view.IconProvider.RightArrow, 3, HotSpotType.Click) + view.Font.Width;

x = AddText(view, x, y, view.Settings.ValueColor, HotSpot.NoneId, $"<Size={MemorySize}>") + view.Font.Width;
x = AddIcon(view, x + 2, y, Icons.Change, 4, HotSpotType.ChangeWrappedType);
x = AddIcon(view, x + 2, y, view.IconProvider.Change, 4, HotSpotType.ChangeWrappedType);

x += view.Font.Width;
x = AddComment(view, x, y);
Expand Down
3 changes: 2 additions & 1 deletion ReClass.NET/Nodes/BitFieldNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ public override Size Draw(ViewInfo view, int x, int y)

AddSelection(view, x, y, view.Font.Height);

x += TextPadding + Icons.Dimensions;
x = AddIconPadding(view, x);
x = AddIconPadding(view, x);

x = AddAddressOffset(view, x, y);

Expand Down
3 changes: 2 additions & 1 deletion ReClass.NET/Nodes/BoolNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ public override Size Draw(ViewInfo view, int x, int y)

AddSelection(view, x, y, view.Font.Height);

x += TextPadding + Icons.Dimensions;
x = AddIconPadding(view, x);
x = AddIconPadding(view, x);

x = AddAddressOffset(view, x, y);

Expand Down
4 changes: 2 additions & 2 deletions ReClass.NET/Nodes/ClassInstanceNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public override Size Draw(ViewInfo view, int x, int y)
AddSelection(view, x, y, view.Font.Height);

x = AddOpenCloseIcon(view, x, y);
x = AddIcon(view, x, y, Icons.Class, HotSpot.NoneId, HotSpotType.None);
x = AddIcon(view, x, y, view.IconProvider.Class, HotSpot.NoneId, HotSpotType.None);

var tx = x;
x = AddAddressOffset(view, x, y);
Expand All @@ -41,7 +41,7 @@ public override Size Draw(ViewInfo view, int x, int y)
x = AddText(view, x, y, view.Settings.NameColor, HotSpot.NameId, Name) + view.Font.Width;
}
x = AddText(view, x, y, view.Settings.ValueColor, HotSpot.NoneId, $"<{InnerNode.Name}>") + view.Font.Width;
x = AddIcon(view, x, y, Icons.Change, 4, HotSpotType.ChangeClassType) + view.Font.Width;
x = AddIcon(view, x, y, view.IconProvider.Change, 4, HotSpotType.ChangeClassType) + view.Font.Width;

x = AddComment(view, x, y);

Expand Down
2 changes: 1 addition & 1 deletion ReClass.NET/Nodes/ClassNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public override Size Draw(ViewInfo view, int x, int y)

var tx = x;

x = AddIcon(view, x, y, Icons.Class, HotSpot.NoneId, HotSpotType.None);
x = AddIcon(view, x, y, view.IconProvider.Class, HotSpot.NoneId, HotSpotType.None);
x = AddText(view, x, y, view.Settings.OffsetColor, 0, AddressFormula) + view.Font.Width;

x = AddText(view, x, y, view.Settings.TypeColor, HotSpot.NoneId, "Class") + view.Font.Width;
Expand Down
2 changes: 1 addition & 1 deletion ReClass.NET/Nodes/DoubleNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public override void GetUserInterfaceInfo(out string name, out Image icon)

public override Size Draw(ViewInfo view, int x, int y)
{
return DrawNumeric(view, x, y, Icons.Double, "Double", ReadValueFromMemory(view.Memory).ToString("0.000"), null);
return DrawNumeric(view, x, y, view.IconProvider.Double, "Double", ReadValueFromMemory(view.Memory).ToString("0.000"), null);
}

public override void Update(HotSpot spot)
Expand Down
6 changes: 3 additions & 3 deletions ReClass.NET/Nodes/EnumNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,9 @@ public override Size Draw(ViewInfo view, int x, int y)

AddSelection(view, x, y, view.Font.Height);

x += TextPadding;
x = AddIconPadding(view, x);

x = AddIcon(view, x, y, Icons.Enum, HotSpot.NoneId, HotSpotType.None);
x = AddIcon(view, x, y, view.IconProvider.Enum, HotSpot.NoneId, HotSpotType.None);

x = AddAddressOffset(view, x, y);

Expand All @@ -158,7 +158,7 @@ public override Size Draw(ViewInfo view, int x, int y)
x = AddText(view, x, y, view.Settings.NameColor, HotSpot.NameId, Name) + view.Font.Width;
}
x = AddText(view, x, y, view.Settings.ValueColor, HotSpot.NoneId, $"<{Enum.Name}>") + view.Font.Width;
x = AddIcon(view, x, y, Icons.Change, 4, HotSpotType.ChangeEnumType) + view.Font.Width;
x = AddIcon(view, x, y, view.IconProvider.Change, 4, HotSpotType.ChangeEnumType) + view.Font.Width;

x = AddText(view, x, y, view.Settings.TextColor, HotSpot.NoneId, "=") + view.Font.Width;

Expand Down
2 changes: 1 addition & 1 deletion ReClass.NET/Nodes/FloatNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public override void GetUserInterfaceInfo(out string name, out Image icon)

public override Size Draw(ViewInfo view, int x, int y)
{
return DrawNumeric(view, x, y, Icons.Float, "Float", ReadValueFromMemory(view.Memory).ToString("0.000"), null);
return DrawNumeric(view, x, y, view.IconProvider.Float, "Float", ReadValueFromMemory(view.Memory).ToString("0.000"), null);
}

public override void Update(HotSpot spot)
Expand Down
6 changes: 3 additions & 3 deletions ReClass.NET/Nodes/FunctionNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ public override Size Draw(ViewInfo view, int x, int y)

AddSelection(view, x, y, view.Font.Height);

x += TextPadding;
x = AddIconPadding(view, x);

x = AddIcon(view, x, y, Icons.Function, HotSpot.NoneId, HotSpotType.None);
x = AddIcon(view, x, y, view.IconProvider.Function, HotSpot.NoneId, HotSpotType.None);

var tx = x;

Expand Down Expand Up @@ -82,7 +82,7 @@ public override Size Draw(ViewInfo view, int x, int y)
y += view.Font.Height;
x = AddText(view, tx, y, view.Settings.TextColor, HotSpot.NoneId, "Belongs to: ");
x = AddText(view, x, y, view.Settings.ValueColor, HotSpot.NoneId, BelongsToClass == null ? "<None>" : $"<{BelongsToClass.Name}>") + view.Font.Width;
x = AddIcon(view, x, y, Icons.Change, 1, HotSpotType.ChangeClassType);
x = AddIcon(view, x, y, view.IconProvider.Change, 1, HotSpotType.ChangeClassType);
size.Width = Math.Max(size.Width, x - origX);
size.Height += view.Font.Height;

Expand Down
2 changes: 1 addition & 1 deletion ReClass.NET/Nodes/Int16Node.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public override void GetUserInterfaceInfo(out string name, out Image icon)
public override Size Draw(ViewInfo view, int x, int y)
{
var value = ReadValueFromMemory(view.Memory);
return DrawNumeric(view, x, y, Icons.Signed, "Int16", value.ToString(), $"0x{value:X}");
return DrawNumeric(view, x, y, view.IconProvider.Signed, "Int16", value.ToString(), $"0x{value:X}");
}

public override void Update(HotSpot spot)
Expand Down
2 changes: 1 addition & 1 deletion ReClass.NET/Nodes/Int32Node.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public override void GetUserInterfaceInfo(out string name, out Image icon)
public override Size Draw(ViewInfo view, int x, int y)
{
var value = ReadValueFromMemory(view.Memory);
return DrawNumeric(view, x, y, Icons.Signed, "Int32", value.ToString(), $"0x{value:X}");
return DrawNumeric(view, x, y, view.IconProvider.Signed, "Int32", value.ToString(), $"0x{value:X}");
}

public override void Update(HotSpot spot)
Expand Down
2 changes: 1 addition & 1 deletion ReClass.NET/Nodes/Int64Node.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public override void GetUserInterfaceInfo(out string name, out Image icon)
public override Size Draw(ViewInfo view, int x, int y)
{
var value = ReadValueFromMemory(view.Memory);
return DrawNumeric(view, x, y, Icons.Signed, "Int64", value.ToString(), $"0x{value:X}");
return DrawNumeric(view, x, y, view.IconProvider.Signed, "Int64", value.ToString(), $"0x{value:X}");
}

public override void Update(HotSpot spot)
Expand Down
Loading