From 6bab9a1f972db43b85fabe53b891f71c3e09a2c5 Mon Sep 17 00:00:00 2001 From: Christopher Dyken Date: Wed, 11 Jun 2014 19:47:42 +0200 Subject: [PATCH 1/3] Pasted touch event handling from old viewlet. --- js/shared/DSRV.js | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/js/shared/DSRV.js b/js/shared/DSRV.js index e7b06a1..5c17d80 100644 --- a/js/shared/DSRV.js +++ b/js/shared/DSRV.js @@ -331,6 +331,40 @@ DSRV.prototype = { this.m_manipulator.setStateNone( x, y ); //this.pushMatrices(); }, + + touchStartEvent: function (event) + { + if( event.touches.length == 1 ) { + event.button = this.ROTATE; + this.mousePressEvent(event); + } + else if( event.touches.length == 2 ) { + event.button = this.ZOOM; + this.mousePressEvent(event); + } + }, + touchEndEvent: function (event) + { + if( event.touches.length == 1 ) { + event.button = this.ROTATE; + this.mouseReleaseEvent(event); + } + else if( event.touches.length == 2 ) { + event.button = this.ZOOM; + this.mouseReleaseEvent(event); + } + }, + touchMoveEvent: function (event) + { + if( event.touches.length == 1 ) { + event.button = this.ROTATE; + this.mouseMoveEvent(event); + } + else if(event.touches.length == 2) { + event.button = this.ZOOM; + this.mouseMoveEvent(event); + } + }, pushMatrices: function() { var viewer = this.m_model.getElementValue( this.m_key ); viewer.updateElement( "modelview", this.m_manipulator.modelviewMatrix() ); From 8cda866622c07a81b2e56da3d08d0864761698d7 Mon Sep 17 00:00:00 2001 From: Christopher Dyken Date: Wed, 11 Jun 2014 20:17:30 +0200 Subject: [PATCH 2/3] Added handling of empty touchlist in touchend (which is the case for touch-emulation in chrome). Cache the most recent event and use that instead. --- js/gui/Canvas.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/js/gui/Canvas.js b/js/gui/Canvas.js index 36ac2fc..8180e93 100644 --- a/js/gui/Canvas.js +++ b/js/gui/Canvas.js @@ -256,6 +256,7 @@ dojo.declare("gui.Canvas", [dijit._Widget], { _touchstart: function (event) { this._active = true; + this._touch_prev = event; // We need to add the relative placement informatoin to all touch events for(var i = 0; i < event.touches.length; ++i) { @@ -280,6 +281,11 @@ dojo.declare("gui.Canvas", [dijit._Widget], { _touchend: function (event) { this._active = false; + if( event.touches.length == 0 ) { + // Use last active position + event = this._touch_prev; + } + for(var i = 0; i < event.touches.length; ++i) { var x = event.touches[i].pageX - this._placementX(); var y = event.touches[i].pageY - this._placementY(); @@ -303,6 +309,7 @@ dojo.declare("gui.Canvas", [dijit._Widget], { }, _touchmove: function (event) { + this._touch_prev = event; for(var i = 0; i < event.touches.length; ++i) { var x = event.touches[i].pageX - this._placementX(); var y = event.touches[i].pageY - this._placementY(); From ccc3b50529869189a11b059e26aa4cc74565943d Mon Sep 17 00:00:00 2001 From: Christopher Dyken Date: Wed, 11 Jun 2014 20:25:13 +0200 Subject: [PATCH 3/3] Fixed usage of undefined constants. --- js/shared/DSRV.js | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/js/shared/DSRV.js b/js/shared/DSRV.js index 5c17d80..5915218 100644 --- a/js/shared/DSRV.js +++ b/js/shared/DSRV.js @@ -335,33 +335,45 @@ DSRV.prototype = { touchStartEvent: function (event) { if( event.touches.length == 1 ) { - event.button = this.ROTATE; + event.button = 0; this.mousePressEvent(event); } else if( event.touches.length == 2 ) { - event.button = this.ZOOM; + event.button = 2; + this.mousePressEvent(event); + } + else if( event.touches.length == 3 ) { + event.button = 1; this.mousePressEvent(event); } }, touchEndEvent: function (event) { if( event.touches.length == 1 ) { - event.button = this.ROTATE; + event.button = 0; this.mouseReleaseEvent(event); } else if( event.touches.length == 2 ) { - event.button = this.ZOOM; + event.button = 2; + this.mouseReleaseEvent(event); + } + else if( event.touches.length == 3 ) { + event.button = 1; this.mouseReleaseEvent(event); } }, touchMoveEvent: function (event) { if( event.touches.length == 1 ) { - event.button = this.ROTATE; + event.button = 0; this.mouseMoveEvent(event); } else if(event.touches.length == 2) { - event.button = this.ZOOM; + event.button = 2; + this.mouseMoveEvent(event); + } + else if(event.touches.length == 3) { + event.button = 1; this.mouseMoveEvent(event); } },