diff options
author | Sylvain Becker <sylvain.becker@gmail.com> | 2019-04-02 16:46:17 +0200 |
---|---|---|
committer | Sylvain Becker <sylvain.becker@gmail.com> | 2019-04-02 16:46:17 +0200 |
commit | be638299ed0491761e5c92987aa11931902e6e7d (patch) | |
tree | 48b387c44c4cc8e52af6279d0df69fe9d7cb3d0b | |
parent | 5438110caff6ece779359ef38fdf0558b9e26df8 (diff) |
Bug 4576: handle mapping of TouchEvents to MouseEvents at higher level
-rw-r--r-- | src/events/SDL_touch.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/events/SDL_touch.c b/src/events/SDL_touch.c index 26565f5675..839ea2e394 100644 --- a/src/events/SDL_touch.c +++ b/src/events/SDL_touch.c @@ -31,6 +31,12 @@ static int SDL_num_touch = 0; static SDL_Touch **SDL_touchDevices = NULL; +/* for mapping touch events to mice */ +#define DUPLICATE_TO_MOUSE_EVENT +#if defined(DUPLICATE_TO_MOUSE_EVENT) +static SDL_bool finger_touching = SDL_FALSE; +static SDL_FingerID first_finger; +#endif /* Public functions */ int @@ -241,6 +247,29 @@ SDL_SendTouch(SDL_TouchID id, SDL_FingerID fingerid, return -1; } +#if defined(DUPLICATE_TO_MOUSE_EVENT) + { + SDL_Window *window = SDL_GetMouseFocus(); + if (window) { + if (down) { + if (finger_touching == SDL_FALSE) { + int pos_x = x * window->w; + int pos_y = y * window->y; + finger_touching = SDL_TRUE; + first_finger = fingerid; + SDL_SendMouseMotion(window, SDL_TOUCH_MOUSEID, 0, pos_x, pos_y); + SDL_SendMouseButton(window, SDL_TOUCH_MOUSEID, SDL_PRESSED, SDL_BUTTON_LEFT); + } + } else { + if (finger_touching == SDL_TRUE && first_finger == fingerid) { + SDL_SendMouseButton(window, SDL_TOUCH_MOUSEID, SDL_RELEASED, SDL_BUTTON_LEFT); + finger_touching = SDL_FALSE; + } + } + } + } +#endif + finger = SDL_GetFinger(touch, fingerid); if (down) { if (finger) { @@ -305,6 +334,19 @@ SDL_SendTouchMotion(SDL_TouchID id, SDL_FingerID fingerid, return -1; } +#if defined(DUPLICATE_TO_MOUSE_EVENT) + { + SDL_Window *window = SDL_GetMouseFocus(); + if (window) { + if (finger_touching == SDL_TRUE && first_finger == fingerid) { + int pos_x = x * window->w; + int pos_y = y * window->y; + SDL_SendMouseMotion(window, SDL_TOUCH_MOUSEID, 0, pos_x, pos_y); + } + } + } +#endif + finger = SDL_GetFinger(touch,fingerid); if (!finger) { return SDL_SendTouch(id, fingerid, SDL_TRUE, x, y, pressure); |