Hi James & Max - here's how to enable Mac trackpad multi-touch navigation in the node editor when the next MoI beta is out. These are all in the file main.js
Inside LGraphCanvas.prototype.bindEvents add this:
code:
this._trackpadgesture_callback = this.bindFunction(this.trackpadHandler, this);
canvas.addEventListener("trackpadgesture", this._trackpadgesture_callback, true);
Inside LGraphCanvas.prototype.unbindEvents add this:
code:
this.canvas.removeEventListener("trackpadggesture", this.trackpadHandler );
Then add this function:
code:
LGraphCanvas.prototype.trackpadHandler = function(e)
{
if(!this.graph || !this.allow_dragcanvas || this.selection_mode) return;
if ( e.gestureType == 'Zoom' )
{
// Pinch gesture.
var speed = 2.0;
var factor = 1.0 + (e.scaleFactor * speed);
var newscale = this.scale * factor;
if ( newscale > 0.0 )
{
this.adjustMouseEvent(e);
this.setZoom( newscale, [ e.localX, e.localY ] );
this.graph.sendActionToCanvas("setDirty",[true,true]);
}
}
else if ( e.gestureType == 'Scroll' )
{
// 2 fingers scroll gesture.
// If Ctrl is down, return without calling event.preventDefault() so
// a mouse wheel event will be triggered.
if ( e.ctrlKey )
return;
var speed = 1.0;
this.offset[0] += (e.deltaX * speed) / this.scale;
this.offset[1] += (e.deltaY * speed) / this.scale;
this.graph.sendActionToCanvas("setDirty",[true,true]);
// Note: don't set this.canvas_moved = true; like right mouse drag uses because
// it's used to disable context menus if the right mouse was dragged instead
// of clicked. If we set it here it makes context menus hard to launch.
}
else if ( e.gestureType == 'SmartZoom' )
{
// 2 finger double tap, use for zoom extents / reset view.
// TODO
}
e.preventDefault();
}
- Michael
|