Emscripten: Switch from canvas[XY] to target[XY]

Allows mouse/touch events to work on non-default canvases
This commit is contained in:
Charlie Birks 2019-05-09 12:09:40 +01:00
parent 60c48ed787
commit 4e5b5cba12
1 changed files with 7 additions and 7 deletions

View File

@ -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);
@ -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;
}
@ -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) {
@ -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);