Skip to content

Commit

Permalink
test non linear scaling
Browse files Browse the repository at this point in the history
  • Loading branch information
Xtr126 committed Aug 5, 2024
1 parent 9a094a7 commit d03bc34
Showing 1 changed file with 26 additions and 5 deletions.
31 changes: 26 additions & 5 deletions app/src/main/java/xtr/keymapper/mouse/MouseAimHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand All @@ -55,6 +57,7 @@ public void setDimensions(int width, int height){
area.top = currentY - config.height;
area.bottom = currentY + config.height;
}

}

public void resetPointer() {
Expand All @@ -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;
Expand All @@ -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);
}
Expand Down

0 comments on commit d03bc34

Please sign in to comment.