Skip to content
Permalink
Browse files

Emscripten: fixed incorrect conversion of touch motion events to mous…

…e motion events
  • Loading branch information
manpat committed May 24, 2017
1 parent 3fd35f6 commit f839b209b93adc1e1aa23329f621dd98ea2f60b5
Showing with 6 additions and 2 deletions.
  1. +6 −2 src/video/emscripten/SDL_emscriptenevents.c
@@ -437,6 +437,7 @@ Emscripten_HandleTouch(int eventType, const EmscriptenTouchEvent *touchEvent, vo
for (i = 0; i < touchEvent->numTouches; i++) {
SDL_FingerID id;
float x, y;
int mx, my;

if (!touchEvent->touches[i].isChanged)
continue;
@@ -445,11 +446,14 @@ Emscripten_HandleTouch(int eventType, const EmscriptenTouchEvent *touchEvent, vo
x = touchEvent->touches[i].canvasX / client_w;
y = touchEvent->touches[i].canvasY / client_h;

mx = x * window_data->window->w;
my = y * window_data->window->h;

if (eventType == EMSCRIPTEN_EVENT_TOUCHSTART) {
if (!window_data->finger_touching) {
window_data->finger_touching = SDL_TRUE;
window_data->first_finger = id;
SDL_SendMouseMotion(window_data->window, SDL_TOUCH_MOUSEID, 0, x, y);
SDL_SendMouseMotion(window_data->window, SDL_TOUCH_MOUSEID, 0, mx, my);
SDL_SendMouseButton(window_data->window, SDL_TOUCH_MOUSEID, SDL_PRESSED, SDL_BUTTON_LEFT);
}
SDL_SendTouch(deviceId, id, SDL_TRUE, x, y, 1.0f);
@@ -459,7 +463,7 @@ Emscripten_HandleTouch(int eventType, const EmscriptenTouchEvent *touchEvent, vo
}
} else if (eventType == EMSCRIPTEN_EVENT_TOUCHMOVE) {
if ((window_data->finger_touching) && (window_data->first_finger == id)) {
SDL_SendMouseMotion(window_data->window, SDL_TOUCH_MOUSEID, 0, x, y);
SDL_SendMouseMotion(window_data->window, SDL_TOUCH_MOUSEID, 0, mx, my);
}
SDL_SendTouchMotion(deviceId, id, x, y, 1.0f);

0 comments on commit f839b20

Please sign in to comment.