diff --git a/src/BizHawk.Client.Common/config/Config.cs b/src/BizHawk.Client.Common/config/Config.cs index 9e4aa62ce9..aeb9923a4d 100644 --- a/src/BizHawk.Client.Common/config/Config.cs +++ b/src/BizHawk.Client.Common/config/Config.cs @@ -431,7 +431,7 @@ namespace BizHawk.Client.Common public int OSDMessageDuration { get; set; } = 2; public Queue RecentCores { get; set; } = new(); - + public Dictionary TrustedExtTools { get; set; } = new(); // RetroAchievements settings @@ -455,5 +455,7 @@ namespace BizHawk.Client.Common public bool GCAdapterSupportEnabled { get; set; } = false; public bool ScaleOSDWithSystemScale { get; set; } = true; + + public int RelativeMouseSensitivity { get; set; } = 100; } } diff --git a/src/BizHawk.Client.EmuHawk/Input/Input.cs b/src/BizHawk.Client.EmuHawk/Input/Input.cs index bff97c0323..3b20a9977e 100644 --- a/src/BizHawk.Client.EmuHawk/Input/Input.cs +++ b/src/BizHawk.Client.EmuHawk/Input/Input.cs @@ -180,7 +180,11 @@ namespace BizHawk.Client.EmuHawk { lock (_axisValues) { - return _axisValues.ToArray(); + var ret = _axisValues.ToArray(); + // since these are deltas, we'll want to reset them once the mainform grabs them + _axisValues["RMouse X"] = 0; + _axisValues["RMouse Y"] = 0; + return ret; } } @@ -241,8 +245,8 @@ namespace BizHawk.Client.EmuHawk HandleButton("WMouse 2", (mouseBtns & MouseButtons.XButton2) != 0, HostInputType.Mouse); // raw (relative) mouse input - _axisValues["RMouse X"] = mouseDeltaX; - _axisValues["RMouse Y"] = mouseDeltaY; + _axisValues["RMouse X"] = mouseDeltaX + _axisValues.GetValueOrDefault("RMouse X"); + _axisValues["RMouse Y"] = mouseDeltaY + _axisValues.GetValueOrDefault("RMouse Y"); } else { diff --git a/src/BizHawk.Client.EmuHawk/MainForm.cs b/src/BizHawk.Client.EmuHawk/MainForm.cs index ef43ae8677..19d99143d7 100644 --- a/src/BizHawk.Client.EmuHawk/MainForm.cs +++ b/src/BizHawk.Client.EmuHawk/MainForm.cs @@ -1287,29 +1287,44 @@ namespace BizHawk.Client.EmuHawk } } // foreach event - //also handle axes - //we'll need to isolate the mouse coordinates so we can translate them - KeyValuePair? mouseX = null, mouseY = null; + // also handle axes + // we'll need to isolate the mouse coordinates so we can translate them + int? mouseX = null, mouseY = null, mouseDeltaX = null, mouseDeltaY = null; foreach (var f in Input.Instance.GetAxisValues()) { if (f.Key == "WMouse X") - mouseX = f; + mouseX = f.Value; else if (f.Key == "WMouse Y") - mouseY = f; + mouseY = f.Value; + else if (f.Key == "RMouse X") + mouseDeltaX = f.Value; + else if (f.Key == "RMouse Y") + mouseDeltaY = f.Value; else finalHostController.AcceptNewAxis(f.Key, f.Value); } - //if we found mouse coordinates (and why wouldn't we?) then translate them now - //NOTE: these must go together, because in the case of screen rotation, X and Y are transformed together - if(mouseX != null && mouseY != null) + // if we found mouse coordinates (and why wouldn't we?) then translate them now + // NOTE: these must go together, because in the case of screen rotation, X and Y are transformed together + if (mouseX != null && mouseY != null) { - var p = DisplayManager.UntransformPoint(new Point(mouseX.Value.Value, mouseY.Value.Value)); - float x = p.X / (float)_currentVideoProvider.BufferWidth; - float y = p.Y / (float)_currentVideoProvider.BufferHeight; + var p = DisplayManager.UntransformPoint(new Point(mouseX.Value, mouseY.Value)); + var x = p.X / (float)_currentVideoProvider.BufferWidth; + var y = p.Y / (float)_currentVideoProvider.BufferHeight; finalHostController.AcceptNewAxis("WMouse X", (int) ((x * 20000) - 10000)); finalHostController.AcceptNewAxis("WMouse Y", (int) ((y * 20000) - 10000)); } + if (mouseDeltaX != null && mouseDeltaY != null) + { + var mouseSensitivity = Config.RelativeMouseSensitivity / 100.0f; + var x = mouseDeltaX.Value * mouseSensitivity; + var y = mouseDeltaY.Value * mouseSensitivity; + const int MAX_REL_MOUSE_RANGE = 120; // arbitrary + x = Math.Min(Math.Max(x, -MAX_REL_MOUSE_RANGE), MAX_REL_MOUSE_RANGE) / MAX_REL_MOUSE_RANGE; + y = Math.Min(Math.Max(y, -MAX_REL_MOUSE_RANGE), MAX_REL_MOUSE_RANGE) / MAX_REL_MOUSE_RANGE; + finalHostController.AcceptNewAxis("RMouse X", (int)(x * 10000)); + finalHostController.AcceptNewAxis("RMouse Y", (int)(y * 10000)); + } } public bool RebootCore()