diff options
author | Alon Zakai <alonzakai@gmail.com> | 2013-06-24 20:24:06 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2013-06-24 20:24:06 -0700 |
commit | 682da36db9b39c9069b6a479c1ad9b14677deda4 (patch) | |
tree | 5b85e89a3f630226906ae1b54e9c535a70aaee78 /src | |
parent | 415a82bfa600aa976749e01431376b9a0a3c4e0a (diff) | |
parent | 26f17cca734aca2b6717e16f0f22ead0e43571b8 (diff) |
Merge pull request #1302 from Manny-MADE/glut_fixes
Several GLUT library improvements
Diffstat (limited to 'src')
-rw-r--r-- | src/library_browser.js | 31 | ||||
-rw-r--r-- | src/library_glut.js | 37 |
2 files changed, 46 insertions, 22 deletions
diff --git a/src/library_browser.js b/src/library_browser.js index 925b64e2..d007d9a7 100644 --- a/src/library_browser.js +++ b/src/library_browser.js @@ -426,8 +426,17 @@ mergeInto(LibraryManager.library, { Browser.mouseMovementX = Browser.getMovementX(event); Browser.mouseMovementY = Browser.getMovementY(event); } - Browser.mouseX = SDL.mouseX + Browser.mouseMovementX; - Browser.mouseY = SDL.mouseY + Browser.mouseMovementY; + + // check if SDL is available + if (typeof SDL != "undefined") { + Browser.mouseX = SDL.mouseX + Browser.mouseMovementX; + Browser.mouseY = SDL.mouseY + Browser.mouseMovementY; + } else { + // just add the mouse delta to the current absolut mouse position + // FIXME: ideally this should be clamped against the canvas size and zero + Browser.mouseX += Browser.mouseMovementX; + Browser.mouseY += Browser.mouseMovementY; + } } else { // Otherwise, calculate the movement based on the changes // in the coordinates. @@ -504,9 +513,12 @@ mergeInto(LibraryManager.library, { this.windowedHeight = canvas.height; canvas.width = screen.width; canvas.height = screen.height; - var flags = {{{ makeGetValue('SDL.screen+Runtime.QUANTUM_SIZE*0', '0', 'i32', 0, 1) }}}; - flags = flags | 0x00800000; // set SDL_FULLSCREEN flag - {{{ makeSetValue('SDL.screen+Runtime.QUANTUM_SIZE*0', '0', 'flags', 'i32') }}} + // check if SDL is available + if (typeof SDL != "undefined") { + var flags = {{{ makeGetValue('SDL.screen+Runtime.QUANTUM_SIZE*0', '0', 'i32', 0, 1) }}}; + flags = flags | 0x00800000; // set SDL_FULLSCREEN flag + {{{ makeSetValue('SDL.screen+Runtime.QUANTUM_SIZE*0', '0', 'flags', 'i32') }}} + } Browser.updateResizeListeners(); }, @@ -514,9 +526,12 @@ mergeInto(LibraryManager.library, { var canvas = Module['canvas']; canvas.width = this.windowedWidth; canvas.height = this.windowedHeight; - var flags = {{{ makeGetValue('SDL.screen+Runtime.QUANTUM_SIZE*0', '0', 'i32', 0, 1) }}}; - flags = flags & ~0x00800000; // clear SDL_FULLSCREEN flag - {{{ makeSetValue('SDL.screen+Runtime.QUANTUM_SIZE*0', '0', 'flags', 'i32') }}} + // check if SDL is available + if (typeof SDL != "undefined") { + var flags = {{{ makeGetValue('SDL.screen+Runtime.QUANTUM_SIZE*0', '0', 'i32', 0, 1) }}}; + flags = flags & ~0x00800000; // clear SDL_FULLSCREEN flag + {{{ makeSetValue('SDL.screen+Runtime.QUANTUM_SIZE*0', '0', 'flags', 'i32') }}} + } Browser.updateResizeListeners(); } diff --git a/src/library_glut.js b/src/library_glut.js index 38cfe55b..36d47787 100644 --- a/src/library_glut.js +++ b/src/library_glut.js @@ -117,9 +117,9 @@ var LibraryGLUT = { if (48 <= keycode && keycode <= 57) return keycode; // numeric TODO handle shift? if (65 <= keycode && keycode <= 90) - return event['shiftKey'] ? keycode : keycode + 32; + return event['shiftKey'] ? keycode : keycode + 32; if (106 <= keycode && keycode <= 111) - return keycode - 106 + 42; // *,+-./ TODO handle shift? + return keycode - 106 + 42; // *,+-./ TODO handle shift? switch (keycode) { case 27: // escape @@ -227,7 +227,7 @@ var LibraryGLUT = { } else { width = GLUT.windowWidth; height = GLUT.windowHeight; - // TODO set position + // TODO set position document.removeEventListener('fullscreenchange', GLUT.onFullScreenEventChange, true); document.removeEventListener('mozfullscreenchange', GLUT.onFullScreenEventChange, true); document.removeEventListener('webkitfullscreenchange', GLUT.onFullScreenEventChange, true); @@ -255,13 +255,14 @@ var LibraryGLUT = { document['cancelFullScreen'] || document['mozCancelFullScreen'] || document['webkitCancelFullScreen'] || - (function() {}); + (function() {}); CFS.apply(document, []); } }, glutGetModifiers: function() { return GLUT.modifiers; }, + glutInit__deps: ['$Browser'], glutInit: function(argcp, argv) { // Ignore arguments GLUT.initTime = Date.now(); @@ -271,6 +272,12 @@ var LibraryGLUT = { window.addEventListener("mousemove", GLUT.onMousemove, true); window.addEventListener("mousedown", GLUT.onMouseButtonDown, true); window.addEventListener("mouseup", GLUT.onMouseButtonUp, true); + + Browser.resizeListeners.push(function(width, height) { + if (GLUT.reshapeFunc) { + Runtime.dynCall('vii', GLUT.reshapeFunc, [width, height]); + } + }); __ATEXIT__.push({ func: function() { window.removeEventListener("keydown", GLUT.onKeydown, true); @@ -294,21 +301,25 @@ var LibraryGLUT = { glutGet: function(type) { switch (type) { case 100: /* GLUT_WINDOW_X */ - return 0; /* TODO */ + return 0; /* TODO */ case 101: /* GLUT_WINDOW_Y */ - return 0; /* TODO */ + return 0; /* TODO */ case 102: /* GLUT_WINDOW_WIDTH */ - return Module['canvas'].width; + return Module['canvas'].width; case 103: /* GLUT_WINDOW_HEIGHT */ - return Module['canvas'].height; + return Module['canvas'].height; + case 200: /* GLUT_SCREEN_WIDTH */ + return Module['canvas'].width; + case 201: /* GLUT_SCREEN_HEIGHT */ + return Module['canvas'].height; case 500: /* GLUT_INIT_WINDOW_X */ - return 0; /* TODO */ + return 0; /* TODO */ case 501: /* GLUT_INIT_WINDOW_Y */ - return 0; /* TODO */ + return 0; /* TODO */ case 502: /* GLUT_INIT_WINDOW_WIDTH */ - return GLUT.initWindowWidth; + return GLUT.initWindowWidth; case 503: /* GLUT_INIT_WINDOW_HEIGHT */ - return GLUT.initWindowHeight; + return GLUT.initWindowHeight; case 700: /* GLUT_ELAPSED_TIME */ var now = Date.now(); return now - GLUT.initTime; @@ -386,10 +397,8 @@ var LibraryGLUT = { glutReshapeWindow__deps: ['$GLUT', 'glutPostRedisplay'], glutReshapeWindow: function(width, height) { GLUT.cancelFullScreen(); - // console.log("glutReshapeWindow: " + width + ", " + height); Browser.setCanvasSize(width, height); if (GLUT.reshapeFunc) { - // console.log("GLUT.reshapeFunc: " + width + ", " + height); Runtime.dynCall('vii', GLUT.reshapeFunc, [width, height]); } _glutPostRedisplay(); |