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;
namespace BizHawk.Client.Common
@ -44,6 +47,8 @@ namespace BizHawk.Client.Common
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)
{
var def = emulator.ControllerDefinition;

View File

@ -1,6 +1,5 @@
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using BizHawk.Client.Common;
@ -30,18 +29,20 @@ namespace BizHawk.Client.EmuHawk
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.
var p = _displayManager.UntransformPoint(Control.MousePosition);
buttons["X"] = p.X;
buttons["Y"] = p.Y;
buttons[MouseButtons.Left.ToString()] = (Control.MouseButtons & MouseButtons.Left) != 0;
buttons[MouseButtons.Middle.ToString()] = (Control.MouseButtons & MouseButtons.Middle) != 0;
buttons[MouseButtons.Right.ToString()] = (Control.MouseButtons & MouseButtons.Right) != 0;
buttons[MouseButtons.XButton1.ToString()] = (Control.MouseButtons & MouseButtons.XButton1) != 0;
buttons[MouseButtons.XButton2.ToString()] = (Control.MouseButtons & MouseButtons.XButton2) != 0;
buttons["Wheel"] = _mainForm.MouseWheelTracker;
return buttons;
var p = _displayManager.UntransformPoint(pos);
return new Dictionary<string, object>
{
["X"] = p.X,
["Y"] = p.Y,
["Left"] = lmb,
["Middle"] = mmb,
["Right"] = rmb,
["XButton1"] = x1mb,
["XButton2"] = x2mb,
["Wheel"] = _mainForm.MouseWheelTracker
};
}
}
}

View File

@ -282,7 +282,22 @@ namespace BizHawk.Client.EmuHawk
Config = config;
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();
movieSession = MovieSession = new MovieSession(
Config.Movies,