Pass IMainForm props in PresentationPanel ctor instead

This commit is contained in:
YoshiRulz 2020-07-08 02:46:18 +10:00
parent 9a45d88301
commit fa7613d481
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
4 changed files with 29 additions and 30 deletions

View File

@ -33,15 +33,6 @@ namespace BizHawk.Client.EmuHawk
/// <remarks>only referenced from <see cref="LuaConsole"/></remarks> /// <remarks>only referenced from <see cref="LuaConsole"/></remarks>
bool IsTurboing { get; } bool IsTurboing { get; }
/// <remarks>only referenced from <see cref="PresentationPanel"/></remarks>
MouseEventHandler MainForm_MouseClick { get; }
/// <remarks>only referenced from <see cref="PresentationPanel"/></remarks>
MouseEventHandler MainForm_MouseMove { get; }
/// <remarks>only referenced from <see cref="PresentationPanel"/></remarks>
MouseEventHandler MainForm_MouseWheel { get; }
int? PauseOnFrame { get; set; } int? PauseOnFrame { get; set; }
/// <remarks>only referenced from <see cref="PlaybackBox"/></remarks> /// <remarks>only referenced from <see cref="PlaybackBox"/></remarks>
@ -102,9 +93,6 @@ namespace BizHawk.Client.EmuHawk
/// <remarks>only referenced from <see cref="BasicBot"/></remarks> /// <remarks>only referenced from <see cref="BasicBot"/></remarks>
void Throttle(); void Throttle();
/// <remarks>only referenced from <see cref="PresentationPanel"/></remarks>
void ToggleFullscreen(bool allowSuppress = false);
/// <remarks>only referenced from <see cref="TAStudio"/></remarks> /// <remarks>only referenced from <see cref="TAStudio"/></remarks>
void TogglePause(); void TogglePause();

View File

@ -2527,12 +2527,6 @@ namespace BizHawk.Client.EmuHawk
AutohideCursor(false); AutohideCursor(false);
} }
public MouseEventHandler MainForm_MouseWheel { get; }
public MouseEventHandler MainForm_MouseMove { get; }
public MouseEventHandler MainForm_MouseClick { get; }
private void MainForm_Resize(object sender, EventArgs e) private void MainForm_Resize(object sender, EventArgs e)
{ {
PresentationPanel.Resized = true; PresentationPanel.Resized = true;

View File

@ -291,7 +291,7 @@ namespace BizHawk.Client.EmuHawk
PauseEmulator, PauseEmulator,
SetMainformMovieInfo); SetMainformMovieInfo);
MouseClick += MainForm_MouseClick = (sender, e) => void MainForm_MouseClick(object sender, MouseEventArgs e)
{ {
AutohideCursor(false); AutohideCursor(false);
if (Config.ShowContextMenu && e.Button == MouseButtons.Right) if (Config.ShowContextMenu && e.Button == MouseButtons.Right)
@ -299,8 +299,10 @@ namespace BizHawk.Client.EmuHawk
MainFormContextMenu.Show(PointToScreen(new Point(e.X, e.Y + MainformMenu.Height))); MainFormContextMenu.Show(PointToScreen(new Point(e.X, e.Y + MainformMenu.Height)));
} }
}; };
MouseMove += MainForm_MouseMove = (sender, e) => AutohideCursor(false); void MainForm_MouseMove(object sender, MouseEventArgs e) => AutohideCursor(false);
MainForm_MouseWheel = (sender, e) => MouseWheelTracker += e.Delta; void MainForm_MouseWheel(object sender, MouseEventArgs e) => MouseWheelTracker += e.Delta;
MouseClick += MainForm_MouseClick;
MouseMove += MainForm_MouseMove;
InitializeComponent(); InitializeComponent();
Icon = Properties.Resources.logo; Icon = Properties.Resources.logo;
@ -325,7 +327,13 @@ namespace BizHawk.Client.EmuHawk
// TODO GL - a lot of disorganized wiring-up here // TODO GL - a lot of disorganized wiring-up here
// installed separately on Unix (via package manager or from https://developer.nvidia.com/cg-toolkit-download), look in $PATH // installed separately on Unix (via package manager or from https://developer.nvidia.com/cg-toolkit-download), look in $PATH
PresentationPanel = new PresentationPanel(this, Config, GlobalWin.GL) PresentationPanel = new PresentationPanel(
Config,
GlobalWin.GL,
ToggleFullscreen,
MainForm_MouseClick,
MainForm_MouseMove,
MainForm_MouseWheel)
{ {
GraphicsControl = { MainWindow = true } GraphicsControl = { MainWindow = true }
}; };

View File

@ -1,4 +1,5 @@
using System.Drawing; using System;
using System.Drawing;
using System.Windows.Forms; using System.Windows.Forms;
using BizHawk.Client.Common; using BizHawk.Client.Common;
@ -11,14 +12,22 @@ namespace BizHawk.Client.EmuHawk
/// </summary> /// </summary>
public class PresentationPanel public class PresentationPanel
{ {
private readonly IMainFormForTools _mainForm;
private readonly Config _config; private readonly Config _config;
public PresentationPanel(IMainFormForTools mainForm, Config config, IGL gl) private readonly Action<bool> _fullscreenToggleCallback;
public PresentationPanel(
Config config,
IGL gl,
Action<bool> fullscreenToggleCallback,
MouseEventHandler onClick,
MouseEventHandler onMove,
MouseEventHandler onWheel)
{ {
_mainForm = mainForm;
_config = config; _config = config;
_fullscreenToggleCallback = fullscreenToggleCallback;
GraphicsControl = new GraphicsControl(gl) GraphicsControl = new GraphicsControl(gl)
{ {
Dock = DockStyle.Fill, Dock = DockStyle.Fill,
@ -27,10 +36,10 @@ 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. // 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) // http://stackoverflow.com/questions/547172/pass-through-mouse-events-to-parent-control (HTTRANSPARENT)
GraphicsControl.MouseClick += onClick;
GraphicsControl.MouseDoubleClick += HandleFullscreenToggle; GraphicsControl.MouseDoubleClick += HandleFullscreenToggle;
GraphicsControl.MouseClick += _mainForm.MainForm_MouseClick; GraphicsControl.MouseMove += onMove;
GraphicsControl.MouseMove += _mainForm.MainForm_MouseMove; GraphicsControl.MouseWheel += onWheel;
GraphicsControl.MouseWheel += _mainForm.MainForm_MouseWheel;
} }
private bool _isDisposed; private bool _isDisposed;
@ -55,7 +64,7 @@ namespace BizHawk.Client.EmuHawk
bool allowSuppress = Control.ModifierKeys != Keys.Shift; bool allowSuppress = Control.ModifierKeys != Keys.Shift;
if (_config.DispChromeAllowDoubleClickFullscreen || !allowSuppress) if (_config.DispChromeAllowDoubleClickFullscreen || !allowSuppress)
{ {
_mainForm.ToggleFullscreen(allowSuppress); _fullscreenToggleCallback(allowSuppress);
} }
} }
} }