Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize for trackpad gesture #439

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 28 additions & 16 deletions src/litegraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -6993,28 +6993,40 @@ LGraphNode.prototype.executeAction = function(action)
if (!this.graph || !this.allow_dragcanvas) {
return;
}

const x = e.clientX;
const y = e.clientY - this.canvas.getBoundingClientRect().top;
const is_inside = !this.viewport || ( this.viewport && x >= this.viewport[0] && x < (this.viewport[0] + this.viewport[2]) && y >= this.viewport[1] && y < (this.viewport[1] + this.viewport[3]) );

var delta = e.wheelDeltaY != null ? e.wheelDeltaY : e.detail * -60;
if(!is_inside) {
return;
}

this.adjustMouseEvent(e);
const isTouchpadPan = !!e.wheelDeltaY && e.wheelDeltaY === e.deltaY * -3

var x = e.clientX;
var y = e.clientY;
var is_inside = !this.viewport || ( this.viewport && x >= this.viewport[0] && x < (this.viewport[0] + this.viewport[2]) && y >= this.viewport[1] && y < (this.viewport[1] + this.viewport[3]) );
if(!is_inside)
return;

var scale = this.ds.scale;
if(isTouchpadPan) { // Touchpad pan
this.ds.offset[0] += e.deltaX / this.ds.scale * -1;
this.ds.offset[1] += e.deltaY / this.ds.scale * -1;
this.dirty_canvas = true;
this.dirty_bgcanvas = true;
} else {
let scale = this.ds.scale;
if(Math.abs(e.deltaY) < 10) { // Treat smaller delta as touchpad zoom
scale *= Math.exp(-e.deltaY / 50);
} 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;
}
}

if (delta > 0) {
scale *= 1.1;
} else if (delta < 0) {
scale *= 1 / 1.1;
//this.setZoom( scale, [ e.clientX, e.clientY ] );
this.ds.changeScale(scale, [x, y]);
}

//this.setZoom( scale, [ e.clientX, e.clientY ] );
this.ds.changeScale(scale, [e.clientX, e.clientY]);

this.graph.change();

e.preventDefault();
Expand Down