forked from phaserjs/phaser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMouseManager.js
More file actions
70 lines (51 loc) · 1.56 KB
/
Copy pathMouseManager.js
File metadata and controls
70 lines (51 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
var Class = require('../../utils/Class');
// https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent
// https://github.com/WICG/EventListenerOptions/blob/gh-pages/explainer.md
var MouseManager = new Class({
initialize:
function MouseManager (inputManager)
{
this.manager = inputManager;
this.enabled = false;
this.target;
this.handler;
},
boot: function ()
{
var config = this.manager.config;
this.enabled = config.inputMouse;
this.target = config.inputMouseEventTarget;
if (!this.target)
{
this.target = this.manager.game.canvas;
}
if (this.enabled)
{
this.startListeners();
}
},
startListeners: function ()
{
var queue = this.manager.queue;
var handler = function (event)
{
if (event.preventDefaulted)
{
// Do nothing if event already handled
return;
}
queue.push(event);
};
this.handler = handler;
this.target.addEventListener('mousemove', handler, false);
this.target.addEventListener('mousedown', handler, false);
this.target.addEventListener('mouseup', handler, false);
},
stopListeners: function ()
{
this.target.removeEventListener('mousemove', this.handler);
this.target.removeEventListener('mousedown', this.handler);
this.target.removeEventListener('mouseup', this.handler);
}
});
module.exports = MouseManager;