More relative input handling

Needs UI for adjusting mouse sensitivity (think it should be 1-400) and a button in bindings for swapping an WMouse axis to the RMouse axis
This commit is contained in:
CasualPokePlayer 2025-02-22 15:53:33 -08:00
parent fe29eb12dd
commit f444d6b0a5
3 changed files with 36 additions and 15 deletions

View File

@ -431,7 +431,7 @@ namespace BizHawk.Client.Common
public int OSDMessageDuration { get; set; } = 2;
public Queue<string> RecentCores { get; set; } = new();
public Dictionary<string, string> 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;
}
}

View File

@ -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
{

View File

@ -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<string, int>? 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()