src/video/emscripten/SDL_emscriptenevents.c
changeset 10320 f2e6dc590643
parent 10319 c16a46e31811
child 10324 efa3b17582ce
equal deleted inserted replaced
10319:c16a46e31811 10320:f2e6dc590643
   348 EM_BOOL
   348 EM_BOOL
   349 Emscripten_HandleMouseFocus(int eventType, const EmscriptenMouseEvent *mouseEvent, void *userData)
   349 Emscripten_HandleMouseFocus(int eventType, const EmscriptenMouseEvent *mouseEvent, void *userData)
   350 {
   350 {
   351     SDL_WindowData *window_data = userData;
   351     SDL_WindowData *window_data = userData;
   352 
   352 
       
   353     int mx = mouseEvent->canvasX, my = mouseEvent->canvasY;
       
   354     EmscriptenPointerlockChangeEvent pointerlock_status;
       
   355 
       
   356     /* check for pointer lock */
       
   357     emscripten_get_pointerlock_status(&pointerlock_status);
       
   358 
       
   359     if (!pointerlock_status.isActive) {
       
   360         /* rescale (in case canvas is being scaled)*/
       
   361         double client_w, client_h;
       
   362         emscripten_get_element_css_size(NULL, &client_w, &client_h);
       
   363 
       
   364         mx = mx * (window_data->window->w / (client_w * window_data->pixel_ratio));
       
   365         my = my * (window_data->window->h / (client_h * window_data->pixel_ratio));
       
   366         SDL_SendMouseMotion(window_data->window, 0, pointerlock_status.isActive, mx, my);
       
   367     }
       
   368 
   353     SDL_SetMouseFocus(eventType == EMSCRIPTEN_EVENT_MOUSEENTER ? window_data->window : NULL);
   369     SDL_SetMouseFocus(eventType == EMSCRIPTEN_EVENT_MOUSEENTER ? window_data->window : NULL);
   354     return 1;
   370     return 1;
   355 }
   371 }
   356 
   372 
   357 EM_BOOL
   373 EM_BOOL