diff --git a/src/pixi/InteractionManager.js b/src/pixi/InteractionManager.js index a3e31bf..646d0a8 100644 --- a/src/pixi/InteractionManager.js +++ b/src/pixi/InteractionManager.js @@ -114,6 +114,12 @@ this.onTouchEnd = this.onTouchEnd.bind(this); /** + * @property onTouchCancel + * @type Function + */ + this.onTouchCancel = this.onTouchCancel.bind(this); + + /** * @property onTouchMove * @type Function */ @@ -240,8 +246,8 @@ // aint no multi touch just yet! domElement.addEventListener('touchstart', this.onTouchStart, true); domElement.addEventListener('touchend', this.onTouchEnd, true); - domElement.addEventListener('touchleave', this.onTouchEnd, true); - domElement.addEventListener('touchcancel', this.onTouchEnd, true); + domElement.addEventListener('touchleave', this.onTouchCancel, true); + domElement.addEventListener('touchcancel', this.onTouchCancel, true); domElement.addEventListener('touchmove', this.onTouchMove, true); window.addEventListener('mouseup', this.onMouseUp, true); @@ -265,8 +271,8 @@ // aint no multi touch just yet! this.interactionDOMElement.removeEventListener('touchstart', this.onTouchStart, true); this.interactionDOMElement.removeEventListener('touchend', this.onTouchEnd, true); - this.interactionDOMElement.removeEventListener('touchleave', this.onTouchEnd, true); - this.interactionDOMElement.removeEventListener('touchcancel', this.onTouchEnd, true); + this.interactionDOMElement.removeEventListener('touchleave', this.onTouchCancel, true); + this.interactionDOMElement.removeEventListener('touchcancel', this.onTouchCancel, true); this.interactionDOMElement.removeEventListener('touchmove', this.onTouchMove, true); this.interactionDOMElement = null; @@ -872,3 +878,67 @@ this.touches[touchEvent.identifier] = null; } }; + +/** + * Is called when a touch is canceled + * + * @method onTouchCancel + * @param event {Event} The DOM event of a touch canceled + * @private + */ +PIXI.InteractionManager.prototype.onTouchCancel = function(event) +{ + if (this.dirty) + { + this.rebuildInteractiveGraph(); + } + + var rect = this.interactionDOMElement.getBoundingClientRect(); + var changedTouches = event.changedTouches; + + for (var i=0; i < changedTouches.length; i++) + { + var 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) + { + //Support for CocoonJS fullscreen scale modes + touchData.global.x = touchEvent.clientX; + touchData.global.y = touchEvent.clientY; + } + + var length = this.interactiveItems.length; + for (var j = 0; j < length; j++) + { + var item = this.interactiveItems[j]; + + if (item.__touchData && item.__touchData[touchEvent.identifier]) + { + + item.__hit = this.hitTest(item, item.__touchData[touchEvent.identifier]); + + // so this one WAS down... + touchData.originalEvent = event; + // hitTest?? + + if (item.touchcancel && !up) + { + item.touchcancel(touchData); + if (!item.interactiveChildren) + { + up = true; + } + } + + item.__isDown = false; + item.__touchData[touchEvent.identifier] = null; + } + } + // remove the touch.. + this.pool.push(touchData); + this.touches[touchEvent.identifier] = null; + } +};