diff options
-rw-r--r-- | src/library_browser.js | 51 | ||||
-rw-r--r-- | src/library_sdl.js | 16 | ||||
-rw-r--r-- | src/shell.html | 2 |
3 files changed, 65 insertions, 4 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., diff --git a/src/library_sdl.js b/src/library_sdl.js index a4923352..d2afebba 100644 --- a/src/library_sdl.js +++ b/src/library_sdl.js @@ -349,8 +349,17 @@ var LibrarySDL = { receiveEvent: function(event) { switch(event.type) { - case 'keydown': case 'keyup': case 'mousedown': case 'mouseup': case 'mousemove': + case 'mousemove': + // workaround for firefox bug 750111 + event.movementX = event.mozMovementX; + event.movementY = event.mozMovementY; + // fall through + case 'keydown': case 'keyup': case 'mousedown': case 'mouseup': SDL.events.push(event); + if (SDL.events.length >= 10000) { + Module.printErr('SDL event queue full, dropping earliest event'); + SDL.events.shift(); + } if ((event.keyCode >= 37 && event.keyCode <= 40) || // arrow keys event.keyCode == 32 || // space event.keyCode == 33 || event.keyCode == 34) { // page up/down @@ -358,7 +367,6 @@ var LibrarySDL = { } break; } - //event.preventDefault(); return false; }, @@ -415,8 +423,8 @@ var LibrarySDL = { {{{ makeSetValue('ptr', 'SDL.structs.MouseMotionEvent.state', 'down ? 1 : 0', 'i8') }}}; {{{ makeSetValue('ptr', 'SDL.structs.MouseMotionEvent.x', 'x', 'i32') }}}; {{{ makeSetValue('ptr', 'SDL.structs.MouseMotionEvent.y', 'y', 'i32') }}}; - {{{ makeSetValue('ptr', 'SDL.structs.MouseMotionEvent.xrel', 'x - SDL.mouseX', 'i32') }}}; - {{{ makeSetValue('ptr', 'SDL.structs.MouseMotionEvent.yrel', 'y - SDL.mouseY', 'i32') }}}; + {{{ makeSetValue('ptr', 'SDL.structs.MouseMotionEvent.xrel', 'Browser.getMovementX(x - SDL.mouseX, event)', 'i32') }}}; + {{{ makeSetValue('ptr', 'SDL.structs.MouseMotionEvent.yrel', 'Browser.getMovementY(y - SDL.mouseY, event)', 'i32') }}}; } SDL.mouseX = x; SDL.mouseY = y; diff --git a/src/shell.html b/src/shell.html index 43878973..4a1cb59c 100644 --- a/src/shell.html +++ b/src/shell.html @@ -13,6 +13,8 @@ </head> <body> <canvas class="emscripten" id="canvas" oncontextmenu="event.preventDefault()"></canvas> + <ht/> + <div class="emscripten"><input type="button" value="fullscreen" onclick="Browser.requestFullScreen()"></div> <hr/> <textarea class="emscripten" id="output" rows="8"></textarea> <hr> |