Fixed mouse coordinate range on Mac OS X
authorSam Lantinga <slouken@libsdl.org>
Thu, 27 Nov 2008 21:53:18 +0000
changeset 2794f7872b7a8732
parent 2793 b14f672b2857
child 2795 9e7ce3069096
Fixed mouse coordinate range on Mac OS X
src/events/SDL_mouse.c
src/events/SDL_mouse_c.h
src/events/SDL_windowevents.c
src/video/win32/SDL_win32events.c
src/video/x11/SDL_x11events.c
     1.1 --- a/src/events/SDL_mouse.c	Thu Nov 27 05:29:12 2008 +0000
     1.2 +++ b/src/events/SDL_mouse.c	Thu Nov 27 21:53:18 2008 +0000
     1.3 @@ -34,7 +34,6 @@
     1.4  static int *SDL_IdIndex = NULL;
     1.5  static int SDL_highestId = -1;
     1.6  static int last_x, last_y;      /* the last reported x and y coordinates by the system cursor */
     1.7 -int x_max, y_max;               /* current window width and height */
     1.8  
     1.9  
    1.10  /* Public functions */
    1.11 @@ -365,6 +364,21 @@
    1.12          if (!focus) {
    1.13              SDL_SendWindowEvent(mouse->focus, SDL_WINDOWEVENT_ENTER, 0, 0);
    1.14          }
    1.15 +        SDL_GetWindowSize(windowID, &mouse->x_max, &mouse->y_max);
    1.16 +    }
    1.17 +}
    1.18 +
    1.19 +void
    1.20 +SDL_SetMouseFocusSize(SDL_WindowID windowID, int w, int h)
    1.21 +{
    1.22 +    int i;
    1.23 +
    1.24 +    for (i = 0; i < SDL_num_mice; ++i) {
    1.25 +        SDL_Mouse *mouse = SDL_GetMouse(i);
    1.26 +        if (mouse && mouse->focus == windowID) {
    1.27 +            mouse->x_max = w;
    1.28 +            mouse->y_max = h;
    1.29 +        }
    1.30      }
    1.31  }
    1.32  
    1.33 @@ -407,15 +421,6 @@
    1.34      int xrel;
    1.35      int yrel;
    1.36  
    1.37 -    /* while using the relative mode and many windows, we have to be sure,
    1.38 -       that the pointers find themselves inside the windows */
    1.39 -    if (x > x_max) {
    1.40 -        x = x_max;
    1.41 -    }
    1.42 -    if (y > y_max) {
    1.43 -        y = y_max;
    1.44 -    }
    1.45 -
    1.46      if (!mouse || mouse->flush_motion) {
    1.47          return 0;
    1.48      }
    1.49 @@ -445,15 +450,17 @@
    1.50          mouse->x = x;
    1.51          mouse->y = y;
    1.52      } else {
    1.53 -        if (mouse->x + xrel > x_max) {
    1.54 -            mouse->x = x_max;
    1.55 +        /* while using the relative mode and many windows, we have to be
    1.56 +           sure that the pointers find themselves inside the windows */
    1.57 +        if (mouse->x + xrel > mouse->x_max) {
    1.58 +            mouse->x = mouse->x_max;
    1.59          } else if (mouse->x + xrel < 0) {
    1.60              mouse->x = 0;
    1.61          } else {
    1.62              mouse->x += xrel;
    1.63          }
    1.64 -        if (mouse->y + yrel > y_max) {
    1.65 -            mouse->y = y_max;
    1.66 +        if (mouse->y + yrel > mouse->y_max) {
    1.67 +            mouse->y = mouse->y_max;
    1.68          } else if (mouse->y + yrel < 0) {
    1.69              mouse->y = 0;
    1.70          } else {
    1.71 @@ -779,13 +786,6 @@
    1.72  }
    1.73  
    1.74  void
    1.75 -SDL_UpdateCoordinates(int x, int y)
    1.76 -{
    1.77 -    x_max = x;
    1.78 -    y_max = y;
    1.79 -}
    1.80 -
    1.81 -void
    1.82  SDL_ChangeEnd(int id, int end)
    1.83  {
    1.84      int index = SDL_GetMouseIndexId(id);
     2.1 --- a/src/events/SDL_mouse_c.h	Thu Nov 27 05:29:12 2008 +0000
     2.2 +++ b/src/events/SDL_mouse_c.h	Thu Nov 27 21:53:18 2008 +0000
     2.3 @@ -66,8 +66,8 @@
     2.4      /* Data common to all mice */
     2.5      SDL_WindowID focus;
     2.6      int which;
     2.7 -    int x;
     2.8 -    int y;
     2.9 +    int x, x_max;
    2.10 +    int y, y_max;
    2.11      int z;                      /* for future use */
    2.12      int xdelta;
    2.13      int ydelta;
    2.14 @@ -112,6 +112,9 @@
    2.15  /* Set the mouse focus window */
    2.16  extern void SDL_SetMouseFocus(int id, SDL_WindowID windowID);
    2.17  
    2.18 +/* Set the size of the mouse focus window */
    2.19 +extern void SDL_SetMouseFocusSize(SDL_WindowID windowID, int w, int h);
    2.20 +
    2.21  /* Send a mouse motion event for a mouse */
    2.22  extern int SDL_SendMouseMotion(int id, int relative, int x, int y, int z);
    2.23  
    2.24 @@ -128,7 +131,6 @@
    2.25  extern void SDL_MouseQuit(void);
    2.26  
    2.27  /* FIXME: Where do these functions go in this header? */
    2.28 -extern void SDL_UpdateCoordinates(int x, int y);
    2.29  extern void SDL_ChangeEnd(int id, int end);
    2.30  
    2.31  #endif /* _SDL_mouse_c_h */
     3.1 --- a/src/events/SDL_windowevents.c	Thu Nov 27 05:29:12 2008 +0000
     3.2 +++ b/src/events/SDL_windowevents.c	Thu Nov 27 21:53:18 2008 +0000
     3.3 @@ -25,6 +25,7 @@
     3.4  
     3.5  #include "SDL_events.h"
     3.6  #include "SDL_events_c.h"
     3.7 +#include "SDL_mouse_c.h"
     3.8  #include "../video/SDL_sysvideo.h"
     3.9  
    3.10  int
    3.11 @@ -73,6 +74,7 @@
    3.12          window->w = data1;
    3.13          window->h = data2;
    3.14          SDL_OnWindowResized(window);
    3.15 +        SDL_SetMouseFocusSize(windowID, window->w, window->h);
    3.16          break;
    3.17      case SDL_WINDOWEVENT_MINIMIZED:
    3.18          if (window->flags & SDL_WINDOW_MINIMIZED) {
     4.1 --- a/src/video/win32/SDL_win32events.c	Thu Nov 27 05:29:12 2008 +0000
     4.2 +++ b/src/video/win32/SDL_win32events.c	Thu Nov 27 21:53:18 2008 +0000
     4.3 @@ -240,13 +240,11 @@
     4.4                      break;
     4.5                  }
     4.6              }
     4.7 +/* FIXME: Doesn't this defeat the point of using raw input? */
     4.8              GetCursorPos(&point);
     4.9 -            ScreenToClient(hwnd, &point);
    4.10 -            SDL_GetWindowSize(data->windowID, &w, &h);
    4.11 -            SDL_UpdateCoordinates(w, h);        /* we're updating the current window size */
    4.12  
    4.13              /* if the message was sent by a tablet we have to send also pressure */
    4.14 -            if (i == tablet) {
    4.15 +            if (index == tablet) {
    4.16                  SDL_SendMouseMotion(index, 0, point.x, point.y, pressure);
    4.17              } else {
    4.18                  SDL_SendMouseMotion(index, 0, point.x, point.y, 0);
     5.1 --- a/src/video/x11/SDL_x11events.c	Thu Nov 27 05:29:12 2008 +0000
     5.2 +++ b/src/video/x11/SDL_x11events.c	Thu Nov 27 21:53:18 2008 +0000
     5.3 @@ -278,16 +278,10 @@
     5.4  
     5.5      default:{
     5.6              if (xevent.type == motion) {        /* MotionNotify */
     5.7 +                XDeviceMotionEvent *move = (XDeviceMotionEvent *) & xevent;
     5.8  #ifdef DEBUG_MOTION
     5.9 -                printf("X11 motion: %d,%d\n", xevent.xmotion.x,
    5.10 -                       xevent.xmotion.y);
    5.11 +                printf("X11 motion: %d,%d\n", move->x, move->y);
    5.12  #endif
    5.13 -                XWindowAttributes attrib;
    5.14 -                XGetWindowAttributes(videodata->display,
    5.15 -                                     ((XAnyEvent *) & xevent)->window,
    5.16 -                                     &attrib);
    5.17 -                SDL_UpdateCoordinates(attrib.width, attrib.height);
    5.18 -                XDeviceMotionEvent *move = (XDeviceMotionEvent *) & xevent;
    5.19                  SDL_SendMouseMotion(move->deviceid, 0, move->x,
    5.20                                      move->y, move->axis_data[2]);
    5.21              } else if (xevent.type == button_pressed) { /* ButtonPress */