2013-08-31 12:54:59 +00:00
|
|
|
/**
|
2013-10-01 12:54:29 +00:00
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
2014-02-05 05:54:25 +00:00
|
|
|
* @copyright 2014 Photon Storm Ltd.
|
2013-10-01 12:54:29 +00:00
|
|
|
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Phaser - MSPointer constructor.
|
2013-08-31 12:54:59 +00:00
|
|
|
*
|
2013-10-01 12:54:29 +00:00
|
|
|
* @class Phaser.MSPointer
|
|
|
|
* @classdesc The MSPointer class handles touch interactions with the game and the resulting Pointer objects.
|
2013-08-31 12:54:59 +00:00
|
|
|
* It will work only in Internet Explorer 10 and Windows Store or Windows Phone 8 apps using JavaScript.
|
|
|
|
* http://msdn.microsoft.com/en-us/library/ie/hh673557(v=vs.85).aspx
|
2013-10-01 12:54:29 +00:00
|
|
|
* @constructor
|
|
|
|
* @param {Phaser.Game} game - A reference to the currently running game.
|
2013-08-31 12:54:59 +00:00
|
|
|
*/
|
2013-08-31 20:50:34 +00:00
|
|
|
Phaser.MSPointer = function (game) {
|
2013-08-31 12:54:59 +00:00
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
/**
|
|
|
|
* @property {Phaser.Game} game - A reference to the currently running game.
|
|
|
|
*/
|
|
|
|
this.game = game;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {Object} callbackContext - The context under which callbacks are called (defaults to game).
|
|
|
|
*/
|
|
|
|
this.callbackContext = this.game;
|
2013-08-31 12:54:59 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* You can disable all Input by setting disabled = true. While set all new input related events will be ignored.
|
2013-10-01 15:39:39 +00:00
|
|
|
* @property {boolean} disabled
|
2013-08-31 12:54:59 +00:00
|
|
|
*/
|
2013-10-02 14:05:55 +00:00
|
|
|
this.disabled = false;
|
2013-08-31 12:54:59 +00:00
|
|
|
|
2013-10-02 14:05:55 +00:00
|
|
|
/**
|
2013-11-25 03:13:04 +00:00
|
|
|
* @property {function} _onMSPointerDown - Internal function to handle MSPointer events.
|
2013-10-02 14:05:55 +00:00
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this._onMSPointerDown = null;
|
2013-10-01 12:54:29 +00:00
|
|
|
|
2013-10-02 14:05:55 +00:00
|
|
|
/**
|
2013-11-25 03:13:04 +00:00
|
|
|
* @property {function} _onMSPointerMove - Internal function to handle MSPointer events.
|
2013-10-02 14:05:55 +00:00
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this._onMSPointerMove = null;
|
2013-10-01 12:54:29 +00:00
|
|
|
|
2013-10-02 14:05:55 +00:00
|
|
|
/**
|
2013-11-25 03:13:04 +00:00
|
|
|
* @property {function} _onMSPointerUp - Internal function to handle MSPointer events.
|
2013-10-02 14:05:55 +00:00
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this._onMSPointerUp = null;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
Phaser.MSPointer.prototype = {
|
2013-08-31 12:54:59 +00:00
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
/**
|
2013-10-01 12:54:29 +00:00
|
|
|
* Starts the event listeners running.
|
2013-10-02 14:05:55 +00:00
|
|
|
* @method Phaser.MSPointer#start
|
2013-08-31 12:54:59 +00:00
|
|
|
*/
|
|
|
|
start: function () {
|
|
|
|
|
|
|
|
var _this = this;
|
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
if (this.game.device.mspointer === true)
|
2013-08-31 12:54:59 +00:00
|
|
|
{
|
|
|
|
this._onMSPointerDown = function (event) {
|
|
|
|
return _this.onPointerDown(event);
|
|
|
|
};
|
|
|
|
|
|
|
|
this._onMSPointerMove = function (event) {
|
|
|
|
return _this.onPointerMove(event);
|
|
|
|
};
|
|
|
|
|
|
|
|
this._onMSPointerUp = function (event) {
|
|
|
|
return _this.onPointerUp(event);
|
|
|
|
};
|
|
|
|
|
2013-09-10 15:46:39 +00:00
|
|
|
this.game.renderer.view.addEventListener('MSPointerDown', this._onMSPointerDown, false);
|
|
|
|
this.game.renderer.view.addEventListener('MSPointerMove', this._onMSPointerMove, false);
|
|
|
|
this.game.renderer.view.addEventListener('MSPointerUp', this._onMSPointerUp, false);
|
2013-08-31 20:50:34 +00:00
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
// IE11+ uses non-prefix events
|
|
|
|
this.game.renderer.view.addEventListener('pointerDown', this._onMSPointerDown, false);
|
|
|
|
this.game.renderer.view.addEventListener('pointerMove', this._onMSPointerMove, false);
|
|
|
|
this.game.renderer.view.addEventListener('pointerUp', this._onMSPointerUp, false);
|
|
|
|
|
2013-09-10 15:46:39 +00:00
|
|
|
this.game.renderer.view.style['-ms-content-zooming'] = 'none';
|
|
|
|
this.game.renderer.view.style['-ms-touch-action'] = 'none';
|
2013-08-31 20:50:34 +00:00
|
|
|
|
2013-08-31 12:54:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2013-11-25 03:13:04 +00:00
|
|
|
* The function that handles the PointerDown event.
|
2013-10-02 14:05:55 +00:00
|
|
|
* @method Phaser.MSPointer#onPointerDown
|
2013-11-25 03:13:04 +00:00
|
|
|
* @param {PointerEvent} event
|
|
|
|
*/
|
2013-08-31 12:54:59 +00:00
|
|
|
onPointerDown: function (event) {
|
|
|
|
|
|
|
|
if (this.game.input.disabled || this.disabled)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
event.identifier = event.pointerId;
|
|
|
|
|
|
|
|
this.game.input.startPointer(event);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2013-11-25 03:13:04 +00:00
|
|
|
* The function that handles the PointerMove event.
|
2013-10-02 14:05:55 +00:00
|
|
|
* @method Phaser.MSPointer#onPointerMove
|
2013-11-25 03:13:04 +00:00
|
|
|
* @param {PointerEvent } event
|
|
|
|
*/
|
2013-08-31 12:54:59 +00:00
|
|
|
onPointerMove: function (event) {
|
|
|
|
|
|
|
|
if (this.game.input.disabled || this.disabled)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
event.identifier = event.pointerId;
|
|
|
|
|
|
|
|
this.game.input.updatePointer(event);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2013-11-25 03:13:04 +00:00
|
|
|
* The function that handles the PointerUp event.
|
2013-10-02 14:05:55 +00:00
|
|
|
* @method Phaser.MSPointer#onPointerUp
|
2013-11-25 03:13:04 +00:00
|
|
|
* @param {PointerEvent} event
|
|
|
|
*/
|
2013-08-31 12:54:59 +00:00
|
|
|
onPointerUp: function (event) {
|
|
|
|
|
|
|
|
if (this.game.input.disabled || this.disabled)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
event.identifier = event.pointerId;
|
|
|
|
|
|
|
|
this.game.input.stopPointer(event);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
/**
|
2013-10-01 12:54:29 +00:00
|
|
|
* Stop the event listeners.
|
2013-10-02 14:05:55 +00:00
|
|
|
* @method Phaser.MSPointer#stop
|
2013-08-31 12:54:59 +00:00
|
|
|
*/
|
|
|
|
stop: function () {
|
|
|
|
|
2014-02-13 12:55:58 +00:00
|
|
|
this.game.canvas.removeEventListener('MSPointerDown', this._onMSPointerDown);
|
|
|
|
this.game.canvas.removeEventListener('MSPointerMove', this._onMSPointerMove);
|
|
|
|
this.game.canvas.removeEventListener('MSPointerUp', this._onMSPointerUp);
|
2013-08-31 12:54:59 +00:00
|
|
|
|
2014-02-13 12:55:58 +00:00
|
|
|
this.game.canvas.removeEventListener('pointerDown', this._onMSPointerDown);
|
|
|
|
this.game.canvas.removeEventListener('pointerMove', this._onMSPointerMove);
|
|
|
|
this.game.canvas.removeEventListener('pointerUp', this._onMSPointerUp);
|
2013-11-25 03:13:04 +00:00
|
|
|
|
2013-08-31 12:54:59 +00:00
|
|
|
}
|
|
|
|
|
2013-12-30 16:54:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Phaser.MSPointer.prototype.constructor = Phaser.MSPointer;
|