From 93eed8ef570d45fcbf53993d59ba64d9f9bb1c95 Mon Sep 17 00:00:00 2001 From: Livingroom Date: Wed, 14 Dec 2011 16:00:28 +0100 Subject: [PATCH] Added a z coordinate to MultiTouchXY z is for Touch Up / Down. Is being send if sendZValue is true (by default false). --- www/js/MultiTouchXY.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/www/js/MultiTouchXY.js b/www/js/MultiTouchXY.js index 4a62b21..9ba2f1f 100644 --- a/www/js/MultiTouchXY.js +++ b/www/js/MultiTouchXY.js @@ -4,6 +4,8 @@ function MultiTouchXY(ctx, props) { this.make(ctx, props); this.xvalue = this.min; this.yvalue = this.min; + this.zvalue = false; + this.sendZValue = (typeof props.sendZValue == "undefined") ? false : props.sendZValue; this.half = (this.width / 8) / 2; this.maxTouches = props.maxTouches > 0 ? props.maxTouches : 1; this.children = []; @@ -73,7 +75,7 @@ MultiTouchXY.prototype.addTouch = function(xPos, yPos, id) { touch.activeNumber = this.children.length; $(touch).text(touch.activeNumber); this.container.appendChild(touch); - //this.changeValue(touch, xPos, yPos); + this.changeValue(touch, xPos, yPos, 1); } MultiTouchXY.prototype.removeTouch = function(touchToRemove) { @@ -106,7 +108,7 @@ MultiTouchXY.prototype.trackTouch = function(xPos, yPos, id) { touchFound.id = id; touchFound.isActive = true; if(touchFound != null) - this.changeValue(touchFound, xPos, yPos); + this.changeValue(touchFound, xPos, yPos, 1); this.lastTouched = touchFound; } @@ -130,7 +132,7 @@ MultiTouchXY.prototype.event = function(event) { for(var t = 0; t < this.children.length; t++) { _t = this.children[t]; if(touch.identifier == _t.id) { - this.changeValue(_t, touch.pageX, touch.pageY); + this.changeValue(_t, touch.pageX, touch.pageY, 1); eval(this.ontouchmove); break; } @@ -141,6 +143,9 @@ MultiTouchXY.prototype.event = function(event) { for(var t = 0; t < this.children.length; t++) { _t = this.children[t]; if(touch.identifier == _t.id) { + if(this.sendZValue){ + this.changeValue(_t, touch.pageX, touch.pageY, 0); + } eval(this.ontouchend); if(this.isMomentary) { this.removeTouch(_t); @@ -155,7 +160,7 @@ MultiTouchXY.prototype.event = function(event) { } } -MultiTouchXY.prototype.changeValue = function(touch, inputX, inputY) { +MultiTouchXY.prototype.changeValue = function(touch, inputX, inputY, inputZ) { var xLeft = inputX - this.half; var xRight = inputX + this.half; var yTop = inputY - this.half; @@ -207,6 +212,7 @@ MultiTouchXY.prototype.changeValue = function(touch, inputX, inputY) { this.xvalue = Math.round(this.min + (touch.xpercentage * range)); this.yvalue = Math.round(this.min + (touch.ypercentage * range)); } + this.zvalue = inputZ; if(this.onvaluechange != null) eval(this.onvaluechange); if(!this.isLocal) this.output(touch); @@ -262,6 +268,9 @@ MultiTouchXY.prototype.output = function(touch) { valueString += "/" + touch.activeNumber; } valueString += ":" + this.xvalue + "," + this.yvalue; + if(this.sendZValue){ + valueString += ","+this.zvalue; + } }else if(_protocol == "MIDI") { var xnum = this.midiNumber + (touch.activeNumber * 2) - 2; var ynum = xnum + 1;