Skip to content

Commit

Permalink
Emscripten: Switch from canvas[XY] to target[XY]
Browse files Browse the repository at this point in the history
Allows mouse/touch events to work on non-default canvases
  • Loading branch information
Daft-Freak committed May 9, 2019
1 parent 60c48ed commit 4e5b5cb
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/video/emscripten/SDL_emscriptenevents.c
Expand Up @@ -330,8 +330,8 @@ Emscripten_HandleMouseMove(int eventType, const EmscriptenMouseEvent *mouseEvent
my = residualy;
residualy -= my;
} else {
mx = mouseEvent->canvasX * xscale;
my = mouseEvent->canvasY * yscale;
mx = mouseEvent->targetX * xscale;
my = mouseEvent->targetY * yscale;
}

SDL_SendMouseMotion(window_data->window, 0, isPointerLocked, mx, my);
Expand Down Expand Up @@ -375,8 +375,8 @@ Emscripten_HandleMouseButton(int eventType, const EmscriptenMouseEvent *mouseEve

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

Expand All @@ -388,7 +388,7 @@ Emscripten_HandleMouseFocus(int eventType, const EmscriptenMouseEvent *mouseEven
{
SDL_WindowData *window_data = userData;

int mx = mouseEvent->canvasX, my = mouseEvent->canvasY;
int mx = mouseEvent->targetX, my = mouseEvent->targetY;
const int isPointerLocked = window_data->has_pointer_lock;

if (!isPointerLocked) {
Expand Down Expand Up @@ -450,8 +450,8 @@ Emscripten_HandleTouch(int eventType, const EmscriptenTouchEvent *touchEvent, vo
continue;

id = touchEvent->touches[i].identifier;
x = touchEvent->touches[i].canvasX / client_w;
y = touchEvent->touches[i].canvasY / client_h;
x = touchEvent->touches[i].targetX / client_w;
y = touchEvent->touches[i].targetY / client_h;

if (eventType == EMSCRIPTEN_EVENT_TOUCHSTART) {
SDL_SendTouch(deviceId, id, SDL_TRUE, x, y, 1.0f);
Expand Down

0 comments on commit 4e5b5cb

Please sign in to comment.