Skip to content

Commit

Permalink
fix: zooming handling
Browse files Browse the repository at this point in the history
  • Loading branch information
yapitw committed Jan 13, 2024
1 parent f0792b9 commit c058c08
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions src/litegraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -7002,30 +7002,28 @@ LGraphNode.prototype.executeAction = function(action)
return;
}

const isTouchPad = !!e.wheelDeltaY && e.wheelDeltaY === e.deltaY * -3

if(isTouchPad) {
const isNatural = event.webkitDirectionInvertedFromDevice
if(e.ctrlKey) {
let scale = this.ds.scale;
let deltaS = Math.exp(-e.deltaY / 100);
scale = isNatural ? scale / deltaS : scale * deltaS
this.ds.changeScale(scale, [x, y]);
}
const isTouchpadPan = !!e.wheelDeltaY && e.wheelDeltaY === e.deltaY * -3

const naturalFix = isNatural ? 1 : -1
if(isTouchpadPan) { // Touchpad pan
const naturalFix = -1;
this.ds.offset[0] += e.deltaX / this.ds.scale * naturalFix;
this.ds.offset[1] += e.deltaY / this.ds.scale * naturalFix;
this.dirty_canvas = true;
this.dirty_bgcanvas = true;
} else {
const delta = e.wheelDeltaY != null ? e.wheelDeltaY : e.detail * -60;
this.adjustMouseEvent(e);
let scale = this.ds.scale;
if (delta > 0) {
scale *= 1.1;
} else if (delta < 0) {
scale *= 1 / 1.1;
if(Math.abs(e.deltaY) < 10) { // Treat smaller delta as touchpad zoom
let deltaS = Math.exp(-e.deltaY / 50);
scale = scale * deltaS;
this.ds.changeScale(scale, [x, y]);
} else { // Mouse zoom
const delta = e.wheelDeltaY != null ? e.wheelDeltaY : e.detail * -60;
this.adjustMouseEvent(e);
if (delta > 0) {
scale *= 1.1;
} else if (delta < 0) {
scale *= 1 / 1.1;
}
}

//this.setZoom( scale, [ e.clientX, e.clientY ] );
Expand Down

0 comments on commit c058c08

Please sign in to comment.