Debugger: Tilemap/Tile viewers - Improved zooming/scrolling

This commit is contained in:
Sour 2019-04-21 17:34:27 -04:00
parent 25f00099b0
commit 51a3e16075
10 changed files with 506 additions and 98 deletions

View file

@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Mesen.GUI.Debugger.Controls
{
public class ctrlPanel : Panel
{
public delegate void ZoomEventHandler(int scaleDelta);
public event ZoomEventHandler OnZoom;
public ctrlPanel()
{
this.DoubleBuffered = true;
}
protected override void OnMouseWheel(MouseEventArgs e)
{
if(Control.ModifierKeys != Keys.Control) {
int hori = this.HorizontalScroll.Value;
int vert = this.VerticalScroll.Value;
if(Control.ModifierKeys == Keys.Shift) {
hori = Math.Max(0, Math.Min(hori - e.Delta, this.HorizontalScroll.Maximum));
} else {
vert = Math.Max(0, Math.Min(vert - e.Delta, this.VerticalScroll.Maximum));
}
this.HorizontalScroll.Value = hori;
this.HorizontalScroll.Value = hori;
this.VerticalScroll.Value = vert;
this.VerticalScroll.Value = vert;
} else {
this.OnZoom?.Invoke(e.Delta > 0 ? 1 : -1);
}
}
}
}

View file

@ -0,0 +1,73 @@
namespace Mesen.GUI.Debugger.PpuViewer
{
partial class ctrlImagePanel
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if(disposing && (components != null)) {
components.Dispose();
}
base.Dispose(disposing);
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.ctrlPanel = new Mesen.GUI.Debugger.Controls.ctrlPanel();
this.ctrlImageViewer = new Mesen.GUI.Debugger.PpuViewer.ctrlImageViewer();
this.ctrlPanel.SuspendLayout();
this.SuspendLayout();
//
// ctrlPanel
//
this.ctrlPanel.AutoScroll = true;
this.ctrlPanel.Controls.Add(this.ctrlImageViewer);
this.ctrlPanel.Dock = System.Windows.Forms.DockStyle.Fill;
this.ctrlPanel.Location = new System.Drawing.Point(0, 0);
this.ctrlPanel.Name = "ctrlPanel";
this.ctrlPanel.Size = new System.Drawing.Size(327, 326);
this.ctrlPanel.TabIndex = 0;
//
// ctrlImageViewer
//
this.ctrlImageViewer.Image = null;
this.ctrlImageViewer.ImageScale = 1;
this.ctrlImageViewer.Location = new System.Drawing.Point(0, 0);
this.ctrlImageViewer.Name = "ctrlImageViewer";
this.ctrlImageViewer.Selection = new System.Drawing.Rectangle(0, 0, 0, 0);
this.ctrlImageViewer.Size = new System.Drawing.Size(327, 326);
this.ctrlImageViewer.TabIndex = 0;
this.ctrlImageViewer.Text = "ctrlImageViewer";
//
// ctrlImagePanel
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.ctrlPanel);
this.Name = "ctrlImagePanel";
this.Size = new System.Drawing.Size(327, 326);
this.ctrlPanel.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private Controls.ctrlPanel ctrlPanel;
private ctrlImageViewer ctrlImageViewer;
}
}

View file

@ -0,0 +1,74 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Mesen.GUI.Controls;
namespace Mesen.GUI.Debugger.PpuViewer
{
public partial class ctrlImagePanel : BaseControl
{
private int _scale = 1;
private Size _imageSize;
public Rectangle Selection { get { return ctrlImageViewer.Selection; } set { ctrlImageViewer.Selection = value; } }
public Size ImageSize { get { return _imageSize; } set { _imageSize = value; UpdateMapSize(); } }
public Image Image { get { return ctrlImageViewer.Image; } set { ctrlImageViewer.Image = value; } }
public int ImageScale { get { return _scale; } set { _scale = value; } }
public new event MouseEventHandler MouseClick { add { ctrlImageViewer.MouseClick += value; } remove { ctrlImageViewer.MouseClick -= value; } }
public ctrlImagePanel()
{
InitializeComponent();
if(DesignMode) {
return;
}
ctrlPanel.OnZoom += (scaleDelta) => {
double hori = (double)ctrlPanel.HorizontalScroll.Value / _scale + (double)ctrlPanel.Width / 2 / _scale;
double vert = (double)ctrlPanel.VerticalScroll.Value / _scale + (double)ctrlPanel.Height / 2 / _scale;
_scale = Math.Min(16, Math.Max(1, _scale + scaleDelta));
UpdateMapSize();
ctrlPanel.HorizontalScroll.Value = Math.Max(0, Math.Min((int)(hori * _scale) - ctrlPanel.Width / 2, ctrlPanel.HorizontalScroll.Maximum));
ctrlPanel.HorizontalScroll.Value = Math.Max(0, Math.Min((int)(hori * _scale) - ctrlPanel.Width / 2, ctrlPanel.HorizontalScroll.Maximum));
ctrlPanel.VerticalScroll.Value = Math.Max(0, Math.Min((int)(vert * _scale) - ctrlPanel.Height / 2, ctrlPanel.VerticalScroll.Maximum));
ctrlPanel.VerticalScroll.Value = Math.Max(0, Math.Min((int)(vert * _scale) - ctrlPanel.Height / 2, ctrlPanel.VerticalScroll.Maximum));
};
}
private void UpdateMapSize()
{
ctrlImageViewer.Width = ImageSize.Width * _scale;
ctrlImageViewer.Height = ImageSize.Height * _scale;
ctrlImageViewer.ImageScale = _scale;
ctrlImageViewer.Invalidate();
}
protected override void OnInvalidated(InvalidateEventArgs e)
{
base.OnInvalidated(e);
ctrlImageViewer.Invalidate();
}
public void ZoomIn()
{
_scale = Math.Min(16, _scale + 1);
UpdateMapSize();
}
public void ZoomOut()
{
_scale = Math.Max(1, _scale - 1);
UpdateMapSize();
}
}
}

View file

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View file

@ -27,9 +27,7 @@
/// </summary>
private void InitializeComponent()
{
this.picTilemap = new Mesen.GUI.Controls.ctrlMesenPictureBox();
this.ctrlScanlineCycleSelect = new Mesen.GUI.Debugger.Controls.ctrlScanlineCycleSelect();
this.pnlTilemap = new System.Windows.Forms.Panel();
this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
this.tableLayoutPanel2 = new System.Windows.Forms.TableLayoutPanel();
this.cboMemoryType = new Mesen.GUI.Debugger.Controls.ComboBoxWithSeparator();
@ -44,23 +42,22 @@
this.lblOffset = new System.Windows.Forms.Label();
this.nudOffset = new Mesen.GUI.Controls.MesenNumericUpDown();
this.ctrlPaletteViewer = new Mesen.GUI.Debugger.ctrlPaletteViewer();
((System.ComponentModel.ISupportInitialize)(this.picTilemap)).BeginInit();
this.pnlTilemap.SuspendLayout();
this.ctrlImagePanel = new Mesen.GUI.Debugger.PpuViewer.ctrlImagePanel();
this.ctrlMesenMenuStrip1 = new Mesen.GUI.Controls.ctrlMesenMenuStrip();
this.mnuFile = new System.Windows.Forms.ToolStripMenuItem();
this.mnuClose = new System.Windows.Forms.ToolStripMenuItem();
this.mnuView = new System.Windows.Forms.ToolStripMenuItem();
this.mnuAutoRefresh = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripMenuItem2 = new System.Windows.Forms.ToolStripSeparator();
this.mnuRefresh = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripSeparator();
this.mnuZoomIn = new System.Windows.Forms.ToolStripMenuItem();
this.mnuZoomOut = new System.Windows.Forms.ToolStripMenuItem();
this.tableLayoutPanel1.SuspendLayout();
this.tableLayoutPanel2.SuspendLayout();
this.ctrlMesenMenuStrip1.SuspendLayout();
this.SuspendLayout();
//
// picTilemap
//
this.picTilemap.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
this.picTilemap.Location = new System.Drawing.Point(0, 0);
this.picTilemap.Name = "picTilemap";
this.picTilemap.Size = new System.Drawing.Size(512, 512);
this.picTilemap.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
this.picTilemap.TabIndex = 0;
this.picTilemap.TabStop = false;
this.picTilemap.DoubleClick += new System.EventHandler(this.picTilemap_DoubleClick);
//
// ctrlScanlineCycleSelect
//
this.ctrlScanlineCycleSelect.Dock = System.Windows.Forms.DockStyle.Bottom;
@ -69,31 +66,20 @@
this.ctrlScanlineCycleSelect.Size = new System.Drawing.Size(737, 28);
this.ctrlScanlineCycleSelect.TabIndex = 5;
//
// pnlTilemap
//
this.pnlTilemap.AutoScroll = true;
this.pnlTilemap.Controls.Add(this.picTilemap);
this.pnlTilemap.Dock = System.Windows.Forms.DockStyle.Fill;
this.pnlTilemap.Location = new System.Drawing.Point(3, 3);
this.pnlTilemap.MinimumSize = new System.Drawing.Size(512, 512);
this.pnlTilemap.Name = "pnlTilemap";
this.pnlTilemap.Size = new System.Drawing.Size(531, 540);
this.pnlTilemap.TabIndex = 6;
//
// tableLayoutPanel1
//
this.tableLayoutPanel1.ColumnCount = 2;
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F));
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle());
this.tableLayoutPanel1.Controls.Add(this.pnlTilemap, 0, 0);
this.tableLayoutPanel1.Controls.Add(this.tableLayoutPanel2, 1, 0);
this.tableLayoutPanel1.Controls.Add(this.ctrlImagePanel, 0, 0);
this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill;
this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 0);
this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 24);
this.tableLayoutPanel1.Name = "tableLayoutPanel1";
this.tableLayoutPanel1.RowCount = 1;
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F));
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
this.tableLayoutPanel1.Size = new System.Drawing.Size(737, 546);
this.tableLayoutPanel1.Size = new System.Drawing.Size(737, 522);
this.tableLayoutPanel1.TabIndex = 7;
//
// tableLayoutPanel2
@ -320,6 +306,99 @@
this.ctrlPaletteViewer.TabIndex = 12;
this.ctrlPaletteViewer.SelectionChanged += new Mesen.GUI.Debugger.ctrlPaletteViewer.SelectionChangedHandler(this.ctrlPaletteViewer_SelectionChanged);
//
// ctrlImagePanel
//
this.ctrlImagePanel.Dock = System.Windows.Forms.DockStyle.Fill;
this.ctrlImagePanel.Image = null;
this.ctrlImagePanel.ImageScale = 1;
this.ctrlImagePanel.ImageSize = new System.Drawing.Size(0, 0);
this.ctrlImagePanel.Location = new System.Drawing.Point(3, 3);
this.ctrlImagePanel.Name = "ctrlImagePanel";
this.ctrlImagePanel.Selection = new System.Drawing.Rectangle(0, 0, 0, 0);
this.ctrlImagePanel.Size = new System.Drawing.Size(531, 516);
this.ctrlImagePanel.TabIndex = 8;
//
// ctrlMesenMenuStrip1
//
this.ctrlMesenMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.mnuFile,
this.mnuView});
this.ctrlMesenMenuStrip1.Location = new System.Drawing.Point(0, 0);
this.ctrlMesenMenuStrip1.Name = "ctrlMesenMenuStrip1";
this.ctrlMesenMenuStrip1.Size = new System.Drawing.Size(737, 24);
this.ctrlMesenMenuStrip1.TabIndex = 9;
this.ctrlMesenMenuStrip1.Text = "ctrlMesenMenuStrip1";
//
// mnuFile
//
this.mnuFile.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.mnuClose});
this.mnuFile.Name = "mnuFile";
this.mnuFile.Size = new System.Drawing.Size(37, 20);
this.mnuFile.Text = "File";
//
// mnuClose
//
this.mnuClose.Image = global::Mesen.GUI.Properties.Resources.Exit;
this.mnuClose.Name = "mnuClose";
this.mnuClose.Size = new System.Drawing.Size(152, 22);
this.mnuClose.Text = "Close";
this.mnuClose.Click += new System.EventHandler(this.mnuClose_Click);
//
// mnuView
//
this.mnuView.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.mnuAutoRefresh,
this.toolStripMenuItem2,
this.mnuRefresh,
this.toolStripMenuItem1,
this.mnuZoomIn,
this.mnuZoomOut});
this.mnuView.Name = "mnuView";
this.mnuView.Size = new System.Drawing.Size(44, 20);
this.mnuView.Text = "View";
//
// mnuAutoRefresh
//
this.mnuAutoRefresh.Checked = true;
this.mnuAutoRefresh.CheckOnClick = true;
this.mnuAutoRefresh.CheckState = System.Windows.Forms.CheckState.Checked;
this.mnuAutoRefresh.Name = "mnuAutoRefresh";
this.mnuAutoRefresh.Size = new System.Drawing.Size(152, 22);
this.mnuAutoRefresh.Text = "Auto-refresh";
//
// toolStripMenuItem2
//
this.toolStripMenuItem2.Name = "toolStripMenuItem2";
this.toolStripMenuItem2.Size = new System.Drawing.Size(149, 6);
//
// mnuRefresh
//
this.mnuRefresh.Image = global::Mesen.GUI.Properties.Resources.Refresh;
this.mnuRefresh.Name = "mnuRefresh";
this.mnuRefresh.Size = new System.Drawing.Size(152, 22);
this.mnuRefresh.Text = "Refresh";
this.mnuRefresh.Click += new System.EventHandler(this.mnuRefresh_Click);
//
// toolStripMenuItem1
//
this.toolStripMenuItem1.Name = "toolStripMenuItem1";
this.toolStripMenuItem1.Size = new System.Drawing.Size(149, 6);
//
// mnuZoomIn
//
this.mnuZoomIn.Name = "mnuZoomIn";
this.mnuZoomIn.Size = new System.Drawing.Size(152, 22);
this.mnuZoomIn.Text = "Zoom In";
this.mnuZoomIn.Click += new System.EventHandler(this.mnuZoomIn_Click);
//
// mnuZoomOut
//
this.mnuZoomOut.Name = "mnuZoomOut";
this.mnuZoomOut.Size = new System.Drawing.Size(152, 22);
this.mnuZoomOut.Text = "Zoom Out";
this.mnuZoomOut.Click += new System.EventHandler(this.mnuZoomOut_Click);
//
// frmTileViewer
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@ -327,22 +406,21 @@
this.ClientSize = new System.Drawing.Size(737, 574);
this.Controls.Add(this.tableLayoutPanel1);
this.Controls.Add(this.ctrlScanlineCycleSelect);
this.Controls.Add(this.ctrlMesenMenuStrip1);
this.Name = "frmTileViewer";
this.Text = "Tile Viewer";
((System.ComponentModel.ISupportInitialize)(this.picTilemap)).EndInit();
this.pnlTilemap.ResumeLayout(false);
this.tableLayoutPanel1.ResumeLayout(false);
this.tableLayoutPanel2.ResumeLayout(false);
this.tableLayoutPanel2.PerformLayout();
this.ctrlMesenMenuStrip1.ResumeLayout(false);
this.ctrlMesenMenuStrip1.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private GUI.Controls.ctrlMesenPictureBox picTilemap;
private Controls.ctrlScanlineCycleSelect ctrlScanlineCycleSelect;
private System.Windows.Forms.Panel pnlTilemap;
private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1;
private System.Windows.Forms.TableLayoutPanel tableLayoutPanel2;
private System.Windows.Forms.CheckBox chkShowTileGrid;
@ -357,5 +435,16 @@
private GUI.Controls.MesenNumericUpDown nudOffset;
private Controls.ComboBoxWithSeparator cboMemoryType;
private ctrlPaletteViewer ctrlPaletteViewer;
private PpuViewer.ctrlImagePanel ctrlImagePanel;
private GUI.Controls.ctrlMesenMenuStrip ctrlMesenMenuStrip1;
private System.Windows.Forms.ToolStripMenuItem mnuFile;
private System.Windows.Forms.ToolStripMenuItem mnuClose;
private System.Windows.Forms.ToolStripMenuItem mnuView;
private System.Windows.Forms.ToolStripMenuItem mnuAutoRefresh;
private System.Windows.Forms.ToolStripSeparator toolStripMenuItem2;
private System.Windows.Forms.ToolStripMenuItem mnuRefresh;
private System.Windows.Forms.ToolStripSeparator toolStripMenuItem1;
private System.Windows.Forms.ToolStripMenuItem mnuZoomIn;
private System.Windows.Forms.ToolStripMenuItem mnuZoomOut;
}
}

View file

@ -1,4 +1,5 @@
using Mesen.GUI.Forms;
using Mesen.GUI.Config;
using Mesen.GUI.Forms;
using System;
using System.Collections.Generic;
using System.ComponentModel;
@ -21,7 +22,6 @@ namespace Mesen.GUI.Debugger
private byte[] _cgram;
private byte[] _tileSource;
private Bitmap _tileImage;
private bool _zoomed;
private SnesMemoryType _memoryType = SnesMemoryType.VideoRam;
private int _addressOffset = 0;
private DateTime _lastUpdate = DateTime.MinValue;
@ -45,7 +45,7 @@ namespace Mesen.GUI.Debugger
_tileData = new byte[512 * 512 * 4];
_tileImage = new Bitmap(512, 512, PixelFormat.Format32bppArgb);
picTilemap.Image = _tileImage;
ctrlImagePanel.Image = _tileImage;
ctrlScanlineCycleSelect.Initialize(241, 0);
@ -59,6 +59,15 @@ namespace Mesen.GUI.Debugger
InitMemoryTypeDropdown();
cboFormat.SetEnumValue(TileFormat.Bpp4);
ctrlPaletteViewer.SelectionMode = PaletteSelectionMode.SixteenColors;
InitShortcuts();
}
private void InitShortcuts()
{
mnuRefresh.InitShortcut(this, nameof(DebuggerShortcutsConfig.Refresh));
mnuZoomIn.InitShortcut(this, nameof(DebuggerShortcutsConfig.ZoomIn));
mnuZoomOut.InitShortcut(this, nameof(DebuggerShortcutsConfig.ZoomOut));
}
protected override void OnFormClosed(FormClosedEventArgs e)
@ -127,7 +136,7 @@ namespace Mesen.GUI.Debugger
if(_tileImage.Width != mapWidth || _tileImage.Height != mapHeight) {
_tileImage = new Bitmap(mapWidth, mapHeight, PixelFormat.Format32bppArgb);
picTilemap.Image = _tileImage;
ctrlImagePanel.Image = _tileImage;
}
using(Graphics g = Graphics.FromImage(_tileImage)) {
@ -141,7 +150,7 @@ namespace Mesen.GUI.Debugger
}
UpdateMapSize();
picTilemap.Invalidate();
ctrlImagePanel.Invalidate();
ctrlPaletteViewer.RefreshViewer();
}
@ -152,8 +161,7 @@ namespace Mesen.GUI.Debugger
int mapWidth = _options.Width * 8;
int mapHeight = tileCount / _options.Width * 8;
picTilemap.Width = _zoomed ? mapWidth * 2 : mapWidth;
picTilemap.Height = _zoomed ? mapHeight * 2 : mapHeight;
ctrlImagePanel.ImageSize = new Size(mapWidth, mapHeight);
}
private void InitMemoryTypeDropdown()
@ -170,12 +178,6 @@ namespace Mesen.GUI.Debugger
cboMemoryType.EndUpdate();
}
private void picTilemap_DoubleClick(object sender, EventArgs e)
{
_zoomed = !_zoomed;
UpdateMapSize();
}
private void chkShowTileGrid_Click(object sender, EventArgs e)
{
_options.ShowTileGrid = chkShowTileGrid.Checked;
@ -238,5 +240,26 @@ namespace Mesen.GUI.Debugger
_options.Palette = ctrlPaletteViewer.SelectedPalette;
RefreshViewer();
}
private void mnuRefresh_Click(object sender, EventArgs e)
{
RefreshData();
RefreshViewer();
}
private void mnuZoomIn_Click(object sender, EventArgs e)
{
ctrlImagePanel.ZoomIn();
}
private void mnuZoomOut_Click(object sender, EventArgs e)
{
ctrlImagePanel.ZoomOut();
}
private void mnuClose_Click(object sender, EventArgs e)
{
Close();
}
}
}

View file

@ -120,4 +120,7 @@
<metadata name="toolTip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="ctrlMesenMenuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>107, 17</value>
</metadata>
</root>

View file

@ -27,13 +27,11 @@
/// </summary>
private void InitializeComponent()
{
this.picTilemap = new Mesen.GUI.Debugger.PpuViewer.ctrlImageViewer();
this.btnLayer1 = new System.Windows.Forms.Button();
this.btnLayer2 = new System.Windows.Forms.Button();
this.btnLayer3 = new System.Windows.Forms.Button();
this.btnLayer4 = new System.Windows.Forms.Button();
this.ctrlScanlineCycleSelect = new Mesen.GUI.Debugger.Controls.ctrlScanlineCycleSelect();
this.pnlTilemap = new System.Windows.Forms.Panel();
this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
this.tableLayoutPanel2 = new System.Windows.Forms.TableLayoutPanel();
this.chkShowScrollOverlay = new System.Windows.Forms.CheckBox();
@ -69,6 +67,7 @@
this.txtBitDepth = new System.Windows.Forms.TextBox();
this.tableLayoutPanel3 = new System.Windows.Forms.TableLayoutPanel();
this.lblLayer = new System.Windows.Forms.Label();
this.ctrlImagePanel = new Mesen.GUI.Debugger.PpuViewer.ctrlImagePanel();
this.ctrlMesenMenuStrip1 = new Mesen.GUI.Controls.ctrlMesenMenuStrip();
this.mnuFile = new System.Windows.Forms.ToolStripMenuItem();
this.mnuClose = new System.Windows.Forms.ToolStripMenuItem();
@ -79,7 +78,6 @@
this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripSeparator();
this.mnuZoomIn = new System.Windows.Forms.ToolStripMenuItem();
this.mnuZoomOut = new System.Windows.Forms.ToolStripMenuItem();
this.pnlTilemap.SuspendLayout();
this.tableLayoutPanel1.SuspendLayout();
this.tableLayoutPanel2.SuspendLayout();
this.grpTileInfo.SuspendLayout();
@ -90,19 +88,6 @@
this.ctrlMesenMenuStrip1.SuspendLayout();
this.SuspendLayout();
//
// picTilemap
//
this.picTilemap.Image = null;
this.picTilemap.ImageScale = 1;
this.picTilemap.Location = new System.Drawing.Point(0, 0);
this.picTilemap.Margin = new System.Windows.Forms.Padding(0);
this.picTilemap.Name = "picTilemap";
this.picTilemap.Selection = new System.Drawing.Rectangle(0, 0, 0, 0);
this.picTilemap.Size = new System.Drawing.Size(512, 471);
this.picTilemap.TabIndex = 0;
this.picTilemap.TabStop = false;
this.picTilemap.MouseClick += new System.Windows.Forms.MouseEventHandler(this.picTilemap_MouseClick);
//
// btnLayer1
//
this.btnLayer1.BackColor = System.Drawing.SystemColors.ControlLight;
@ -159,24 +144,14 @@
this.ctrlScanlineCycleSelect.Size = new System.Drawing.Size(668, 28);
this.ctrlScanlineCycleSelect.TabIndex = 5;
//
// pnlTilemap
//
this.pnlTilemap.AutoScroll = true;
this.pnlTilemap.Controls.Add(this.picTilemap);
this.pnlTilemap.Dock = System.Windows.Forms.DockStyle.Fill;
this.pnlTilemap.Location = new System.Drawing.Point(3, 31);
this.pnlTilemap.Name = "pnlTilemap";
this.pnlTilemap.Size = new System.Drawing.Size(513, 474);
this.pnlTilemap.TabIndex = 6;
//
// tableLayoutPanel1
//
this.tableLayoutPanel1.ColumnCount = 2;
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F));
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle());
this.tableLayoutPanel1.Controls.Add(this.pnlTilemap, 0, 1);
this.tableLayoutPanel1.Controls.Add(this.tableLayoutPanel2, 1, 0);
this.tableLayoutPanel1.Controls.Add(this.tableLayoutPanel3, 0, 0);
this.tableLayoutPanel1.Controls.Add(this.ctrlImagePanel, 0, 1);
this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill;
this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 24);
this.tableLayoutPanel1.Name = "tableLayoutPanel1";
@ -583,6 +558,18 @@
this.lblLayer.TabIndex = 5;
this.lblLayer.Text = "Layer:";
//
// ctrlImagePanel
//
this.ctrlImagePanel.Dock = System.Windows.Forms.DockStyle.Fill;
this.ctrlImagePanel.Image = null;
this.ctrlImagePanel.ImageSize = new System.Drawing.Size(0, 0);
this.ctrlImagePanel.Location = new System.Drawing.Point(3, 31);
this.ctrlImagePanel.Name = "ctrlImagePanel";
this.ctrlImagePanel.Selection = new System.Drawing.Rectangle(0, 0, 0, 0);
this.ctrlImagePanel.Size = new System.Drawing.Size(513, 474);
this.ctrlImagePanel.TabIndex = 9;
this.ctrlImagePanel.MouseClick += new System.Windows.Forms.MouseEventHandler(this.ctrlImagePanel_MouseClick);
//
// ctrlMesenMenuStrip1
//
this.ctrlMesenMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
@ -675,7 +662,6 @@
this.MainMenuStrip = this.ctrlMesenMenuStrip1;
this.Name = "frmTilemapViewer";
this.Text = "Tilemap Viewer";
this.pnlTilemap.ResumeLayout(false);
this.tableLayoutPanel1.ResumeLayout(false);
this.tableLayoutPanel2.ResumeLayout(false);
this.tableLayoutPanel2.PerformLayout();
@ -695,14 +681,11 @@
}
#endregion
private Mesen.GUI.Debugger.PpuViewer.ctrlImageViewer picTilemap;
private System.Windows.Forms.Button btnLayer1;
private System.Windows.Forms.Button btnLayer2;
private System.Windows.Forms.Button btnLayer3;
private System.Windows.Forms.Button btnLayer4;
private Controls.ctrlScanlineCycleSelect ctrlScanlineCycleSelect;
private System.Windows.Forms.Panel pnlTilemap;
private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1;
private System.Windows.Forms.TableLayoutPanel tableLayoutPanel2;
private System.Windows.Forms.CheckBox chkShowTileGrid;
@ -748,5 +731,6 @@
private System.Windows.Forms.TextBox txtTileSize;
private System.Windows.Forms.TextBox txtTilesetAddress;
private System.Windows.Forms.TextBox txtBitDepth;
private PpuViewer.ctrlImagePanel ctrlImagePanel;
}
}

View file

@ -25,7 +25,6 @@ namespace Mesen.GUI.Debugger
private byte[] _vram;
private byte[] _tilemapData;
private Bitmap _tilemapImage;
private int _scale = 1;
private int _selectedRow = 0;
private int _selectedColumn = 0;
private DateTime _lastUpdate = DateTime.MinValue;
@ -49,7 +48,7 @@ namespace Mesen.GUI.Debugger
_tilemapData = new byte[1024 * 1024 * 4];
_tilemapImage = new Bitmap(1024, 1024, PixelFormat.Format32bppArgb);
picTilemap.Image = _tilemapImage;
ctrlImagePanel.Image = _tilemapImage;
ctrlScanlineCycleSelect.Initialize(241, 0);
@ -162,7 +161,7 @@ namespace Mesen.GUI.Debugger
int mapHeight = GetHeight();
if(_tilemapImage.Width != mapWidth || _tilemapImage.Height != mapHeight) {
_tilemapImage = new Bitmap(mapWidth, mapHeight, PixelFormat.Format32bppArgb);
picTilemap.Image = _tilemapImage;
ctrlImagePanel.Image = _tilemapImage;
}
using(Graphics g = Graphics.FromImage(_tilemapImage)) {
GCHandle handle = GCHandle.Alloc(_tilemapData, GCHandleType.Pinned);
@ -181,20 +180,12 @@ namespace Mesen.GUI.Debugger
btnLayer3.Enabled = _layerBpp[_state.Ppu.BgMode, 2] > 0;
btnLayer4.Enabled = _layerBpp[_state.Ppu.BgMode, 3] > 0;
UpdateMapSize();
picTilemap.Selection = new Rectangle(_selectedColumn * 8, _selectedRow * 8, IsLargeTileWidth ? 16 : 8, IsLargeTileHeight ? 16 : 8);
picTilemap.Invalidate();
ctrlImagePanel.ImageSize = new Size(GetWidth(), GetHeight());
ctrlImagePanel.Selection = new Rectangle(_selectedColumn * 8, _selectedRow * 8, IsLargeTileWidth ? 16 : 8, IsLargeTileHeight ? 16 : 8);
UpdateFields();
}
private void UpdateMapSize()
{
picTilemap.ImageScale = _scale;
picTilemap.Width = GetWidth() * _scale;
picTilemap.Height = GetHeight() * _scale;
}
private void UpdateFields()
{
if(_state.Ppu.BgMode == 7) {
@ -292,14 +283,12 @@ namespace Mesen.GUI.Debugger
private void mnuZoomIn_Click(object sender, EventArgs e)
{
_scale = Math.Min(8, _scale + 1);
UpdateMapSize();
ctrlImagePanel.ZoomIn();
}
private void mnuZoomOut_Click(object sender, EventArgs e)
{
_scale = Math.Max(1, _scale - 1);
UpdateMapSize();
ctrlImagePanel.ZoomOut();
}
private void mnuClose_Click(object sender, EventArgs e)
@ -307,10 +296,10 @@ namespace Mesen.GUI.Debugger
Close();
}
private void picTilemap_MouseClick(object sender, MouseEventArgs e)
private void ctrlImagePanel_MouseClick(object sender, MouseEventArgs e)
{
_selectedColumn = e.X / (8 * _scale);
_selectedRow = e.Y / (8 * _scale);
_selectedColumn = e.X / (8 * ctrlImagePanel.ImageScale);
_selectedRow = e.Y / (8 * ctrlImagePanel.ImageScale);
if(IsLargeTileWidth) {
_selectedColumn &= 0xFE;

View file

@ -252,6 +252,9 @@
<Compile Include="Debugger\Code\IDisassemblyManager.cs" />
<Compile Include="Debugger\Config\DebuggerShortcutsConfig.cs" />
<Compile Include="Debugger\Config\DebuggerInfo.cs" />
<Compile Include="Debugger\Controls\ctrlPanel.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="Debugger\Controls\ctrlPpuStatus.cs">
<SubType>UserControl</SubType>
</Compile>
@ -276,6 +279,12 @@
<Compile Include="Debugger\frmBreakOn.Designer.cs">
<DependentUpon>frmBreakOn.cs</DependentUpon>
</Compile>
<Compile Include="Debugger\PpuViewer\ctrlImagePanel.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="Debugger\PpuViewer\ctrlImagePanel.Designer.cs">
<DependentUpon>ctrlImagePanel.cs</DependentUpon>
</Compile>
<Compile Include="Debugger\PpuViewer\ctrlImageViewer.cs">
<SubType>Component</SubType>
</Compile>
@ -793,6 +802,9 @@
<EmbeddedResource Include="Debugger\MemoryTools\frmMemoryViewerColors.resx">
<DependentUpon>frmMemoryViewerColors.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Debugger\PpuViewer\ctrlImagePanel.resx">
<DependentUpon>ctrlImagePanel.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Debugger\PpuViewer\ctrlPaletteViewer.resx">
<DependentUpon>ctrlPaletteViewer.cs</DependentUpon>
</EmbeddedResource>