src/video/emscripten/SDL_emscriptenevents.c
changeset 12573 296d155a8ce5
parent 12572 397aa57185c4
child 12574 109c919d61f6
equal deleted inserted replaced
12572:397aa57185c4 12573:296d155a8ce5
   343 {
   343 {
   344     SDL_WindowData *window_data = userData;
   344     SDL_WindowData *window_data = userData;
   345     Uint8 sdl_button;
   345     Uint8 sdl_button;
   346     Uint8 sdl_button_state;
   346     Uint8 sdl_button_state;
   347     SDL_EventType sdl_event_type;
   347     SDL_EventType sdl_event_type;
       
   348     double css_w, css_h;
   348 
   349 
   349     switch (mouseEvent->button) {
   350     switch (mouseEvent->button) {
   350         case 0:
   351         case 0:
   351             sdl_button = SDL_BUTTON_LEFT;
   352             sdl_button = SDL_BUTTON_LEFT;
   352             break;
   353             break;
   369     } else {
   370     } else {
   370         sdl_button_state = SDL_RELEASED;
   371         sdl_button_state = SDL_RELEASED;
   371         sdl_event_type = SDL_MOUSEBUTTONUP;
   372         sdl_event_type = SDL_MOUSEBUTTONUP;
   372     }
   373     }
   373     SDL_SendMouseButton(window_data->window, 0, sdl_button_state, sdl_button);
   374     SDL_SendMouseButton(window_data->window, 0, sdl_button_state, sdl_button);
       
   375 
       
   376     /* Do not consume the event if the mouse is outside of the canvas. */
       
   377     emscripten_get_element_css_size(NULL, &css_w, &css_h);
       
   378     if (mouseEvent->canvasX < 0 || mouseEvent->canvasX >= css_w ||
       
   379         mouseEvent->canvasY < 0 || mouseEvent->canvasY >= css_h) {
       
   380         return 0;
       
   381     }
       
   382 
   374     return SDL_GetEventState(sdl_event_type) == SDL_ENABLE;
   383     return SDL_GetEventState(sdl_event_type) == SDL_ENABLE;
   375 }
   384 }
   376 
   385 
   377 static EM_BOOL
   386 static EM_BOOL
   378 Emscripten_HandleMouseFocus(int eventType, const EmscriptenMouseEvent *mouseEvent, void *userData)
   387 Emscripten_HandleMouseFocus(int eventType, const EmscriptenMouseEvent *mouseEvent, void *userData)