From 1f1861dae63ff096b5c878f06a0c0d4db2d51718 Mon Sep 17 00:00:00 2001 From: ocornut Date: Thu, 2 Feb 2023 18:33:04 +0100 Subject: [PATCH 1/2] Backends: Added support for SDL 2.0.18+ preciseX/preciseY mouse wheel data for smooth scrolling + scaling for Emscripten. (#4019, #6096) + Missing changelog entries. --- backends/imgui_impl_glfw.cpp | 5 +++++ backends/imgui_impl_sdl.cpp | 10 ++++++++++ docs/CHANGELOG.txt | 5 ++++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/backends/imgui_impl_glfw.cpp b/backends/imgui_impl_glfw.cpp index d0dedf643..9192d19e3 100644 --- a/backends/imgui_impl_glfw.cpp +++ b/backends/imgui_impl_glfw.cpp @@ -16,6 +16,7 @@ // CHANGELOG // (minor and older changes stripped away, please see git history for details) +// 2023-02-02: Inputs: Scaling X value on Emscripten (bug?). (#4019, #6096) // 2023-01-04: Inputs: Fixed mods state on Linux when using Alt-GR text input (e.g. German keyboard layout), could lead to broken text input. Revert a 2022/01/17 change were we resumed using mods provided by GLFW, turns out they were faulty. // 2022-11-22: Perform a dummy glfwGetError() read to cancel missing names with glfwGetKeyName(). (#5908) // 2022-10-18: Perform a dummy glfwGetError() read to cancel missing mouse cursors errors. Using GLFW_VERSION_COMBINED directly. (#5785) @@ -283,6 +284,10 @@ void ImGui_ImplGlfw_ScrollCallback(GLFWwindow* window, double xoffset, double yo if (bd->PrevUserCallbackScroll != nullptr && window == bd->Window) bd->PrevUserCallbackScroll(window, xoffset, yoffset); +#ifdef __EMSCRIPTEN__ + xoffset /= 100.0; +#endif + ImGuiIO& io = ImGui::GetIO(); io.AddMouseWheelEvent((float)xoffset, (float)yoffset); } diff --git a/backends/imgui_impl_sdl.cpp b/backends/imgui_impl_sdl.cpp index 1de0447bb..72005784b 100644 --- a/backends/imgui_impl_sdl.cpp +++ b/backends/imgui_impl_sdl.cpp @@ -18,6 +18,7 @@ // CHANGELOG // (minor and older changes stripped away, please see git history for details) +// 2023-02-02: Added support for SDL 2.0.18+ preciseX/preciseY mouse wheel data for smooth scrolling + Scaling X value on Emscripten (bug?). (#4019, #6096) // 2023-02-02: Removed SDL_MOUSEWHEEL value clamping, as values seem correct in latest Emscripten. (#4019) // 2023-02-01: Flipping SDL_MOUSEWHEEL 'wheel.x' value to match other backends and offer consistent horizontal scrolling direction. (#4019, #6096, #1463) // 2022-10-11: Using 'nullptr' instead of 'NULL' as per our switch to C++11. @@ -262,8 +263,17 @@ bool ImGui_ImplSDL2_ProcessEvent(const SDL_Event* event) } case SDL_MOUSEWHEEL: { + //IMGUI_DEBUG_LOG("wheel %.2f %.2f, precise %.2f %.2f\n", (float)event->wheel.x, (float)event->wheel.y, event->wheel.preciseX, event->wheel.preciseY); +#if SDL_VERSION_ATLEAST(2,0,18) // If this fails to compile on Emscripten: update to latest Emscripten! + float wheel_x = -event->wheel.preciseX; + float wheel_y = event->wheel.preciseY; +#else float wheel_x = -(float)event->wheel.x; float wheel_y = (float)event->wheel.y; +#endif +#ifdef __EMSCRIPTEN__ + wheel_x /= 100.0f; +#endif io.AddMouseWheelEvent(wheel_x, wheel_y); return true; } diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index c18e95cec..99b3b74e3 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -90,13 +90,16 @@ All changes: - Backends: OSX: Fixed scroll/wheel scaling for devices emitting events with hasPreciseScrollingDeltas==false (e.g. non-Apple mices). - Backends: SDL: Removed SDL_MOUSEWHEEL value clamping. (#4019, #6096, #6081) - Latest Emscripten seems to emit correct values. +- Backends: SDL: Added support for SDL 2.0.18+ preciseX/preciseY mouse wheel data + for smooth scrolling as reported by SDL. (#4019, #6096) - Backend: WebGPU: Fix building for latest WebGPU specs (remove implicit layout generation). (#6117, #4116, #3632) [@tonygrue, @bfierz] - Examples: refactord all examples to use a "MainLoopStep()" function. This is in order to be able to trivially make some compile with Emscripten. (#2492, #3699) While not all examples are expected to compile on Emscripten, we try to keep all of them as close as possible to each others. +- Examples: Emscripten: The main SDL+GL and GLFW+GL examples now supports Emscripten. + (the dedicated example_emscripten_opengl3/ has been removed) (#2492, #2494, #3699, #3705) - Examples: Win32: Fixed examples using RegisterClassW() since 1.89 to also call DefWindowProcW() instead of DefWindowProc() so that title text are correctly converted when application is compiled without /DUNICODE. (#5725, #5961, #5975) [@markreidvfx] From 46efed8b7013d8576ebd8c632a501d4bdee2afc8 Mon Sep 17 00:00:00 2001 From: ocornut Date: Thu, 2 Feb 2023 19:33:03 +0100 Subject: [PATCH 2/2] CI: Fix Emscripten build. --- .github/workflows/build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 2bc86106c..f3b758b6a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -482,12 +482,12 @@ jobs: emsdk-master/emsdk install latest emsdk-master/emsdk activate latest - - name: Build example_emscripten_opengl3 + - name: Build example_sdl_opengl3 with Emscripten run: | pushd emsdk-master source ./emsdk_env.sh popd - make -C examples/example_emscripten_opengl3 + make -C examples/example_sdl_opengl3 -f Makefile.emscripten - name: Build example_emscripten_wgpu run: |