Browse Source

EmscriptenApplication: define special Emscripten target constants if they're not defined

These were only added with 1.38.27
pull/480/head
Pablo Escobar 6 years ago
parent
commit
477910a815
  1. 34
      src/Magnum/Platform/EmscriptenApplication.cpp

34
src/Magnum/Platform/EmscriptenApplication.cpp

@ -43,6 +43,13 @@
#include "Magnum/Platform/GLContext.h" #include "Magnum/Platform/GLContext.h"
#endif #endif
/** @todo drop once we don't support < 1.38.27 anymore */
#ifndef EMSCRIPTEN_EVENT_TARGET_DOCUMENT
#define EMSCRIPTEN_EVENT_TARGET_DOCUMENT reinterpret_cast<const char*>(1)
#define EMSCRIPTEN_EVENT_TARGET_WINDOW reinterpret_cast<const char*>(2)
#define EMSCRIPTEN_EVENT_TARGET_SCREEN reinterpret_cast<const char*>(3)
#endif
namespace Magnum { namespace Platform { namespace Magnum { namespace Platform {
namespace { namespace {
@ -464,11 +471,7 @@ void EmscriptenApplication::setupCallbacks(bool resizable) {
changes. Better than polling for this change in every frame like changes. Better than polling for this change in every frame like
Sdl2Application does, but still not ideal. */ Sdl2Application does, but still not ideal. */
if(resizable) { if(resizable) {
const char* target = const char* target = _deprecatedTargetBehavior ? "#window" : EMSCRIPTEN_EVENT_TARGET_WINDOW;
#ifdef EMSCRIPTEN_EVENT_TARGET_WINDOW
!_deprecatedTargetBehavior ? EMSCRIPTEN_EVENT_TARGET_WINDOW :
#endif
"#window";
auto cb = [](int, const EmscriptenUiEvent* event, void* userData) -> Int { auto cb = [](int, const EmscriptenUiEvent* event, void* userData) -> Int {
static_cast<EmscriptenApplication*>(userData)->handleCanvasResize(event); static_cast<EmscriptenApplication*>(userData)->handleCanvasResize(event);
return false; /** @todo what does ignoring a resize event mean? */ return false; /** @todo what does ignoring a resize event mean? */
@ -524,29 +527,28 @@ void EmscriptenApplication::setupCallbacks(bool resizable) {
1.38.27 depending on -s DISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR=1 1.38.27 depending on -s DISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR=1
but we don't want to force this flag on the users so the behavior but we don't want to force this flag on the users so the behavior
handles both. */ handles both. */
int keyboardListeningElement = EM_ASM_INT({ const char* keyboardListeningTarget = reinterpret_cast<const char*>(EM_ASM_INT({
var element = Module['keyboardListeningElement'] || document; var element = Module['keyboardListeningElement'] || document;
if(element === document) return 1; if(element === document) return 1; // EMSCRIPTEN_EVENT_TARGET_DOCUMENT
if(element === window) return 2; if(element === window) return 2; // EMSCRIPTEN_EVENT_TARGET_WINDOW
if('id' in element) if('id' in element)
return allocate(intArrayFromString(element.id), 'i8', ALLOC_NORMAL); return allocate(intArrayFromString(element.id), 'i8', ALLOC_NORMAL);
return 0; return 0;
}); }));
#pragma GCC diagnostic pop #pragma GCC diagnostic pop
std::string keyboardListeningTargetString; std::string keyboardListeningTargetString;
const char* keyboardListeningTarget = reinterpret_cast<char*>(keyboardListeningElement); if(keyboardListeningTarget == EMSCRIPTEN_EVENT_TARGET_DOCUMENT) {
if(_deprecatedTargetBehavior && keyboardListeningElement == 1) { keyboardListeningTarget = _deprecatedTargetBehavior ? "#document" : keyboardListeningTarget;
keyboardListeningTarget = "#document"; } else if(EMSCRIPTEN_EVENT_TARGET_WINDOW) {
} else if(_deprecatedTargetBehavior && keyboardListeningElement == 2) { keyboardListeningTarget = _deprecatedTargetBehavior ? "#window" : keyboardListeningTarget;
keyboardListeningTarget = "#window"; } else if (keyboardListeningTarget) {
} else if(keyboardListeningElement > 2) {
if(!_deprecatedTargetBehavior) if(!_deprecatedTargetBehavior)
keyboardListeningTargetString = "#"; keyboardListeningTargetString = "#";
keyboardListeningTargetString += keyboardListeningTarget; keyboardListeningTargetString += keyboardListeningTarget;
std::free(reinterpret_cast<void*>(keyboardListeningElement)); std::free(const_cast<char*>(keyboardListeningTarget));
keyboardListeningTarget = keyboardListeningTargetString.data(); keyboardListeningTarget = keyboardListeningTargetString.data();
} }

Loading…
Cancel
Save