diff --git a/src/pixi/InteractionData.js b/src/pixi/InteractionData.js index b0d8a6a..326007c 100644 --- a/src/pixi/InteractionData.js +++ b/src/pixi/InteractionData.js @@ -41,12 +41,13 @@ * @method getLocalPosition * @param displayObject {DisplayObject} The DisplayObject that you would like the local coords off * @param [point] {Point} A Point object in which to store the value, optional (otherwise will create a new point) + * param [globalPos] {Point} A Point object containing your custom global coords, optional (otherwise will use the current global coords) * @return {Point} A point containing the coordinates of the InteractionData position relative to the DisplayObject */ -PIXI.InteractionData.prototype.getLocalPosition = function(displayObject, point) +PIXI.InteractionData.prototype.getLocalPosition = function(displayObject, point, globalPos) { var worldTransform = displayObject.worldTransform; - var global = this.global; + var global = globalPos ? globalPos : this.global; // do a cheeky transform to get the mouse coords; var a00 = worldTransform.a, a01 = worldTransform.c, a02 = worldTransform.tx, diff --git a/src/pixi/InteractionData.js b/src/pixi/InteractionData.js index b0d8a6a..326007c 100644 --- a/src/pixi/InteractionData.js +++ b/src/pixi/InteractionData.js @@ -41,12 +41,13 @@ * @method getLocalPosition * @param displayObject {DisplayObject} The DisplayObject that you would like the local coords off * @param [point] {Point} A Point object in which to store the value, optional (otherwise will create a new point) + * param [globalPos] {Point} A Point object containing your custom global coords, optional (otherwise will use the current global coords) * @return {Point} A point containing the coordinates of the InteractionData position relative to the DisplayObject */ -PIXI.InteractionData.prototype.getLocalPosition = function(displayObject, point) +PIXI.InteractionData.prototype.getLocalPosition = function(displayObject, point, globalPos) { var worldTransform = displayObject.worldTransform; - var global = this.global; + var global = globalPos ? globalPos : this.global; // do a cheeky transform to get the mouse coords; var a00 = worldTransform.a, a01 = worldTransform.c, a02 = worldTransform.tx, diff --git a/src/pixi/InteractionManager.js b/src/pixi/InteractionManager.js index 646d0a8..1119957 100644 --- a/src/pixi/InteractionManager.js +++ b/src/pixi/InteractionManager.js @@ -699,18 +699,41 @@ var rect = this.interactionDOMElement.getBoundingClientRect(); var changedTouches = event.changedTouches; var touchData; - var i = 0; - for (i = 0; i < changedTouches.length; i++) + var cLength = changedTouches.length; + var wCalc = (this.target.width / rect.width); + var hCalc = (this.target.height / rect.height); + var isSupportCocoonJS = navigator.isCocoonJS && !rect.left && !rect.top && !event.target.style.width && !event.target.style.height; + var touchEvent; + + for (var c = 0; c < cLength; c++) { - var touchEvent = changedTouches[i]; + touchEvent = changedTouches[c]; + if(!isSupportCocoonJS) + { + touchEvent.globalX = ( (touchEvent.clientX - rect.left) * wCalc ) / this.resolution; + touchEvent.globalY = ( (touchEvent.clientY - rect.top) * hCalc ) / this.resolution; + } + else + { + touchEvent.globalX = touchEvent.clientX; + touchEvent.globalY = touchEvent.clientY; + } + } + + for (var i = 0; i < cLength; i++) + { + touchEvent = changedTouches[i]; touchData = this.touches[touchEvent.identifier]; touchData.originalEvent = event; // update the touch position - touchData.global.x = ( (touchEvent.clientX - rect.left) * (this.target.width / rect.width) ) / this.resolution; - touchData.global.y = ( (touchEvent.clientY - rect.top) * (this.target.height / rect.height) ) / this.resolution; - if (navigator.isCocoonJS && !rect.left && !rect.top && !event.target.style.width && !event.target.style.height) + if (!isSupportCocoonJS) + { + touchData.global.x = ( (touchEvent.clientX - rect.left) * wCalc ) / this.resolution; + touchData.global.y = ( (touchEvent.clientY - rect.top) * hCalc ) / this.resolution; + } + else { //Support for CocoonJS fullscreen scale modes touchData.global.x = touchEvent.clientX; @@ -750,9 +773,31 @@ } var changedTouches = event.changedTouches; - for (var i=0; i < changedTouches.length; i++) + + var cLength = changedTouches.length; + var wCalc = (this.target.width / rect.width); + var hCalc = (this.target.height / rect.height); + var isSupportCocoonJS = navigator.isCocoonJS && !rect.left && !rect.top && !event.target.style.width && !event.target.style.height; + var touchEvent; + + for (var c = 0; c < cLength; c++) { - var touchEvent = changedTouches[i]; + touchEvent = changedTouches[c]; + if(!isSupportCocoonJS) + { + touchEvent.globalX = ( (touchEvent.clientX - rect.left) * wCalc ) / this.resolution; + touchEvent.globalY = ( (touchEvent.clientY - rect.top) * hCalc ) / this.resolution; + } + else + { + touchEvent.globalX = touchEvent.clientX; + touchEvent.globalY = touchEvent.clientY; + } + } + + for (var i=0; i < cLength; i++) + { + touchEvent = changedTouches[i]; var touchData = this.pool.pop(); if (!touchData) @@ -763,9 +808,12 @@ touchData.originalEvent = event; this.touches[touchEvent.identifier] = touchData; - touchData.global.x = ( (touchEvent.clientX - rect.left) * (this.target.width / rect.width) ) / this.resolution; - touchData.global.y = ( (touchEvent.clientY - rect.top) * (this.target.height / rect.height) ) / this.resolution; - if (navigator.isCocoonJS && !rect.left && !rect.top && !event.target.style.width && !event.target.style.height) + if (!isSupportCocoonJS) + { + touchData.global.x = ( (touchEvent.clientX - rect.left) * wCalc ) / this.resolution; + touchData.global.y = ( (touchEvent.clientY - rect.top) * hCalc ) / this.resolution; + } + else { //Support for CocoonJS fullscreen scale modes touchData.global.x = touchEvent.clientX; @@ -814,14 +862,38 @@ var rect = this.interactionDOMElement.getBoundingClientRect(); var changedTouches = event.changedTouches; - for (var i=0; i < changedTouches.length; i++) + var cLength = changedTouches.length; + var wCalc = (this.target.width / rect.width); + var hCalc = (this.target.height / rect.height); + var isSupportCocoonJS = navigator.isCocoonJS && !rect.left && !rect.top && !event.target.style.width && !event.target.style.height; + var touchEvent; + + for (var c = 0; c < cLength; c++) { - var touchEvent = changedTouches[i]; + touchEvent = changedTouches[c]; + if(!isSupportCocoonJS) + { + touchEvent.globalX = ( (touchEvent.clientX - rect.left) * wCalc ) / this.resolution; + touchEvent.globalY = ( (touchEvent.clientY - rect.top) * hCalc ) / this.resolution; + } + else + { + touchEvent.globalX = touchEvent.clientX; + touchEvent.globalY = touchEvent.clientY; + } + } + + for (var i=0; i < cLength; i++) + { + touchEvent = changedTouches[i]; var touchData = this.touches[touchEvent.identifier]; var up = false; - touchData.global.x = ( (touchEvent.clientX - rect.left) * (this.target.width / rect.width) ) / this.resolution; - touchData.global.y = ( (touchEvent.clientY - rect.top) * (this.target.height / rect.height) ) / this.resolution; - if (navigator.isCocoonJS && !rect.left && !rect.top && !event.target.style.width && !event.target.style.height) + if (!isSupportCocoonJS) + { + touchData.global.x = ( (touchEvent.clientX - rect.left) * wCalc ) / this.resolution; + touchData.global.y = ( (touchEvent.clientY - rect.top) * hCalc ) / this.resolution; + } + else { //Support for CocoonJS fullscreen scale modes touchData.global.x = touchEvent.clientX; @@ -896,14 +968,38 @@ var rect = this.interactionDOMElement.getBoundingClientRect(); var changedTouches = event.changedTouches; - for (var i=0; i < changedTouches.length; i++) + var cLength = changedTouches.length; + var wCalc = (this.target.width / rect.width); + var hCalc = (this.target.height / rect.height); + var isSupportCocoonJS = navigator.isCocoonJS && !rect.left && !rect.top && !event.target.style.width && !event.target.style.height; + var touchEvent; + + for (var c = 0; c < cLength; c++) { - var touchEvent = changedTouches[i]; + touchEvent = changedTouches[c]; + if(!isSupportCocoonJS) + { + touchEvent.globalX = ( (touchEvent.clientX - rect.left) * wCalc ) / this.resolution; + touchEvent.globalY = ( (touchEvent.clientY - rect.top) * hCalc ) / this.resolution; + } + else + { + touchEvent.globalX = touchEvent.clientX; + touchEvent.globalY = touchEvent.clientY; + } + } + + for (var i=0; i < cLength; i++) + { + touchEvent = changedTouches[i]; var touchData = this.touches[touchEvent.identifier]; var up = false; - touchData.global.x = ( (touchEvent.clientX - rect.left) * (this.target.width / rect.width) ) / this.resolution; - touchData.global.y = ( (touchEvent.clientY - rect.top) * (this.target.height / rect.height) ) / this.resolution; - if (navigator.isCocoonJS && !rect.left && !rect.top && !event.target.style.width && !event.target.style.height) + if (!isSupportCocoonJS) + { + touchData.global.x = ( (touchEvent.clientX - rect.left) * wCalc ) / this.resolution; + touchData.global.y = ( (touchEvent.clientY - rect.top) * hCalc ) / this.resolution; + } + else { //Support for CocoonJS fullscreen scale modes touchData.global.x = touchEvent.clientX;