-
Notifications
You must be signed in to change notification settings - Fork 386
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
Implement faded (configurable colour) zeroes in the Hex Editor #4098
base: master
Are you sure you want to change the base?
Changes from all commits
d0411b5
1c7684c
7ed6906
f7bc67f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -133,6 +133,7 @@ internal class ColorConfig | |
public Color Freeze { get; set; }= Color.LightBlue; | ||
public Color Highlight { get; set; } = Color.Pink; | ||
public Color HighlightFreeze { get; set; } = Color.Violet; | ||
public Color Foreground00 { get; set; } = Color.SlateGray; | ||
} | ||
|
||
[ConfigPersist] | ||
|
@@ -219,11 +220,21 @@ private void HexEditor_Load(object sender, EventArgs e) | |
|
||
protected override void UpdateAfter() | ||
{ | ||
if (AddressesLabel.ZeroColor != Colors.Foreground00) | ||
{ | ||
AddressesLabel.ZeroColor = Colors.Foreground00; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this belongs here |
||
|
||
AddressesLabel.Text = GenerateMemoryViewString(true); | ||
} | ||
|
||
protected override void GeneralUpdate() | ||
{ | ||
if (AddressesLabel.ZeroColor != Colors.Foreground00) | ||
{ | ||
AddressesLabel.ZeroColor = Colors.Foreground00; | ||
} | ||
|
||
AddressesLabel.Text = GenerateMemoryViewString(true); | ||
AddressLabel.Text = GenerateAddressString(); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,4 +10,9 @@ | |
<PackageReference Include="System.Drawing.Common" /> | ||
<ProjectReference Include="$(ProjectDir)../BizHawk.Common/BizHawk.Common.csproj" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Update="LabelEx\HexLabelEx.cs"> | ||
<SubType>Component</SubType> | ||
</Compile> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this have any effect? If so then I'd expect the rest of the controls in this project to be missing their IDE icons or whatever, since they're obviously not listed here. |
||
</ItemGroup> | ||
</Project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
using System.ComponentModel; | ||
using System.Drawing; | ||
using System.Windows.Forms; | ||
using BizHawk.Common; | ||
|
||
|
||
namespace BizHawk.WinForms.Controls | ||
{ | ||
/// <inheritdoc cref="Docs.LabelOrLinkLabel"/> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should add a |
||
public class HexLabelEx : LabelExBase | ||
{ | ||
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] | ||
public new bool AutoSize => base.AutoSize; | ||
|
||
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] | ||
public new Size Size => base.Size; | ||
|
||
public Color ZeroColor { get; set; } = Color.SlateGray; | ||
|
||
private float spacingHexModifier; | ||
private float spacingPreDivider; | ||
private float spacingPostDividerModifier; | ||
private float spacingAscii; | ||
private float spacingLineModifier; | ||
|
||
public HexLabelEx() | ||
{ | ||
base.AutoSize = true; | ||
this.BackColor = Color.Transparent; | ||
|
||
spacingHexModifier = 0.7F; | ||
spacingPreDivider = 3.0F; | ||
spacingPostDividerModifier = 3.5F; | ||
spacingAscii = 7.0F; | ||
spacingLineModifier = 0.56F; | ||
|
||
if (OSTailoredCode.IsUnixHost) | ||
{ | ||
// TODO: spacing values will probably be different on linux | ||
} | ||
} | ||
|
||
protected override void OnPaint(PaintEventArgs e) | ||
{ | ||
string text = this.Text; | ||
Font font = this.Font; | ||
PointF point = new PointF(0, 0); | ||
char gap = ' '; | ||
|
||
string[] lines = text.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None); | ||
|
||
Color color = this.ForeColor; | ||
|
||
foreach (string line in lines) | ||
{ | ||
// split left and right panes | ||
string[] panes = line.Split('|'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Really don't like this. The caller has full knowledge of the content that's being passed in and should be able to make separate calls before or instead of passing in a concatenated line. |
||
|
||
if (panes.Length < 2) | ||
{ | ||
// skip - last line appears to be empty | ||
continue; | ||
} | ||
else if (panes.Length > 2) | ||
{ | ||
// pipe character present in the ascii pane? | ||
for (int i = 2; i < panes.Length; i++) | ||
{ | ||
panes[1] += "|" + panes[i]; | ||
} | ||
} | ||
|
||
// hex pane | ||
string[] words = panes[0].Split(gap); | ||
foreach (var word in words) | ||
{ | ||
SizeF size = e.Graphics.MeasureString(word, font); | ||
|
||
switch (word) | ||
{ | ||
case "00": | ||
color = ZeroColor; | ||
break; | ||
|
||
default: | ||
color = this.ForeColor; | ||
break; | ||
} | ||
|
||
DrawString(word, font, point, color); | ||
|
||
point.X += size.Width + e.Graphics.MeasureString(gap.ToString(), font).Width + spacingHexModifier; | ||
} | ||
|
||
// divider | ||
string div = "|"; | ||
point.X -= spacingPreDivider; | ||
SizeF sizeDiv = e.Graphics.MeasureString(div, font); | ||
|
||
DrawString(div, font, point, this.ForeColor); | ||
|
||
point.X += e.Graphics.MeasureString(gap.ToString(), font).Width + spacingPostDividerModifier; | ||
|
||
// ascii pane | ||
char[] chars = panes[1].ToCharArray(); | ||
foreach (var c in chars) | ||
{ | ||
string str = c.ToString(); | ||
DrawString(str, font, point, this.ForeColor); | ||
|
||
// fixed size | ||
point.X += spacingAscii; | ||
} | ||
|
||
point.X = 0; | ||
point.Y += e.Graphics.MeasureString(line, font).Height + spacingLineModifier; | ||
} | ||
|
||
void DrawString(string s, Font f, PointF p, Color color) | ||
{ | ||
using (Brush brush = new SolidBrush(color)) | ||
{ | ||
e.Graphics.DrawString(s, f, brush, p); | ||
} | ||
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe use
Zeroes
in identifiers instead of00