From 4e5b5cba121f9c14a59d0726b09ec609a04b9ada Mon Sep 17 00:00:00 2001 From: Charlie Birks Date: Thu, 9 May 2019 12:09:40 +0100 Subject: [PATCH] Emscripten: Switch from canvas[XY] to target[XY] Allows mouse/touch events to work on non-default canvases --- src/video/emscripten/SDL_emscriptenevents.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/video/emscripten/SDL_emscriptenevents.c b/src/video/emscripten/SDL_emscriptenevents.c index 5d5f88f43..09003af49 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);