Skip to content

Commit

Permalink
send mouse move on enter/leave
Browse files Browse the repository at this point in the history
  • Loading branch information
Daft-Freak committed Sep 13, 2016
1 parent a2ef0db commit 98ec844
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/video/emscripten/SDL_emscriptenevents.c
Expand Up @@ -350,6 +350,22 @@ Emscripten_HandleMouseFocus(int eventType, const EmscriptenMouseEvent *mouseEven
{
SDL_WindowData *window_data = userData;

int mx = mouseEvent->canvasX, my = mouseEvent->canvasY;
EmscriptenPointerlockChangeEvent pointerlock_status;

/* check for pointer lock */
emscripten_get_pointerlock_status(&pointerlock_status);

if (!pointerlock_status.isActive) {
/* rescale (in case canvas is being scaled)*/
double client_w, client_h;
emscripten_get_element_css_size(NULL, &client_w, &client_h);

mx = mx * (window_data->window->w / (client_w * window_data->pixel_ratio));
my = my * (window_data->window->h / (client_h * window_data->pixel_ratio));
SDL_SendMouseMotion(window_data->window, 0, pointerlock_status.isActive, mx, my);
}

SDL_SetMouseFocus(eventType == EMSCRIPTEN_EVENT_MOUSEENTER ? window_data->window : NULL);
return 1;
}
Expand Down

0 comments on commit 98ec844

Please sign in to comment.