diff options
author | Vladimir Vukicevic <vladimir@pobox.com> | 2013-03-17 20:24:47 -0400 |
---|---|---|
committer | Vladimir Vukicevic <vladimir@pobox.com> | 2013-03-19 15:58:17 -0400 |
commit | 5762096f05b3f6def9ca82688840bf5b87ca0f85 (patch) | |
tree | c41277674b232e9fd415cec668fbc430afe34098 | |
parent | 8754ddc7e358b04aefbb453f3d07fd597474a1bf (diff) |
teach library_browser about non-fullscreen pointerlock if Module.elementPointerLock is true
-rw-r--r-- | src/library_browser.js | 46 |
1 files changed, 29 insertions, 17 deletions
diff --git a/src/library_browser.js b/src/library_browser.js index bdd94bac..5526456a 100644 --- a/src/library_browser.js +++ b/src/library_browser.js @@ -193,6 +193,35 @@ mergeInto(LibraryManager.library, { } }; Module['preloadPlugins'].push(audioPlugin); + + // is this the right place? + var canvas = Module['canvas']; + canvas.requestPointerLock = canvas['requestPointerLock'] || + canvas['mozRequestPointerLock'] || + canvas['webkitRequestPointerLock']; + canvas.exitPointerLock = document['exitPointerLock'] || + document['mozExitPointerLock'] || + document['webkitExitPointerLock']; + canvas.exitPointerLock = canvas.exitPointerLock.bind(document); + + function pointerLockChange() { + Browser.pointerLock = document['pointerLockElement'] === canvas || + document['mozPointerLockElement'] === canvas || + document['webkitPointerLockElement'] === canvas; + } + + document.addEventListener('pointerlockchange', pointerLockChange, false); + document.addEventListener('mozpointerlockchange', pointerLockChange, false); + document.addEventListener('webkitpointerlockchange', pointerLockChange, false); + + if (Module['elementPointerLock']) { + canvas.addEventListener("click", function(ev) { + if (!Browser.pointerLock && canvas.requestPointerLock) { + canvas.requestPointerLock(); + ev.preventDefault(); + } + }, false); + } }, createContext: function(canvas, useWebGL, setInModule) { @@ -292,13 +321,6 @@ mergeInto(LibraryManager.library, { if ((document['webkitFullScreenElement'] || document['webkitFullscreenElement'] || document['mozFullScreenElement'] || document['mozFullscreenElement'] || document['fullScreenElement'] || document['fullscreenElement']) === canvas) { - canvas.requestPointerLock = canvas['requestPointerLock'] || - canvas['mozRequestPointerLock'] || - canvas['webkitRequestPointerLock']; - canvas.exitPointerLock = document['exitPointerLock'] || - document['mozExitPointerLock'] || - document['webkitExitPointerLock']; - canvas.exitPointerLock = canvas.exitPointerLock.bind(document); canvas.cancelFullScreen = document['cancelFullScreen'] || document['mozCancelFullScreen'] || document['webkitCancelFullScreen']; @@ -312,21 +334,11 @@ mergeInto(LibraryManager.library, { if (Module['onFullScreen']) Module['onFullScreen'](Browser.isFullScreen); } - function pointerLockChange() { - Browser.pointerLock = document['pointerLockElement'] === canvas || - document['mozPointerLockElement'] === canvas || - document['webkitPointerLockElement'] === canvas; - } - if (!this.fullScreenHandlersInstalled) { this.fullScreenHandlersInstalled = true; document.addEventListener('fullscreenchange', fullScreenChange, false); document.addEventListener('mozfullscreenchange', fullScreenChange, false); document.addEventListener('webkitfullscreenchange', fullScreenChange, false); - - document.addEventListener('pointerlockchange', pointerLockChange, false); - document.addEventListener('mozpointerlockchange', pointerLockChange, false); - document.addEventListener('webkitpointerlockchange', pointerLockChange, false); } canvas.requestFullScreen = canvas['requestFullScreen'] || |