diff options
author | Alon Zakai <alonzakai@gmail.com> | 2013-08-25 12:36:23 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2013-08-25 12:36:23 -0700 |
commit | cad7d6a4d31c078a8ee8ec0252dc3b64480f35e5 (patch) | |
tree | 3d7728c9f88825d0c3e1559d79be9f58d40d8673 | |
parent | 0a574eea0da61705b5f157eade4172bc0a59f18e (diff) | |
parent | 70161252a9d748e98cd7df3b35b0630660cbbea7 (diff) |
Merge pull request #1556 from ToadKing/getcanvassize
Ability to get current canvas size
-rw-r--r-- | src/library_browser.js | 7 | ||||
-rw-r--r-- | system/include/emscripten/emscripten.h | 6 | ||||
-rw-r--r-- | tests/sdl_canvas.c | 11 |
3 files changed, 24 insertions, 0 deletions
diff --git a/src/library_browser.js b/src/library_browser.js index 558c9a59..591a3c11 100644 --- a/src/library_browser.js +++ b/src/library_browser.js @@ -821,6 +821,13 @@ mergeInto(LibraryManager.library, { emscripten_set_canvas_size: function(width, height) { Browser.setCanvasSize(width, height); }, + + emscripten_get_canvas_size: function(width, height, isFullscreen) { + var canvas = Module['canvas']; + {{{ makeSetValue('width', '0', 'canvas.width', 'i32') }}}; + {{{ makeSetValue('height', '0', 'canvas.height', 'i32') }}}; + {{{ makeSetValue('isFullscreen', '0', 'Browser.isFullScreen ? 1 : 0', 'i32') }}}; + }, emscripten_get_now: function() { if (ENVIRONMENT_IS_NODE) { diff --git a/system/include/emscripten/emscripten.h b/system/include/emscripten/emscripten.h index 1ed4c721..1b9a8f25 100644 --- a/system/include/emscripten/emscripten.h +++ b/system/include/emscripten/emscripten.h @@ -170,6 +170,12 @@ void emscripten_hide_mouse(); void emscripten_set_canvas_size(int width, int height); /* + * Get the current pixel width and height of the <canvas> element + * as well as whether the canvas is fullscreen or not. + */ +void emscripten_get_canvas_size(int *width, int *height, int *isFullscreen); + +/* * Returns the highest-precision representation of the * current time that the browser provides. This uses either * Date.now or performance.now. The result is *not* an diff --git a/tests/sdl_canvas.c b/tests/sdl_canvas.c index 10044ff4..6bd659b8 100644 --- a/tests/sdl_canvas.c +++ b/tests/sdl_canvas.c @@ -1,4 +1,5 @@ #include <stdio.h> +#include <stdlib.h> #include <SDL/SDL.h> #include <SDL/SDL_ttf.h> #include <emscripten.h> @@ -43,6 +44,16 @@ int main(int argc, char **argv) { SDL_Flip(screen); SDL_LockSurface(screen); + + int width, height, isFullscreen; + emscripten_get_canvas_size(&width, &height, &isFullscreen); + + if (width != 600 && height != 450) + { + printf("error: wrong width/height\n"); + abort(); + } + int sum = 0; for (int i = 0; i < screen->h; i++) { sum += *((char*)screen->pixels + i*screen->w*4 + i*4 + 0); |