src/video/emscripten/SDL_emscriptenevents.c
changeset 12572 397aa57185c4
parent 12570 bb39a14d510c
child 12573 296d155a8ce5
equal deleted inserted replaced
12571:aa455cfe9ff3 12572:397aa57185c4
   456                 SDL_SendMouseMotion(window_data->window, SDL_TOUCH_MOUSEID, 0, mx, my);
   456                 SDL_SendMouseMotion(window_data->window, SDL_TOUCH_MOUSEID, 0, mx, my);
   457                 SDL_SendMouseButton(window_data->window, SDL_TOUCH_MOUSEID, SDL_PRESSED, SDL_BUTTON_LEFT);
   457                 SDL_SendMouseButton(window_data->window, SDL_TOUCH_MOUSEID, SDL_PRESSED, SDL_BUTTON_LEFT);
   458             }
   458             }
   459             SDL_SendTouch(deviceId, id, SDL_TRUE, x, y, 1.0f);
   459             SDL_SendTouch(deviceId, id, SDL_TRUE, x, y, 1.0f);
   460 
   460 
       
   461             /* disable browser scrolling/pinch-to-zoom if app handles touch events */
   461             if (!preventDefault && SDL_GetEventState(SDL_FINGERDOWN) == SDL_ENABLE) {
   462             if (!preventDefault && SDL_GetEventState(SDL_FINGERDOWN) == SDL_ENABLE) {
   462                 preventDefault = 1;
   463                 preventDefault = 1;
   463             }
   464             }
   464         } else if (eventType == EMSCRIPTEN_EVENT_TOUCHMOVE) {
   465         } else if (eventType == EMSCRIPTEN_EVENT_TOUCHMOVE) {
   465             if ((window_data->finger_touching) && (window_data->first_finger == id)) {
   466             if ((window_data->finger_touching) && (window_data->first_finger == id)) {
   466                 SDL_SendMouseMotion(window_data->window, SDL_TOUCH_MOUSEID, 0, mx, my);
   467                 SDL_SendMouseMotion(window_data->window, SDL_TOUCH_MOUSEID, 0, mx, my);
   467             }
   468             }
   468             SDL_SendTouchMotion(deviceId, id, x, y, 1.0f);
   469             SDL_SendTouchMotion(deviceId, id, x, y, 1.0f);
   469 
       
   470             if (!preventDefault && SDL_GetEventState(SDL_FINGERMOTION) == SDL_ENABLE) {
       
   471                 preventDefault = 1;
       
   472             }
       
   473         } else {
   470         } else {
   474             if ((window_data->finger_touching) && (window_data->first_finger == id)) {
   471             if ((window_data->finger_touching) && (window_data->first_finger == id)) {
   475                 SDL_SendMouseButton(window_data->window, SDL_TOUCH_MOUSEID, SDL_RELEASED, SDL_BUTTON_LEFT);
   472                 SDL_SendMouseButton(window_data->window, SDL_TOUCH_MOUSEID, SDL_RELEASED, SDL_BUTTON_LEFT);
   476                 window_data->finger_touching = SDL_FALSE;
   473                 window_data->finger_touching = SDL_FALSE;
   477             }
   474             }
   478             SDL_SendTouch(deviceId, id, SDL_FALSE, x, y, 1.0f);
   475             SDL_SendTouch(deviceId, id, SDL_FALSE, x, y, 1.0f);
   479 
   476 
   480             if (!preventDefault && SDL_GetEventState(SDL_FINGERUP) == SDL_ENABLE) {
   477             /* block browser's simulated mousedown/mouseup on touchscreen devices */
   481                 preventDefault = 1;
   478             preventDefault = 1;
   482             }
       
   483         }
   479         }
   484     }
   480     }
   485 
   481 
   486     return preventDefault;
   482     return preventDefault;
   487 }
   483 }