From 1c051dffdb27ff6ebaa96802b021e99e49afb861 Mon Sep 17 00:00:00 2001 From: mattkae Date: Sun, 1 May 2022 21:55:18 -0400 Subject: Fixed resize issue --- themes/WebglContext.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'themes/WebglContext.cpp') diff --git a/themes/WebglContext.cpp b/themes/WebglContext.cpp index 0f2e2d3..df49c2d 100644 --- a/themes/WebglContext.cpp +++ b/themes/WebglContext.cpp @@ -2,12 +2,24 @@ #include +EM_BOOL onResize(int eventType, const EmscriptenUiEvent *uiEvent, void *userData) { + WebglContext* context = (WebglContext*)userData; + + f64 inWidth, inHeight; + emscripten_get_element_css_size(context->query, &inWidth, &inHeight); + + context->width = static_cast(inWidth); + context->height = static_cast(inHeight); + + return true; +} + void WebglContext::init(const char* inQuery) { strcpy(query, inQuery); f64 inWidth, inHeight; emscripten_get_element_css_size(query, &inWidth, &inHeight); - width = static_cast(inWidth); - height = static_cast(inHeight); + width = static_cast(inWidth); + height = static_cast(inHeight); emscripten_set_canvas_element_size( query, width, height); EmscriptenWebGLContextAttributes attrs; @@ -21,6 +33,8 @@ void WebglContext::init(const char* inQuery) { makeCurrentContext(); glClearColor(0, 0, 0, 0.0f); + + emscripten_set_resize_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, this, false, onResize); }; void WebglContext::makeCurrentContext() { -- cgit v1.2.1