Skip to content

Commit b1a45f9

Browse files
committed
Split bitfield display in groups.
1 parent 504dc19 commit b1a45f9

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

ReClass.NET/Nodes/BitFieldNode.cs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Diagnostics.Contracts;
33
using System.Drawing;
4+
using System.Text;
45
using ReClassNET.Memory;
56
using ReClassNET.UI;
67

@@ -88,7 +89,7 @@ public BaseNumericNode GetUnderlayingNode()
8889
/// <summary>Converts the memory value to a bit string.</summary>
8990
/// <param name="memory">The process memory.</param>
9091
/// <returns>The value converted to a bit string.</returns>
91-
private string ConvertValueToBitString(MemoryBuffer memory)
92+
private string ConvertValueToGroupedBitString(MemoryBuffer memory)
9293
{
9394
Contract.Requires(memory != null);
9495
Contract.Ensures(Contract.Result<string>() != null);
@@ -109,7 +110,17 @@ private string ConvertValueToBitString(MemoryBuffer memory)
109110
str = Convert.ToString(memory.ReadUInt8(Offset), 2);
110111
break;
111112
}
112-
return str.PadLeft(bits, '0');
113+
114+
str = str.PadLeft(bits, '0');
115+
116+
var sb = new StringBuilder(str);
117+
118+
for (var i = bits - 4; i > 0; i -= 4)
119+
{
120+
sb.Insert(i, ' ');
121+
}
122+
123+
return sb.ToString();
113124
}
114125

115126
public override Size Draw(ViewInfo view, int x, int y)
@@ -143,7 +154,10 @@ public override Size Draw(ViewInfo view, int x, int y)
143154
var rect = new Rectangle(x + i * view.Font.Width, y, view.Font.Width, view.Font.Height);
144155
AddHotSpot(view, rect, string.Empty, i, HotSpotType.Edit);
145156
}
146-
x = AddText(view, x, y, view.Settings.ValueColor, HotSpot.NoneId, ConvertValueToBitString(view.Memory)) + view.Font.Width;
157+
158+
var value = ConvertValueToGroupedBitString(view.Memory);
159+
160+
x = AddText(view, x, y, view.Settings.ValueColor, HotSpot.NoneId, value) + view.Font.Width;
147161

148162
x += view.Font.Width;
149163

@@ -161,11 +175,11 @@ public override Size Draw(ViewInfo view, int x, int y)
161175

162176
using (var brush = new SolidBrush(view.Settings.ValueColor))
163177
{
164-
view.Context.DrawString("0", view.Font.Font, brush, tx + (bits - 1) * view.Font.Width + 1, y, format);
178+
var maxCharCount = bits + (bits / 4 - 1) - 1;
165179

166-
for (var i = 4; i < bits; i += 4)
180+
for (int bitCount = 0, padding = 0; bitCount < bits; bitCount += 4, padding += 5)
167181
{
168-
view.Context.DrawString(i.ToString(), view.Font.Font, brush, tx + (bits - i - 1) * view.Font.Width, y, format);
182+
view.Context.DrawString(bitCount.ToString(), view.Font.Font, brush, tx + (maxCharCount - padding) * view.Font.Width, y, format);
169183
}
170184
}
171185

0 commit comments

Comments
 (0)