Hex Editor - refactor so scrollbar & paint logic are part of the MemoryViewer custom control. Still a few bugs like no border or text display
This commit is contained in:
parent
f1dd4c625a
commit
1ccb2a002e
|
@ -3,7 +3,7 @@
|
|||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>9.0.30729</ProductVersion>
|
||||
<ProductVersion>9.0.21022</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{DD448B37-BA3F-4544-9754-5406E8094723}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
|
@ -267,6 +267,7 @@
|
|||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="ArchiveChooser.resx">
|
||||
<DependentUpon>ArchiveChooser.cs</DependentUpon>
|
||||
<SubType>Designer</SubType>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="config\InputConfig.resx">
|
||||
<DependentUpon>InputConfig.cs</DependentUpon>
|
||||
|
|
|
@ -43,7 +43,6 @@
|
|||
this.settingsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.restoreWindowSizeToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.autoloadToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.vScrollBar1 = new System.Windows.Forms.VScrollBar();
|
||||
this.MemoryViewer = new BizHawk.MultiClient.MemoryViewer();
|
||||
this.menuStrip1.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
|
@ -164,17 +163,6 @@
|
|||
this.autoloadToolStripMenuItem.Size = new System.Drawing.Size(186, 22);
|
||||
this.autoloadToolStripMenuItem.Text = "Auto-load";
|
||||
//
|
||||
// vScrollBar1
|
||||
//
|
||||
this.vScrollBar1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
|
||||
| System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.vScrollBar1.LargeChange = 16;
|
||||
this.vScrollBar1.Location = new System.Drawing.Point(515, 42);
|
||||
this.vScrollBar1.Name = "vScrollBar1";
|
||||
this.vScrollBar1.Size = new System.Drawing.Size(16, 323);
|
||||
this.vScrollBar1.TabIndex = 0;
|
||||
this.vScrollBar1.Scroll += new System.Windows.Forms.ScrollEventHandler(this.vScrollBar1_Scroll);
|
||||
//
|
||||
// MemoryViewer
|
||||
//
|
||||
this.MemoryViewer.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
|
||||
|
@ -186,14 +174,12 @@
|
|||
this.MemoryViewer.TabIndex = 0;
|
||||
this.MemoryViewer.TabStop = false;
|
||||
this.MemoryViewer.Text = "RAM";
|
||||
this.MemoryViewer.Paint += new System.Windows.Forms.PaintEventHandler(this.MemoryViewer_Paint);
|
||||
//
|
||||
// HexEditor
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(534, 377);
|
||||
this.Controls.Add(this.vScrollBar1);
|
||||
this.Controls.Add(this.MemoryViewer);
|
||||
this.Controls.Add(this.menuStrip1);
|
||||
this.MainMenuStrip = this.menuStrip1;
|
||||
|
@ -226,6 +212,5 @@
|
|||
private System.Windows.Forms.ToolStripMenuItem settingsToolStripMenuItem;
|
||||
private System.Windows.Forms.ToolStripMenuItem restoreWindowSizeToolStripMenuItem;
|
||||
private System.Windows.Forms.ToolStripMenuItem autoloadToolStripMenuItem;
|
||||
private System.Windows.Forms.VScrollBar vScrollBar1;
|
||||
}
|
||||
}
|
|
@ -25,15 +25,12 @@ namespace BizHawk.MultiClient
|
|||
//Show num addresses in group box title (show "address" if 1 address)
|
||||
//big font for currently mouse over'ed value?
|
||||
|
||||
Font font = new Font("Courier New", 10);
|
||||
Brush regBrush = Brushes.Black;
|
||||
int RowsVisible = 0;
|
||||
|
||||
|
||||
const string HEADER = " 0 1 2 3 4 5 6 7 8 9 A B C D E F";
|
||||
|
||||
|
||||
int defaultWidth;
|
||||
int defaultHeight;
|
||||
MemoryDomain Domain = new MemoryDomain("NULL", 1, Endian.Little, addr => 0, (a, v) => { });
|
||||
|
||||
public HexEditor()
|
||||
{
|
||||
|
@ -70,34 +67,6 @@ namespace BizHawk.MultiClient
|
|||
this.Close();
|
||||
}
|
||||
|
||||
private void MemoryViewer_Paint(object sender, PaintEventArgs e)
|
||||
{
|
||||
unchecked
|
||||
{
|
||||
int row = 0;
|
||||
int rowX = 8;
|
||||
int rowY = 16;
|
||||
int rowYoffset = 20;
|
||||
string rowStr;
|
||||
|
||||
e.Graphics.DrawString(HEADER, font, regBrush, new Point(rowX, rowY));
|
||||
e.Graphics.DrawLine(new Pen(regBrush), MemoryViewer.Left + 38, MemoryViewer.Top, MemoryViewer.Left + 38, MemoryViewer.Bottom - 40);
|
||||
e.Graphics.DrawLine(new Pen(regBrush), MemoryViewer.Left, 34, MemoryViewer.Right - 16, 34);
|
||||
|
||||
for (int i = 0; i < RowsVisible; i++)
|
||||
{
|
||||
row = i+vScrollBar1.Value;
|
||||
rowStr = String.Format("{0:X4}", row*16) + " "; //TODO: num digits based on size of domain
|
||||
for (int j = 0; j < 16; j++)
|
||||
{
|
||||
rowStr += String.Format("{0:X2}", Domain.PeekByte((row*16)+j)) + " "; //TODO: format based on data size
|
||||
}
|
||||
|
||||
e.Graphics.DrawString(rowStr, font, regBrush, new Point(rowX, (rowY*(i+1))+rowYoffset));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateValues()
|
||||
{
|
||||
if (!this.IsHandleCreated || this.IsDisposed) return;
|
||||
|
@ -107,7 +76,8 @@ namespace BizHawk.MultiClient
|
|||
public void Restart()
|
||||
{
|
||||
SetMemoryDomainMenu(); //Calls update routines
|
||||
SetUpScrollBar();
|
||||
MemoryViewer.ResetScrollBar();
|
||||
MemoryViewer.SetUpScrollBar();
|
||||
MemoryViewer.Refresh();
|
||||
}
|
||||
|
||||
|
@ -130,17 +100,17 @@ namespace BizHawk.MultiClient
|
|||
{
|
||||
if (pos < Global.Emulator.MemoryDomains.Count) //Sanity check
|
||||
{
|
||||
Domain = Global.Emulator.MemoryDomains[pos];
|
||||
MemoryViewer.SetMemoryDomain(Global.Emulator.MemoryDomains[pos]);
|
||||
}
|
||||
UpdateDomainString();
|
||||
SetUpScrollBar();
|
||||
vScrollBar1.Value = 0;
|
||||
MemoryViewer.ResetScrollBar();
|
||||
MemoryViewer.SetUpScrollBar();
|
||||
MemoryViewer.Refresh();
|
||||
}
|
||||
|
||||
private void UpdateDomainString()
|
||||
{
|
||||
string memoryDomain = Domain.ToString();
|
||||
string memoryDomain = MemoryViewer.GetMemoryDomainStr();
|
||||
string systemID = Global.Emulator.SystemId;
|
||||
MemoryViewer.Text = systemID + " " + memoryDomain;
|
||||
}
|
||||
|
@ -169,10 +139,6 @@ namespace BizHawk.MultiClient
|
|||
}
|
||||
else
|
||||
memoryDomainsToolStripMenuItem.Enabled = false;
|
||||
|
||||
SetUpScrollBar();
|
||||
vScrollBar1.Value = 0;
|
||||
MemoryViewer.Refresh();
|
||||
}
|
||||
|
||||
private void goToAddressToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
|
@ -180,34 +146,14 @@ namespace BizHawk.MultiClient
|
|||
//TODO
|
||||
}
|
||||
|
||||
private void SetUpScrollBar()
|
||||
{
|
||||
RowsVisible = MemoryViewer.Height / 16;
|
||||
int totalRows = Domain.Size / 16;
|
||||
int MaxRows = (totalRows - RowsVisible) + 17;
|
||||
|
||||
if (MaxRows > 0)
|
||||
{
|
||||
vScrollBar1.Visible = true;
|
||||
if (vScrollBar1.Value > MaxRows)
|
||||
vScrollBar1.Value = MaxRows;
|
||||
vScrollBar1.Maximum = MaxRows;
|
||||
}
|
||||
else
|
||||
vScrollBar1.Visible = false;
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void HexEditor_Resize(object sender, EventArgs e)
|
||||
{
|
||||
SetUpScrollBar();
|
||||
MemoryViewer.SetUpScrollBar();
|
||||
MemoryViewer.Refresh();
|
||||
}
|
||||
|
||||
private void vScrollBar1_Scroll(object sender, ScrollEventArgs e)
|
||||
{
|
||||
SetUpScrollBar();
|
||||
MemoryViewer.Refresh();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
@ -8,11 +9,109 @@ namespace BizHawk.MultiClient
|
|||
{
|
||||
public class MemoryViewer : GroupBox
|
||||
{
|
||||
public VScrollBar vScrollBar1;
|
||||
MemoryDomain Domain = new MemoryDomain("NULL", 1, Endian.Little, addr => 0, (a, v) => { });
|
||||
Font font = new Font("Courier New", 10);
|
||||
Brush regBrush = Brushes.Black;
|
||||
int RowsVisible = 0;
|
||||
|
||||
const string HEADER = " 0 1 2 3 4 5 6 7 8 9 A B C D E F"; //TODO: not constant, must deal with bite size
|
||||
|
||||
public MemoryViewer()
|
||||
{
|
||||
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
|
||||
SetStyle(ControlStyles.UserPaint, true);
|
||||
SetStyle(ControlStyles.DoubleBuffer, true);
|
||||
|
||||
this.vScrollBar1 = new VScrollBar();
|
||||
|
||||
//TODO: based on size of MemoryViewer?
|
||||
Point n = new Point(this.Size);
|
||||
this.vScrollBar1.Location = new System.Drawing.Point(n.X-16, n.Y-this.Height);
|
||||
this.vScrollBar1.Size = new System.Drawing.Size(16, 323);
|
||||
|
||||
this.vScrollBar1.Height = this.Height;
|
||||
this.vScrollBar1.Width = 16;
|
||||
this.vScrollBar1.Visible = true;
|
||||
this.vScrollBar1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
|
||||
| System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.vScrollBar1.LargeChange = 16;
|
||||
this.vScrollBar1.Name = "vScrollBar1";
|
||||
this.vScrollBar1.TabIndex = 0;
|
||||
this.vScrollBar1.Scroll += new System.Windows.Forms.ScrollEventHandler(this.vScrollBar1_Scroll);
|
||||
|
||||
this.Controls.Add(this.vScrollBar1);
|
||||
}
|
||||
|
||||
protected unsafe override void OnPaint(PaintEventArgs e)
|
||||
{
|
||||
unchecked
|
||||
{
|
||||
int row = 0;
|
||||
int rowX = 8;
|
||||
int rowY = 16;
|
||||
int rowYoffset = 20;
|
||||
string rowStr;
|
||||
|
||||
e.Graphics.DrawString(HEADER, font, regBrush, new Point(rowX, rowY));
|
||||
e.Graphics.DrawLine(new Pen(regBrush), this.Left + 38, this.Top, this.Left + 38, this.Bottom - 40);
|
||||
e.Graphics.DrawLine(new Pen(regBrush), this.Left, 34, this.Right - 16, 34);
|
||||
|
||||
for (int i = 0; i < RowsVisible; i++)
|
||||
{
|
||||
row = i + vScrollBar1.Value;
|
||||
rowStr = String.Format("{0:X4}", row * 16) + " "; //TODO: num digits based on size of domain
|
||||
for (int j = 0; j < 16; j++)
|
||||
{
|
||||
rowStr += String.Format("{0:X2}", Domain.PeekByte((row * 16) + j)) + " "; //TODO: format based on data size
|
||||
}
|
||||
|
||||
e.Graphics.DrawString(rowStr, font, regBrush, new Point(rowX, (rowY * (i + 1)) + rowYoffset));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void ResetScrollBar()
|
||||
{
|
||||
vScrollBar1.Value = 0;
|
||||
Refresh();
|
||||
}
|
||||
|
||||
public void SetUpScrollBar()
|
||||
{
|
||||
RowsVisible = this.Height / 16;
|
||||
int totalRows = Domain.Size / 16;
|
||||
int MaxRows = (totalRows - RowsVisible) + 17;
|
||||
|
||||
if (MaxRows > 0)
|
||||
{
|
||||
vScrollBar1.Visible = true;
|
||||
if (vScrollBar1.Value > MaxRows)
|
||||
vScrollBar1.Value = MaxRows;
|
||||
vScrollBar1.Maximum = MaxRows;
|
||||
}
|
||||
else
|
||||
vScrollBar1.Visible = false;
|
||||
|
||||
}
|
||||
|
||||
public void SetMemoryDomain(MemoryDomain d)
|
||||
{
|
||||
Domain = d;
|
||||
SetUpScrollBar();
|
||||
vScrollBar1.Value = 0;
|
||||
Refresh();
|
||||
}
|
||||
|
||||
public string GetMemoryDomainStr()
|
||||
{
|
||||
return Domain.ToString();
|
||||
}
|
||||
|
||||
private void vScrollBar1_Scroll(object sender, ScrollEventArgs e)
|
||||
{
|
||||
this.SetUpScrollBar();
|
||||
this.Refresh();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue