src/events/SDL_mouse.c
changeset 8953 dc80dc0bd22e
parent 8815 c6d0a457f3b2
parent 8952 4bb098814ec4
child 8955 7a74b402790c
     1.1 --- a/src/events/SDL_mouse.c	Wed Jun 25 02:08:37 2014 -0700
     1.2 +++ b/src/events/SDL_mouse.c	Wed Jun 25 17:06:12 2014 -0400
     1.3 @@ -140,14 +140,14 @@
     1.4  SDL_UpdateMouseFocus(SDL_Window * window, int x, int y, Uint32 buttonstate)
     1.5  {
     1.6      SDL_Mouse *mouse = SDL_GetMouse();
     1.7 -    int w, h;
     1.8 -    SDL_bool inWindow;
     1.9 +    SDL_bool inWindow = SDL_TRUE;
    1.10  
    1.11 -    SDL_GetWindowSize(window, &w, &h);
    1.12 -    if (x < 0 || y < 0 || x >= w || y >= h) {
    1.13 -        inWindow = SDL_FALSE;
    1.14 -    } else {
    1.15 -        inWindow = SDL_TRUE;
    1.16 +    if ((window->flags & SDL_WINDOW_MOUSE_CAPTURE) == 0) {
    1.17 +        int w, h;
    1.18 +        SDL_GetWindowSize(window, &w, &h);
    1.19 +        if (x < 0 || y < 0 || x >= w || y >= h) {
    1.20 +            inWindow = SDL_FALSE;
    1.21 +        }
    1.22      }
    1.23  
    1.24  /* Linux doesn't give you mouse events outside your window unless you grab
    1.25 @@ -246,24 +246,29 @@
    1.26          mouse->y += yrel;
    1.27      }
    1.28  
    1.29 -    /* !!! FIXME: shouldn't this be (window) instead of (mouse->focus)? */
    1.30 -    SDL_GetWindowSize(mouse->focus, &x_max, &y_max);
    1.31 -    --x_max;
    1.32 -    --y_max;
    1.33 +    /* make sure that the pointers find themselves inside the windows,
    1.34 +       unless we have the mouse captured. */
    1.35 +    if ((window->flags & SDL_WINDOW_MOUSE_CAPTURE) == 0) {
    1.36 +        int x_max = 0, y_max = 0;
    1.37  
    1.38 -    /* make sure that the pointers find themselves inside the windows */
    1.39 -    if (mouse->x > x_max) {
    1.40 -        mouse->x = x_max;
    1.41 -    }
    1.42 -    if (mouse->x < 0) {
    1.43 -        mouse->x = 0;
    1.44 -    }
    1.45 +        // !!! FIXME: shouldn't this be (window) instead of (mouse->focus)?
    1.46 +        SDL_GetWindowSize(mouse->focus, &x_max, &y_max);
    1.47 +        --x_max;
    1.48 +        --y_max;
    1.49  
    1.50 -    if (mouse->y > y_max) {
    1.51 -        mouse->y = y_max;
    1.52 -    }
    1.53 -    if (mouse->y < 0) {
    1.54 -        mouse->y = 0;
    1.55 +        if (mouse->x > x_max) {
    1.56 +            mouse->x = x_max;
    1.57 +        }
    1.58 +        if (mouse->x < 0) {
    1.59 +            mouse->x = 0;
    1.60 +        }
    1.61 +
    1.62 +        if (mouse->y > y_max) {
    1.63 +            mouse->y = y_max;
    1.64 +        }
    1.65 +        if (mouse->y < 0) {
    1.66 +            mouse->y = 0;
    1.67 +        }
    1.68      }
    1.69  
    1.70      mouse->xdelta += xrel;
    1.71 @@ -426,6 +431,7 @@
    1.72      SDL_Cursor *cursor, *next;
    1.73      SDL_Mouse *mouse = SDL_GetMouse();
    1.74  
    1.75 +    SDL_CaptureMouse(SDL_FALSE);
    1.76      SDL_SetRelativeMouseMode(SDL_FALSE);
    1.77      SDL_ShowCursor(1);
    1.78  
    1.79 @@ -477,16 +483,42 @@
    1.80      return mouse->buttonstate;
    1.81  }
    1.82  
    1.83 +Uint32
    1.84 +SDL_GetGlobalMouseState(int *x, int *y)
    1.85 +{
    1.86 +    SDL_Mouse *mouse = SDL_GetMouse();
    1.87 +    int tmpx, tmpy;
    1.88 +
    1.89 +    /* make sure these are never NULL for the backend implementations... */
    1.90 +    if (!x) {
    1.91 +        x = &tmpx;
    1.92 +    }
    1.93 +    if (!y) {
    1.94 +        y = &tmpy;
    1.95 +    }
    1.96 +
    1.97 +    *x = *y = 0;
    1.98 +
    1.99 +    if (!mouse->GetGlobalMouseState) {
   1.100 +        SDL_assert(0 && "This should really be implemented for every target.");
   1.101 +        return 0;
   1.102 +    }
   1.103 +
   1.104 +    return mouse->GetGlobalMouseState(x, y);
   1.105 +}
   1.106 +
   1.107  void
   1.108  SDL_WarpMouseInWindow(SDL_Window * window, int x, int y)
   1.109  {
   1.110      SDL_Mouse *mouse = SDL_GetMouse();
   1.111  
   1.112 -    if (window == NULL)
   1.113 +    if (window == NULL) {
   1.114          window = mouse->focus;
   1.115 +    }
   1.116  
   1.117 -    if (window == NULL)
   1.118 +    if (window == NULL) {
   1.119          return;
   1.120 +    }
   1.121  
   1.122      if (mouse->WarpMouse) {
   1.123          mouse->WarpMouse(window, x, y);