From ac1c7d0992cf70da41294e3785008b664d582dab Mon Sep 17 00:00:00 2001 From: adelikat Date: Thu, 24 Dec 2015 15:46:57 -0500 Subject: [PATCH] HexView - setting up some API --- .../CustomControls/HexView.cs | 51 +++++++++++++++++++ .../tools/HexEditor/NewHexEditor.Designer.cs | 21 ++++---- .../tools/HexEditor/NewHexEditor.cs | 25 ++++++++- 3 files changed, 86 insertions(+), 11 deletions(-) diff --git a/BizHawk.Client.EmuHawk/CustomControls/HexView.cs b/BizHawk.Client.EmuHawk/CustomControls/HexView.cs index 9c8af21eea..30faae953b 100644 --- a/BizHawk.Client.EmuHawk/CustomControls/HexView.cs +++ b/BizHawk.Client.EmuHawk/CustomControls/HexView.cs @@ -16,6 +16,8 @@ namespace BizHawk.Client.EmuHawk private readonly Font NormalFont; private Size _charSize; + private long _arrayLength; + public HexView() { NormalFont = new Font("Courier New", 8); // Only support fixed width @@ -43,6 +45,8 @@ namespace BizHawk.Client.EmuHawk base.Dispose(disposing); } + #region Paint + protected override void OnPaint(PaintEventArgs e) { using (var LCK = Gdi.LockGraphics(e.Graphics)) @@ -61,5 +65,52 @@ namespace BizHawk.Client.EmuHawk Gdi.EndOffScreenBitmap(); } } + + #endregion + + #region Properties + + /// + /// Gets or sets the sets the virtual number of the length of the array to display + /// + [Category("Behavior")] + public long ArrayLength + { + get + { + return _arrayLength; + } + + set + { + _arrayLength = value; + RecalculateScrollBars(); + } + } + + #endregion + + #region Event Handlers + + [Category("Virtual")] + public event QueryIndexValueHandler QueryIndexValue; + + [Category("Virtual")] + public event QueryIndexBkColorHandler QueryIndexBgColor; + + [Category("Virtual")] + public event QueryIndexForeColorHandler QueryIndexForeColor; + + public delegate void QueryIndexValueHandler(int index, out long value); + + public delegate void QueryIndexBkColorHandler(int index, ref Color color); + + public delegate void QueryIndexForeColorHandler(int index, ref Color color); + + #endregion + + private void RecalculateScrollBars() + { + } } } diff --git a/BizHawk.Client.EmuHawk/tools/HexEditor/NewHexEditor.Designer.cs b/BizHawk.Client.EmuHawk/tools/HexEditor/NewHexEditor.Designer.cs index e07734890e..d6074c0358 100644 --- a/BizHawk.Client.EmuHawk/tools/HexEditor/NewHexEditor.Designer.cs +++ b/BizHawk.Client.EmuHawk/tools/HexEditor/NewHexEditor.Designer.cs @@ -31,7 +31,7 @@ this.HexMenu = new System.Windows.Forms.MenuStrip(); this.FileSubMenu = new System.Windows.Forms.ToolStripMenuItem(); this.ExitMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.hexView1 = new BizHawk.Client.EmuHawk.HexView(); + this.HexViewControl = new BizHawk.Client.EmuHawk.HexView(); this.HexMenu.SuspendLayout(); this.SuspendLayout(); // @@ -62,23 +62,24 @@ this.ExitMenuItem.Text = "E&xit"; this.ExitMenuItem.Click += new System.EventHandler(this.ExitMenuItem_Click); // - // hexView1 + // HexViewControl // - this.hexView1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + this.HexViewControl.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); - this.hexView1.Location = new System.Drawing.Point(12, 27); - this.hexView1.Name = "hexView1"; - this.hexView1.Size = new System.Drawing.Size(424, 231); - this.hexView1.TabIndex = 1; - this.hexView1.Text = "hexView1"; + this.HexViewControl.ArrayLength = 0; + this.HexViewControl.Location = new System.Drawing.Point(12, 27); + this.HexViewControl.Name = "HexViewControl"; + this.HexViewControl.Size = new System.Drawing.Size(424, 231); + this.HexViewControl.TabIndex = 1; + this.HexViewControl.Text = "hexView1"; // // NewHexEditor // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(448, 270); - this.Controls.Add(this.hexView1); + this.Controls.Add(this.HexViewControl); this.Controls.Add(this.HexMenu); this.MainMenuStrip = this.HexMenu; this.Name = "NewHexEditor"; @@ -96,6 +97,6 @@ private System.Windows.Forms.MenuStrip HexMenu; private System.Windows.Forms.ToolStripMenuItem FileSubMenu; private System.Windows.Forms.ToolStripMenuItem ExitMenuItem; - private HexView hexView1; + private HexView HexViewControl; } } \ No newline at end of file diff --git a/BizHawk.Client.EmuHawk/tools/HexEditor/NewHexEditor.cs b/BizHawk.Client.EmuHawk/tools/HexEditor/NewHexEditor.cs index 1bc295183b..dc34d45caa 100644 --- a/BizHawk.Client.EmuHawk/tools/HexEditor/NewHexEditor.cs +++ b/BizHawk.Client.EmuHawk/tools/HexEditor/NewHexEditor.cs @@ -23,11 +23,15 @@ namespace BizHawk.Client.EmuHawk InitializeComponent(); Closing += (o, e) => SaveConfigSettings(); + + HexViewControl.QueryIndexValue += HexView_QueryIndexValue; + HexViewControl.QueryIndexForeColor += HexView_QueryIndexForeColor; + HexViewControl.QueryIndexBgColor += HexView_QueryIndexForeColor; } private void NewHexEditor_Load(object sender, EventArgs e) { - + HexViewControl.ArrayLength = MemoryDomains.MainMemory.Size; } private void SaveConfigSettings() @@ -63,6 +67,25 @@ namespace BizHawk.Client.EmuHawk #endregion + #region HexView Callbacks + + private void HexView_QueryIndexValue(int index, out long value) + { + value = MemoryDomains.MainMemory.PeekByte(index); + } + + private void HexView_QueryIndexBgColor(int index, ref Color color) + { + color = Color.White; + } + + private void HexView_QueryIndexForeColor(int index, ref Color color) + { + color = Color.Black; + } + + #endregion + #region Menu Items private void FileSubMenu_DropDownOpened(object sender, EventArgs e)