/**
* [read-only] The x coordinate on the canvas area of the latest touch event.
*
* @static
* @property x
* @type Number
*/
Object.defineProperty(TouchInput, 'x', {
get: function() {
return this._x;
},
configurable: true
});
/**
* [read-only] The y coordinate on the canvas area of the latest touch event.
*
* @static
* @property y
* @type Number
*/
Object.defineProperty(TouchInput, 'y', {
get: function() {
return this._y;
},
configurable: true
});
/**
* [read-only] The time of the last input in milliseconds.
*
* @static
* @property date
* @type Number
*/
Object.defineProperty(TouchInput, 'date', {
get: function() {
return this._date;
},
configurable: true
});
/**
* @static
* @method _setupEventHandlers
* @private
*/
TouchInput._setupEventHandlers = function() {
document.addEventListener('mousedown', this._onMouseDown.bind(this));
document.addEventListener('mousemove', this._onMouseMove.bind(this));
document.addEventListener('mouseup', this._onMouseUp.bind(this));
document.addEventListener('wheel', this._onWheel.bind(this));
document.addEventListener('touchstart', this._onTouchStart.bind(this));
document.addEventListener('touchmove', this._onTouchMove.bind(this));
document.addEventListener('touchend', this._onTouchEnd.bind(this));
document.addEventListener('touchcancel', this._onTouchCancel.bind(this));
document.addEventListener('pointerdown', this._onPointerDown.bind(this));
};
/**
* @static
* @method _onMouseDown
* @param {MouseEvent} event
* @private
*/
TouchInput._onMouseDown = function(event) {
if (event.button === 0) {
this._onLeftButtonDown(event);
} else if (event.button === 1) {
this._onMiddleButtonDown(event);
} else if (event.button === 2) {
this._onRightButtonDown(event);
}
};
/**
* @static
* @method _onLeftButtonDown
* @param {MouseEvent} event
* @private
*/
TouchInput._onLeftButtonDown = function(event) {
var x = Graphics.pageToCanvasX(event.pageX);
var y = Graphics.pageToCanvasY(event.pageY);
if (Graphics.isInsideCanvas(x, y)) {
this._mousePressed = true;
this._pressedTime = 0;
this._onTrigger(x, y);
}
};