emscripten: send fake mouse events for touches, like other targets do.
authorRyan C. Gordon <icculus@icculus.org>
Fri, 12 Aug 2016 19:59:00 -0400
changeset 10284c09f06c4e8c8
parent 10283 1b8594db77f1
child 10285 b1f031450499
emscripten: send fake mouse events for touches, like other targets do.

(This really should be handled at the higher level and not in the individual
targets, but this fixes the immediate bug.)
src/video/emscripten/SDL_emscriptenevents.c
src/video/emscripten/SDL_emscriptenvideo.h
     1.1 --- a/src/video/emscripten/SDL_emscriptenevents.c	Fri Aug 12 00:03:58 2016 -0400
     1.2 +++ b/src/video/emscripten/SDL_emscriptenevents.c	Fri Aug 12 19:59:00 2016 -0400
     1.3 @@ -391,11 +391,24 @@
     1.4          x = touchEvent->touches[i].canvasX / (float)window_data->windowed_width;
     1.5          y = touchEvent->touches[i].canvasY / (float)window_data->windowed_height;
     1.6  
     1.7 -        if (eventType == EMSCRIPTEN_EVENT_TOUCHMOVE) {
     1.8 +        if (eventType == EMSCRIPTEN_EVENT_TOUCHSTART) {
     1.9 +            if (!window_data->finger_touching) {
    1.10 +                window_data->finger_touching = SDL_TRUE;
    1.11 +                window_data->first_finger = id;
    1.12 +                SDL_SendMouseMotion(window_data->window, SDL_TOUCH_MOUSEID, 0, x, y);
    1.13 +                SDL_SendMouseButton(window_data->window, SDL_TOUCH_MOUSEID, SDL_PRESSED, SDL_BUTTON_LEFT);
    1.14 +            }
    1.15 +            SDL_SendTouch(deviceId, id, SDL_TRUE, x, y, 1.0f);
    1.16 +        } else if (eventType == EMSCRIPTEN_EVENT_TOUCHMOVE) {
    1.17 +            if ((window_data->finger_touching) && (window_data->first_finger == id)) {
    1.18 +                SDL_SendMouseMotion(window_data->window, SDL_TOUCH_MOUSEID, 0, x, y);
    1.19 +            }
    1.20              SDL_SendTouchMotion(deviceId, id, x, y, 1.0f);
    1.21 -        } else if (eventType == EMSCRIPTEN_EVENT_TOUCHSTART) {
    1.22 -            SDL_SendTouch(deviceId, id, SDL_TRUE, x, y, 1.0f);
    1.23          } else {
    1.24 +            if ((window_data->finger_touching) && (window_data->first_finger == id)) {
    1.25 +                SDL_SendMouseButton(window_data->window, SDL_TOUCH_MOUSEID, SDL_RELEASED, SDL_BUTTON_LEFT);
    1.26 +                window_data->finger_touching = SDL_FALSE;
    1.27 +            }
    1.28              SDL_SendTouch(deviceId, id, SDL_FALSE, x, y, 1.0f);
    1.29          }
    1.30      }
     2.1 --- a/src/video/emscripten/SDL_emscriptenvideo.h	Fri Aug 12 00:03:58 2016 -0400
     2.2 +++ b/src/video/emscripten/SDL_emscriptenvideo.h	Fri Aug 12 19:59:00 2016 -0400
     2.3 @@ -24,6 +24,7 @@
     2.4  #define _SDL_emscriptenvideo_h
     2.5  
     2.6  #include "../SDL_sysvideo.h"
     2.7 +#include "../../events/SDL_touch_c.h"
     2.8  #include <emscripten/emscripten.h>
     2.9  #include <emscripten/html5.h>
    2.10  
    2.11 @@ -45,6 +46,9 @@
    2.12      SDL_bool external_size;
    2.13  
    2.14      int requested_fullscreen_mode;
    2.15 +
    2.16 +    SDL_bool finger_touching;  /* for mapping touch events to mice */
    2.17 +    SDL_FingerID first_finger;
    2.18  } SDL_WindowData;
    2.19  
    2.20  #endif /* _SDL_emscriptenvideo_h */