Emscripten: Switch from canvas[XY] to target[XY]
authorCharlie Birks <charlie@daftgames.net>
Thu, 09 May 2019 12:09:40 +0100
changeset 127255ef84902d1a0
parent 12724 19c373658809
child 12726 1db0606a7b0c
Emscripten: Switch from canvas[XY] to target[XY]
Allows mouse/touch events to work on non-default canvases
src/video/emscripten/SDL_emscriptenevents.c
     1.1 --- a/src/video/emscripten/SDL_emscriptenevents.c	Thu May 09 12:09:34 2019 +0100
     1.2 +++ b/src/video/emscripten/SDL_emscriptenevents.c	Thu May 09 12:09:40 2019 +0100
     1.3 @@ -330,8 +330,8 @@
     1.4          my = residualy;
     1.5          residualy -= my;
     1.6      } else {
     1.7 -        mx = mouseEvent->canvasX * xscale;
     1.8 -        my = mouseEvent->canvasY * yscale;
     1.9 +        mx = mouseEvent->targetX * xscale;
    1.10 +        my = mouseEvent->targetY * yscale;
    1.11      }
    1.12  
    1.13      SDL_SendMouseMotion(window_data->window, 0, isPointerLocked, mx, my);
    1.14 @@ -375,8 +375,8 @@
    1.15  
    1.16      /* Do not consume the event if the mouse is outside of the canvas. */
    1.17      emscripten_get_element_css_size(window_data->canvas_id, &css_w, &css_h);
    1.18 -    if (mouseEvent->canvasX < 0 || mouseEvent->canvasX >= css_w ||
    1.19 -        mouseEvent->canvasY < 0 || mouseEvent->canvasY >= css_h) {
    1.20 +    if (mouseEvent->targetX < 0 || mouseEvent->targetX >= css_w ||
    1.21 +        mouseEvent->targetY < 0 || mouseEvent->targetY >= css_h) {
    1.22          return 0;
    1.23      }
    1.24  
    1.25 @@ -388,7 +388,7 @@
    1.26  {
    1.27      SDL_WindowData *window_data = userData;
    1.28  
    1.29 -    int mx = mouseEvent->canvasX, my = mouseEvent->canvasY;
    1.30 +    int mx = mouseEvent->targetX, my = mouseEvent->targetY;
    1.31      const int isPointerLocked = window_data->has_pointer_lock;
    1.32  
    1.33      if (!isPointerLocked) {
    1.34 @@ -450,8 +450,8 @@
    1.35              continue;
    1.36  
    1.37          id = touchEvent->touches[i].identifier;
    1.38 -        x = touchEvent->touches[i].canvasX / client_w;
    1.39 -        y = touchEvent->touches[i].canvasY / client_h;
    1.40 +        x = touchEvent->touches[i].targetX / client_w;
    1.41 +        y = touchEvent->touches[i].targetY / client_h;
    1.42  
    1.43          if (eventType == EMSCRIPTEN_EVENT_TOUCHSTART) {
    1.44              SDL_SendTouch(deviceId, id, SDL_TRUE, x, y, 1.0f);