-
Notifications
You must be signed in to change notification settings - Fork 396
Expand file tree
/
Copy pathBaseWrapperArrayNode.cs
More file actions
152 lines (125 loc) · 3.69 KB
/
BaseWrapperArrayNode.cs
File metadata and controls
152 lines (125 loc) · 3.69 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
using System;
using System.Drawing;
using ReClassNET.Controls;
using ReClassNET.UI;
namespace ReClassNET.Nodes
{
public abstract class BaseWrapperArrayNode : BaseWrapperNode
{
public override int MemorySize => InnerNode.MemorySize * Count;
public int CurrentIndex { get; set; }
public int Count { get; set; } = 1;
public bool IsReadOnly { get; protected set; }
protected override bool PerformCycleCheck => true;
public override bool CanChangeInnerNodeTo(BaseNode node)
{
switch (node)
{
case null:
case ClassNode _:
case VirtualMethodNode _:
return false;
}
return true;
}
protected Size Draw(DrawContext context, int x, int y, string type)
{
if (IsHidden && !IsWrapped)
{
return DrawHidden(context, x, y);
}
var origX = x;
AddSelection(context, x, y, context.Font.Height);
x = AddOpenCloseIcon(context, x, y);
x = AddIcon(context, x, y, context.IconProvider.Array, HotSpot.NoneId, HotSpotType.None);
var tx = x;
x = AddAddressOffset(context, x, y);
x = AddText(context, x, y, context.Settings.TypeColor, HotSpot.NoneId, type) + context.Font.Width;
if (!IsWrapped)
{
x = AddText(context, x, y, context.Settings.NameColor, HotSpot.NameId, Name);
}
x = AddText(context, x, y, context.Settings.IndexColor, HotSpot.NoneId, "[");
x = AddText(context, x, y, context.Settings.IndexColor, IsReadOnly ? HotSpot.NoneId : 0, Count.ToString());
x = AddText(context, x, y, context.Settings.IndexColor, HotSpot.NoneId, "]");
x = AddIcon(context, x, y, context.IconProvider.LeftArrow, 2, HotSpotType.Click);
x = AddText(context, x, y, context.Settings.IndexColor, HotSpot.NoneId, "(");
x = AddText(context, x, y, context.Settings.IndexColor, 1, CurrentIndex.ToString());
x = AddText(context, x, y, context.Settings.IndexColor, HotSpot.NoneId, ")");
x = AddIcon(context, x, y, context.IconProvider.RightArrow, 3, HotSpotType.Click) + context.Font.Width;
x = AddText(context, x, y, context.Settings.ValueColor, HotSpot.NoneId, $"<Size={MemorySize}>") + context.Font.Width;
x = AddIcon(context, x + 2, y, context.IconProvider.Change, 4, HotSpotType.ChangeWrappedType);
x += context.Font.Width;
x = AddComment(context, x, y);
DrawInvalidMemoryIndicatorIcon(context, y);
AddContextDropDownIcon(context, y);
AddDeleteIcon(context, y);
y += context.Font.Height;
var size = new Size(x - origX, context.Font.Height);
if (LevelsOpen[context.Level])
{
var childSize = DrawChild(context, tx, y);
size.Width = Math.Max(size.Width, childSize.Width + tx - origX);
size.Height += childSize.Height;
}
return size;
}
protected abstract Size DrawChild(DrawContext context, int x, int y);
public override int CalculateDrawnHeight(DrawContext context)
{
if (IsHidden && !IsWrapped)
{
return HiddenHeight;
}
var height = context.Font.Height;
if (LevelsOpen[context.Level])
{
height += InnerNode.CalculateDrawnHeight(context);
}
return height;
}
public override void Update(HotSpot spot)
{
base.Update(spot);
if (spot.Id == 0 || spot.Id == 1)
{
if (int.TryParse(spot.Text, out var value))
{
if (spot.Id == 0 && !IsReadOnly)
{
if (value != 0)
{
Count = value;
if (CurrentIndex >= value)
{
CurrentIndex = value - 1;
}
GetParentContainer()?.ChildHasChanged(this);
}
}
else
{
if (value < Count)
{
CurrentIndex = value;
}
}
}
}
else if (spot.Id == 2)
{
if (CurrentIndex > 0)
{
--CurrentIndex;
}
}
else if (spot.Id == 3)
{
if (CurrentIndex < Count - 1)
{
++CurrentIndex;
}
}
}
}
}