src/events/SDL_mouse.c
changeset 2940 b93965a16fe0
parent 2860 6ce28e5287e9
child 3112 8f3fd508734b
     1.1 --- a/src/events/SDL_mouse.c	Thu Jan 01 07:58:20 2009 +0000
     1.2 +++ b/src/events/SDL_mouse.c	Thu Jan 01 07:59:08 2009 +0000
     1.3 @@ -31,8 +31,6 @@
     1.4  static int SDL_num_mice = 0;
     1.5  static int SDL_current_mouse = -1;
     1.6  static SDL_Mouse **SDL_mice = NULL;
     1.7 -static int *SDL_IdIndex = NULL;
     1.8 -static int SDL_highestId = -1;
     1.9  
    1.10  
    1.11  /* Public functions */
    1.12 @@ -51,62 +49,44 @@
    1.13      return SDL_mice[index];
    1.14  }
    1.15  
    1.16 -int
    1.17 -SDL_SetMouseIndexId(int id, int index)
    1.18 +static int
    1.19 +SDL_GetMouseIndexId(int id)
    1.20  {
    1.21 -    if (id < 0) {
    1.22 -        SDL_SetError("Invalid Mouse ID");
    1.23 -        return -1;
    1.24 +    int index;
    1.25 +    SDL_Mouse *mouse;
    1.26 +
    1.27 +    for (index = 0; index < SDL_num_mice; ++index) {
    1.28 +        mouse = SDL_GetMouse(index);
    1.29 +        if (mouse->id == id) {
    1.30 +            return index;
    1.31 +        }
    1.32      }
    1.33 -    if (id > SDL_highestId) {
    1.34 -        int *indexes;
    1.35 -        int i;
    1.36 -        indexes = (int *) SDL_realloc(SDL_IdIndex, (id + 1) * sizeof(int));
    1.37 -        if (!indexes) {
    1.38 -            SDL_OutOfMemory();
    1.39 -            return -1;
    1.40 -        }
    1.41 -        SDL_IdIndex = indexes;
    1.42 -        for (i = SDL_highestId + 1; i <= id; i++)
    1.43 -            SDL_IdIndex[i] = -1;
    1.44 -        SDL_IdIndex[id] = index;
    1.45 -        SDL_highestId = id;
    1.46 -    } else {
    1.47 -        SDL_IdIndex[id] = index;
    1.48 -    }
    1.49 -    return 1;
    1.50 +    return -1;
    1.51  }
    1.52  
    1.53  int
    1.54 -SDL_GetMouseIndexId(int id)
    1.55 -{
    1.56 -    if (id < 0 || id > SDL_highestId) {
    1.57 -        return -1;
    1.58 -    }
    1.59 -    return SDL_IdIndex[id];
    1.60 -}
    1.61 -
    1.62 -int
    1.63 -SDL_AddMouse(const SDL_Mouse * mouse, int index, char *name, int pressure_max,
    1.64 +SDL_AddMouse(const SDL_Mouse * mouse, char *name, int pressure_max,
    1.65               int pressure_min, int ends)
    1.66  {
    1.67      SDL_Mouse **mice;
    1.68      int selected_mouse;
    1.69 -    int length;
    1.70 +    int index, length;
    1.71 +
    1.72 +    if (SDL_GetMouseIndexId(mouse->id) != -1) {
    1.73 +        SDL_SetError("Mouse ID already in use");
    1.74 +    }
    1.75  
    1.76      /* Add the mouse to the list of mice */
    1.77 -    if (index < 0 || index >= SDL_num_mice || SDL_mice[index]) {
    1.78 -        mice =
    1.79 -            (SDL_Mouse **) SDL_realloc(SDL_mice,
    1.80 -                                       (SDL_num_mice + 1) * sizeof(*mice));
    1.81 -        if (!mice) {
    1.82 -            SDL_OutOfMemory();
    1.83 -            return -1;
    1.84 -        }
    1.85 +    mice = (SDL_Mouse **) SDL_realloc(SDL_mice,
    1.86 +                                      (SDL_num_mice + 1) * sizeof(*mice));
    1.87 +    if (!mice) {
    1.88 +        SDL_OutOfMemory();
    1.89 +        return -1;
    1.90 +    }
    1.91  
    1.92 -        SDL_mice = mice;
    1.93 -        index = SDL_num_mice++;
    1.94 -    }
    1.95 +    SDL_mice = mice;
    1.96 +    index = SDL_num_mice++;
    1.97 +
    1.98      SDL_mice[index] = (SDL_Mouse *) SDL_malloc(sizeof(*SDL_mice[index]));
    1.99      if (!SDL_mice[index]) {
   1.100          SDL_OutOfMemory();