mirror of
https://github.com/moonlight-stream/moonlight-android.git
synced 2026-10-20 15:27:18 +00:00
Analog stick for scrolling in mouse emulation mode
This commit is contained in:
1 parent
3f9f8f7b3b
commit
3aab9eb13b
10 files changed
+107
-12
No files matched your search
@@ -1857,21 +1857,30 @@ public class ControllerHandler implements InputManager.InputDeviceListener, UsbD
|
||||
return true;
|
||||
}
|
||||
|
||||
private short scaleRawStickAxis(float stickValue) {
|
||||
return (short)Math.pow(stickValue, 3);
|
||||
}
|
||||
|
||||
private void sendEmulatedMouseEvent(short x, short y) {
|
||||
private Vector2d convertRawStickAxisToPixelMovement(short stickX, short stickY) {
|
||||
Vector2d vector = new Vector2d();
|
||||
vector.initialize(x, y);
|
||||
vector.initialize(stickX, stickY);
|
||||
vector.scalarMultiply(1 / 32766.0f);
|
||||
vector.scalarMultiply(4);
|
||||
if (vector.getMagnitude() > 0) {
|
||||
// Move faster as the stick is pressed further from center
|
||||
vector.scalarMultiply(Math.pow(vector.getMagnitude(), 2));
|
||||
if (vector.getMagnitude() >= 1) {
|
||||
conn.sendMouseMove((short)vector.getX(), (short)-vector.getY());
|
||||
}
|
||||
}
|
||||
return vector;
|
||||
}
|
||||
|
||||
private void sendEmulatedMouseMove(short x, short y) {
|
||||
Vector2d vector = convertRawStickAxisToPixelMovement(x, y);
|
||||
if (vector.getMagnitude() >= 1) {
|
||||
conn.sendMouseMove((short)vector.getX(), (short)-vector.getY());
|
||||
}
|
||||
}
|
||||
|
||||
private void sendEmulatedMouseScroll(short x, short y) {
|
||||
Vector2d vector = convertRawStickAxisToPixelMovement(x, y);
|
||||
if (vector.getMagnitude() >= 1) {
|
||||
conn.sendMouseHighResScroll((short)vector.getY());
|
||||
conn.sendMouseHighResHScroll((short)vector.getX());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2906,9 +2915,19 @@ public class ControllerHandler implements InputManager.InputDeviceListener, UsbD
|
||||
return;
|
||||
}
|
||||
|
||||
// Send mouse movement events from analog sticks
|
||||
sendEmulatedMouseEvent(leftStickX, leftStickY);
|
||||
sendEmulatedMouseEvent(rightStickX, rightStickY);
|
||||
// Send mouse events from analog sticks
|
||||
if (prefConfig.analogStickForScrolling == PreferenceConfiguration.AnalogStickForScrolling.RIGHT) {
|
||||
sendEmulatedMouseMove(leftStickX, leftStickY);
|
||||
sendEmulatedMouseScroll(rightStickX, rightStickY);
|
||||
}
|
||||
else if (prefConfig.analogStickForScrolling == PreferenceConfiguration.AnalogStickForScrolling.LEFT) {
|
||||
sendEmulatedMouseMove(rightStickX, rightStickY);
|
||||
sendEmulatedMouseScroll(leftStickX, leftStickY);
|
||||
}
|
||||
else {
|
||||
sendEmulatedMouseMove(leftStickX, leftStickY);
|
||||
sendEmulatedMouseMove(rightStickX, rightStickY);
|
||||
}
|
||||
|
||||
// Requeue the callback
|
||||
mainThreadHandler.postDelayed(this, mouseEmulationReportPeriod);
|
||||
|
||||
Reference in new issue
Block a user