From d03bc3472dbedd4858c00d0050e3b58bb29a517d Mon Sep 17 00:00:00 2001 From: Xtr126 <80520774+Xtr126@users.noreply.github.com> Date: Mon, 5 Aug 2024 12:58:46 +0530 Subject: [PATCH] test non linear scaling --- .../xtr/keymapper/mouse/MouseAimHandler.java | 31 ++++++++++++++++--- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/xtr/keymapper/mouse/MouseAimHandler.java b/app/src/main/java/xtr/keymapper/mouse/MouseAimHandler.java index 382073f2..eb0c263a 100644 --- a/app/src/main/java/xtr/keymapper/mouse/MouseAimHandler.java +++ b/app/src/main/java/xtr/keymapper/mouse/MouseAimHandler.java @@ -27,14 +27,16 @@ public class MouseAimHandler { private final int pointerIdMouse = PointerId.pid1.id; private final int pointerIdAim = PointerId.pid2.id; private final Handler mHandler; - private final boolean limitedBounds; + private final boolean islimitedBounds; + private final boolean applyNonLinearScaling; public MouseAimHandler(MouseAimConfig config){ currentX = config.xCenter; currentY = config.yCenter; this.config = config; - this.limitedBounds = config.limitedBounds; + this.islimitedBounds = config.limitedBounds; + this.applyNonLinearScaling = true; // config.applyNonLinearScaling; mHandler = new Handler(Looper.getMainLooper()); } @@ -55,6 +57,7 @@ public void setDimensions(int width, int height){ area.top = currentY - config.height; area.bottom = currentY + config.height; } + } public void resetPointer() { @@ -70,14 +73,14 @@ public void resetPointer() { public void handleEvent(int code, int value, OnButtonClickListener listener) { switch (code) { case REL_X: - currentX += value; - if (limitedBounds && (currentX > area.right || currentX < area.left)) + currentX += (float) (value / calculateScaleX()); + if (islimitedBounds && (currentX > area.right || currentX < area.left)) resetPointer(); service.injectEvent(currentX, currentY, MOVE, pointerIdAim); break; case REL_Y: currentY += value; - if (limitedBounds && (currentY > area.bottom || currentY < area.top)) + if (islimitedBounds && (currentY > area.bottom || currentY < area.top)) resetPointer(); service.injectEvent(currentX, currentY, MOVE, pointerIdAim); break; @@ -95,6 +98,24 @@ public void handleEvent(int code, int value, OnButtonClickListener listener) { } } + public double calculateScaleX() { + if (applyNonLinearScaling) { + double dx = Math.abs(config.xCenter - currentX); + double dy = Math.abs(config.yCenter - currentY); + double distance = Math.hypot(dx, dy); + + double maxWidth = area.right - area.left; + double minDistanceToApplyScaling = maxWidth / 20; + if (distance > minDistanceToApplyScaling) { + return Math.sqrt(2 * distance / minDistanceToApplyScaling); + } else { + return 1; + } + } else { + return 1; + } + } + public void stop() { service.injectEvent(currentX, currentY, UP, pointerIdAim); }