Skip to content
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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
40 changes: 30 additions & 10 deletions src/BizHawk.Client.EmuHawk/tools/HexEditor/HexColor.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions src/BizHawk.Client.EmuHawk/tools/HexEditor/HexColor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ private void HexColors_Form_Load(object sender, EventArgs e)
HexFreeze.BackColor = _hexEditor.Colors.Freeze;
HexFreezeHL.BackColor = _hexEditor.Colors.HighlightFreeze;
HexHighlight.BackColor = _hexEditor.Colors.Highlight;
Hex00.BackColor = _hexEditor.Colors.Foreground00;
Copy link
Member

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 of 00

}

private void HexBackground_Click(object sender, MouseEventArgs e)
Expand All @@ -33,6 +34,15 @@ private void HexBackground_Click(object sender, MouseEventArgs e)
}
}

private void Hex00_Click(object sender, MouseEventArgs e)
{
if (colorDialog1.ShowDialog().IsOk())
{
_hexEditor.Colors.Foreground00 = colorDialog1.Color;
Hex00.BackColor = colorDialog1.Color;
}
}

private void HexForeground_Click(object sender, MouseEventArgs e)
{
if (colorDialog1.ShowDialog().IsOk())
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions src/BizHawk.Client.EmuHawk/tools/HexEditor/HexEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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;
}
Copy link
Member

Choose a reason for hiding this comment

The 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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Copy link
Member

Choose a reason for hiding this comment

The 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>
128 changes: 128 additions & 0 deletions src/BizHawk.WinForms.Controls/LabelEx/HexLabelEx.cs
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"/>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should add a <seealso/> to those docs

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('|');
Copy link
Member

Choose a reason for hiding this comment

The 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);
}
}
}
}
}