Skip to content

Commit

Permalink
Merge pull request #19 from HalfdanJ/develop
Browse files Browse the repository at this point in the history
MultiTouchXY
  • Loading branch information
charlieroberts-rit committed Dec 14, 2011
2 parents 7ce2a54 + 93eed8e commit 3a3689a
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions www/js/MultiTouchXY.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 3a3689a

Please sign in to comment.