Mercurial > sdl-ios-xcode
diff src/events/SDL_mouse.c @ 2940:b93965a16fe0
Fixed X11 mouse motion/button events - it's not actually safe to cast mouse events to device events.
Fixed building SDL without XInput support
Simplified the process of registering a mouse device
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Thu, 01 Jan 2009 07:59:08 +0000 |
parents | 6ce28e5287e9 |
children | 8f3fd508734b |
line wrap: on
line diff
--- a/src/events/SDL_mouse.c Thu Jan 01 07:58:20 2009 +0000 +++ b/src/events/SDL_mouse.c Thu Jan 01 07:59:08 2009 +0000 @@ -31,8 +31,6 @@ static int SDL_num_mice = 0; static int SDL_current_mouse = -1; static SDL_Mouse **SDL_mice = NULL; -static int *SDL_IdIndex = NULL; -static int SDL_highestId = -1; /* Public functions */ @@ -51,62 +49,44 @@ return SDL_mice[index]; } -int -SDL_SetMouseIndexId(int id, int index) +static int +SDL_GetMouseIndexId(int id) { - if (id < 0) { - SDL_SetError("Invalid Mouse ID"); - return -1; + int index; + SDL_Mouse *mouse; + + for (index = 0; index < SDL_num_mice; ++index) { + mouse = SDL_GetMouse(index); + if (mouse->id == id) { + return index; + } } - if (id > SDL_highestId) { - int *indexes; - int i; - indexes = (int *) SDL_realloc(SDL_IdIndex, (id + 1) * sizeof(int)); - if (!indexes) { - SDL_OutOfMemory(); - return -1; - } - SDL_IdIndex = indexes; - for (i = SDL_highestId + 1; i <= id; i++) - SDL_IdIndex[i] = -1; - SDL_IdIndex[id] = index; - SDL_highestId = id; - } else { - SDL_IdIndex[id] = index; - } - return 1; + return -1; } int -SDL_GetMouseIndexId(int id) -{ - if (id < 0 || id > SDL_highestId) { - return -1; - } - return SDL_IdIndex[id]; -} - -int -SDL_AddMouse(const SDL_Mouse * mouse, int index, char *name, int pressure_max, +SDL_AddMouse(const SDL_Mouse * mouse, char *name, int pressure_max, int pressure_min, int ends) { SDL_Mouse **mice; int selected_mouse; - int length; + int index, length; + + if (SDL_GetMouseIndexId(mouse->id) != -1) { + SDL_SetError("Mouse ID already in use"); + } /* Add the mouse to the list of mice */ - if (index < 0 || index >= SDL_num_mice || SDL_mice[index]) { - mice = - (SDL_Mouse **) SDL_realloc(SDL_mice, - (SDL_num_mice + 1) * sizeof(*mice)); - if (!mice) { - SDL_OutOfMemory(); - return -1; - } + mice = (SDL_Mouse **) SDL_realloc(SDL_mice, + (SDL_num_mice + 1) * sizeof(*mice)); + if (!mice) { + SDL_OutOfMemory(); + return -1; + } - SDL_mice = mice; - index = SDL_num_mice++; - } + SDL_mice = mice; + index = SDL_num_mice++; + SDL_mice[index] = (SDL_Mouse *) SDL_malloc(sizeof(*SDL_mice[index])); if (!SDL_mice[index]) { SDL_OutOfMemory();