diff options
author | Sylvain Becker <sylvain.becker@gmail.com> | 2019-04-10 10:59:53 +0200 |
---|---|---|
committer | Sylvain Becker <sylvain.becker@gmail.com> | 2019-04-10 10:59:53 +0200 |
commit | 906a13383118100423c1291975987e2798762205 (patch) | |
tree | 1cfecc2910b849c2c747ca5e9f4b34ea799304b2 | |
parent | 5d941182b35cf1e1575609a13c4258f8700d6574 (diff) |
Fixed bug 4581 - generate synthetic mouse events at window boundaries
when real touch events are actually outside the window.
-rw-r--r-- | src/events/SDL_touch.c | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/src/events/SDL_touch.c b/src/events/SDL_touch.c index a5278d4e7c..caf5e5644b 100644 --- a/src/events/SDL_touch.c +++ b/src/events/SDL_touch.c @@ -257,18 +257,16 @@ SDL_SendTouch(SDL_TouchID id, SDL_FingerID fingerid, if (finger_touching == SDL_FALSE) { int pos_x = (int)(x * (float)window->w); int pos_y = (int)(y * (float)window->h); - if (pos_x >= 0 && pos_y >= 0 && pos_x < window->w && pos_y < window->h) { - SDL_SendMouseMotion(window, SDL_TOUCH_MOUSEID, 0, pos_x, pos_y); - SDL_SendMouseButton(window, SDL_TOUCH_MOUSEID, SDL_PRESSED, SDL_BUTTON_LEFT); - } + if (pos_x < 0) pos_x = 0; + if (pos_x > window->w - 1) pos_x = window->w - 1; + if (pos_y < 0) pos_y = 0; + if (pos_y > window->h - 1) pos_y = window->h - 1; + 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 && track_touchid == id && track_fingerid == fingerid) { - int pos_x = (int)(x * (float)window->w); - int pos_y = (int)(y * (float)window->h); - if (pos_x >= 0 && pos_y >= 0 && pos_x < window->w && pos_y < window->h) { - SDL_SendMouseButton(window, SDL_TOUCH_MOUSEID, SDL_RELEASED, SDL_BUTTON_LEFT); - } + SDL_SendMouseButton(window, SDL_TOUCH_MOUSEID, SDL_RELEASED, SDL_BUTTON_LEFT); } } } @@ -361,9 +359,11 @@ SDL_SendTouchMotion(SDL_TouchID id, SDL_FingerID fingerid, if (finger_touching == SDL_TRUE && track_touchid == id && track_fingerid == fingerid) { int pos_x = (int)(x * (float)window->w); int pos_y = (int)(y * (float)window->h); - if (pos_x >= 0 && pos_y >= 0 && pos_x < window->w && pos_y < window->h) { - SDL_SendMouseMotion(window, SDL_TOUCH_MOUSEID, 0, pos_x, pos_y); - } + if (pos_x < 0) pos_x = 0; + if (pos_x > window->w - 1) pos_x = window->w - 1; + if (pos_y < 0) pos_y = 0; + if (pos_y > window->h - 1) pos_y = window->h - 1; + SDL_SendMouseMotion(window, SDL_TOUCH_MOUSEID, 0, pos_x, pos_y); } } } |