use css size for touch normalisation
authorCharlie Birks <admin@daftgames.net>
Mon, 12 Sep 2016 23:58:08 -0700
changeset 1031676bcc22dc5e4
parent 10315 da4e06838c1e
child 10317 4a45690d5d82
use css size for touch normalisation
src/video/emscripten/SDL_emscriptenevents.c
     1.1 --- a/src/video/emscripten/SDL_emscriptenevents.c	Fri Sep 09 15:12:09 2016 -0700
     1.2 +++ b/src/video/emscripten/SDL_emscriptenevents.c	Mon Sep 12 23:58:08 2016 -0700
     1.3 @@ -374,12 +374,15 @@
     1.4  {
     1.5      SDL_WindowData *window_data = userData;
     1.6      int i;
     1.7 +    double client_w, client_h;
     1.8  
     1.9      SDL_TouchID deviceId = 1;
    1.10      if (SDL_AddTouch(deviceId, "") < 0) {
    1.11           return 0;
    1.12      }
    1.13  
    1.14 +    emscripten_get_element_css_size(NULL, &client_w, &client_h);
    1.15 +
    1.16      for (i = 0; i < touchEvent->numTouches; i++) {
    1.17          SDL_FingerID id;
    1.18          float x, y;
    1.19 @@ -388,8 +391,8 @@
    1.20              continue;
    1.21  
    1.22          id = touchEvent->touches[i].identifier;
    1.23 -        x = touchEvent->touches[i].canvasX / (float)window_data->windowed_width;
    1.24 -        y = touchEvent->touches[i].canvasY / (float)window_data->windowed_height;
    1.25 +        x = touchEvent->touches[i].canvasX / client_w;
    1.26 +        y = touchEvent->touches[i].canvasY / client_h;
    1.27  
    1.28          if (eventType == EMSCRIPTEN_EVENT_TOUCHSTART) {
    1.29              if (!window_data->finger_touching) {