Debugger: PPU Viewer - Added options to display/copy hex/rgb color codes in all tabs

This commit is contained in:
Sour 2018-06-24 18:30:31 -04:00
parent 0aa365ebcc
commit a38e33f189
6 changed files with 228 additions and 37 deletions

View File

@ -27,6 +27,7 @@
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.grpColorInfo = new System.Windows.Forms.GroupBox();
this.tableLayoutPanel4 = new System.Windows.Forms.TableLayoutPanel();
this.txtPaletteAddress = new System.Windows.Forms.TextBox();
@ -35,11 +36,18 @@
this.lblColorTile = new System.Windows.Forms.Label();
this.txtColor = new System.Windows.Forms.TextBox();
this.picColor = new System.Windows.Forms.PictureBox();
this.lblColorHex = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.txtColorCodeHex = new System.Windows.Forms.TextBox();
this.txtColorCodeRgb = new System.Windows.Forms.TextBox();
this.tableLayoutPanel3 = new System.Windows.Forms.TableLayoutPanel();
this.picPalette = new System.Windows.Forms.PictureBox();
this.flowLayoutPanel1 = new System.Windows.Forms.FlowLayoutPanel();
this.picHelp = new System.Windows.Forms.PictureBox();
this.lblClickColorHint = new System.Windows.Forms.Label();
this.ctxMenu = new System.Windows.Forms.ContextMenuStrip(this.components);
this.mnuCopyHexColor = new System.Windows.Forms.ToolStripMenuItem();
this.mnuCopyRgbColor = new System.Windows.Forms.ToolStripMenuItem();
this.grpColorInfo.SuspendLayout();
this.tableLayoutPanel4.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.picColor)).BeginInit();
@ -47,6 +55,7 @@
((System.ComponentModel.ISupportInitialize)(this.picPalette)).BeginInit();
this.flowLayoutPanel1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.picHelp)).BeginInit();
this.ctxMenu.SuspendLayout();
this.SuspendLayout();
//
// grpColorInfo
@ -72,23 +81,27 @@
this.tableLayoutPanel4.Controls.Add(this.lblColorTile, 0, 2);
this.tableLayoutPanel4.Controls.Add(this.txtColor, 1, 0);
this.tableLayoutPanel4.Controls.Add(this.picColor, 1, 2);
this.tableLayoutPanel4.Controls.Add(this.lblColorHex, 0, 3);
this.tableLayoutPanel4.Controls.Add(this.label1, 0, 4);
this.tableLayoutPanel4.Controls.Add(this.txtColorCodeHex, 1, 3);
this.tableLayoutPanel4.Controls.Add(this.txtColorCodeRgb, 1, 4);
this.tableLayoutPanel4.Dock = System.Windows.Forms.DockStyle.Fill;
this.tableLayoutPanel4.Location = new System.Drawing.Point(3, 16);
this.tableLayoutPanel4.Name = "tableLayoutPanel4";
this.tableLayoutPanel4.RowCount = 4;
this.tableLayoutPanel4.RowCount = 6;
this.tableLayoutPanel4.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tableLayoutPanel4.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tableLayoutPanel4.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tableLayoutPanel4.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tableLayoutPanel4.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tableLayoutPanel4.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F));
this.tableLayoutPanel4.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
this.tableLayoutPanel4.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
this.tableLayoutPanel4.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
this.tableLayoutPanel4.Size = new System.Drawing.Size(532, 286);
this.tableLayoutPanel4.TabIndex = 0;
//
// txtPaletteAddress
//
this.txtPaletteAddress.Location = new System.Drawing.Point(93, 29);
this.txtPaletteAddress.BackColor = System.Drawing.SystemColors.ControlLightLight;
this.txtPaletteAddress.Location = new System.Drawing.Point(103, 29);
this.txtPaletteAddress.Name = "txtPaletteAddress";
this.txtPaletteAddress.ReadOnly = true;
this.txtPaletteAddress.Size = new System.Drawing.Size(42, 20);
@ -126,7 +139,8 @@
//
// txtColor
//
this.txtColor.Location = new System.Drawing.Point(93, 3);
this.txtColor.BackColor = System.Drawing.SystemColors.ControlLightLight;
this.txtColor.Location = new System.Drawing.Point(103, 3);
this.txtColor.Name = "txtColor";
this.txtColor.ReadOnly = true;
this.txtColor.Size = new System.Drawing.Size(26, 20);
@ -135,13 +149,51 @@
// picColor
//
this.picColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.picColor.Location = new System.Drawing.Point(93, 55);
this.picColor.Location = new System.Drawing.Point(103, 55);
this.picColor.Name = "picColor";
this.picColor.Size = new System.Drawing.Size(66, 66);
this.picColor.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
this.picColor.TabIndex = 12;
this.picColor.TabStop = false;
//
// lblColorHex
//
this.lblColorHex.Anchor = System.Windows.Forms.AnchorStyles.Left;
this.lblColorHex.AutoSize = true;
this.lblColorHex.Location = new System.Drawing.Point(3, 130);
this.lblColorHex.Name = "lblColorHex";
this.lblColorHex.Size = new System.Drawing.Size(90, 13);
this.lblColorHex.TabIndex = 13;
this.lblColorHex.Text = "Color Code (Hex):";
//
// label1
//
this.label1.Anchor = System.Windows.Forms.AnchorStyles.Left;
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(3, 156);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(94, 13);
this.label1.TabIndex = 14;
this.label1.Text = "Color Code (RGB):";
//
// txtColorCodeHex
//
this.txtColorCodeHex.BackColor = System.Drawing.SystemColors.ControlLightLight;
this.txtColorCodeHex.Location = new System.Drawing.Point(103, 127);
this.txtColorCodeHex.Name = "txtColorCodeHex";
this.txtColorCodeHex.ReadOnly = true;
this.txtColorCodeHex.Size = new System.Drawing.Size(66, 20);
this.txtColorCodeHex.TabIndex = 15;
//
// txtColorCodeRgb
//
this.txtColorCodeRgb.BackColor = System.Drawing.SystemColors.ControlLightLight;
this.txtColorCodeRgb.Location = new System.Drawing.Point(103, 153);
this.txtColorCodeRgb.Name = "txtColorCodeRgb";
this.txtColorCodeRgb.ReadOnly = true;
this.txtColorCodeRgb.Size = new System.Drawing.Size(108, 20);
this.txtColorCodeRgb.TabIndex = 16;
//
// tableLayoutPanel3
//
this.tableLayoutPanel3.ColumnCount = 3;
@ -163,6 +215,7 @@
// picPalette
//
this.picPalette.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.picPalette.ContextMenuStrip = this.ctxMenu;
this.picPalette.Cursor = System.Windows.Forms.Cursors.Hand;
this.picPalette.Location = new System.Drawing.Point(4, 4);
this.picPalette.Margin = new System.Windows.Forms.Padding(4);
@ -203,6 +256,27 @@
this.lblClickColorHint.TabIndex = 5;
this.lblClickColorHint.Text = "Click on a color to change it";
//
// ctxMenu
//
this.ctxMenu.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.mnuCopyHexColor,
this.mnuCopyRgbColor});
this.ctxMenu.Name = "ctxMenu";
this.ctxMenu.Size = new System.Drawing.Size(160, 70);
this.ctxMenu.Opening += new System.ComponentModel.CancelEventHandler(this.ctxMenu_Opening);
//
// mnuCopyHexColor
//
this.mnuCopyHexColor.Name = "mnuCopyHexColor";
this.mnuCopyHexColor.Size = new System.Drawing.Size(159, 22);
this.mnuCopyHexColor.Text = "Copy Hex Color";
//
// mnuCopyRgbColor
//
this.mnuCopyRgbColor.Name = "mnuCopyRgbColor";
this.mnuCopyRgbColor.Size = new System.Drawing.Size(159, 22);
this.mnuCopyRgbColor.Text = "Copy RGB Color";
//
// ctrlPaletteViewer
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@ -219,6 +293,7 @@
((System.ComponentModel.ISupportInitialize)(this.picPalette)).EndInit();
this.flowLayoutPanel1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.picHelp)).EndInit();
this.ctxMenu.ResumeLayout(false);
this.ResumeLayout(false);
}
@ -238,5 +313,12 @@
private System.Windows.Forms.Label lblClickColorHint;
private System.Windows.Forms.FlowLayoutPanel flowLayoutPanel1;
private System.Windows.Forms.PictureBox picHelp;
private System.Windows.Forms.Label lblColorHex;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox txtColorCodeHex;
private System.Windows.Forms.TextBox txtColorCodeRgb;
private System.Windows.Forms.ContextMenuStrip ctxMenu;
private System.Windows.Forms.ToolStripMenuItem mnuCopyHexColor;
private System.Windows.Forms.ToolStripMenuItem mnuCopyRgbColor;
}
}

View File

@ -32,8 +32,6 @@ namespace Mesen.GUI.Debugger.Controls
public void RefreshViewer()
{
_paletteIndex = -1;
GCHandle handle = GCHandle.Alloc(this._palettePixelData, GCHandleType.Pinned);
try {
Bitmap source = new Bitmap(4, 8, 4*4, System.Drawing.Imaging.PixelFormat.Format32bppArgb, handle.AddrOfPinnedObject());
@ -60,6 +58,10 @@ namespace Mesen.GUI.Debugger.Controls
} finally {
handle.Free();
}
if(_paletteIndex == -1) {
UpdateColorInformation(0);
}
}
private void picPalette_MouseMove(object sender, MouseEventArgs e)
@ -67,38 +69,79 @@ namespace Mesen.GUI.Debugger.Controls
int tileX = Math.Min(e.X * 128 / (picPalette.Width - 2) / 32, 31);
int tileY = Math.Min(e.Y * 256 / (picPalette.Height - 2) / 32, 31);
int tileIndex = tileY * 4 + tileX;
int paletteIndex = tileY * 4 + tileX;
if(tileIndex != _paletteIndex) {
_paletteIndex = tileIndex;
this.txtColor.Text = _paletteRam[tileIndex].ToString("X2");
this.txtPaletteAddress.Text = (0x3F00 + tileIndex).ToString("X4");
Bitmap tile = new Bitmap(64, 64);
using(Graphics g = Graphics.FromImage(tile)) {
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.None;
g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.Half;
g.DrawImage(picPalette.Image, new Rectangle(0, 0, 64, 64), new Rectangle(tileX*32, tileY*32, 32, 32), GraphicsUnit.Pixel);
}
this.picColor.Image = tile;
if(paletteIndex != _paletteIndex) {
UpdateColorInformation(paletteIndex);
}
}
private void UpdateColorInformation(int paletteIndex)
{
int tileX = paletteIndex % 4;
int tileY = paletteIndex / 4;
_paletteIndex = paletteIndex;
this.txtColor.Text = _paletteRam[paletteIndex].ToString("X2");
this.txtPaletteAddress.Text = (0x3F00 + paletteIndex).ToString("X4");
Color selectedColor = Color.FromArgb(_palettePixelData[paletteIndex]);
this.txtColorCodeHex.Text = GetHexColorString();
this.txtColorCodeRgb.Text = GetRgbColorString();
Bitmap tile = new Bitmap(64, 64);
using(Graphics g = Graphics.FromImage(tile)) {
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.None;
g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.Half;
g.DrawImage(picPalette.Image, new Rectangle(0, 0, 64, 64), new Rectangle(tileX * 32, tileY * 32, 32, 32), GraphicsUnit.Pixel);
}
this.picColor.Image = tile;
}
private void picPalette_MouseDown(object sender, MouseEventArgs e)
{
using(frmSelectColor frm = new frmSelectColor()) {
if(frm.ShowDialog(this) == DialogResult.OK) {
int x = Math.Min(e.X * 128 / picPalette.Width / 32, 31);
int y = Math.Min(e.Y * 256 / picPalette.Height / 32, 31);
int colorAddress = y * 4 + x;
if(e.Button == MouseButtons.Left) {
using(frmSelectColor frm = new frmSelectColor()) {
if(frm.ShowDialog(this) == DialogResult.OK) {
int x = Math.Min(e.X * 128 / picPalette.Width / 32, 31);
int y = Math.Min(e.Y * 256 / picPalette.Height / 32, 31);
int colorAddress = y * 4 + x;
InteropEmu.DebugSetMemoryValue(DebugMemoryType.PaletteMemory, (uint)colorAddress, (byte)frm.ColorIndex);
this.GetData();
this.RefreshViewer();
InteropEmu.DebugSetMemoryValue(DebugMemoryType.PaletteMemory, (uint)colorAddress, (byte)frm.ColorIndex);
this.GetData();
this.RefreshViewer();
this.UpdateColorInformation(this._paletteIndex);
}
}
}
}
private string GetHexColorString()
{
return "#" + _palettePixelData[_paletteIndex].ToString("X8").Substring(2, 6);
}
private string GetRgbColorString()
{
Color selectedColor = Color.FromArgb(_palettePixelData[_paletteIndex]);
return "rgb(" + selectedColor.R.ToString() + ", " + selectedColor.G.ToString() + ", " + selectedColor.B.ToString() + ")";
}
private void ctxMenu_Opening(object sender, CancelEventArgs e)
{
mnuCopyHexColor.Text = "Copy Hex Color - " + GetHexColorString();
mnuCopyRgbColor.Text = "Copy RGB Color - " + GetRgbColorString();
}
private void mnuCopyHexColor_Click(object sender, EventArgs e)
{
Clipboard.SetText(GetHexColorString());
}
private void mnuCopyRgbColor_Click(object sender, EventArgs e)
{
Clipboard.SetText(GetRgbColorString());
}
}
}

View File

@ -117,4 +117,7 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="ctxMenu.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>

View File

@ -27,13 +27,19 @@
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.picPaletteSelection = new System.Windows.Forms.PictureBox();
this.ctxMenu = new System.Windows.Forms.ContextMenuStrip(this.components);
this.mnuCopyHexColor = new System.Windows.Forms.ToolStripMenuItem();
this.mnuCopyRgbColor = new System.Windows.Forms.ToolStripMenuItem();
((System.ComponentModel.ISupportInitialize)(this.picPaletteSelection)).BeginInit();
this.ctxMenu.SuspendLayout();
this.SuspendLayout();
//
// picPaletteSelection
//
this.picPaletteSelection.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.picPaletteSelection.ContextMenuStrip = this.ctxMenu;
this.picPaletteSelection.Dock = System.Windows.Forms.DockStyle.Fill;
this.picPaletteSelection.Location = new System.Drawing.Point(0, 0);
this.picPaletteSelection.Name = "picPaletteSelection";
@ -45,6 +51,29 @@
this.picPaletteSelection.MouseLeave += new System.EventHandler(this.picPaletteSelection_MouseLeave);
this.picPaletteSelection.MouseMove += new System.Windows.Forms.MouseEventHandler(this.picPaletteSelection_MouseMove);
//
// ctxMenu
//
this.ctxMenu.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.mnuCopyHexColor,
this.mnuCopyRgbColor});
this.ctxMenu.Name = "ctxMenu";
this.ctxMenu.Size = new System.Drawing.Size(160, 70);
this.ctxMenu.Opening += new System.ComponentModel.CancelEventHandler(this.ctxMenu_Opening);
//
// mnuCopyHexColor
//
this.mnuCopyHexColor.Name = "mnuCopyHexColor";
this.mnuCopyHexColor.Size = new System.Drawing.Size(159, 22);
this.mnuCopyHexColor.Text = "Copy Hex Color";
this.mnuCopyHexColor.Click += new System.EventHandler(this.mnuCopyHexColor_Click);
//
// mnuCopyRgbColor
//
this.mnuCopyRgbColor.Name = "mnuCopyRgbColor";
this.mnuCopyRgbColor.Size = new System.Drawing.Size(159, 22);
this.mnuCopyRgbColor.Text = "Copy RGB Color";
this.mnuCopyRgbColor.Click += new System.EventHandler(this.mnuCopyRgbColor_Click);
//
// ctrlTilePalette
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@ -53,6 +82,7 @@
this.Name = "ctrlTilePalette";
this.Size = new System.Drawing.Size(130, 34);
((System.ComponentModel.ISupportInitialize)(this.picPaletteSelection)).EndInit();
this.ctxMenu.ResumeLayout(false);
this.ResumeLayout(false);
}
@ -60,5 +90,8 @@
#endregion
private System.Windows.Forms.PictureBox picPaletteSelection;
private System.Windows.Forms.ContextMenuStrip ctxMenu;
private System.Windows.Forms.ToolStripMenuItem mnuCopyHexColor;
private System.Windows.Forms.ToolStripMenuItem mnuCopyRgbColor;
}
}

View File

@ -20,7 +20,8 @@ namespace Mesen.GUI.Debugger.Controls
private bool _allowSelection = false;
private int _hoverColor = -1;
private int _selectedColor = 0;
private int[] _currentPalette = new int[4];
public bool HighlightMouseOver { get; set; }
public bool DisplayIndexes { get; set; }
@ -99,24 +100,23 @@ namespace Mesen.GUI.Debugger.Controls
return;
}
int[] currentPalette = new int[4];
int[] paletteColorCodes = new int[4];
if(_paletteColors.HasValue) {
int[] paletteData = InteropEmu.GetRgbPalette();
for(int i = 0; i < 4; i++) {
paletteColorCodes[i] = (int)(_paletteColors.Value >> (8 * i)) & 0x3F;
currentPalette[i] = paletteData[paletteColorCodes[i]];
_currentPalette[i] = paletteData[paletteColorCodes[i]];
}
} else {
byte[] paletteRam = InteropEmu.DebugGetMemoryState(DebugMemoryType.PaletteMemory);
int[] palette = InteropEmu.DebugGetPalette();
Array.Copy(palette, _selectedPalette * 4, currentPalette, 0, 4);
Array.Copy(palette, _selectedPalette * 4, _currentPalette, 0, 4);
for(int i = 0; i < 4; i++) {
paletteColorCodes[i] = paletteRam[_selectedPalette * 4 + i];
}
}
GCHandle handle = GCHandle.Alloc(currentPalette, GCHandleType.Pinned);
GCHandle handle = GCHandle.Alloc(_currentPalette, GCHandleType.Pinned);
try {
Bitmap source = new Bitmap(4, 1, 4*4, System.Drawing.Imaging.PixelFormat.Format32bppArgb, handle.AddrOfPinnedObject());
Bitmap target = new Bitmap(128, 32);
@ -175,5 +175,32 @@ namespace Mesen.GUI.Debugger.Controls
_hoverColor = -1;
RefreshPalette();
}
private string GetHexColorString()
{
return "#" + _currentPalette[this.SelectedColor].ToString("X8").Substring(2, 6);
}
private string GetRgbColorString()
{
Color selectedColor = Color.FromArgb(_currentPalette[this.SelectedColor]);
return "rgb(" + selectedColor.R.ToString() + ", " + selectedColor.G.ToString() + ", " + selectedColor.B.ToString() + ")";
}
private void ctxMenu_Opening(object sender, CancelEventArgs e)
{
mnuCopyHexColor.Text = "Copy Hex Color - " + GetHexColorString();
mnuCopyRgbColor.Text = "Copy RGB Color - " + GetRgbColorString();
}
private void mnuCopyHexColor_Click(object sender, EventArgs e)
{
Clipboard.SetText(GetHexColorString());
}
private void mnuCopyRgbColor_Click(object sender, EventArgs e)
{
Clipboard.SetText(GetRgbColorString());
}
}
}

View File

@ -117,4 +117,7 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="ctxMenu.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>