Added UI registers change functionality.

This commit is contained in:
Vladimir Kononovich 2020-10-12 16:51:04 +03:00
parent 7a75651541
commit 27c6df32c3
2 changed files with 48 additions and 9 deletions

View file

@ -9,6 +9,7 @@ using System.Threading.Tasks;
using System.Windows.Forms;
using Mesen.GUI.Controls;
using Mesen.GUI.Forms;
using System.Globalization;
namespace Mesen.GUI.Debugger.Controls
{
@ -25,15 +26,15 @@ namespace Mesen.GUI.Debugger.Controls
}
_cpuBinder.Entity = new CpuState();
_cpuBinder.AddBinding(nameof(CpuState.A), txtA);
_cpuBinder.AddBinding(nameof(CpuState.X), txtX);
_cpuBinder.AddBinding(nameof(CpuState.Y), txtY);
_cpuBinder.AddBinding(nameof(CpuState.D), txtD);
_cpuBinder.AddBinding(nameof(CpuState.DBR), txtDB);
_cpuBinder.AddBinding(nameof(CpuState.SP), txtS);
_cpuBinder.AddBinding(nameof(CpuState.PS), txtP);
_cpuBinder.AddBinding(nameof(CpuState.A), txtA, onEditHandler: (s, e) => { DebugApi.SetCpuRegister(CpuRegister.CpuRegA, UInt16.Parse(txtA.Text, NumberStyles.HexNumber)); });
_cpuBinder.AddBinding(nameof(CpuState.X), txtX, onEditHandler: (s, e) => { DebugApi.SetCpuRegister(CpuRegister.CpuRegX, UInt16.Parse(txtX.Text, NumberStyles.HexNumber)); });
_cpuBinder.AddBinding(nameof(CpuState.Y), txtY, onEditHandler: (s, e) => { DebugApi.SetCpuRegister(CpuRegister.CpuRegY, UInt16.Parse(txtY.Text, NumberStyles.HexNumber)); });
_cpuBinder.AddBinding(nameof(CpuState.D), txtD, onEditHandler: (s, e) => { DebugApi.SetCpuRegister(CpuRegister.CpuRegD, UInt16.Parse(txtD.Text, NumberStyles.HexNumber)); });
_cpuBinder.AddBinding(nameof(CpuState.DBR), txtDB, onEditHandler: (s, e) => { DebugApi.SetCpuRegister(CpuRegister.CpuRegDBR, UInt16.Parse(txtDB.Text, NumberStyles.HexNumber)); });
_cpuBinder.AddBinding(nameof(CpuState.SP), txtS, onEditHandler: (s, e) => { DebugApi.SetCpuRegister(CpuRegister.CpuRegSP, UInt16.Parse(txtS.Text, NumberStyles.HexNumber)); });
_cpuBinder.AddBinding(nameof(CpuState.PS), txtP, onEditHandler: (s, e) => { DebugApi.SetCpuRegister(CpuRegister.CpuRegPS, UInt16.Parse(txtP.Text, NumberStyles.HexNumber)); });
_cpuBinder.AddBinding(nameof(CpuState.NmiFlag), chkNmi);
_cpuBinder.AddBinding(nameof(CpuState.NmiFlag), chkNmi, onEditHandler: (s, e) => { DebugApi.SetCpuRegister(CpuRegister.CpuRegNmiFlag, (UInt16)(chkNmi.Checked ? 1 : 0)); });
}
public void UpdateStatus(CpuState state)

View file

@ -17,6 +17,7 @@ namespace Mesen.GUI.Forms
public class EntityBinder
{
private Dictionary<string, object> _bindings = new Dictionary<string, object>();
private Dictionary<string, EventHandler> _bindedHandlers = new Dictionary<string, EventHandler>();
private Dictionary<string, eNumberFormat> _fieldFormat = new Dictionary<string, eNumberFormat>();
private Dictionary<string, FieldInfoWrapper> _fieldInfo = null;
@ -29,7 +30,7 @@ namespace Mesen.GUI.Forms
public bool Updating { get; private set; }
public void AddBinding(string fieldName, object bindedField, eNumberFormat format = eNumberFormat.Default)
public void AddBinding(string fieldName, object bindedField, eNumberFormat format = eNumberFormat.Default, EventHandler onEditHandler = null)
{
if(BindedType == null) {
throw new Exception("Need to override BindedType to use bindings");
@ -54,6 +55,43 @@ namespace Mesen.GUI.Forms
BaseConfigForm.InitializeComboBox(((ComboBox)bindedField), fieldType);
}
_bindings[fieldName] = bindedField;
_bindedHandlers[fieldName] = onEditHandler;
if(bindedField is TextBox) {
((TextBox)bindedField).Leave += onEditHandler;
} else if(bindedField is ctrlPathSelection) {
((ctrlPathSelection)bindedField).Leave += onEditHandler;
} else if(bindedField is CheckBox) {
((CheckBox)bindedField).CheckedChanged += onEditHandler;
} else if(bindedField is ToolStripMenuItem) {
((ToolStripMenuItem)bindedField).CheckedChanged += onEditHandler;
} else if(bindedField is ctrlRiskyOption) {
((ctrlRiskyOption)bindedField).Click += onEditHandler;
} else if(bindedField is RadioButton) {
((RadioButton)bindedField).CheckedChanged += onEditHandler;
} else if(bindedField is PictureBox) {
((PictureBox)bindedField).BackColorChanged += onEditHandler;
} else if(bindedField is Panel) {
FieldInfoWrapper field = _fieldInfo[fieldName];
object value = field.GetValue(this.Entity);
RadioButton radio = ((Panel)bindedField).Controls.OfType<RadioButton>().FirstOrDefault(r => r.Tag.Equals(value));
if(radio != null) {
radio.CheckedChanged += onEditHandler;
} else {
throw new Exception("No radio button matching value found");
}
} else if(bindedField is ctrlTrackbar) {
((ctrlTrackbar)bindedField).ValueChanged += onEditHandler;
} else if(bindedField is ctrlHorizontalTrackbar) {
((ctrlHorizontalTrackbar)bindedField).ValueChanged += onEditHandler;
} else if(bindedField is TrackBar) {
((TrackBar)bindedField).ValueChanged += onEditHandler;
} else if(bindedField is MesenNumericUpDown) {
((MesenNumericUpDown)bindedField).ValueChanged += onEditHandler;
} else if(bindedField is ComboBox) {
((ComboBox)bindedField).SelectedIndexChanged += onEditHandler;
}
_fieldFormat[fieldName] = format;
} else {
throw new Exception("Invalid field name");