Remove GlobalWin.DisplayManager, pass it through from MainForm instead

This commit is contained in:
YoshiRulz 2020-11-28 22:07:10 +10:00
parent 78daf4913d
commit b0b2b8fa63
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
6 changed files with 30 additions and 18 deletions

View File

@ -19,6 +19,8 @@ namespace BizHawk.Client.EmuHawk
private readonly Action<string> LogCallback;
private readonly DisplayManager _displayManager;
private readonly Dictionary<string, Image> _imageCache = new Dictionary<string, Image>();
private readonly Bitmap _nullGraphicsBitmap = new Bitmap(1, 1);
@ -45,7 +47,11 @@ namespace BizHawk.Client.EmuHawk
public bool HasGUISurface => _GUISurface != null;
public GuiApi(Action<string> logCallback) => LogCallback = logCallback;
public GuiApi(Action<string> logCallback, IMainFormForApi mainForm, DisplayManager displayManager, InputManager inputManager, Config config, IEmulator emulator, IGameInfo game)
{
LogCallback = logCallback;
_displayManager = displayManager;
}
private SolidBrush GetBrush(Color color) => _solidBrushes.TryGetValue(color, out var b) ? b : (_solidBrushes[color] = new SolidBrush(color));
@ -76,7 +82,7 @@ namespace BizHawk.Client.EmuHawk
try
{
DrawFinish();
_GUISurface = GlobalWin.DisplayManager.LockLuaSurface(name, clear);
_GUISurface = _displayManager.LockLuaSurface(name, clear);
}
catch (InvalidOperationException ex)
{
@ -86,7 +92,7 @@ namespace BizHawk.Client.EmuHawk
public void DrawFinish()
{
if (_GUISurface != null) GlobalWin.DisplayManager.UnlockLuaSurface(_GUISurface);
if (_GUISurface != null) _displayManager.UnlockLuaSurface(_GUISurface);
_GUISurface = null;
}
@ -476,7 +482,7 @@ namespace BizHawk.Client.EmuHawk
break;
}
using var g = GetGraphics();
var font = new Font(GlobalWin.DisplayManager.CustomFonts.Families[index], 8, FontStyle.Regular, GraphicsUnit.Pixel);
var font = new Font(_displayManager.CustomFonts.Families[index], 8, FontStyle.Regular, GraphicsUnit.Pixel);
var sizeOfText = g.MeasureString(
message,
font,

View File

@ -22,7 +22,6 @@ namespace BizHawk.Client.EmuHawk
public static Sound Sound;
public static readonly OSDManager OSD = new OSDManager();
public static DisplayManager DisplayManager;
public static Dictionary<string, object> UserBag { get; set; } = new Dictionary<string, object>();

View File

@ -311,7 +311,6 @@ namespace BizHawk.Client.EmuHawk
GlobalWin.Game = GameInfo.NullInstance;
_throttle = new Throttle();
Emulator = new NullEmulator();
Tools = new ToolManager(this, Config, InputManager, Emulator, MovieSession, Game);
UpdateStatusSlots();
UpdateKeyPriorityIcon();
@ -337,10 +336,12 @@ namespace BizHawk.Client.EmuHawk
{
GraphicsControl = { MainWindow = true }
};
GlobalWin.DisplayManager = new DisplayManager(OSD, GlobalWin.GL, _presentationPanel, () => DisableSecondaryThrottling);
DisplayManager = new DisplayManager(OSD, GlobalWin.GL, _presentationPanel, () => DisableSecondaryThrottling);
Controls.Add(_presentationPanel);
Controls.SetChildIndex(_presentationPanel, 0);
Tools = new ToolManager(this, Config, DisplayManager, InputManager, Emulator, MovieSession, Game);
// TODO GL - move these event handlers somewhere less obnoxious line in the On* overrides
Load += (o, e) =>
{
@ -717,7 +718,7 @@ namespace BizHawk.Client.EmuHawk
if (DisplayManager != null)
{
DisplayManager.Dispose();
GlobalWin.DisplayManager = null;
DisplayManager = null;
}
if (disposing)
@ -858,7 +859,7 @@ namespace BizHawk.Client.EmuHawk
public readonly ToolManager Tools;
private DisplayManager DisplayManager => GlobalWin.DisplayManager;
private DisplayManager DisplayManager;
public IMovieSession MovieSession
{

View File

@ -120,17 +120,17 @@ namespace BizHawk.Client.EmuHawk
{
Settings.Columns = LuaListView.AllColumns;
GlobalWin.DisplayManager.ClearLuaSurfaces();
DisplayManager.ClearLuaSurfaces();
if (GlobalWin.DisplayManager.ClientExtraPadding != Padding.Empty)
if (DisplayManager.ClientExtraPadding != Padding.Empty)
{
GlobalWin.DisplayManager.ClientExtraPadding = new Padding(0);
DisplayManager.ClientExtraPadding = new Padding(0);
MainForm.FrameBufferResized();
}
if (GlobalWin.DisplayManager.GameExtraPadding != Padding.Empty)
if (DisplayManager.GameExtraPadding != Padding.Empty)
{
GlobalWin.DisplayManager.GameExtraPadding = new Padding(0);
DisplayManager.GameExtraPadding = new Padding(0);
MainForm.FrameBufferResized();
}
@ -236,7 +236,7 @@ namespace BizHawk.Client.EmuHawk
var currentScripts = LuaImp?.ScriptList; // Temp fix for now
LuaImp = OSTailoredCode.IsUnixHost
? new UnixLuaLibraries()
: new Win32LuaLibraries(Emulator.ServiceProvider, (MainForm) MainForm, GlobalWin.DisplayManager, InputManager, Config, Emulator, Game);
: new Win32LuaLibraries(Emulator.ServiceProvider, (MainForm) MainForm, DisplayManager, InputManager, Config, Emulator, Game);
LuaImp.ScriptList.AddRange(currentScripts ?? Enumerable.Empty<LuaFile>());
InputBox.AutoCompleteCustomSource.AddRange(LuaImp.Docs.Select(a => $"{a.Library}.{a.Name}").ToArray());
@ -1533,7 +1533,7 @@ namespace BizHawk.Client.EmuHawk
private void EraseToolbarItem_Click(object sender, EventArgs e)
{
GlobalWin.DisplayManager.ClearLuaSurfaces();
DisplayManager.ClearLuaSurfaces();
}
// Stupid designer

View File

@ -13,6 +13,8 @@ namespace BizHawk.Client.EmuHawk
{
public ToolManager Tools { get; set; }
public DisplayManager DisplayManager { get; set; }
public InputManager InputManager { get; set; }
public IMainFormForTools MainForm { get; set; }

View File

@ -20,6 +20,7 @@ namespace BizHawk.Client.EmuHawk
{
private readonly MainForm _owner;
private readonly Config _config;
private readonly DisplayManager _displayManager;
private readonly InputManager _inputManager;
private IExternalApiProvider _apiProvider;
private IEmulator _emulator;
@ -43,6 +44,7 @@ namespace BizHawk.Client.EmuHawk
public ToolManager(
MainForm owner,
Config config,
DisplayManager displayManager,
InputManager inputManager,
IEmulator emulator,
IMovieSession movieSession,
@ -50,11 +52,12 @@ namespace BizHawk.Client.EmuHawk
{
_owner = owner;
_config = config;
_displayManager = displayManager;
_inputManager = inputManager;
_emulator = emulator;
_movieSession = movieSession;
_game = game;
ApiProvider = ApiManager.Restart(_emulator.ServiceProvider, _owner, GlobalWin.DisplayManager, _inputManager, this, _config, _emulator, _game);
ApiProvider = ApiManager.Restart(_emulator.ServiceProvider, _owner, _displayManager, _inputManager, this, _config, _emulator, _game);
}
/// <summary>
@ -84,6 +87,7 @@ namespace BizHawk.Client.EmuHawk
{
tool.Tools = this;
tool.Config = _config;
tool.DisplayManager = _displayManager;
tool.InputManager = _inputManager;
tool.MainForm = _owner;
tool.MovieSession = _movieSession;
@ -505,7 +509,7 @@ namespace BizHawk.Client.EmuHawk
{
_emulator = emulator;
_game = game;
ApiProvider = ApiManager.Restart(_emulator.ServiceProvider, _owner, GlobalWin.DisplayManager, _inputManager, this, _config, _emulator, _game);
ApiProvider = ApiManager.Restart(_emulator.ServiceProvider, _owner, _displayManager, _inputManager, this, _config, _emulator, _game);
// If Cheat tool is loaded, restarting will restart the list too anyway
if (!Has<Cheats>())
{