Emscripten: Fixed touch coordinates not being normalized.
authorPhilipp Wiesemann <philipp.wiesemann@arcor.de>
Wed, 06 May 2015 21:10:48 +0200
changeset 9591ebc2a308211b
parent 9590 597d75e56b12
child 9592 ba866f4ec675
Emscripten: Fixed touch coordinates not being normalized.
src/video/emscripten/SDL_emscriptenevents.c
     1.1 --- a/src/video/emscripten/SDL_emscriptenevents.c	Wed May 06 21:09:33 2015 +0200
     1.2 +++ b/src/video/emscripten/SDL_emscriptenevents.c	Wed May 06 21:10:48 2015 +0200
     1.3 @@ -371,7 +371,7 @@
     1.4  EM_BOOL
     1.5  Emscripten_HandleTouch(int eventType, const EmscriptenTouchEvent *touchEvent, void *userData)
     1.6  {
     1.7 -    /*SDL_WindowData *window_data = userData;*/
     1.8 +    SDL_WindowData *window_data = userData;
     1.9      int i;
    1.10  
    1.11      SDL_TouchID deviceId = 0;
    1.12 @@ -382,14 +382,15 @@
    1.13      }
    1.14  
    1.15      for (i = 0; i < touchEvent->numTouches; i++) {
    1.16 -        long x, y, id;
    1.17 +        SDL_FingerID id;
    1.18 +        float x, y;
    1.19  
    1.20          if (!touchEvent->touches[i].isChanged)
    1.21              continue;
    1.22  
    1.23          id = touchEvent->touches[i].identifier;
    1.24 -        x = touchEvent->touches[i].canvasX;
    1.25 -        y = touchEvent->touches[i].canvasY;
    1.26 +        x = touchEvent->touches[i].canvasX / (float)window_data->windowed_width;
    1.27 +        y = touchEvent->touches[i].canvasY / (float)window_data->windowed_height;
    1.28  
    1.29          if (eventType == EMSCRIPTEN_EVENT_TOUCHMOVE) {
    1.30              SDL_SendTouchMotion(deviceId, id, x, y, 1.0f);