Skip to content

Commit

Permalink
Emscripten: Do not consume mouseup event outside of the canvas
Browse files Browse the repository at this point in the history
  • Loading branch information
kichikuou committed Jan 29, 2019
1 parent 2838abb commit ed66a43
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/video/emscripten/SDL_emscriptenevents.c
Expand Up @@ -345,6 +345,7 @@ Emscripten_HandleMouseButton(int eventType, const EmscriptenMouseEvent *mouseEve
Uint8 sdl_button;
Uint8 sdl_button_state;
SDL_EventType sdl_event_type;
double css_w, css_h;

switch (mouseEvent->button) {
case 0:
Expand All @@ -371,6 +372,14 @@ Emscripten_HandleMouseButton(int eventType, const EmscriptenMouseEvent *mouseEve
sdl_event_type = SDL_MOUSEBUTTONUP;
}
SDL_SendMouseButton(window_data->window, 0, sdl_button_state, sdl_button);

/* Do not consume the event if the mouse is outside of the canvas. */
emscripten_get_element_css_size(NULL, &css_w, &css_h);
if (mouseEvent->canvasX < 0 || mouseEvent->canvasX >= css_w ||
mouseEvent->canvasY < 0 || mouseEvent->canvasY >= css_h) {
return 0;
}

return SDL_GetEventState(sdl_event_type) == SDL_ENABLE;
}

Expand Down

0 comments on commit ed66a43

Please sign in to comment.