From 27c6df32c3e18577c73a2ee1644cb86a24c2557d Mon Sep 17 00:00:00 2001 From: Vladimir Kononovich Date: Mon, 12 Oct 2020 16:51:04 +0300 Subject: [PATCH] Added UI registers change functionality. --- UI/Debugger/Controls/ctrlCpuStatus.cs | 17 ++++++------ UI/Forms/EntityBinder.cs | 40 ++++++++++++++++++++++++++- 2 files changed, 48 insertions(+), 9 deletions(-) diff --git a/UI/Debugger/Controls/ctrlCpuStatus.cs b/UI/Debugger/Controls/ctrlCpuStatus.cs index ca4f6ef..443fc7b 100644 --- a/UI/Debugger/Controls/ctrlCpuStatus.cs +++ b/UI/Debugger/Controls/ctrlCpuStatus.cs @@ -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) diff --git a/UI/Forms/EntityBinder.cs b/UI/Forms/EntityBinder.cs index b9d1876..ca22856 100644 --- a/UI/Forms/EntityBinder.cs +++ b/UI/Forms/EntityBinder.cs @@ -17,6 +17,7 @@ namespace Mesen.GUI.Forms public class EntityBinder { private Dictionary _bindings = new Dictionary(); + private Dictionary _bindedHandlers = new Dictionary(); private Dictionary _fieldFormat = new Dictionary(); private Dictionary _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().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");