mirror of
https://github.com/photonstorm/phaser
synced 2024-11-27 23:20:59 +00:00
Added window specific handlers
And game config option: ``` input: { windowEvents: false }, ```
This commit is contained in:
parent
c9e730379f
commit
c90ae09f9f
2 changed files with 66 additions and 3 deletions
|
@ -275,6 +275,11 @@ var Config = new Class({
|
|||
*/
|
||||
this.inputQueue = GetValue(config, 'input.queue', false);
|
||||
|
||||
/**
|
||||
* @const {boolean} Phaser.Core.Config#inputWindowEvents - Should Phaser listen for input events on the Window?
|
||||
*/
|
||||
this.inputWindowEvents = GetValue(config, 'input.windowEvents', true);
|
||||
|
||||
/**
|
||||
* @const {boolean} Phaser.Core.Config#inputGamepad - Enable the Gamepad Plugin. This can be disabled in games that don't need gamepad input.
|
||||
*/
|
||||
|
|
|
@ -116,6 +116,28 @@ var MouseManager = new Class({
|
|||
*/
|
||||
this.onMouseUp = NOOP;
|
||||
|
||||
/**
|
||||
* The Mouse Down Event handler specifically for events on the Window.
|
||||
* This function is sent the native DOM MouseEvent.
|
||||
* Initially empty and bound in the `startListeners` method.
|
||||
*
|
||||
* @name Phaser.Input.Mouse.MouseManager#onMouseDownWindow
|
||||
* @type {function}
|
||||
* @since 3.16.3
|
||||
*/
|
||||
this.onMouseDownWindow = NOOP;
|
||||
|
||||
/**
|
||||
* The Mouse Up Event handler specifically for events on the Window.
|
||||
* This function is sent the native DOM MouseEvent.
|
||||
* Initially empty and bound in the `startListeners` method.
|
||||
*
|
||||
* @name Phaser.Input.Mouse.MouseManager#onMouseUpWindow
|
||||
* @type {function}
|
||||
* @since 3.16.3
|
||||
*/
|
||||
this.onMouseUpWindow = NOOP;
|
||||
|
||||
/**
|
||||
* The Mouse Over Event handler.
|
||||
* This function is sent the native DOM MouseEvent.
|
||||
|
@ -282,6 +304,8 @@ var MouseManager = new Class({
|
|||
|
||||
this.onMouseDown = function (event)
|
||||
{
|
||||
console.log('down');
|
||||
|
||||
if (autoFocus)
|
||||
{
|
||||
window.focus();
|
||||
|
@ -301,6 +325,25 @@ var MouseManager = new Class({
|
|||
}
|
||||
};
|
||||
|
||||
this.onMouseDownWindow = function (event)
|
||||
{
|
||||
console.log('window down');
|
||||
|
||||
if (event.defaultPrevented || !_this.enabled || !_this.manager)
|
||||
{
|
||||
// Do nothing if event already handled
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.target !== canvas)
|
||||
{
|
||||
console.log('window process');
|
||||
|
||||
// Only process the event if the target isn't the canvas
|
||||
_this.manager.queueMouseDown(event);
|
||||
}
|
||||
};
|
||||
|
||||
this.onMouseUp = function (event)
|
||||
{
|
||||
if (event.defaultPrevented || !_this.enabled || !_this.manager)
|
||||
|
@ -317,6 +360,21 @@ var MouseManager = new Class({
|
|||
}
|
||||
};
|
||||
|
||||
this.onMouseUpWindow = function (event)
|
||||
{
|
||||
if (event.defaultPrevented || !_this.enabled || !_this.manager)
|
||||
{
|
||||
// Do nothing if event already handled
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.target !== canvas)
|
||||
{
|
||||
// Only process the event if the target isn't the canvas
|
||||
_this.manager.queueMouseUp(event);
|
||||
}
|
||||
};
|
||||
|
||||
this.onMouseOver = function (event)
|
||||
{
|
||||
if (event.defaultPrevented || !_this.enabled || !_this.manager)
|
||||
|
@ -355,10 +413,10 @@ var MouseManager = new Class({
|
|||
target.addEventListener('mouseover', this.onMouseOver, (this.capture) ? nonPassive : passive);
|
||||
target.addEventListener('mouseout', this.onMouseOut, (this.capture) ? nonPassive : passive);
|
||||
|
||||
if (window)
|
||||
if (window && this.manager.game.config.inputWindowEvents)
|
||||
{
|
||||
window.addEventListener('mousedown', this.onMouseDown, nonPassive);
|
||||
window.addEventListener('mouseup', this.onMouseUp, nonPassive);
|
||||
window.addEventListener('mousedown', this.onMouseDownWindow, nonPassive);
|
||||
window.addEventListener('mouseup', this.onMouseUpWindow, nonPassive);
|
||||
}
|
||||
|
||||
if (Features.pointerLock)
|
||||
|
|
Loading…
Reference in a new issue