From 910a47676e2bf7c9f052bd489a1c48512139b317 Mon Sep 17 00:00:00 2001 From: Pablo Escobar Date: Thu, 5 Nov 2020 22:26:03 +0100 Subject: [PATCH] EmscriptenApplication: add custom canvas test --- src/Magnum/Platform/Test/CMakeLists.txt | 16 +++++++++ ...EmscriptenApplicationCustomCanvasTest.html | 34 +++++++++++++++++++ .../Test/EmscriptenApplicationTest.cpp | 6 +++- .../PatchWebApplicationCssCustomCanvas.cmake | 3 ++ 4 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 src/Magnum/Platform/Test/EmscriptenApplicationCustomCanvasTest.html create mode 100644 src/Magnum/Platform/Test/PatchWebApplicationCssCustomCanvas.cmake diff --git a/src/Magnum/Platform/Test/CMakeLists.txt b/src/Magnum/Platform/Test/CMakeLists.txt index 7fa2dfc4e..9c7d5e085 100644 --- a/src/Magnum/Platform/Test/CMakeLists.txt +++ b/src/Magnum/Platform/Test/CMakeLists.txt @@ -51,6 +51,22 @@ if(WITH_EMSCRIPTENAPPLICATION) COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/EmscriptenApplicationTest.html $/PlatformEmscriptenApplicationTest.html) + + add_executable(PlatformEmscriptenApplicationCustomCanvasTest EmscriptenApplicationTest.cpp) + target_link_libraries(PlatformEmscriptenApplicationCustomCanvasTest PRIVATE MagnumEmscriptenApplication MagnumGL) + set_target_properties(PlatformEmscriptenApplicationCustomCanvasTest PROPERTIES FOLDER "Magnum/Platform/Test") + target_compile_definitions(PlatformEmscriptenApplicationCustomCanvasTest PRIVATE CUSTOM_CANVAS_ID) + add_custom_command(TARGET PlatformEmscriptenApplicationCustomCanvasTest POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_if_different + ${CMAKE_CURRENT_SOURCE_DIR}/../WebApplication.css + ${CMAKE_CURRENT_SOURCE_DIR}/../EmscriptenApplication.js + ${CMAKE_CURRENT_SOURCE_DIR}/PatchWebApplicationCssCustomCanvas.cmake + $ + COMMAND ${CMAKE_COMMAND} -P PatchWebApplicationCssCustomCanvas.cmake + COMMAND ${CMAKE_COMMAND} -E copy_if_different + ${CMAKE_CURRENT_SOURCE_DIR}/EmscriptenApplicationCustomCanvasTest.html + $/PlatformEmscriptenApplicationCustomCanvasTest.html + WORKING_DIRECTORY $) endif() if(WITH_GLFWAPPLICATION) diff --git a/src/Magnum/Platform/Test/EmscriptenApplicationCustomCanvasTest.html b/src/Magnum/Platform/Test/EmscriptenApplicationCustomCanvasTest.html new file mode 100644 index 000000000..840d12d41 --- /dev/null +++ b/src/Magnum/Platform/Test/EmscriptenApplicationCustomCanvasTest.html @@ -0,0 +1,34 @@ + + + + + Magnum EmscriptenApplication Test + + + + +

Magnum EmscriptenApplication Custom Canvas Test

+
+
+ +
Initialization...
+
+ + + + +
+ + +
+ + diff --git a/src/Magnum/Platform/Test/EmscriptenApplicationTest.cpp b/src/Magnum/Platform/Test/EmscriptenApplicationTest.cpp index 4ad684d6e..9cb8a105c 100644 --- a/src/Magnum/Platform/Test/EmscriptenApplicationTest.cpp +++ b/src/Magnum/Platform/Test/EmscriptenApplicationTest.cpp @@ -153,7 +153,11 @@ EmscriptenApplicationTest::EmscriptenApplicationTest(const Arguments& arguments) return; } - create(Configuration{}.setWindowFlags(Configuration::WindowFlag::Resizable) + create(Configuration{} + .setWindowFlags(Configuration::WindowFlag::Resizable) + #ifdef CUSTOM_CANVAS_ID + .setCanvasTarget("#canvas2") + #endif //, GLConfiguration{}.setFlags({}) ); diff --git a/src/Magnum/Platform/Test/PatchWebApplicationCssCustomCanvas.cmake b/src/Magnum/Platform/Test/PatchWebApplicationCssCustomCanvas.cmake new file mode 100644 index 000000000..be47740c4 --- /dev/null +++ b/src/Magnum/Platform/Test/PatchWebApplicationCssCustomCanvas.cmake @@ -0,0 +1,3 @@ +file(READ ${CMAKE_CURRENT_LIST_DIR}/WebApplication.css CONTENT) +string(REPLACE "#canvas" "#canvas2" CONTENT "${CONTENT}") +file(WRITE ${CMAKE_CURRENT_LIST_DIR}/WebApplicationCustomCanvas.css "${CONTENT}")