mirror of
https://github.com/raysan5/raylib.git
synced 2026-04-28 09:37:25 -04:00
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
This commit is contained in:
@ -1447,15 +1447,37 @@ void PollInputEvents(void)
|
|||||||
} break;
|
} break;
|
||||||
case RGFW_mousePosChanged:
|
case RGFW_mousePosChanged:
|
||||||
{
|
{
|
||||||
|
float event_x = 0.0f, event_y = 0.0f;
|
||||||
if (RGFW_window_isCaptured(platform.window))
|
if (RGFW_window_isCaptured(platform.window))
|
||||||
{
|
{
|
||||||
CORE.Input.Mouse.currentPosition.x += (float)rgfw_event.mouse.vecX;
|
event_x = (float)rgfw_event.mouse.vecX;
|
||||||
CORE.Input.Mouse.currentPosition.y += (float)rgfw_event.mouse.vecY;
|
event_y = (float)rgfw_event.mouse.vecY;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
CORE.Input.Mouse.currentPosition.x = (float)rgfw_event.mouse.x;
|
event_x = (float)rgfw_event.mouse.x;
|
||||||
CORE.Input.Mouse.currentPosition.y = (float)rgfw_event.mouse.y;
|
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;
|
CORE.Input.Touch.position[0] = CORE.Input.Mouse.currentPosition;
|
||||||
|
|||||||
Reference in New Issue
Block a user