src/video/emscripten/SDL_emscriptenevents.c
changeset 12573 296d155a8ce5
parent 12572 397aa57185c4
child 12574 109c919d61f6
     1.1 --- a/src/video/emscripten/SDL_emscriptenevents.c	Tue Jan 29 12:14:44 2019 +0000
     1.2 +++ b/src/video/emscripten/SDL_emscriptenevents.c	Tue Jan 29 12:14:54 2019 +0000
     1.3 @@ -345,6 +345,7 @@
     1.4      Uint8 sdl_button;
     1.5      Uint8 sdl_button_state;
     1.6      SDL_EventType sdl_event_type;
     1.7 +    double css_w, css_h;
     1.8  
     1.9      switch (mouseEvent->button) {
    1.10          case 0:
    1.11 @@ -371,6 +372,14 @@
    1.12          sdl_event_type = SDL_MOUSEBUTTONUP;
    1.13      }
    1.14      SDL_SendMouseButton(window_data->window, 0, sdl_button_state, sdl_button);
    1.15 +
    1.16 +    /* Do not consume the event if the mouse is outside of the canvas. */
    1.17 +    emscripten_get_element_css_size(NULL, &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 +        return 0;
    1.21 +    }
    1.22 +
    1.23      return SDL_GetEventState(sdl_event_type) == SDL_ENABLE;
    1.24  }
    1.25