diff --git a/site/source/api_items.py b/site/source/api_items.py index 8d2e4aa0ea67a..fcd6efa716005 100644 --- a/site/source/api_items.py +++ b/site/source/api_items.py @@ -116,7 +116,6 @@ def get_mapped_items(): mapped_wiki_inline_code['emscripten_set_beforeunload_callback']=':c:func:`emscripten_set_beforeunload_callback`' mapped_wiki_inline_code['emscripten_random()']=':c:func:`emscripten_random`' mapped_wiki_inline_code['EMSCRIPTEN_RESULT']=':c:macro:`EMSCRIPTEN_RESULT`' - mapped_wiki_inline_code['emscripten_get_canvas_size']=':c:func:`emscripten_get_canvas_size`' mapped_wiki_inline_code['emscripten_async_run_script']=':c:func:`emscripten_async_run_script`' mapped_wiki_inline_code['emscripten_worker_respond()']=':c:func:`emscripten_worker_respond`' mapped_wiki_inline_code['DOM_DELTA_PIXEL']=':c:macro:`DOM_DELTA_PIXEL`' @@ -264,11 +263,8 @@ def get_mapped_items(): mapped_wiki_inline_code['EMSCRIPTEN_NETWORK_WEBRTC']=':c:macro:`EMSCRIPTEN_NETWORK_WEBRTC`' mapped_wiki_inline_code['emscripten_log']=':c:func:`emscripten_log`' mapped_wiki_inline_code['emscripten_set_wheel_callback']=':c:func:`emscripten_set_wheel_callback`' - mapped_wiki_inline_code['emscripten_set_canvas_size']=':c:func:`emscripten_set_canvas_size`' mapped_wiki_inline_code['DOM_DELTA_PAGE']=':c:macro:`DOM_DELTA_PAGE`' - mapped_wiki_inline_code['emscripten_get_canvas_size()']=':c:func:`emscripten_get_canvas_size`' mapped_wiki_inline_code['*emscripten_get_preloaded_image_data_from_FILE()']=':c:func:`*emscripten_get_preloaded_image_data_from_FILE`' - mapped_wiki_inline_code['emscripten_set_canvas_size()']=':c:func:`emscripten_set_canvas_size`' mapped_wiki_inline_code['emscripten_get_callstack']=':c:func:`emscripten_get_callstack`' mapped_wiki_inline_code['HEAPU32']=':js:data:`HEAPU32`' mapped_wiki_inline_code['EMSCRIPTEN_VISIBILITY_HIDDEN']=':c:macro:`EMSCRIPTEN_VISIBILITY_HIDDEN`' diff --git a/site/source/docs/api_reference/emscripten.h.rst b/site/source/docs/api_reference/emscripten.h.rst index cbc18af015d51..46d643d432267 100644 --- a/site/source/docs/api_reference/emscripten.h.rst +++ b/site/source/docs/api_reference/emscripten.h.rst @@ -465,23 +465,6 @@ Functions Note that SDL’s ``SDL_ShowCursor`` command shows and hides the SDL cursor, not the OS one. This command is useful to hide the OS cursor if your app draws its own cursor. -.. c:function:: void emscripten_set_canvas_size(int width, int height) - - Resizes the pixel width and height of the ```` element on the Emscripten web page. - - :param int width: New pixel width of canvas element. - :param int height: New pixel height of canvas element. - - -.. c:function:: void emscripten_get_canvas_size(int * width, int * height, int * isFullscreen) - - Gets the current pixel width and height of the ```` element as well as whether the canvas is fullscreen or not. - - :param int* width: Pixel width of canvas element. - :param int* height: New pixel height of canvas element. - :param int* isFullscreen: If True (``*int > 0``), ```` is full screen. - - .. c:function:: double emscripten_get_now(void) Returns the highest-precision representation of the current time that the browser provides. diff --git a/site/source/docs/api_reference/html5.h.rst b/site/source/docs/api_reference/html5.h.rst index 8b9000de830dc..c8b2ff585d566 100644 --- a/site/source/docs/api_reference/html5.h.rst +++ b/site/source/docs/api_reference/html5.h.rst @@ -1043,7 +1043,7 @@ Defines Specifies that the Emscripten runtime should explicitly scale the CSS size of the target element to cover the whole screen, while adding either vertical or horizontal black letterbox padding to preserve the aspect ratio of the content. The aspect ratio that is used here is the render target size of the canvas element. To change the - desired aspect ratio, call :c:func:`emscripten_set_canvas_size` before entering fullscreen mode. + desired aspect ratio, call :c:func:`emscripten_set_canvas_element_size` before entering fullscreen mode. .. c:macro:: EMSCRIPTEN_FULLSCREEN_CANVAS_SCALE @@ -2140,6 +2140,26 @@ Functions :rtype: |EM_BOOL| +.. c:function:: EMSCRIPTEN_RESULT emscripten_set_canvas_element_size(const char *target, int width, int height) + + Resizes the pixel width and height of the given Canvas element in the DOM. + + :param target: Specifies a selector for the canvas to resize. + :param width: New pixel width of canvas element. + :param height: New pixel height of canvas element. + :returns: EMSCRIPTEN_RESULT_SUCCESS if resizing succeeded, and one of the EMSCRIPTEN_RESULT_* error values on failure. + + +.. c:function:: EMSCRIPTEN_RESULT emscripten_get_canvas_element_size(const char *target, int *width, int *height) + + Gets the current pixel width and height of the given Canvas element in the DOM. + + :param target: Specifies a selector for the canvas to resize. + :param width: A pointer to memory location where the width of the canvas element is received. This pointer may not be null. + :param height: A pointer to memory location where the height of the canvas element is received. This pointer may not be null. + :returns: EMSCRIPTEN_RESULT_SUCCESS if resizing succeeded, and one of the EMSCRIPTEN_RESULT_* error values on failure. + + CSS === diff --git a/src/library_sdl.js b/src/library_sdl.js index b85969d7d6c3a..e12503a41260f 100644 --- a/src/library_sdl.js +++ b/src/library_sdl.js @@ -11,7 +11,7 @@ // Notes: // SDL_VIDEORESIZE: This is sent when the canvas is resized. Note that the user // cannot manually do so, so this is only sent when the -// program manually resizes it (emscripten_set_canvas_size +// program manually resizes it (emscripten_set_canvas_element_size // or otherwise). var LibrarySDL = { diff --git a/tests/gl_textures.cpp b/tests/gl_textures.cpp index 862db286f7063..1f2f9b7e37326 100644 --- a/tests/gl_textures.cpp +++ b/tests/gl_textures.cpp @@ -31,8 +31,8 @@ GLuint program; void draw() { - int w, h, fs; - emscripten_get_canvas_size(&w, &h, &fs); + int w, h; + emscripten_get_canvas_element_size("#canvas", &w, &h); float xs = (float)h / w; float ys = 1.0f; float mat[] = { xs, 0, 0, 0, 0, ys, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 }; @@ -57,7 +57,7 @@ void draw() int main() { - emscripten_set_canvas_size(256, 256); + emscripten_set_canvas_element_size("#canvas", 256, 256); EmscriptenWebGLContextAttributes attr; emscripten_webgl_init_context_attributes(&attr); attr.alpha = attr.depth = attr.stencil = attr.antialias = attr.preserveDrawingBuffer = attr.failIfMajorPerformanceCaveat = 0; diff --git a/tests/sdl2_canvas_size.c b/tests/sdl2_canvas_size.c index dc4bbd0162fed..c35262095bc9f 100644 --- a/tests/sdl2_canvas_size.c +++ b/tests/sdl2_canvas_size.c @@ -12,6 +12,7 @@ #include #include +#include int result = 0; @@ -36,15 +37,15 @@ int main(int argc, char *argv[]) ); // Test 2: Check that getting current canvas size works. - int w, h, fs; - emscripten_get_canvas_size(&w, &h, &fs); + int w, h; + emscripten_get_canvas_element_size("#canvas", &w, &h); printf("w:%d,h:%d\n", w,h); assert(w == 700); assert(h == 200); // Test 3: Check that resizing the canvas works as well. - emscripten_set_canvas_size(640, 480); - emscripten_get_canvas_size(&w, &h, &fs); + emscripten_set_canvas_element_size("#canvas", 640, 480); + emscripten_get_canvas_element_size("#canvas", &w, &h); printf("w:%d,h:%d\n", w,h); assert(w == 640); assert(h == 480); diff --git a/tests/sdl_canvas.c b/tests/sdl_canvas.c index 5897cb7fb2c43..be293667ebe7a 100644 --- a/tests/sdl_canvas.c +++ b/tests/sdl_canvas.c @@ -10,6 +10,7 @@ #include #include #include +#include int main(int argc, char **argv) { @@ -52,8 +53,8 @@ int main(int argc, char **argv) { SDL_LockSurface(screen); - int width, height, isFullscreen; - emscripten_get_canvas_size(&width, &height, &isFullscreen); + int width, height; + emscripten_get_canvas_element_size("#canvas", &width, &height); if (width != 600 && height != 450) { diff --git a/tests/sdl_canvas_alpha.c b/tests/sdl_canvas_alpha.c index 51153cf90fdcf..f6fb01e5d773e 100644 --- a/tests/sdl_canvas_alpha.c +++ b/tests/sdl_canvas_alpha.c @@ -11,6 +11,7 @@ #include #include #include +#include int main(int argc, char **argv) { @@ -43,8 +44,8 @@ int main(int argc, char **argv) { SDL_LockSurface(screen); - int width, height, isFullscreen; - emscripten_get_canvas_size(&width, &height, &isFullscreen); + int width, height; + emscripten_get_canvas_element_size("#canvas", &width, &height); if (width != 600 && height != 450) { diff --git a/tests/sdl_fullscreen_samecanvassize.c b/tests/sdl_fullscreen_samecanvassize.c index f5907bc8823b4..81e2a6c096452 100644 --- a/tests/sdl_fullscreen_samecanvassize.c +++ b/tests/sdl_fullscreen_samecanvassize.c @@ -10,6 +10,7 @@ #include #include #include +#include int result = 1; @@ -22,8 +23,8 @@ int wasFullscreen = 0; int finished = 0; void render() { - int width, height, isfs; - emscripten_get_canvas_size(&width, &height, &isfs); + int width, height; + emscripten_get_canvas_element_size("#canvas", &width, &height); SDL_Rect rect = { 0, 0, width, height }; SDL_FillRect(screen, &rect, 0xff00ffff); } @@ -78,8 +79,8 @@ void mainloop() { } int main() { - int w, h, fs; - emscripten_get_canvas_size(&w, &h, &fs); + int w, h; + emscripten_get_canvas_element_size("#canvas", &w, &h); printf("w:%d,h:%d\n", w,h); SDL_Init(SDL_INIT_VIDEO); diff --git a/tests/sdl_togglefullscreen.c b/tests/sdl_togglefullscreen.c index 2155ce51d2b4b..035fa5e98d820 100644 --- a/tests/sdl_togglefullscreen.c +++ b/tests/sdl_togglefullscreen.c @@ -74,8 +74,8 @@ static void render() { SDL_RenderClear(renderer); SDL_RenderPresent(renderer); #else - int width, height, isfs; - emscripten_get_canvas_size(&width, &height, &isfs); + int width, height; + emscripten_get_canvas_element_size("#canvas", &width, &height); SDL_Rect rect = { 0, 0, width, height }; SDL_FillRect(screen, &rect, 0xff00ffff); #endif diff --git a/tests/sdl_wm_togglefullscreen.c b/tests/sdl_wm_togglefullscreen.c index 1a640afda8666..89222cd8fe8b2 100644 --- a/tests/sdl_wm_togglefullscreen.c +++ b/tests/sdl_wm_togglefullscreen.c @@ -10,6 +10,7 @@ #include #include #include +#include int result = 1; @@ -22,8 +23,8 @@ int wasFullscreen = 0; int finished = 0; void render() { - int width, height, isfs; - emscripten_get_canvas_size(&width, &height, &isfs); + int width, height; + emscripten_get_canvas_element_size("#canvas", &width, &height); SDL_Rect rect = { 0, 0, width, height }; SDL_FillRect(screen, &rect, 0xff00ffff); } diff --git a/tests/test_html5_fullscreen.c b/tests/test_html5_fullscreen.c index 53247a86f1172..e3cafb89fa102 100644 --- a/tests/test_html5_fullscreen.c +++ b/tests/test_html5_fullscreen.c @@ -110,8 +110,8 @@ GLuint program; void draw() { - int w, h, fs; - emscripten_get_canvas_size(&w, &h, &fs); + int w, h; + emscripten_get_canvas_element_size("#canvas", &w, &h); float t = emscripten_get_now() / 1000.0f; float xs = (float)h / w; float ys = 1.0f; @@ -124,8 +124,8 @@ void draw() EM_BOOL on_canvassize_changed(int eventType, const void *reserved, void *userData) { - int w, h, fs; - emscripten_get_canvas_size(&w, &h, &fs); + int w, h; + emscripten_get_canvas_element_size("#canvas", &w, &h); double cssW, cssH; emscripten_get_element_css_size(0, &cssW, &cssH); printf("Canvas resized: WebGL RTT size: %dx%d, canvas CSS size: %02gx%02g\n", w, h, cssW, cssH); diff --git a/tests/test_html5_mouse.c b/tests/test_html5_mouse.c index c3ccf25e73e1c..661a84674cc0d 100644 --- a/tests/test_html5_mouse.c +++ b/tests/test_html5_mouse.c @@ -112,7 +112,7 @@ EM_BOOL wheel_callback(int eventType, const EmscriptenWheelEvent *e, void *userD int main() { // Make the canvas area stand out from the background. - emscripten_set_canvas_size(400, 300); + emscripten_set_canvas_element_size("#canvas", 400, 300); EM_ASM(Module['canvas'].style.backgroundColor = 'black';); EMSCRIPTEN_RESULT ret = emscripten_set_click_callback(0, 0, 1, mouse_callback); diff --git a/tests/test_html5_pointerlockerror.c b/tests/test_html5_pointerlockerror.c index 5e9c7edd80f41..cb7ae7dadbf0d 100644 --- a/tests/test_html5_pointerlockerror.c +++ b/tests/test_html5_pointerlockerror.c @@ -84,7 +84,7 @@ int main() printf("Reject the pointer lock request after clicking on canvas.\n"); // Make the canvas area stand out from the background. - emscripten_set_canvas_size(400, 300); + emscripten_set_canvas_element_size( "#canvas", 400, 300 ); EM_ASM(Module['canvas'].style.backgroundColor = 'black';); EMSCRIPTEN_RESULT ret = emscripten_set_click_callback(0, 0, 1, click_callback); diff --git a/tests/webgl2_garbage_free_entrypoints.cpp b/tests/webgl2_garbage_free_entrypoints.cpp index ec97c113540e7..ad4199117a3ee 100644 --- a/tests/webgl2_garbage_free_entrypoints.cpp +++ b/tests/webgl2_garbage_free_entrypoints.cpp @@ -21,7 +21,7 @@ GLuint CompileShader(GLenum type, const char *src) int main(int argc, char *argv[]) { - emscripten_set_canvas_size(256, 256); + emscripten_set_canvas_element_size("#canvas", 256, 256); EmscriptenWebGLContextAttributes attr; emscripten_webgl_init_context_attributes(&attr); attr.alpha = attr.depth = attr.stencil = attr.antialias = attr.preserveDrawingBuffer = attr.failIfMajorPerformanceCaveat = 0; diff --git a/tests/webgl2_objects.cpp b/tests/webgl2_objects.cpp index 5d6bf480fc1ae..f8f245b1e9a6b 100644 --- a/tests/webgl2_objects.cpp +++ b/tests/webgl2_objects.cpp @@ -27,7 +27,7 @@ int result = 0; int main() { - emscripten_set_canvas_size( 100, 100 ); + emscripten_set_canvas_element_size( "#canvas", 100, 100 ); EmscriptenWebGLContextAttributes attrs; emscripten_webgl_init_context_attributes(&attrs); diff --git a/tests/webgl_shader_source_length.cpp b/tests/webgl_shader_source_length.cpp index 102f0d17e335c..93ff8c28b6f8f 100644 --- a/tests/webgl_shader_source_length.cpp +++ b/tests/webgl_shader_source_length.cpp @@ -28,7 +28,7 @@ int result = 0; int main() { - emscripten_set_canvas_size( 100, 100 ); + emscripten_set_canvas_element_size( "#canvas", 100, 100 ); EmscriptenWebGLContextAttributes attrs; emscripten_webgl_init_context_attributes(&attrs); diff --git a/tests/webgl_with_closure.cpp b/tests/webgl_with_closure.cpp index e9d4756543f1c..877295fccda80 100644 --- a/tests/webgl_with_closure.cpp +++ b/tests/webgl_with_closure.cpp @@ -67,7 +67,7 @@ int main() { - emscripten_set_canvas_size( 100, 100 ); + emscripten_set_canvas_element_size( "#canvas", 100, 100 ); EmscriptenWebGLContextAttributes attrs; emscripten_webgl_init_context_attributes(&attrs);