phaser/v3/src/input/mouse/MouseManager.js

68 lines
1.5 KiB
JavaScript
Raw Normal View History

2017-06-14 00:20:01 +00:00
// https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent
// https://github.com/WICG/EventListenerOptions/blob/gh-pages/explainer.md
var MouseManager = function (inputManager)
{
this.manager = inputManager;
this.enabled = false;
this.target;
2017-06-14 00:20:01 +00:00
this.handler;
};
MouseManager.prototype.constructor = MouseManager;
MouseManager.prototype = {
boot: function ()
{
var config = this.manager.gameConfig;
this.enabled = config.inputMouse;
this.target = config.inputMouseEventTarget;
if (!this.target)
{
this.target = this.manager.game.canvas;
}
if (this.enabled)
{
this.startListeners();
}
},
startListeners: function ()
{
2017-06-14 00:20:01 +00:00
var queue = this.manager.queue;
2017-06-14 00:20:01 +00:00
var handler = function (event)
{
if (event.preventDefaulted)
{
// Do nothing if event already handled
return;
}
queue.push(event);
};
2017-06-14 00:20:01 +00:00
this.handler = handler;
2017-06-14 00:20:01 +00:00
this.target.addEventListener('mousemove', handler, false);
this.target.addEventListener('mousedown', handler, false);
this.target.addEventListener('mouseup', handler, false);
},
stopListeners: function ()
{
2017-06-14 00:20:01 +00:00
this.target.removeEventListener('mousemove', this.handler);
this.target.removeEventListener('mousedown', this.handler);
this.target.removeEventListener('mouseup', this.handler);
}
};
module.exports = MouseManager;