Mesen-SX/UI/Debugger/PpuViewer/frmPaletteViewer.cs

77 lines
1.9 KiB
C#
Raw Normal View History

2019-03-16 16:38:28 -04:00
using Mesen.GUI.Forms;
using System;
using System.Windows.Forms;
namespace Mesen.GUI.Debugger
{
public partial class frmPaletteViewer : BaseForm
{
private NotificationListener _notifListener;
public frmPaletteViewer()
{
InitializeComponent();
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
if(DesignMode) {
return;
}
_notifListener = new NotificationListener();
_notifListener.OnNotification += OnNotificationReceived;
ctrlScanlineCycleSelect.Initialize(241, 0);
2019-03-23 15:39:21 -04:00
ctrlPaletteViewer.RefreshData();
ctrlPaletteViewer.RefreshViewer();
2019-03-16 16:38:28 -04:00
}
private void UpdateFields()
{
int index = ctrlPaletteViewer.SelectedPalette;
byte[] cgram = ctrlPaletteViewer.CgRam;
int color = (cgram[index * 2] | (cgram[index * 2 + 1] << 8));
txtIndex.Text = index.ToString();
txtValue.Text = color.ToString("X4");
txtR.Text = (color & 0x1F).ToString();
txtG.Text = ((color >> 5) & 0x1F).ToString();
txtB.Text = ((color >> 10) & 0x1F).ToString();
txtRgb.Text = (ctrlPaletteViewer.ToArgb(color) & 0xFFFFFF).ToString("X6");
}
2019-03-16 16:38:28 -04:00
protected override void OnFormClosed(FormClosedEventArgs e)
{
base.OnFormClosed(e);
_notifListener?.Dispose();
}
private void OnNotificationReceived(NotificationEventArgs e)
{
switch(e.NotificationType) {
case ConsoleNotificationType.CodeBreak:
2019-03-16 16:38:28 -04:00
case ConsoleNotificationType.ViewerRefresh:
if(e.Parameter.ToInt32() == ctrlScanlineCycleSelect.ViewerId) {
2019-03-23 15:39:21 -04:00
ctrlPaletteViewer.RefreshData();
2019-03-16 16:38:28 -04:00
this.BeginInvoke((Action)(() => {
2019-03-23 15:39:21 -04:00
ctrlPaletteViewer.RefreshViewer();
UpdateFields();
2019-03-16 16:38:28 -04:00
}));
}
break;
case ConsoleNotificationType.GameLoaded:
//Configuration is lost when debugger is restarted (when switching game or power cycling)
ctrlScanlineCycleSelect.RefreshSettings();
break;
2019-03-16 16:38:28 -04:00
}
}
private void ctrlPaletteViewer_SelectionChanged()
{
UpdateFields();
}
2019-03-16 16:38:28 -04:00
}
2019-03-23 15:39:21 -04:00
}