send mouse move on enter/leave
authorCharlie Birks <admin@daftgames.net>
Tue, 13 Sep 2016 00:03:39 -0700
changeset 10320f2e6dc590643
parent 10319 c16a46e31811
child 10321 6564d3e3c5f6
send mouse move on enter/leave
src/video/emscripten/SDL_emscriptenevents.c
     1.1 --- a/src/video/emscripten/SDL_emscriptenevents.c	Tue Sep 13 00:03:37 2016 -0700
     1.2 +++ b/src/video/emscripten/SDL_emscriptenevents.c	Tue Sep 13 00:03:39 2016 -0700
     1.3 @@ -350,6 +350,22 @@
     1.4  {
     1.5      SDL_WindowData *window_data = userData;
     1.6  
     1.7 +    int mx = mouseEvent->canvasX, my = mouseEvent->canvasY;
     1.8 +    EmscriptenPointerlockChangeEvent pointerlock_status;
     1.9 +
    1.10 +    /* check for pointer lock */
    1.11 +    emscripten_get_pointerlock_status(&pointerlock_status);
    1.12 +
    1.13 +    if (!pointerlock_status.isActive) {
    1.14 +        /* rescale (in case canvas is being scaled)*/
    1.15 +        double client_w, client_h;
    1.16 +        emscripten_get_element_css_size(NULL, &client_w, &client_h);
    1.17 +
    1.18 +        mx = mx * (window_data->window->w / (client_w * window_data->pixel_ratio));
    1.19 +        my = my * (window_data->window->h / (client_h * window_data->pixel_ratio));
    1.20 +        SDL_SendMouseMotion(window_data->window, 0, pointerlock_status.isActive, mx, my);
    1.21 +    }
    1.22 +
    1.23      SDL_SetMouseFocus(eventType == EMSCRIPTEN_EVENT_MOUSEENTER ? window_data->window : NULL);
    1.24      return 1;
    1.25  }