Skip to content

Commit

Permalink
add current X/Y tracking, alter setDeltaXY logic to use this var inst…
Browse files Browse the repository at this point in the history
…ead of initial and alter touchpad onMove to calculate and use totalDeltaXY instead of incremental
  • Loading branch information
Nerwyn committed Dec 8, 2024
1 parent 0e065e8 commit e6730c5
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
2 changes: 1 addition & 1 deletion dist/universal-remote-card.min.js

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions src/classes/base-remote-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ export class BaseRemoteElement extends LitElement {
swiping?: boolean = false;
initialX?: number;
initialY?: number;
currentX?: number;
currentY?: number;
deltaX?: number;
deltaY?: number;

Expand All @@ -68,6 +70,8 @@ export class BaseRemoteElement extends LitElement {
this.swiping = false;
this.initialX = undefined;
this.initialY = undefined;
this.currentX = undefined;
this.currentY = undefined;
this.deltaX = undefined;
this.deltaY = undefined;
}
Expand Down Expand Up @@ -634,6 +638,8 @@ export class BaseRemoteElement extends LitElement {
unit: this.unitOfMeasurement,
initialX: this.initialX,
initialY: this.initialY,
currentX: this.currentX,
currentY: this.currentY,
deltaX: this.deltaX,
deltaY: this.deltaY,
config: {
Expand Down
2 changes: 0 additions & 2 deletions src/classes/remote-mousepad.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ export class RemoteMousepad extends RemoteTouchpad {
}

this.setDeltaXY(e);
this.initialX = this.deltaX ?? 0 + this.initialX;
this.initialY = this.deltaY ?? 0 + this.initialY;

// Only consider significant enough movement
const sensitivity = 2;
Expand Down
19 changes: 12 additions & 7 deletions src/classes/remote-touchpad.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,19 +153,21 @@ export class RemoteTouchpad extends BaseRemoteElement {
}

this.setDeltaXY(e);
const totalDeltaX = this.currentX ?? 0 - this.initialX;
const totalDeltaY = this.currentY ?? 0 - this.initialY;

// Only consider significant enough movement
const sensitivity = 2;
if (
Math.abs(Math.abs(this.deltaX ?? 0) - Math.abs(this.deltaY ?? 0)) >
Math.abs(Math.abs(totalDeltaX ?? 0) - Math.abs(totalDeltaY ?? 0)) >
sensitivity
) {
if (Math.abs(this.deltaX ?? 0) > Math.abs(this.deltaY ?? 0)) {
if (Math.abs(totalDeltaX ?? 0) > Math.abs(totalDeltaY ?? 0)) {
// Sliding horizontally
this.direction = this.deltaX ?? 0 < 0 ? 'left' : 'right';
this.direction = totalDeltaX ?? 0 < 0 ? 'left' : 'right';
} else {
// Sliding vertically
this.direction = this.deltaY ?? 0 < 0 ? 'up' : 'down';
this.direction = totalDeltaY ?? 0 < 0 ? 'up' : 'down';
}
if (!this.holdMove) {
this.fireHapticEvent('light');
Expand Down Expand Up @@ -209,7 +211,6 @@ export class RemoteTouchpad extends BaseRemoteElement {
}
}
}
console.log(this.targetTouches[0]);
}

setInitialXY(e: TouchEvent | MouseEvent) {
Expand All @@ -227,6 +228,8 @@ export class RemoteTouchpad extends BaseRemoteElement {
this.initialX = e.clientX;
this.initialY = e.clientY;
}
this.currentX = this.initialX;
this.currentY = this.initialY;
console.log(`INITIAL: ${this.initialX},${this.initialY}`);
}

Expand All @@ -246,8 +249,10 @@ export class RemoteTouchpad extends BaseRemoteElement {
currentY = e.clientY ?? 0;
}

this.deltaX = currentX - (this.initialX ?? 0);
this.deltaY = currentY - (this.initialY ?? 0);
this.deltaX = currentX - (this.currentX ?? 0);
this.deltaY = currentY - (this.currentY ?? 0);
this.currentX = currentX;
this.currentY = currentY;
console.log(`DELTA: ${this.deltaX},${this.deltaY}`);
}

Expand Down

0 comments on commit e6730c5

Please sign in to comment.