Mercurial > sdl-ios-xcode
comparison 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 |
comparison
equal
deleted
inserted
replaced
2939:084e5b4fc5be | 2940:b93965a16fe0 |
---|---|
29 | 29 |
30 | 30 |
31 static int SDL_num_mice = 0; | 31 static int SDL_num_mice = 0; |
32 static int SDL_current_mouse = -1; | 32 static int SDL_current_mouse = -1; |
33 static SDL_Mouse **SDL_mice = NULL; | 33 static SDL_Mouse **SDL_mice = NULL; |
34 static int *SDL_IdIndex = NULL; | |
35 static int SDL_highestId = -1; | |
36 | 34 |
37 | 35 |
38 /* Public functions */ | 36 /* Public functions */ |
39 int | 37 int |
40 SDL_MouseInit(void) | 38 SDL_MouseInit(void) |
49 return NULL; | 47 return NULL; |
50 } | 48 } |
51 return SDL_mice[index]; | 49 return SDL_mice[index]; |
52 } | 50 } |
53 | 51 |
54 int | 52 static int |
55 SDL_SetMouseIndexId(int id, int index) | |
56 { | |
57 if (id < 0) { | |
58 SDL_SetError("Invalid Mouse ID"); | |
59 return -1; | |
60 } | |
61 if (id > SDL_highestId) { | |
62 int *indexes; | |
63 int i; | |
64 indexes = (int *) SDL_realloc(SDL_IdIndex, (id + 1) * sizeof(int)); | |
65 if (!indexes) { | |
66 SDL_OutOfMemory(); | |
67 return -1; | |
68 } | |
69 SDL_IdIndex = indexes; | |
70 for (i = SDL_highestId + 1; i <= id; i++) | |
71 SDL_IdIndex[i] = -1; | |
72 SDL_IdIndex[id] = index; | |
73 SDL_highestId = id; | |
74 } else { | |
75 SDL_IdIndex[id] = index; | |
76 } | |
77 return 1; | |
78 } | |
79 | |
80 int | |
81 SDL_GetMouseIndexId(int id) | 53 SDL_GetMouseIndexId(int id) |
82 { | 54 { |
83 if (id < 0 || id > SDL_highestId) { | 55 int index; |
84 return -1; | 56 SDL_Mouse *mouse; |
85 } | 57 |
86 return SDL_IdIndex[id]; | 58 for (index = 0; index < SDL_num_mice; ++index) { |
87 } | 59 mouse = SDL_GetMouse(index); |
88 | 60 if (mouse->id == id) { |
89 int | 61 return index; |
90 SDL_AddMouse(const SDL_Mouse * mouse, int index, char *name, int pressure_max, | 62 } |
63 } | |
64 return -1; | |
65 } | |
66 | |
67 int | |
68 SDL_AddMouse(const SDL_Mouse * mouse, char *name, int pressure_max, | |
91 int pressure_min, int ends) | 69 int pressure_min, int ends) |
92 { | 70 { |
93 SDL_Mouse **mice; | 71 SDL_Mouse **mice; |
94 int selected_mouse; | 72 int selected_mouse; |
95 int length; | 73 int index, length; |
74 | |
75 if (SDL_GetMouseIndexId(mouse->id) != -1) { | |
76 SDL_SetError("Mouse ID already in use"); | |
77 } | |
96 | 78 |
97 /* Add the mouse to the list of mice */ | 79 /* Add the mouse to the list of mice */ |
98 if (index < 0 || index >= SDL_num_mice || SDL_mice[index]) { | 80 mice = (SDL_Mouse **) SDL_realloc(SDL_mice, |
99 mice = | 81 (SDL_num_mice + 1) * sizeof(*mice)); |
100 (SDL_Mouse **) SDL_realloc(SDL_mice, | 82 if (!mice) { |
101 (SDL_num_mice + 1) * sizeof(*mice)); | 83 SDL_OutOfMemory(); |
102 if (!mice) { | 84 return -1; |
103 SDL_OutOfMemory(); | 85 } |
104 return -1; | 86 |
105 } | 87 SDL_mice = mice; |
106 | 88 index = SDL_num_mice++; |
107 SDL_mice = mice; | 89 |
108 index = SDL_num_mice++; | |
109 } | |
110 SDL_mice[index] = (SDL_Mouse *) SDL_malloc(sizeof(*SDL_mice[index])); | 90 SDL_mice[index] = (SDL_Mouse *) SDL_malloc(sizeof(*SDL_mice[index])); |
111 if (!SDL_mice[index]) { | 91 if (!SDL_mice[index]) { |
112 SDL_OutOfMemory(); | 92 SDL_OutOfMemory(); |
113 return -1; | 93 return -1; |
114 } | 94 } |