From 1e74aba7c37095a337d4ba3881459ae3609db530 Mon Sep 17 00:00:00 2001 From: Krzysztof Szenk Date: Mon, 23 Mar 2026 11:31:06 +0100 Subject: [PATCH] WebRGFW: remapping mouse/touch position to canvas pixel coordinates (#5679) * RGFW also requires RGBA8 images as window icons, as raylib already reports in raylib.h * LibraryConfigurations.cmake: exchanged MATCHES -> STREQUAL in platform choosing if-statements * WebRGFW: remapping mouse/touch position to canvas pixel coordinates * fix 'typo' * has to be done like that because of += in case of captured mouse --- src/platforms/rcore_desktop_rgfw.c | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/src/platforms/rcore_desktop_rgfw.c b/src/platforms/rcore_desktop_rgfw.c index 87ad7d7c4..7817c7874 100755 --- a/src/platforms/rcore_desktop_rgfw.c +++ b/src/platforms/rcore_desktop_rgfw.c @@ -1447,15 +1447,37 @@ void PollInputEvents(void) } break; case RGFW_mousePosChanged: { + float event_x = 0.0f, event_y = 0.0f; if (RGFW_window_isCaptured(platform.window)) { - CORE.Input.Mouse.currentPosition.x += (float)rgfw_event.mouse.vecX; - CORE.Input.Mouse.currentPosition.y += (float)rgfw_event.mouse.vecY; + event_x = (float)rgfw_event.mouse.vecX; + event_y = (float)rgfw_event.mouse.vecY; } else { - CORE.Input.Mouse.currentPosition.x = (float)rgfw_event.mouse.x; - CORE.Input.Mouse.currentPosition.y = (float)rgfw_event.mouse.y; + event_x = (float)rgfw_event.mouse.x; + event_y = (float)rgfw_event.mouse.y; + } + +#if defined(__EMSCRIPTEN__) + { + double canvasWidth = 0.0; + double canvasHeight = 0.0; + emscripten_get_element_css_size("#canvas", &canvasWidth, &canvasHeight); + event_x *= ((float)GetScreenWidth() / (float)canvasWidth); + event_y *= ((float)GetScreenHeight() / (float)canvasHeight); + } +#endif + + if (RGFW_window_isCaptured(platform.window)) + { + CORE.Input.Mouse.currentPosition.x += event_x; + CORE.Input.Mouse.currentPosition.y += event_y; + } + else + { + CORE.Input.Mouse.currentPosition.x = event_x; + CORE.Input.Mouse.currentPosition.y = event_y; } CORE.Input.Touch.position[0] = CORE.Input.Mouse.currentPosition;