From 205313e3cf72e81039cb76aab3f78468e4235d50 Mon Sep 17 00:00:00 2001 From: Xtr126 <80520774+Xtr126@users.noreply.github.com> Date: Sat, 10 Aug 2024 17:08:07 +0530 Subject: [PATCH] feat: vertical/horizontal sensitivity adjustment for aiming --- .../xtr/keymapper/mouse/MouseAimConfig.java | 17 +++++++++++++- .../xtr/keymapper/mouse/MouseAimHandler.java | 23 +++++++++---------- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/xtr/keymapper/mouse/MouseAimConfig.java b/app/src/main/java/xtr/keymapper/mouse/MouseAimConfig.java index 270477fd..a366105a 100644 --- a/app/src/main/java/xtr/keymapper/mouse/MouseAimConfig.java +++ b/app/src/main/java/xtr/keymapper/mouse/MouseAimConfig.java @@ -14,6 +14,8 @@ public class MouseAimConfig implements Parcelable { public boolean limitedBounds = true; private static final int initXY = 300; public static final String TAG = "MOUSE_AIM"; + public float xSensitivity = 1, ySensitivity = 1; + public boolean applyNonLinearScaling = false; public MouseAimConfig() { xCenter = xleftClick = yleftClick = yCenter = initXY; @@ -27,6 +29,9 @@ protected MouseAimConfig(Parcel in) { width = in.readFloat(); height = in.readFloat(); limitedBounds = in.readByte() != 0; + xSensitivity = in.readFloat(); + ySensitivity = in.readFloat(); + applyNonLinearScaling = in.readByte() != 0; } public static final Creator CREATOR = new Creator<>() { @@ -49,6 +54,11 @@ public MouseAimConfig parse(String[] data){ height = Float.parseFloat(data[5]); xleftClick = Float.parseFloat(data[6]); yleftClick = Float.parseFloat(data[7]); + if (data.length == 11) { + xSensitivity = Float.parseFloat(data[8]); + ySensitivity = Float.parseFloat(data[9]); + applyNonLinearScaling = Integer.parseInt(data[10]) != 0; + } return this; } @@ -56,7 +66,9 @@ public String getData() { return TAG + " " + xCenter + " " + yCenter + " " + (limitedBounds ? 1 : 0) + " " + width + " " + height + " " - + xleftClick + " " + yleftClick; + + xleftClick + " " + yleftClick + " " + + xSensitivity + " " + ySensitivity + " " + + (limitedBounds ? 1 : 0); } public void setCenterXY(MovableFrameLayout crosshair){ @@ -83,5 +95,8 @@ public void writeToParcel(@NonNull Parcel dest, int flags) { dest.writeFloat(width); dest.writeFloat(height); dest.writeByte((byte) (limitedBounds ? 1 : 0)); + dest.writeFloat(xSensitivity); + dest.writeFloat(ySensitivity); + dest.writeByte((byte) (applyNonLinearScaling ? 1 : 0)); } } \ No newline at end of file diff --git a/app/src/main/java/xtr/keymapper/mouse/MouseAimHandler.java b/app/src/main/java/xtr/keymapper/mouse/MouseAimHandler.java index eb0c263a..f9480093 100644 --- a/app/src/main/java/xtr/keymapper/mouse/MouseAimHandler.java +++ b/app/src/main/java/xtr/keymapper/mouse/MouseAimHandler.java @@ -27,16 +27,11 @@ public class MouseAimHandler { private final int pointerIdMouse = PointerId.pid1.id; private final int pointerIdAim = PointerId.pid2.id; private final Handler mHandler; - private final boolean islimitedBounds; - private final boolean applyNonLinearScaling; - public MouseAimHandler(MouseAimConfig config){ currentX = config.xCenter; currentY = config.yCenter; this.config = config; - this.islimitedBounds = config.limitedBounds; - this.applyNonLinearScaling = true; // config.applyNonLinearScaling; mHandler = new Handler(Looper.getMainLooper()); } @@ -73,14 +68,14 @@ public void resetPointer() { public void handleEvent(int code, int value, OnButtonClickListener listener) { switch (code) { case REL_X: - currentX += (float) (value / calculateScaleX()); - if (islimitedBounds && (currentX > area.right || currentX < area.left)) + currentX += calculateScaledX(value); + if (config.limitedBounds && (currentX > area.right || currentX < area.left)) resetPointer(); service.injectEvent(currentX, currentY, MOVE, pointerIdAim); break; case REL_Y: - currentY += value; - if (islimitedBounds && (currentY > area.bottom || currentY < area.top)) + currentY += calculateScaledY(value);; + if (config.limitedBounds && (currentY > area.bottom || currentY < area.top)) resetPointer(); service.injectEvent(currentX, currentY, MOVE, pointerIdAim); break; @@ -98,8 +93,8 @@ public void handleEvent(int code, int value, OnButtonClickListener listener) { } } - public double calculateScaleX() { - if (applyNonLinearScaling) { + public double calculateScaledX(int value) { + if (config.applyNonLinearScaling) { double dx = Math.abs(config.xCenter - currentX); double dy = Math.abs(config.yCenter - currentY); double distance = Math.hypot(dx, dy); @@ -107,7 +102,7 @@ public double calculateScaleX() { double maxWidth = area.right - area.left; double minDistanceToApplyScaling = maxWidth / 20; if (distance > minDistanceToApplyScaling) { - return Math.sqrt(2 * distance / minDistanceToApplyScaling); + return config.xSensitivity * value * Math.sqrt(minDistanceToApplyScaling / distance); } else { return 1; } @@ -116,6 +111,10 @@ public double calculateScaleX() { } } + private double calculateScaledY(int value) { + return value * config.ySensitivity; + } + public void stop() { service.injectEvent(currentX, currentY, UP, pointerIdAim); }