diff options
author | Behdad Esfahbod <behdad@behdad.org> | 2012-04-06 00:14:46 -0400 |
---|---|---|
committer | Behdad Esfahbod <behdad@behdad.org> | 2012-04-06 00:14:46 -0400 |
commit | 940d108b2ac9466e45fffcc5fd133523b58f0891 (patch) | |
tree | 390a10ca83cd0a25df7ee5d59262fdd6f18d7669 | |
parent | dc898cd7f2287766d47fd7fad1e66bdad8ec5f17 (diff) |
Make 'exit fullscreen' restore window size
-rw-r--r-- | src/library_glut.js | 48 |
1 files changed, 37 insertions, 11 deletions
diff --git a/src/library_glut.js b/src/library_glut.js index 5d9fb672..b49073fb 100644 --- a/src/library_glut.js +++ b/src/library_glut.js @@ -18,6 +18,11 @@ var LibraryGLUT = { modifiers: 0, initWindowWidth: 256, initWindowHeight: 256, + // Set when going fullscreen + windowX: 0, + windowY: 0, + windowWidth: 0, + windowHeight: 0, savePosition: function(event) { /* TODO maybe loop here ala http://www.quirksmode.org/js/findpos.html */ @@ -183,6 +188,31 @@ var LibraryGLUT = { } }, + // TODO add fullscreen API ala: + // http://johndyer.name/native-fullscreen-javascript-api-plus-jquery-plugin/ + onFullScreenEventChange: function(event){ + var width; + var height; + if (document.fullScreen || document.mozFullScreen || document.webkitIsFullScreen) { + width = screen["width"]; + height = screen["height"]; + } else { + width = GLUT.windowWidth; + height = GLUT.windowHeight; + // TODO set position + document.removeEventListener('fullscreenchange', GLUT.onFullScreenEventChange, true); + document.removeEventListener('mozfullscreenchange', GLUT.onFullScreenEventChange, true); + document.removeEventListener('webkitfullscreenchange', GLUT.onFullScreenEventChange, true); + } + Module['canvas'].width = width; + Module['canvas'].height = height; + /* Can't call _glutReshapeWindow as that requests cancelling fullscreen. */ + if (GLUT.reshapeFunc) { + FUNCTION_TABLE[GLUT.reshapeFunc](width, height); + } + _glutPostRedisplay(); + }, + requestFullScreen: function() { var RFS = function() {}; if (Module["canvas"]['requestFullscreen']) { @@ -423,18 +453,14 @@ var LibraryGLUT = { glutFullScreen__deps: ['$GLUT', 'glutPostRedisplay'], glutFullScreen: function() { - var width = screen["width"]; - var height = screen["height"]; - /* Can't call _glutReshapeWindow as that requests cancelling fullscreen. */ - Module['canvas'].width = width; - Module['canvas'].height = height; - if (GLUT.reshapeFunc) { - FUNCTION_TABLE[GLUT.reshapeFunc](width, height); - } + GLUT.windowX = 0; // TODO + GLUT.windowY = 0; // TODO + GLUT.windowWidth = Module['canvas'].width; + GLUT.windowHeight = Module['canvas'].height; + document.addEventListener('fullscreenchange', GLUT.onFullScreenEventChange, true); + document.addEventListener('mozfullscreenchange', GLUT.onFullScreenEventChange, true); + document.addEventListener('webkitfullscreenchange', GLUT.onFullScreenEventChange, true); GLUT.requestFullScreen(); - window.setTimeout(function() { - _glutPostRedisplay(); - }, 0); }, glutInitDisplayMode: function(mode) {}, |