2015-08-08 22:36:39 -04:00
|
|
|
|
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 System.Runtime.InteropServices;
|
2016-12-11 14:25:29 -05:00
|
|
|
|
using Mesen.GUI.Controls;
|
2017-08-14 20:50:13 -04:00
|
|
|
|
using Mesen.GUI.Forms;
|
2015-08-08 22:36:39 -04:00
|
|
|
|
|
|
|
|
|
namespace Mesen.GUI.Debugger.Controls
|
|
|
|
|
{
|
2016-12-11 14:25:29 -05:00
|
|
|
|
public partial class ctrlPaletteViewer : BaseControl
|
2015-08-08 22:36:39 -04:00
|
|
|
|
{
|
|
|
|
|
private byte[] _paletteRam;
|
2017-08-15 22:01:54 -04:00
|
|
|
|
private int[] _palettePixelData;
|
2017-03-24 12:14:33 -04:00
|
|
|
|
private int _paletteIndex = -1;
|
2015-08-08 22:36:39 -04:00
|
|
|
|
|
|
|
|
|
public ctrlPaletteViewer()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
}
|
2018-02-16 17:36:37 -05:00
|
|
|
|
|
2016-11-26 20:44:23 -05:00
|
|
|
|
public void GetData()
|
2015-08-08 22:36:39 -04:00
|
|
|
|
{
|
|
|
|
|
this._paletteRam = InteropEmu.DebugGetMemoryState(DebugMemoryType.PaletteMemory);
|
2016-11-26 20:44:23 -05:00
|
|
|
|
this._palettePixelData = InteropEmu.DebugGetPalette();
|
|
|
|
|
}
|
2015-08-08 22:36:39 -04:00
|
|
|
|
|
2016-11-26 20:44:23 -05:00
|
|
|
|
public void RefreshViewer()
|
|
|
|
|
{
|
|
|
|
|
GCHandle handle = GCHandle.Alloc(this._palettePixelData, GCHandleType.Pinned);
|
2015-08-08 22:36:39 -04:00
|
|
|
|
try {
|
|
|
|
|
Bitmap source = new Bitmap(4, 8, 4*4, System.Drawing.Imaging.PixelFormat.Format32bppArgb, handle.AddrOfPinnedObject());
|
|
|
|
|
Bitmap target = new Bitmap(128, 256);
|
|
|
|
|
|
|
|
|
|
using(Graphics g = Graphics.FromImage(target)) {
|
|
|
|
|
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
|
|
|
|
|
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.None;
|
|
|
|
|
g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.Half;
|
2016-12-13 22:19:18 -05:00
|
|
|
|
g.ScaleTransform(32, 32);
|
|
|
|
|
g.DrawImageUnscaled(source, 0, 0);
|
2017-08-14 20:50:13 -04:00
|
|
|
|
|
2017-12-29 11:05:43 -05:00
|
|
|
|
g.ResetTransform();
|
2017-09-16 22:02:05 -04:00
|
|
|
|
Font font = new Font(BaseControl.MonospaceFontFamily, BaseControl.DefaultFontSize - 2, GraphicsUnit.Pixel);
|
2017-08-14 20:50:13 -04:00
|
|
|
|
using(Brush bg = new SolidBrush(Color.FromArgb(150, Color.LightGray))) {
|
|
|
|
|
for(int y = 0; y < 8; y++) {
|
|
|
|
|
for(int x = 0; x < 4; x++) {
|
|
|
|
|
g.DrawOutlinedString(_paletteRam[y*4+x].ToString("X2"), font, Brushes.Black, bg, 32*x+14, 32*y+18);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-08-08 22:36:39 -04:00
|
|
|
|
}
|
|
|
|
|
this.picPalette.Image = target;
|
|
|
|
|
} finally {
|
|
|
|
|
handle.Free();
|
|
|
|
|
}
|
2018-06-24 18:30:31 -04:00
|
|
|
|
|
2019-01-14 22:48:57 -05:00
|
|
|
|
this.picPalette.Refresh();
|
|
|
|
|
|
2018-06-24 18:30:31 -04:00
|
|
|
|
if(_paletteIndex == -1) {
|
|
|
|
|
UpdateColorInformation(0);
|
|
|
|
|
}
|
2015-08-08 22:36:39 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void picPalette_MouseMove(object sender, MouseEventArgs e)
|
|
|
|
|
{
|
2017-09-28 20:34:14 -04:00
|
|
|
|
int tileX = Math.Min(e.X * 128 / (picPalette.Width - 2) / 32, 31);
|
|
|
|
|
int tileY = Math.Min(e.Y * 256 / (picPalette.Height - 2) / 32, 31);
|
2017-03-24 12:14:33 -04:00
|
|
|
|
|
2018-06-24 18:30:31 -04:00
|
|
|
|
int paletteIndex = tileY * 4 + tileX;
|
2015-08-08 22:36:39 -04:00
|
|
|
|
|
2018-06-24 18:30:31 -04:00
|
|
|
|
if(paletteIndex != _paletteIndex) {
|
|
|
|
|
UpdateColorInformation(paletteIndex);
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-08-08 22:36:39 -04:00
|
|
|
|
|
2018-06-24 18:30:31 -04:00
|
|
|
|
private void UpdateColorInformation(int paletteIndex)
|
|
|
|
|
{
|
|
|
|
|
int tileX = paletteIndex % 4;
|
|
|
|
|
int tileY = paletteIndex / 4;
|
|
|
|
|
_paletteIndex = paletteIndex;
|
2017-03-24 12:14:33 -04:00
|
|
|
|
|
2018-06-24 18:30:31 -04:00
|
|
|
|
this.txtColor.Text = _paletteRam[paletteIndex].ToString("X2");
|
|
|
|
|
this.txtPaletteAddress.Text = (0x3F00 + paletteIndex).ToString("X4");
|
|
|
|
|
|
|
|
|
|
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);
|
2015-08-08 22:36:39 -04:00
|
|
|
|
}
|
2018-06-24 18:30:31 -04:00
|
|
|
|
this.picColor.Image = tile;
|
2015-08-08 22:36:39 -04:00
|
|
|
|
}
|
2017-08-14 20:50:13 -04:00
|
|
|
|
|
|
|
|
|
private void picPalette_MouseDown(object sender, MouseEventArgs e)
|
|
|
|
|
{
|
2018-06-24 18:30:31 -04:00
|
|
|
|
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();
|
|
|
|
|
this.UpdateColorInformation(this._paletteIndex);
|
|
|
|
|
}
|
2017-08-14 20:50:13 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-06-24 18:30:31 -04:00
|
|
|
|
|
|
|
|
|
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());
|
|
|
|
|
}
|
2015-08-08 22:36:39 -04:00
|
|
|
|
}
|
|
|
|
|
}
|