mirror of https://github.com/encounter/SDL.git
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.)
This commit is contained in:
parent
3b88f5c690
commit
d05ae1941c
|
@ -391,11 +391,24 @@ Emscripten_HandleTouch(int eventType, const EmscriptenTouchEvent *touchEvent, vo
|
||||||
x = touchEvent->touches[i].canvasX / (float)window_data->windowed_width;
|
x = touchEvent->touches[i].canvasX / (float)window_data->windowed_width;
|
||||||
y = touchEvent->touches[i].canvasY / (float)window_data->windowed_height;
|
y = touchEvent->touches[i].canvasY / (float)window_data->windowed_height;
|
||||||
|
|
||||||
if (eventType == EMSCRIPTEN_EVENT_TOUCHMOVE) {
|
if (eventType == EMSCRIPTEN_EVENT_TOUCHSTART) {
|
||||||
SDL_SendTouchMotion(deviceId, id, x, y, 1.0f);
|
if (!window_data->finger_touching) {
|
||||||
} else if (eventType == EMSCRIPTEN_EVENT_TOUCHSTART) {
|
window_data->finger_touching = SDL_TRUE;
|
||||||
|
window_data->first_finger = id;
|
||||||
|
SDL_SendMouseMotion(window_data->window, SDL_TOUCH_MOUSEID, 0, x, y);
|
||||||
|
SDL_SendMouseButton(window_data->window, SDL_TOUCH_MOUSEID, SDL_PRESSED, SDL_BUTTON_LEFT);
|
||||||
|
}
|
||||||
SDL_SendTouch(deviceId, id, SDL_TRUE, x, y, 1.0f);
|
SDL_SendTouch(deviceId, id, SDL_TRUE, x, y, 1.0f);
|
||||||
|
} else if (eventType == EMSCRIPTEN_EVENT_TOUCHMOVE) {
|
||||||
|
if ((window_data->finger_touching) && (window_data->first_finger == id)) {
|
||||||
|
SDL_SendMouseMotion(window_data->window, SDL_TOUCH_MOUSEID, 0, x, y);
|
||||||
|
}
|
||||||
|
SDL_SendTouchMotion(deviceId, id, x, y, 1.0f);
|
||||||
} else {
|
} else {
|
||||||
|
if ((window_data->finger_touching) && (window_data->first_finger == id)) {
|
||||||
|
SDL_SendMouseButton(window_data->window, SDL_TOUCH_MOUSEID, SDL_RELEASED, SDL_BUTTON_LEFT);
|
||||||
|
window_data->finger_touching = SDL_FALSE;
|
||||||
|
}
|
||||||
SDL_SendTouch(deviceId, id, SDL_FALSE, x, y, 1.0f);
|
SDL_SendTouch(deviceId, id, SDL_FALSE, x, y, 1.0f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
#define _SDL_emscriptenvideo_h
|
#define _SDL_emscriptenvideo_h
|
||||||
|
|
||||||
#include "../SDL_sysvideo.h"
|
#include "../SDL_sysvideo.h"
|
||||||
|
#include "../../events/SDL_touch_c.h"
|
||||||
#include <emscripten/emscripten.h>
|
#include <emscripten/emscripten.h>
|
||||||
#include <emscripten/html5.h>
|
#include <emscripten/html5.h>
|
||||||
|
|
||||||
|
@ -45,6 +46,9 @@ typedef struct SDL_WindowData
|
||||||
SDL_bool external_size;
|
SDL_bool external_size;
|
||||||
|
|
||||||
int requested_fullscreen_mode;
|
int requested_fullscreen_mode;
|
||||||
|
|
||||||
|
SDL_bool finger_touching; /* for mapping touch events to mice */
|
||||||
|
SDL_FingerID first_finger;
|
||||||
} SDL_WindowData;
|
} SDL_WindowData;
|
||||||
|
|
||||||
#endif /* _SDL_emscriptenvideo_h */
|
#endif /* _SDL_emscriptenvideo_h */
|
||||||
|
|
Loading…
Reference in New Issue