diff options
Diffstat (limited to 'src/library_browser.js')
-rw-r--r-- | src/library_browser.js | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/library_browser.js b/src/library_browser.js index 48b6d8af..4d7178ab 100644 --- a/src/library_browser.js +++ b/src/library_browser.js @@ -41,6 +41,8 @@ mergeInto(LibraryManager.library, { }, $Browser: { + pointerLock: false, + createContext: function(canvas, useWebGL) { #if !USE_TYPED_ARRAYS if (useWebGL) { @@ -101,6 +103,55 @@ mergeInto(LibraryManager.library, { return ctx; }, + requestFullScreen: function() { + var canvas = Module.canvas; + function fullScreenChange() { + if (document.webkitFullScreenElement === canvas || + document.mozFullScreenElement === canvas || + document.fullScreenElement === canvas) { + canvas.requestPointerLock = canvas.requestPointerLock || + canvas.mozRequestPointerLock || + canvas.webkitRequestPointerLock; + canvas.requestPointerLock(); + } + } + + document.addEventListener('fullscreenchange', fullScreenChange, false); + document.addEventListener('mozfullscreenchange', fullScreenChange, false); + document.addEventListener('webkitfullscreenchange', fullScreenChange, false); + + 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); + + canvas.requestFullScreen = canvas.requestFullScreen || + canvas.mozRequestFullScreen || + canvas.webkitRequestFullScreen; + canvas.requestFullScreen(); + }, + + getMovementX: function(delta, event) { + if (!Browser.pointerLock) return delta; + return event.movementX || + event.mozMovementX || + event.webkitMovementX || + 0; // delta; + }, + + getMovementY: function(delta, event) { + if (!Browser.pointerLock) return delta; + return event.movementY || + event.mozMovementY || + event.webkitMovementY || + 0; // delta; + }, + // Given binary data for an image, in a format like PNG or JPG, we convert it // to flat pixel data. We do so using the browser's native code. // This is deprecated, it is preferred to load binary files, createObjectURL, etc., |