From 0a93fbe055dbedf7790dc1e7706d3df359266742 Mon Sep 17 00:00:00 2001 From: Brett Date: Mon, 29 Apr 2024 15:31:47 -0400 Subject: [PATCH] we now get the width and height of a screen when in emscripten mode --- CMakeLists.txt | 2 +- include/blt/gfx/window.h | 2 +- src/blt/gfx/window.cpp | 14 +++++++++++++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0208fbc..4565258 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.25) -set(BLT_GRAPHICS_VERSION 0.11.2) +set(BLT_GRAPHICS_VERSION 0.11.3) set(BLT_GRAPHICS_TEST_VERSION 0.0.1) project(BLT_WITH_GRAPHICS VERSION ${BLT_GRAPHICS_VERSION}) diff --git a/include/blt/gfx/window.h b/include/blt/gfx/window.h index 1d73277..fdf2b12 100644 --- a/include/blt/gfx/window.h +++ b/include/blt/gfx/window.h @@ -74,7 +74,7 @@ namespace blt::gfx } }; - void init(const window_data& data); + void init(window_data data); double getMouseX(); diff --git a/src/blt/gfx/window.cpp b/src/blt/gfx/window.cpp index 77b1be2..623b46f 100644 --- a/src/blt/gfx/window.cpp +++ b/src/blt/gfx/window.cpp @@ -17,6 +17,7 @@ #ifdef __EMSCRIPTEN__ #include +#include #endif @@ -193,15 +194,26 @@ namespace blt::gfx return false; } + + EM_JS(int, get_screen_width, (), { + return window.innerWidth; + }); + + EM_JS(int, get_screen_height, (), { + return window.innerHeight; + }); #endif - void init(const window_data& data) + void init(window_data data) { #ifdef __EMSCRIPTEN__ blt::logging::setLogOutputFormat("[${{TIME}}] [${{LOG_LEVEL}}] (${{FILE}}:${{LINE}}) ${{STR}}\n"); emscripten_set_resize_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, nullptr, false, emscripten_resize_callback); + + data.width = get_screen_width(); + data.height = get_screen_height(); #endif /* -- Set up Error Callback -- */ glfwSetErrorCallback(error_callback);