Added SDL_WINDOWEVENT_HIT_TEST.
authorRyan C. Gordon <icculus@icculus.org>
Tue, 21 Apr 2015 10:10:59 -0400
changeset 10028da668b612d10
parent 10027 f7ab0613164a
child 10029 4c992fd19316
Added SDL_WINDOWEVENT_HIT_TEST.

This lets windows know when they are dropping a mouse event because their
hit test reported something other than SDL_HITTEST_NORMAL. It lets them know
exactly where in the event queue this happened.

This patch is based on work in Unreal Engine 4's fork of SDL,
compliments of Epic Games.
include/SDL_video.h
src/video/cocoa/SDL_cocoawindow.m
src/video/windows/SDL_windowsevents.c
src/video/x11/SDL_x11events.c
     1.1 --- a/include/SDL_video.h	Tue Apr 21 09:45:58 2015 -0400
     1.2 +++ b/include/SDL_video.h	Tue Apr 21 10:10:59 2015 -0400
     1.3 @@ -160,8 +160,8 @@
     1.4      SDL_WINDOWEVENT_LEAVE,          /**< Window has lost mouse focus */
     1.5      SDL_WINDOWEVENT_FOCUS_GAINED,   /**< Window has gained keyboard focus */
     1.6      SDL_WINDOWEVENT_FOCUS_LOST,     /**< Window has lost keyboard focus */
     1.7 -    SDL_WINDOWEVENT_CLOSE           /**< The window manager requests that the
     1.8 -                                         window be closed */
     1.9 +    SDL_WINDOWEVENT_CLOSE,          /**< The window manager requests that the window be closed */
    1.10 +    SDL_WINDOWEVENT_HIT_TEST        /** Window had a hit test that wasn't SDL_HITTEST_NORMAL. */
    1.11  } SDL_WindowEventID;
    1.12  
    1.13  /**
     2.1 --- a/src/video/cocoa/SDL_cocoawindow.m	Tue Apr 21 09:45:58 2015 -0400
     2.2 +++ b/src/video/cocoa/SDL_cocoawindow.m	Tue Apr 21 10:10:59 2015 -0400
     2.3 @@ -852,6 +852,7 @@
     2.4      }
     2.5  
     2.6      if ([self processHitTest:theEvent]) {
     2.7 +        SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_HIT_TEST, 0, 0);
     2.8          return;  /* dragging, drop event. */
     2.9      }
    2.10  
    2.11 @@ -894,6 +895,7 @@
    2.12      int button;
    2.13  
    2.14      if ([self processHitTest:theEvent]) {
    2.15 +        SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_HIT_TEST, 0, 0);
    2.16          return;  /* stopped dragging, drop event. */
    2.17      }
    2.18  
    2.19 @@ -937,6 +939,7 @@
    2.20      int x, y;
    2.21  
    2.22      if ([self processHitTest:theEvent]) {
    2.23 +        SDL_SendWindowEvent(window, SDL_WINDOWEVENT_HIT_TEST, 0, 0);
    2.24          return;  /* dragging, drop event. */
    2.25      }
    2.26  
     3.1 --- a/src/video/windows/SDL_windowsevents.c	Tue Apr 21 09:45:58 2015 -0400
     3.2 +++ b/src/video/windows/SDL_windowsevents.c	Tue Apr 21 10:10:59 2015 -0400
     3.3 @@ -928,15 +928,17 @@
     3.4                      const SDL_Point point = { (int) winpoint.x, (int) winpoint.y };
     3.5                      const SDL_HitTestResult rc = window->hit_test(window, &point, window->hit_test_data);
     3.6                      switch (rc) {
     3.7 -                        case SDL_HITTEST_DRAGGABLE: return HTCAPTION;
     3.8 -                        case SDL_HITTEST_RESIZE_TOPLEFT: return HTTOPLEFT;
     3.9 -                        case SDL_HITTEST_RESIZE_TOP: return HTTOP;
    3.10 -                        case SDL_HITTEST_RESIZE_TOPRIGHT: return HTTOPRIGHT;
    3.11 -                        case SDL_HITTEST_RESIZE_RIGHT: return HTRIGHT;
    3.12 -                        case SDL_HITTEST_RESIZE_BOTTOMRIGHT: return HTBOTTOMRIGHT;
    3.13 -                        case SDL_HITTEST_RESIZE_BOTTOM: return HTBOTTOM;
    3.14 -                        case SDL_HITTEST_RESIZE_BOTTOMLEFT: return HTBOTTOMLEFT;
    3.15 -                        case SDL_HITTEST_RESIZE_LEFT: return HTLEFT;
    3.16 +                        #define POST_HIT_TEST(ret) { SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_HIT_TEST, 0, 0); return ret; }
    3.17 +                        case SDL_HITTEST_DRAGGABLE: POST_HIT_TEST(HTCAPTION);
    3.18 +                        case SDL_HITTEST_RESIZE_TOPLEFT: POST_HIT_TEST(HTTOPLEFT);
    3.19 +                        case SDL_HITTEST_RESIZE_TOP: POST_HIT_TEST(HTTOP);
    3.20 +                        case SDL_HITTEST_RESIZE_TOPRIGHT: POST_HIT_TEST(HTTOPRIGHT);
    3.21 +                        case SDL_HITTEST_RESIZE_RIGHT: POST_HIT_TEST(HTRIGHT);
    3.22 +                        case SDL_HITTEST_RESIZE_BOTTOMRIGHT: POST_HIT_TEST(HTBOTTOMRIGHT);
    3.23 +                        case SDL_HITTEST_RESIZE_BOTTOM: POST_HIT_TEST(HTBOTTOM);
    3.24 +                        case SDL_HITTEST_RESIZE_BOTTOMLEFT: POST_HIT_TEST(HTBOTTOMLEFT);
    3.25 +                        case SDL_HITTEST_RESIZE_LEFT: POST_HIT_TEST(HTLEFT);
    3.26 +                        #undef POST_HIT_TEST
    3.27                          case SDL_HITTEST_NORMAL: return HTCLIENT;
    3.28                      }
    3.29                  }
     4.1 --- a/src/video/x11/SDL_x11events.c	Tue Apr 21 09:45:58 2015 -0400
     4.2 +++ b/src/video/x11/SDL_x11events.c	Tue Apr 21 10:10:59 2015 -0400
     4.3 @@ -1011,6 +1011,7 @@
     4.4                  int button = xevent.xbutton.button;
     4.5                  if(button == Button1) {
     4.6                      if (ProcessHitTest(_this, data, &xevent)) {
     4.7 +                        SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_HIT_TEST, 0, 0);
     4.8                          break;  /* don't pass this event on to app. */
     4.9                      }
    4.10                  }