Retrieve canvas width/height directly instead of relying on emscripten_get_canvas_element_size

This commit is contained in:
UnknownShadow200 2020-10-29 22:30:30 +11:00
parent 04f4818e53
commit e3b9f5b531

View File

@ -3049,9 +3049,12 @@ void Window_FreeFramebuffer(struct Bitmap* bmp) {
#include <emscripten/key_codes.h> #include <emscripten/key_codes.h>
static cc_bool keyboardOpen, needResize, goingFullscreen; static cc_bool keyboardOpen, needResize, goingFullscreen;
static int GetCanvasWidth(void) { return EM_ASM_INT_V({ return Module['canvas'].width }); }
static int GetCanvasHeight(void) { return EM_ASM_INT_V({ return Module['canvas'].height }); }
static void UpdateWindowBounds(void) { static void UpdateWindowBounds(void) {
int width, height; int width = GetCanvasWidth();
emscripten_get_canvas_element_size("#canvas", &width, &height); int height = GetCanvasHeight();
if (width == WindowInfo.Width && height == WindowInfo.Height) return; if (width == WindowInfo.Width && height == WindowInfo.Height) return;
WindowInfo.Width = width; WindowInfo.Width = width;
@ -3378,8 +3381,9 @@ void Window_Create(int width, int height) {
WindowInfo.Exists = true; WindowInfo.Exists = true;
WindowInfo.Focused = true; WindowInfo.Focused = true;
HookEvents(); HookEvents();
/* let the webpage decide on bounds */ /* Let the webpage decide on initial bounds */
emscripten_get_canvas_element_size("#canvas", &WindowInfo.Width, &WindowInfo.Height); WindowInfo.Width = GetCanvasWidth();
WindowInfo.Height = GetCanvasHeight();
} }
void Window_SetTitle(const cc_string* title) { void Window_SetTitle(const cc_string* title) {