From 23ec25d582d50318df04d4e5b2baf07566058d0a Mon Sep 17 00:00:00 2001 From: Pablo Escobar Date: Sun, 8 Nov 2020 21:54:32 +0100 Subject: [PATCH] EmscriptenApplication: move private static functions to an anonymous namespace --- src/Magnum/Platform/EmscriptenApplication.cpp | 62 +++++++++---------- src/Magnum/Platform/EmscriptenApplication.h | 4 -- 2 files changed, 30 insertions(+), 36 deletions(-) diff --git a/src/Magnum/Platform/EmscriptenApplication.cpp b/src/Magnum/Platform/EmscriptenApplication.cpp index d3782be3e..fa3e5de96 100644 --- a/src/Magnum/Platform/EmscriptenApplication.cpp +++ b/src/Magnum/Platform/EmscriptenApplication.cpp @@ -181,6 +181,36 @@ namespace { return Key::Unknown; } + + std::string canvasId() { + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wgnu-zero-variadic-macro-arguments" + char* id = reinterpret_cast(EM_ASM_INT({ + return allocate(intArrayFromString(Module['canvas'].id), 'i8', ALLOC_NORMAL); + })); + #pragma GCC diagnostic pop + std::string str = id; + std::free(id); + return str; + } + + bool checkForDeprecatedEmscriptenTargetBehavior() { + /* Emscripten 1.38.27 changed to generic CSS selectors from element IDs + depending on -s DISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR=1 being + set. + https://github.com/emscripten-core/emscripten/pull/7977 + There is no simple way to check for compiler options so check + whether the new CSS selectors are being used. If so, it should find + canvas#[id] which is any canvas with the ID of Module.canvas. + The old target behavior will look for an element with id="canvas#[id]" + which could theoretically exist but that's highly unlikely. */ + bool deprecated = true; + Vector2d tempSize; + if(emscripten_get_element_css_size(("canvas#" + canvasId()).data(), &tempSize.x(), &tempSize.y()) >= 0) { + deprecated = false; + } + return deprecated; + } } EmscriptenApplication::EmscriptenApplication(const Arguments& arguments): EmscriptenApplication{arguments, Configuration{}} {} @@ -750,38 +780,6 @@ void EmscriptenApplication::exit(int) { _flags |= Flag::ExitRequested; } -bool EmscriptenApplication::checkForDeprecatedEmscriptenTargetBehavior() { - /* Emscripten 1.38.27 changed to generic CSS selectors from element IDs - depending on -s DISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR=1 being - set. - https://github.com/emscripten-core/emscripten/pull/7977 - There is no simple way to check for compiler options so check - whether the new CSS selectors are being used. If so, it should find - canvas#[id] which is any canvas with the ID of Module.canvas. - The old target behavior will look for an element with id="canvas#[id]" - which could theoretically exist but that's highly unlikely. */ - bool deprecated = true; - #ifdef EMSCRIPTEN_EVENT_TARGET_WINDOW - Vector2d tempSize; - if(emscripten_get_element_css_size(("canvas#" + canvasId()).data(), &tempSize.x(), &tempSize.y()) >= 0) { - deprecated = false; - } - #endif - return deprecated; -} - -std::string EmscriptenApplication::canvasId() { - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wgnu-zero-variadic-macro-arguments" - char* id = reinterpret_cast(EM_ASM_INT({ - return allocate(intArrayFromString(Module['canvas'].id), 'i8', ALLOC_NORMAL); - })); - #pragma GCC diagnostic pop - std::string str = id; - std::free(id); - return str; -} - EmscriptenApplication::MouseEvent::Button EmscriptenApplication::MouseEvent::button() const { return Button(_event.button); } diff --git a/src/Magnum/Platform/EmscriptenApplication.h b/src/Magnum/Platform/EmscriptenApplication.h index 399223876..f75770e03 100644 --- a/src/Magnum/Platform/EmscriptenApplication.h +++ b/src/Magnum/Platform/EmscriptenApplication.h @@ -874,10 +874,6 @@ class EmscriptenApplication { * @} */ - private: - static bool checkForDeprecatedEmscriptenTargetBehavior(); - static std::string canvasId(); - private: enum class Flag: UnsignedByte { Redraw = 1 << 0,