Emscripten: Fixed touch coordinates not being normalized.
authorPhilipp Wiesemann <philipp.wiesemann@arcor.de>
Wed, 06 May 2015 21:10:48 +0200
changeset 9591 ebc2a308211b
parent 9590 597d75e56b12
child 9592 ba866f4ec675
Emscripten: Fixed touch coordinates not being normalized.
src/video/emscripten/SDL_emscriptenevents.c
--- a/src/video/emscripten/SDL_emscriptenevents.c	Wed May 06 21:09:33 2015 +0200
+++ b/src/video/emscripten/SDL_emscriptenevents.c	Wed May 06 21:10:48 2015 +0200
@@ -371,7 +371,7 @@
 EM_BOOL
 Emscripten_HandleTouch(int eventType, const EmscriptenTouchEvent *touchEvent, void *userData)
 {
-    /*SDL_WindowData *window_data = userData;*/
+    SDL_WindowData *window_data = userData;
     int i;
 
     SDL_TouchID deviceId = 0;
@@ -382,14 +382,15 @@
     }
 
     for (i = 0; i < touchEvent->numTouches; i++) {
-        long x, y, id;
+        SDL_FingerID id;
+        float x, y;
 
         if (!touchEvent->touches[i].isChanged)
             continue;
 
         id = touchEvent->touches[i].identifier;
-        x = touchEvent->touches[i].canvasX;
-        y = touchEvent->touches[i].canvasY;
+        x = touchEvent->touches[i].canvasX / (float)window_data->windowed_width;
+        y = touchEvent->touches[i].canvasY / (float)window_data->windowed_height;
 
         if (eventType == EMSCRIPTEN_EVENT_TOUCHMOVE) {
             SDL_SendTouchMotion(deviceId, id, x, y, 1.0f);