Fixed bug 4581 - generate synthetic mouse events at window boundaries
authorSylvain Becker <sylvain.becker@gmail.com>
Wed, 10 Apr 2019 10:59:53 +0200
changeset 127013477a301a5a8
parent 12700 1223f50edde3
child 12702 0ff5bbe35bf5
Fixed bug 4581 - generate synthetic mouse events at window boundaries
when real touch events are actually outside the window.
src/events/SDL_touch.c
     1.1 --- a/src/events/SDL_touch.c	Mon Apr 08 21:27:24 2019 +0200
     1.2 +++ b/src/events/SDL_touch.c	Wed Apr 10 10:59:53 2019 +0200
     1.3 @@ -257,18 +257,16 @@
     1.4                          if (finger_touching == SDL_FALSE) {
     1.5                              int pos_x = (int)(x * (float)window->w);
     1.6                              int pos_y = (int)(y * (float)window->h);
     1.7 -                            if (pos_x >= 0 && pos_y >= 0 && pos_x < window->w && pos_y < window->h) {
     1.8 -                                SDL_SendMouseMotion(window, SDL_TOUCH_MOUSEID, 0, pos_x, pos_y);
     1.9 -                                SDL_SendMouseButton(window, SDL_TOUCH_MOUSEID, SDL_PRESSED, SDL_BUTTON_LEFT);
    1.10 -                            }
    1.11 +                            if (pos_x < 0) pos_x = 0;
    1.12 +                            if (pos_x > window->w - 1) pos_x = window->w - 1;
    1.13 +                            if (pos_y < 0) pos_y = 0;
    1.14 +                            if (pos_y > window->h - 1) pos_y = window->h - 1;
    1.15 +                            SDL_SendMouseMotion(window, SDL_TOUCH_MOUSEID, 0, pos_x, pos_y);
    1.16 +                            SDL_SendMouseButton(window, SDL_TOUCH_MOUSEID, SDL_PRESSED, SDL_BUTTON_LEFT);
    1.17                          }
    1.18                      } else {
    1.19                          if (finger_touching == SDL_TRUE && track_touchid == id && track_fingerid == fingerid) {
    1.20 -                            int pos_x = (int)(x * (float)window->w);
    1.21 -                            int pos_y = (int)(y * (float)window->h);
    1.22 -                            if (pos_x >= 0 && pos_y >= 0 && pos_x < window->w && pos_y < window->h) {
    1.23 -                                SDL_SendMouseButton(window, SDL_TOUCH_MOUSEID, SDL_RELEASED, SDL_BUTTON_LEFT);
    1.24 -                            }
    1.25 +                            SDL_SendMouseButton(window, SDL_TOUCH_MOUSEID, SDL_RELEASED, SDL_BUTTON_LEFT);
    1.26                          }
    1.27                      }
    1.28                  }
    1.29 @@ -361,9 +359,11 @@
    1.30                      if (finger_touching == SDL_TRUE && track_touchid == id && track_fingerid == fingerid) {
    1.31                          int pos_x = (int)(x * (float)window->w);
    1.32                          int pos_y = (int)(y * (float)window->h);
    1.33 -                        if (pos_x >= 0 && pos_y >= 0 && pos_x < window->w && pos_y < window->h) {
    1.34 -                            SDL_SendMouseMotion(window, SDL_TOUCH_MOUSEID, 0, pos_x, pos_y);
    1.35 -                        }
    1.36 +                        if (pos_x < 0) pos_x = 0;
    1.37 +                        if (pos_x > window->w - 1) pos_x = window->w - 1;
    1.38 +                        if (pos_y < 0) pos_y = 0;
    1.39 +                        if (pos_y > window->h - 1) pos_y = window->h - 1;
    1.40 +                        SDL_SendMouseMotion(window, SDL_TOUCH_MOUSEID, 0, pos_x, pos_y);
    1.41                      }
    1.42                  }
    1.43              }