Emscripten: Switch from canvas[XY] to target[XY] Allows mouse/touch events to work on non-default canvases
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
diff --git a/src/video/emscripten/SDL_emscriptenevents.c b/src/video/emscripten/SDL_emscriptenevents.c
index 5d5f88f..09003af 100644
--- a/src/video/emscripten/SDL_emscriptenevents.c
+++ b/src/video/emscripten/SDL_emscriptenevents.c
@@ -330,8 +330,8 @@ Emscripten_HandleMouseMove(int eventType, const EmscriptenMouseEvent *mouseEvent
my = residualy;
residualy -= my;
} else {
- mx = mouseEvent->canvasX * xscale;
- my = mouseEvent->canvasY * yscale;
+ mx = mouseEvent->targetX * xscale;
+ my = mouseEvent->targetY * yscale;
}
SDL_SendMouseMotion(window_data->window, 0, isPointerLocked, mx, my);
@@ -375,8 +375,8 @@ Emscripten_HandleMouseButton(int eventType, const EmscriptenMouseEvent *mouseEve
/* Do not consume the event if the mouse is outside of the canvas. */
emscripten_get_element_css_size(window_data->canvas_id, &css_w, &css_h);
- if (mouseEvent->canvasX < 0 || mouseEvent->canvasX >= css_w ||
- mouseEvent->canvasY < 0 || mouseEvent->canvasY >= css_h) {
+ if (mouseEvent->targetX < 0 || mouseEvent->targetX >= css_w ||
+ mouseEvent->targetY < 0 || mouseEvent->targetY >= css_h) {
return 0;
}
@@ -388,7 +388,7 @@ Emscripten_HandleMouseFocus(int eventType, const EmscriptenMouseEvent *mouseEven
{
SDL_WindowData *window_data = userData;
- int mx = mouseEvent->canvasX, my = mouseEvent->canvasY;
+ int mx = mouseEvent->targetX, my = mouseEvent->targetY;
const int isPointerLocked = window_data->has_pointer_lock;
if (!isPointerLocked) {
@@ -450,8 +450,8 @@ Emscripten_HandleTouch(int eventType, const EmscriptenTouchEvent *touchEvent, vo
continue;
id = touchEvent->touches[i].identifier;
- x = touchEvent->touches[i].canvasX / client_w;
- y = touchEvent->touches[i].canvasY / client_h;
+ x = touchEvent->touches[i].targetX / client_w;
+ y = touchEvent->touches[i].targetY / client_h;
if (eventType == EMSCRIPTEN_EVENT_TOUCHSTART) {
SDL_SendTouch(deviceId, id, SDL_TRUE, x, y, 1.0f);