src/events/SDL_mouse.c
changeset 2860 6ce28e5287e9
parent 2859 99210400e8b9
child 2940 b93965a16fe0
     1.1 --- a/src/events/SDL_mouse.c	Mon Dec 08 00:27:32 2008 +0000
     1.2 +++ b/src/events/SDL_mouse.c	Mon Dec 08 00:52:12 2008 +0000
     1.3 @@ -33,7 +33,6 @@
     1.4  static SDL_Mouse **SDL_mice = NULL;
     1.5  static int *SDL_IdIndex = NULL;
     1.6  static int SDL_highestId = -1;
     1.7 -static int last_x, last_y;      /* the last reported x and y coordinates by the system cursor */
     1.8  
     1.9  
    1.10  /* Public functions */
    1.11 @@ -61,12 +60,15 @@
    1.12      }
    1.13      if (id > SDL_highestId) {
    1.14          int *indexes;
    1.15 +        int i;
    1.16          indexes = (int *) SDL_realloc(SDL_IdIndex, (id + 1) * sizeof(int));
    1.17          if (!indexes) {
    1.18              SDL_OutOfMemory();
    1.19              return -1;
    1.20          }
    1.21          SDL_IdIndex = indexes;
    1.22 +        for (i = SDL_highestId + 1; i <= id; i++)
    1.23 +            SDL_IdIndex[i] = -1;
    1.24          SDL_IdIndex[id] = index;
    1.25          SDL_highestId = id;
    1.26      } else {
    1.27 @@ -378,8 +380,8 @@
    1.28          return 0;
    1.29      }
    1.30  
    1.31 -    last_x = x;
    1.32 -    last_y = y;
    1.33 +    mouse->last_x = x;
    1.34 +    mouse->last_y = y;
    1.35      if (SDL_ProcessEvents[type] == SDL_ENABLE) {
    1.36          SDL_Event event;
    1.37          event.proximity.which = (Uint8) index;
    1.38 @@ -405,6 +407,7 @@
    1.39      int posted;
    1.40      int xrel;
    1.41      int yrel;
    1.42 +    int x_max = 0, y_max = 0;
    1.43  
    1.44      if (!mouse || mouse->flush_motion) {
    1.45          return 0;
    1.46 @@ -412,8 +415,8 @@
    1.47  
    1.48      /* if the mouse is out of proximity we don't to want to have any motion from it */
    1.49      if (mouse->proximity == SDL_FALSE) {
    1.50 -        last_x = x;
    1.51 -        last_y = y;
    1.52 +        mouse->last_x = x;
    1.53 +        mouse->last_y = y;
    1.54          return 0;
    1.55      }
    1.56  
    1.57 @@ -421,11 +424,11 @@
    1.58      if (relative) {
    1.59          xrel = x;
    1.60          yrel = y;
    1.61 -        x = (last_x + x);
    1.62 -        y = (last_y + y);
    1.63 +        x = (mouse->last_x + x);
    1.64 +        y = (mouse->last_y + y);
    1.65      } else {
    1.66 -        xrel = x - last_x;
    1.67 -        yrel = y - last_y;
    1.68 +        xrel = x - mouse->last_x;
    1.69 +        yrel = y - mouse->last_y;
    1.70      }
    1.71  
    1.72      /* Drop events that don't change state */
    1.73 @@ -441,27 +444,26 @@
    1.74          mouse->x = x;
    1.75          mouse->y = y;
    1.76      } else {
    1.77 -        /* while using the relative mode and many windows, we have to be
    1.78 -           sure that the pointers find themselves inside the windows */
    1.79 -        int x_max, y_max;
    1.80 +        mouse->x += xrel;
    1.81 +        mouse->y += yrel;
    1.82 +    }
    1.83  
    1.84 -        SDL_GetWindowSize(mouse->focus, &x_max, &y_max);
    1.85 +    SDL_GetWindowSize(mouse->focus, &x_max, &y_max);
    1.86  
    1.87 -        if (mouse->x + xrel > x_max) {
    1.88 -            mouse->x = x_max;
    1.89 -        } else if (mouse->x + xrel < 0) {
    1.90 -            mouse->x = 0;
    1.91 -        } else {
    1.92 -            mouse->x += xrel;
    1.93 -        }
    1.94 -        if (mouse->y + yrel > y_max) {
    1.95 -            mouse->y = y_max;
    1.96 -        } else if (mouse->y + yrel < 0) {
    1.97 -            mouse->y = 0;
    1.98 -        } else {
    1.99 -            mouse->y += yrel;
   1.100 -        }
   1.101 +    /* make sure that the pointers find themselves inside the windows */
   1.102 +    /* only check if mouse->xmax is set ! */
   1.103 +    if (x_max && mouse->x > x_max) {
   1.104 +        mouse->x = x_max;
   1.105 +    } else if (mouse->x < 0) {
   1.106 +        mouse->x = 0;
   1.107      }
   1.108 +
   1.109 +    if (y_max && mouse->y > y_max) {
   1.110 +        mouse->y = y_max;
   1.111 +    } else if (mouse->y < 0) {
   1.112 +        mouse->y = 0;
   1.113 +    }
   1.114 +
   1.115      mouse->xdelta += xrel;
   1.116      mouse->ydelta += yrel;
   1.117      mouse->pressure = pressure;
   1.118 @@ -491,8 +493,8 @@
   1.119          event.motion.cursor = mouse->current_end;
   1.120          posted = (SDL_PushEvent(&event) > 0);
   1.121      }
   1.122 -    last_x = x;
   1.123 -    last_y = y;
   1.124 +    mouse->last_x = x;
   1.125 +    mouse->last_y = y;
   1.126      return posted;
   1.127  }
   1.128