Skip to content

Commit b6b7715

Browse files
committed
Mouse Input Handler working. Demo created.
1 parent ca1b483 commit b6b7715

10 files changed

Lines changed: 64 additions & 20 deletions

File tree

v3/src/boot/Config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ var Config = function (config)
5050
this.inputKeyboard = GetValue(config, 'input.keyboard', true);
5151
this.inputKeyboardEventTarget = GetValue(config, 'input.keyboard.target', window);
5252

53+
this.inputMouse = GetValue(config, 'input.mouse', true);
54+
this.inputMouseEventTarget = GetValue(config, 'input.mouse.target', null);
55+
5356
// If you do: { banner: false } it won't display any banner at all
5457
this.hideBanner = (GetValue(config, 'banner', null) === false);
5558

v3/src/checksum.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
var CHECKSUM = {
2-
build: '907ae780-4d47-11e7-a1ba-9fe9a3b95341'
2+
build: 'ef0a8d80-4fc4-11e7-8a79-a19b26898a36'
33
};
44
module.exports = CHECKSUM;

v3/src/input/GlobalInputManager.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// GlobalInputManager
22

33
var Keyboard = require('./keyboard/KeyboardManager');
4+
var Mouse = require('./mouse/MouseManager');
45

56
var GlobalInputManager = function (game, gameConfig)
67
{

v3/src/input/keyboard/KeyboardManager.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,20 +214,22 @@ KeyboardManager.prototype = {
214214

215215
update: function ()
216216
{
217-
if (!this.enabled)
217+
var len = this.queue.length;
218+
219+
if (!this.enabled || len === 0)
218220
{
219221
return;
220222
}
221223

222224
// Clears the queue array, and also means we don't work on array data that could potentially
223225
// be modified during the processing phase
224-
var queue = this.queue.splice(0, this.queue.length);
226+
var queue = this.queue.splice(0, len);
225227

226228
var keys = this.keys;
227229
var singleKey;
228230

229231
// Process the event queue, dispatching all of the events that have stored up
230-
for (var i = 0; i < queue.length; i++)
232+
for (var i = 0; i < len; i++)
231233
{
232234
var event = queue[i];
233235

v3/src/input/mouse/MouseManager.js

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ MouseManager.prototype = {
3535
this.enabled = config.inputMouse;
3636
this.target = config.inputMouseEventTarget;
3737

38+
if (!this.target)
39+
{
40+
this.target = this.manager.game.canvas;
41+
}
42+
3843
if (this.enabled)
3944
{
4045
this.startListeners();
@@ -44,7 +49,6 @@ MouseManager.prototype = {
4449
startListeners: function ()
4550
{
4651
var queue = this.queue;
47-
// var captures = this.captures;
4852

4953
var mouseHandler = function (event)
5054
{
@@ -55,11 +59,6 @@ MouseManager.prototype = {
5559
}
5660

5761
queue.push(event);
58-
59-
// if (captures[event.keyCode])
60-
// {
61-
// event.preventDefault();
62-
// }
6362
};
6463

6564
this.mouseHandler = mouseHandler;
@@ -77,30 +76,39 @@ MouseManager.prototype = {
7776
},
7877

7978
// https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent
79+
// https://github.com/WICG/EventListenerOptions/blob/gh-pages/explainer.md
8080

8181
update: function ()
8282
{
83-
if (!this.enabled)
83+
var len = this.queue.length;
84+
85+
if (!this.enabled || len === 0)
8486
{
8587
return;
8688
}
8789

8890
// Clears the queue array, and also means we don't work on array data that could potentially
8991
// be modified during the processing phase
90-
var queue = this.queue.splice(0, this.queue.length);
92+
var queue = this.queue.splice(0, len);
9193

9294
// Process the event queue, dispatching all of the events that have stored up
93-
for (var i = 0; i < queue.length; i++)
95+
for (var i = 0; i < len; i++)
9496
{
9597
var event = queue[i];
9698

97-
if (event.type === 'mousedown')
99+
switch (event.type)
98100
{
99-
this.events.dispatch(new Event.MOUSE_DOWN_EVENT(event));
100-
}
101-
else if (event.type === 'mouseup')
102-
{
103-
this.events.dispatch(new Event.MOUSE_UP_EVENT(event));
101+
case 'mousemove':
102+
this.events.dispatch(new Event.MOUSE_MOVE_EVENT(event));
103+
break;
104+
105+
case 'mousedown':
106+
this.events.dispatch(new Event.MOUSE_DOWN_EVENT(event));
107+
break;
108+
109+
case 'mouseup':
110+
this.events.dispatch(new Event.MOUSE_UP_EVENT(event));
111+
break;
104112
}
105113
}
106114
}

v3/src/input/mouse/events/MouseDownEvent.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ var MouseDownEvent = function (nativeEvent)
55
Event.call(this, 'MOUSE_DOWN_EVENT');
66

77
this.data = nativeEvent;
8+
9+
this.x = nativeEvent.clientX;
10+
this.y = nativeEvent.clientY;
811
};
912

1013
MouseDownEvent.prototype = Object.create(Event.prototype);
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
var Event = require('../../../events/Event');
2+
3+
var MouseMoveEvent = function (nativeEvent)
4+
{
5+
Event.call(this, 'MOUSE_MOVE_EVENT');
6+
7+
this.data = nativeEvent;
8+
9+
this.x = nativeEvent.clientX;
10+
this.y = nativeEvent.clientY;
11+
};
12+
13+
MouseMoveEvent.prototype = Object.create(Event.prototype);
14+
MouseMoveEvent.prototype.constructor = MouseMoveEvent;
15+
16+
module.exports = MouseMoveEvent;

v3/src/input/mouse/events/MouseUpEvent.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ var MouseUpEvent = function (nativeEvent)
55
Event.call(this, 'MOUSE_UP_EVENT');
66

77
this.data = nativeEvent;
8+
9+
this.x = nativeEvent.clientX;
10+
this.y = nativeEvent.clientY;
811
};
912

1013
MouseUpEvent.prototype = Object.create(Event.prototype);

v3/src/input/mouse/events/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11

22
module.exports = {
33
MOUSE_DOWN_EVENT: require('./MouseDownEvent'),
4-
MOUSE_UP_EVENT: require('./MouseUpEvent')
4+
MOUSE_UP_EVENT: require('./MouseUpEvent'),
5+
MOUSE_MOVE_EVENT: require('./MouseMoveEvent')
56
};

v3/src/input/mouse/index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Phaser.Input.Mouse
2+
3+
module.exports = {
4+
5+
MouseManager: require('./MouseManager')
6+
7+
};

0 commit comments

Comments
 (0)