Use callbacks to get mouse pos+buttons to InputApi via InputManager

This commit is contained in:
YoshiRulz 2020-12-03 18:14:49 +10:00
parent 4ade496de5
commit 6be371aadd
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
3 changed files with 35 additions and 14 deletions

View File

@ -1,4 +1,7 @@
using System.Collections.Generic; using System;
using System.Collections.Generic;
using System.Drawing;
using BizHawk.Emulation.Common; using BizHawk.Emulation.Common;
namespace BizHawk.Client.Common namespace BizHawk.Client.Common
@ -44,6 +47,8 @@ namespace BizHawk.Client.Common
public Controller ClientControls { get; set; } public Controller ClientControls { get; set; }
public Func<(Point Pos, bool LMB, bool MMB, bool RMB, bool X1MB, bool X2MB)> GetMainFormMouseInfo { get; set; }
public void SyncControls(IEmulator emulator, IMovieSession session, Config config) public void SyncControls(IEmulator emulator, IMovieSession session, Config config)
{ {
var def = emulator.ControllerDefinition; var def = emulator.ControllerDefinition;

View File

@ -1,6 +1,5 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Windows.Forms;
using BizHawk.Client.Common; using BizHawk.Client.Common;
@ -30,18 +29,20 @@ namespace BizHawk.Client.EmuHawk
public Dictionary<string, object> GetMouse() public Dictionary<string, object> GetMouse()
{ {
var buttons = new Dictionary<string, object>(); var (pos, lmb, mmb, rmb, x1mb, x2mb) = _inputManager.GetMainFormMouseInfo();
// TODO - need to specify whether in "emu" or "native" coordinate space. // TODO - need to specify whether in "emu" or "native" coordinate space.
var p = _displayManager.UntransformPoint(Control.MousePosition); var p = _displayManager.UntransformPoint(pos);
buttons["X"] = p.X; return new Dictionary<string, object>
buttons["Y"] = p.Y; {
buttons[MouseButtons.Left.ToString()] = (Control.MouseButtons & MouseButtons.Left) != 0; ["X"] = p.X,
buttons[MouseButtons.Middle.ToString()] = (Control.MouseButtons & MouseButtons.Middle) != 0; ["Y"] = p.Y,
buttons[MouseButtons.Right.ToString()] = (Control.MouseButtons & MouseButtons.Right) != 0; ["Left"] = lmb,
buttons[MouseButtons.XButton1.ToString()] = (Control.MouseButtons & MouseButtons.XButton1) != 0; ["Middle"] = mmb,
buttons[MouseButtons.XButton2.ToString()] = (Control.MouseButtons & MouseButtons.XButton2) != 0; ["Right"] = rmb,
buttons["Wheel"] = _mainForm.MouseWheelTracker; ["XButton1"] = x1mb,
return buttons; ["XButton2"] = x2mb,
["Wheel"] = _mainForm.MouseWheelTracker
};
} }
} }
} }

View File

@ -282,7 +282,22 @@ namespace BizHawk.Client.EmuHawk
Config = config; Config = config;
GL = gl; GL = gl;
InputManager = new InputManager { ControllerInputCoalescer = new ControllerInputCoalescer() }; InputManager = new InputManager
{
ControllerInputCoalescer = new ControllerInputCoalescer(),
GetMainFormMouseInfo = () =>
{
var b = Control.MouseButtons;
return (
Control.MousePosition,
(b & MouseButtons.Left) != 0,
(b & MouseButtons.Middle) != 0,
(b & MouseButtons.Right) != 0,
(b & MouseButtons.XButton1) != 0,
(b & MouseButtons.XButton2) != 0
);
}
};
FirmwareManager = new FirmwareManager(); FirmwareManager = new FirmwareManager();
movieSession = MovieSession = new MovieSession( movieSession = MovieSession = new MovieSession(
Config.Movies, Config.Movies,