From e3c54b226841d0d5a22386853764d5f29afdec3e Mon Sep 17 00:00:00 2001 From: YoshiRulz Date: Wed, 17 Jun 2020 10:42:22 +1000 Subject: [PATCH] Change some MainForm event handlers to delegate typed properties makes encapsulation easier --- .../MainForm.Designer.cs | 2 -- src/BizHawk.Client.EmuHawk/MainForm.Events.cs | 20 +++---------------- src/BizHawk.Client.EmuHawk/MainForm.cs | 11 ++++++++++ .../PresentationPanel.cs | 6 +++--- 4 files changed, 17 insertions(+), 22 deletions(-) diff --git a/src/BizHawk.Client.EmuHawk/MainForm.Designer.cs b/src/BizHawk.Client.EmuHawk/MainForm.Designer.cs index bda960e044..1ca63f4b12 100644 --- a/src/BizHawk.Client.EmuHawk/MainForm.Designer.cs +++ b/src/BizHawk.Client.EmuHawk/MainForm.Designer.cs @@ -3230,8 +3230,6 @@ this.Load += new System.EventHandler(this.MainForm_Load); this.Shown += new System.EventHandler(this.MainForm_Shown); this.Enter += new System.EventHandler(this.MainForm_Enter); - this.MouseClick += new System.Windows.Forms.MouseEventHandler(this.MainForm_MouseClick); - this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.MainForm_MouseMove); this.Resize += new System.EventHandler(this.MainForm_Resize); this.MainformMenu.ResumeLayout(false); this.MainformMenu.PerformLayout(); diff --git a/src/BizHawk.Client.EmuHawk/MainForm.Events.cs b/src/BizHawk.Client.EmuHawk/MainForm.Events.cs index ba392a8571..6824b59d72 100644 --- a/src/BizHawk.Client.EmuHawk/MainForm.Events.cs +++ b/src/BizHawk.Client.EmuHawk/MainForm.Events.cs @@ -2613,25 +2613,11 @@ namespace BizHawk.Client.EmuHawk AutohideCursor(false); } - public void MainForm_MouseWheel(object sender, MouseEventArgs e) - { - MouseWheelTracker += e.Delta; - } + public MouseEventHandler MainForm_MouseWheel { get; } - public void MainForm_MouseMove(object sender, MouseEventArgs e) - { - AutohideCursor(false); - } + public MouseEventHandler MainForm_MouseMove { get; } - public void MainForm_MouseClick(object sender, MouseEventArgs e) - { - AutohideCursor(false); - if (Config.ShowContextMenu && e.Button == MouseButtons.Right) - { - MainFormContextMenu.Show( - PointToScreen(new Point(e.X, e.Y + MainformMenu.Height))); - } - } + public MouseEventHandler MainForm_MouseClick { get; } private void MainForm_Resize(object sender, EventArgs e) { diff --git a/src/BizHawk.Client.EmuHawk/MainForm.cs b/src/BizHawk.Client.EmuHawk/MainForm.cs index b818896663..c9f035e104 100644 --- a/src/BizHawk.Client.EmuHawk/MainForm.cs +++ b/src/BizHawk.Client.EmuHawk/MainForm.cs @@ -371,6 +371,17 @@ namespace BizHawk.Client.EmuHawk Sound?.StartSound(); }; + MouseClick += MainForm_MouseClick = (sender, e) => + { + AutohideCursor(false); + if (Config.ShowContextMenu && e.Button == MouseButtons.Right) + { + MainFormContextMenu.Show(PointToScreen(new Point(e.X, e.Y + MainformMenu.Height))); + } + }; + MouseMove += MainForm_MouseMove = (sender, e) => AutohideCursor(false); + MainForm_MouseWheel = (sender, e) => MouseWheelTracker += e.Delta; + Input.Instance.MainFormInputAllowedCallback = yieldAlt => { // the main form gets input if (ActiveForm == this) diff --git a/src/BizHawk.Client.EmuHawk/PresentationPanel.cs b/src/BizHawk.Client.EmuHawk/PresentationPanel.cs index 1e553c9f98..ff1213a8b3 100644 --- a/src/BizHawk.Client.EmuHawk/PresentationPanel.cs +++ b/src/BizHawk.Client.EmuHawk/PresentationPanel.cs @@ -28,9 +28,9 @@ namespace BizHawk.Client.EmuHawk // pass through these events to the form. we might need a more scalable solution for mousedown etc. for zapper and whatnot. // http://stackoverflow.com/questions/547172/pass-through-mouse-events-to-parent-control (HTTRANSPARENT) GraphicsControl.MouseDoubleClick += HandleFullscreenToggle; - GraphicsControl.MouseClick += (o, e) => _mainForm.MainForm_MouseClick(o, e); - GraphicsControl.MouseMove += (o, e) => _mainForm.MainForm_MouseMove(o, e); - GraphicsControl.MouseWheel += (o, e) => _mainForm.MainForm_MouseWheel(o, e); + GraphicsControl.MouseClick += _mainForm.MainForm_MouseClick; + GraphicsControl.MouseMove += _mainForm.MainForm_MouseMove; + GraphicsControl.MouseWheel += _mainForm.MainForm_MouseWheel; } private bool _isDisposed;