aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Riss <Michael.Riss@gmx.de>2013-02-20 01:09:18 +0100
committerMichael Riss <Michael.Riss@gmx.de>2013-03-06 10:43:17 +0100
commitb6032ff72c81c4768ece98f9c31708af95b96863 (patch)
tree9eac01ff624b3e3e97663891c20463f54d2f3a74
parent0b364c0894cafda3c925639a9835c67c36bbc882 (diff)
- fixed formatting issues
- bugfix: an existing pointerLockChange handler now gets properly removed before it is installed anew - completed the implementation of the SDL_ShowCursor() function: - can now query the current state of the cursor/pointer - properly delivers adequate return values - added safeguard: when not in fullscreen mode, attempts to lock the pointer are ignored as they would fail due to the security model of the browser and a return value indicating the error is returned Signed-off-by: Michael Riss <Michael.Riss@gmx.de>
-rw-r--r--src/library_browser.js35
-rw-r--r--src/library_sdl.js27
2 files changed, 39 insertions, 23 deletions
diff --git a/src/library_browser.js b/src/library_browser.js
index d5ff4017..98639522 100644
--- a/src/library_browser.js
+++ b/src/library_browser.js
@@ -3,7 +3,7 @@
// Utilities for browser environments
mergeInto(LibraryManager.library, {
- $Browser__postset: 'Module["requestFullScreen"] = function(doLockPointer, doResizeCanvas) { Browser.requestFullScreen(doLockPointer, doResizeCanvas) };\n' + // exports
+ $Browser__postset: 'Module["requestFullScreen"] = function(lockPointer, resizeCanvas) { Browser.requestFullScreen(lockPointer, resizeCanvas) };\n' + // exports
'Module["requestAnimationFrame"] = function(func) { Browser.requestAnimationFrame(func) };\n' +
'Module["pauseMainLoop"] = function() { Browser.mainLoop.pause() };\n' +
'Module["resumeMainLoop"] = function() { Browser.mainLoop.resume() };\n',
@@ -40,6 +40,7 @@ mergeInto(LibraryManager.library, {
}
}
},
+ isFullScreen: false,
pointerLock: false,
moduleContextCreatedCallbacks: [],
workers: [],
@@ -278,13 +279,13 @@ mergeInto(LibraryManager.library, {
storedFullScreenHandler: null,
storedPointerLockHandler: null,
- requestFullScreen: function(doLockPointer, doResizeCanvas) {
- if(typeof(doLockPointer)==='undefined') doLockPointer = true;
- if(typeof(doResizeCanvas)==='undefined') doResizeCanvas = false;
+ requestFullScreen: function(lockPointer, resizeCanvas) {
+ if (typeof lockPointer === 'undefined') lockPointer = true;
+ if (typeof resizeCanvas === 'undefined') resizeCanvas = false;
var canvas = Module['canvas'];
function fullScreenChange() {
- var isFullScreen = false;
+ Browser.isFullScreen = false;
if ((document['webkitFullScreenElement'] || document['webkitFullscreenElement'] ||
document['mozFullScreenElement'] || document['mozFullscreenElement'] ||
document['fullScreenElement'] || document['fullscreenElement']) === canvas) {
@@ -294,18 +295,18 @@ mergeInto(LibraryManager.library, {
canvas.exitPointerLock = document['exitPointerLock'] ||
document['mozExitPointerLock'] ||
document['webkitExitPointerLock'];
- canvas.exitPointerLock = canvas.exitPointerLock.bind( document );
+ canvas.exitPointerLock = canvas.exitPointerLock.bind(document);
canvas.cancelFullScreen = document['cancelFullScreen'] ||
document['mozCancelFullScreen'] ||
document['webkitCancelFullScreen'];
- canvas.cancelFullScreen = canvas.cancelFullScreen.bind( document );
- if (doLockPointer) canvas.requestPointerLock();
- isFullScreen = true;
- if(doResizeCanvas) Browser.setFullScreenCanvasSize();
- } else if(doResizeCanvas){
+ canvas.cancelFullScreen = canvas.cancelFullScreen.bind(document);
+ if (lockPointer) canvas.requestPointerLock();
+ Browser.isFullScreen = true;
+ if (resizeCanvas) Browser.setFullScreenCanvasSize();
+ } else if (resizeCanvas){
Browser.setWindowedCanvasSize();
}
- if (Module['onFullScreen']) Module['onFullScreen'](isFullScreen);
+ if (Module['onFullScreen']) Module['onFullScreen'](Browser.isFullScreen);
}
function pointerLockChange() {
@@ -314,16 +315,16 @@ mergeInto(LibraryManager.library, {
document['webkitPointerLockElement'] === canvas;
}
- if( !(this.storedFullScreenHandler == null) ){
+ if (this.storedFullScreenHandler) {
document.removeEventListener('fullscreenchange', this.storedFullScreenHandler, false);
document.removeEventListener('mozfullscreenchange', this.storedFullScreenHandler, false);
document.removeEventListener('webkitfullscreenchange', this.storedFullScreenHandler, false);
this.storedFullScreenHandler = null;
}
- if( !(this.storedPointerLockHandler == null) ){
- document.addEventListener('pointerlockchange', this.storedPointerLockHandler, false);
- document.addEventListener('mozpointerlockchange', this.storedPointerLockHandler, false);
- document.addEventListener('webkitpointerlockchange', this.storedPointerLockHandler, false);
+ if (this.storedPointerLockHandler) {
+ document.removeEventListener('pointerlockchange', this.storedPointerLockHandler, false);
+ document.removeEventListener('mozpointerlockchange', this.storedPointerLockHandler, false);
+ document.removeEventListener('webkitpointerlockchange', this.storedPointerLockHandler, false);
this.storedPointerLockHandler = null;
}
diff --git a/src/library_sdl.js b/src/library_sdl.js
index ec3c5455..99189d8a 100644
--- a/src/library_sdl.js
+++ b/src/library_sdl.js
@@ -661,8 +661,8 @@ var LibrarySDL = {
{{{ makeSetValue('ret+Runtime.QUANTUM_SIZE*0', '0', '0', 'i32') }}} // TODO
{{{ makeSetValue('ret+Runtime.QUANTUM_SIZE*1', '0', '0', 'i32') }}} // TODO
{{{ makeSetValue('ret+Runtime.QUANTUM_SIZE*2', '0', '0', 'void*') }}}
- {{{ makeSetValue('ret+Runtime.QUANTUM_SIZE*3', '0', 'Module[\'canvas\'].width', 'i32') }}}
- {{{ makeSetValue('ret+Runtime.QUANTUM_SIZE*4', '0', 'Module[\'canvas\'].height', 'i32') }}}
+ {{{ makeSetValue('ret+Runtime.QUANTUM_SIZE*3', '0', 'Module["canvas"].width', 'i32') }}}
+ {{{ makeSetValue('ret+Runtime.QUANTUM_SIZE*4', '0', 'Module["canvas"].height', 'i32') }}}
return ret;
},
@@ -919,10 +919,25 @@ var LibrarySDL = {
},
SDL_ShowCursor: function(toggle) {
- if(toggle){
- Module['canvas'].exitPointerLock();
- } else {
- Module['canvas'].requestPointerLock();
+ switch (toggle) {
+ case 0: // SDL_DISABLE
+ if (Browser.isFullScreen) { // only try to lock the pointer when in full screen mode
+ Module['canvas'].requestPointerLock();
+ return 0;
+ } else { // else return SDL_ENABLE to indicate the failure
+ return 1;
+ }
+ break;
+ case 1: // SDL_ENABLE
+ Module['canvas'].exitPointerLock();
+ return 1;
+ break;
+ case -1: // SDL_QUERY
+ return !Browser.pointerLock;
+ break;
+ default:
+ console.log( "SDL_ShowCursor called with unknown toggle parameter value: " + toggle + "." );
+ break;
}
},