-
Notifications
You must be signed in to change notification settings - Fork 396
Expand file tree
/
Copy pathClassNode.cs
More file actions
189 lines (147 loc) · 4.56 KB
/
ClassNode.cs
File metadata and controls
189 lines (147 loc) · 4.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
using System;
using System.Diagnostics.Contracts;
using System.Drawing;
using System.Linq;
using ReClassNET.Controls;
using ReClassNET.UI;
namespace ReClassNET.Nodes
{
public delegate void ClassCreatedEventHandler(ClassNode node);
public class ClassNode : BaseContainerNode
{
public static event ClassCreatedEventHandler ClassCreated;
#if RECLASSNET64
public static IntPtr DefaultAddress { get; } = (IntPtr)0x140000000;
public static string DefaultAddressFormula { get; } = "140000000";
#else
public static IntPtr DefaultAddress { get; } = (IntPtr)0x400000;
public static string DefaultAddressFormula { get; } = "400000";
#endif
public override int MemorySize => Nodes.Sum(n => n.MemorySize);
protected override bool ShouldCompensateSizeChanges => true;
public Guid Uuid { get; set; }
public string AddressFormula { get; set; } = DefaultAddressFormula;
public event NodeEventHandler NodesChanged;
internal ClassNode(bool notifyClassCreated)
{
Contract.Ensures(AddressFormula != null);
LevelsOpen.DefaultValue = true;
Uuid = Guid.NewGuid();
if (notifyClassCreated)
{
ClassCreated?.Invoke(this);
}
}
public static ClassNode Create()
{
Contract.Ensures(Contract.Result<ClassNode>() != null);
return new ClassNode(true);
}
public override void GetUserInterfaceInfo(out string name, out Image icon)
{
throw new InvalidOperationException($"The '{nameof(ClassNode)}' node should not be accessible from the ui.");
}
public override bool CanHandleChildNode(BaseNode node)
{
switch (node)
{
case null:
case ClassNode _:
case VirtualMethodNode _:
return false;
}
return true;
}
public override void Initialize()
{
AddBytes(IntPtr.Size);
}
public override Size Draw(DrawContext context, int x, int y)
{
AddSelection(context, 0, y, context.Font.Height);
var origX = x;
var origY = y;
x = AddOpenCloseIcon(context, x, y);
var tx = x;
x = AddIcon(context, x, y, context.IconProvider.Class, HotSpot.NoneId, HotSpotType.None);
x = AddText(context, x, y, context.Settings.OffsetColor, 0, AddressFormula) + context.Font.Width;
x = AddText(context, x, y, context.Settings.TypeColor, HotSpot.NoneId, "Class") + context.Font.Width;
x = AddText(context, x, y, context.Settings.NameColor, HotSpot.NameId, Name) + context.Font.Width;
x = AddText(context, x, y, context.Settings.ValueColor, HotSpot.NoneId, $"[{MemorySize}]") + context.Font.Width;
x = AddComment(context, x, y);
y += context.Font.Height;
var size = new Size(x - origX, y - origY);
if (LevelsOpen[context.Level])
{
var childOffset = tx - origX;
var innerContext = context.Clone();
innerContext.Level++;
foreach (var node in Nodes)
{
Size AggregateNodeSizes(Size baseSize, Size newSize)
{
return new Size(Math.Max(baseSize.Width, newSize.Width), baseSize.Height + newSize.Height);
}
Size ExtendWidth(Size baseSize, int width)
{
return new Size(baseSize.Width + width, baseSize.Height);
}
// Draw the node if it is in the visible area.
if (context.ClientArea.Contains(tx, y))
{
var innerSize = node.Draw(innerContext, tx, y);
size = AggregateNodeSizes(size, ExtendWidth(innerSize, childOffset));
y += innerSize.Height;
}
else
{
// Otherwise calculate the height...
var calculatedHeight = node.CalculateDrawnHeight(innerContext);
// and check if the node area overlaps with the visible area...
if (new Rectangle(tx, y, 9999999, calculatedHeight).IntersectsWith(context.ClientArea))
{
// then draw the node...
var innerSize = node.Draw(innerContext, tx, y);
size = AggregateNodeSizes(size, ExtendWidth(innerSize, childOffset));
y += innerSize.Height;
}
else
{
// or skip drawing and just use the calculated height.
size = AggregateNodeSizes(size, new Size(0, calculatedHeight));
y += calculatedHeight;
}
}
}
}
return size;
}
public override int CalculateDrawnHeight(DrawContext context)
{
if (IsHidden)
{
return HiddenHeight;
}
var height = context.Font.Height;
if (LevelsOpen[context.Level])
{
var nv = context.Clone();
nv.Level++;
height += Nodes.Sum(n => n.CalculateDrawnHeight(nv));
}
return height;
}
public override void Update(HotSpot spot)
{
base.Update(spot);
if (spot.Id == 0)
{
AddressFormula = spot.Text;
}
}
protected internal override void ChildHasChanged(BaseNode child)
{
NodesChanged?.Invoke(this);
}
}
}