2017-07-13 16:21:37 +00:00
|
|
|
// Phaser.Input.Pointer
|
|
|
|
|
|
|
|
var Class = require('../utils/Class');
|
|
|
|
|
|
|
|
var Pointer = new Class({
|
|
|
|
|
|
|
|
initialize:
|
|
|
|
|
2017-07-21 02:39:55 +00:00
|
|
|
function Pointer (manager, id)
|
2017-07-13 16:21:37 +00:00
|
|
|
{
|
|
|
|
this.manager = manager;
|
|
|
|
|
2017-07-21 02:39:55 +00:00
|
|
|
this.id = id;
|
|
|
|
|
2017-07-18 01:36:45 +00:00
|
|
|
this.event;
|
|
|
|
|
2017-07-25 11:33:53 +00:00
|
|
|
// 0 : No button or un-initialized
|
|
|
|
// 1 : Left button
|
|
|
|
// 2 : Right button
|
|
|
|
// 4 : Wheel button or middle button
|
|
|
|
// 8 : 4th button (typically the "Browser Back" button)
|
|
|
|
// 16 : 5th button (typically the "Browser Forward" button)
|
|
|
|
this.buttons = 0;
|
2017-07-17 22:38:43 +00:00
|
|
|
|
2017-07-13 16:21:37 +00:00
|
|
|
this.x = 0;
|
|
|
|
this.y = 0;
|
|
|
|
|
|
|
|
this.isDown = false;
|
2017-07-14 00:38:21 +00:00
|
|
|
|
|
|
|
this.dirty = false;
|
|
|
|
|
|
|
|
this.justDown = false;
|
|
|
|
this.justUp = false;
|
|
|
|
this.justMoved = false;
|
|
|
|
},
|
|
|
|
|
|
|
|
reset: function ()
|
|
|
|
{
|
2017-07-25 11:33:53 +00:00
|
|
|
this.buttons = 0;
|
|
|
|
|
2017-07-14 00:38:21 +00:00
|
|
|
this.dirty = false;
|
2017-07-18 16:22:14 +00:00
|
|
|
this.isDown = false;
|
2017-07-14 00:38:21 +00:00
|
|
|
this.justDown = false;
|
|
|
|
this.justUp = false;
|
|
|
|
this.justMoved = false;
|
2017-07-13 16:21:37 +00:00
|
|
|
},
|
|
|
|
|
2017-07-14 00:38:21 +00:00
|
|
|
move: function (event)
|
2017-07-13 16:21:37 +00:00
|
|
|
{
|
2017-07-25 11:33:53 +00:00
|
|
|
if (event.buttons)
|
2017-07-17 22:38:43 +00:00
|
|
|
{
|
2017-07-25 11:33:53 +00:00
|
|
|
this.buttons = event.buttons;
|
2017-07-17 22:38:43 +00:00
|
|
|
}
|
2017-07-14 00:38:21 +00:00
|
|
|
|
2017-07-18 01:36:45 +00:00
|
|
|
this.event = event;
|
2017-07-14 00:38:21 +00:00
|
|
|
|
2017-07-17 22:38:43 +00:00
|
|
|
this.x = this.manager.transformX(event.pageX);
|
|
|
|
this.y = this.manager.transformY(event.pageY);
|
|
|
|
|
2017-07-14 00:38:21 +00:00
|
|
|
this.justMoved = true;
|
2017-07-18 16:22:14 +00:00
|
|
|
|
|
|
|
this.dirty = true;
|
2017-07-14 00:38:21 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
down: function (event)
|
|
|
|
{
|
2017-07-25 11:33:53 +00:00
|
|
|
if (event.buttons)
|
2017-07-18 01:36:45 +00:00
|
|
|
{
|
2017-07-25 11:33:53 +00:00
|
|
|
this.buttons = event.buttons;
|
2017-07-18 01:36:45 +00:00
|
|
|
}
|
2017-07-14 00:38:21 +00:00
|
|
|
|
2017-07-18 01:36:45 +00:00
|
|
|
this.event = event;
|
|
|
|
|
|
|
|
this.x = this.manager.transformX(event.pageX);
|
|
|
|
this.y = this.manager.transformY(event.pageY);
|
|
|
|
|
2017-07-14 00:38:21 +00:00
|
|
|
this.justDown = true;
|
2017-07-18 16:22:14 +00:00
|
|
|
this.isDown = true;
|
|
|
|
|
|
|
|
this.dirty = true;
|
2017-07-14 00:38:21 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
up: function (event)
|
|
|
|
{
|
2017-07-25 11:33:53 +00:00
|
|
|
if (event.buttons)
|
2017-07-18 01:36:45 +00:00
|
|
|
{
|
2017-07-25 11:33:53 +00:00
|
|
|
this.buttons = event.buttons;
|
2017-07-18 01:36:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this.event = event;
|
|
|
|
|
|
|
|
this.x = this.manager.transformX(event.pageX);
|
|
|
|
this.y = this.manager.transformY(event.pageY);
|
2017-07-14 00:38:21 +00:00
|
|
|
|
|
|
|
this.justUp = true;
|
2017-07-18 16:22:14 +00:00
|
|
|
this.isDown = false;
|
|
|
|
|
|
|
|
this.dirty = true;
|
2017-07-25 11:33:53 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
noButtonDown: function ()
|
|
|
|
{
|
|
|
|
return (this.buttons === 0);
|
|
|
|
},
|
|
|
|
|
|
|
|
leftButtonDown: function ()
|
|
|
|
{
|
|
|
|
return (this.buttons & 1);
|
|
|
|
},
|
|
|
|
|
|
|
|
rightButtonDown: function ()
|
|
|
|
{
|
|
|
|
return (this.buttons & 2);
|
|
|
|
},
|
|
|
|
|
|
|
|
middleButtonDown: function ()
|
|
|
|
{
|
|
|
|
return (this.buttons & 4);
|
|
|
|
},
|
|
|
|
|
|
|
|
backButtonDown: function ()
|
|
|
|
{
|
|
|
|
return (this.buttons & 8);
|
|
|
|
},
|
|
|
|
|
|
|
|
forwardButtonDown: function ()
|
|
|
|
{
|
|
|
|
return (this.buttons & 16);
|
2017-07-13 16:21:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = Pointer;
|