comparison src/events/SDL_mouse.c @ 4465:3e69e077cb95

Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API. Plus, this lets me start implementing cursor support.
author Sam Lantinga <slouken@libsdl.org>
date Sun, 09 May 2010 20:47:22 -0700
parents faa9fc8e7f67
children 9322f7db8603
comparison
equal deleted inserted replaced
4464:fa77a6429698 4465:3e69e077cb95
27 #include "SDL_events_c.h" 27 #include "SDL_events_c.h"
28 #include "default_cursor.h" 28 #include "default_cursor.h"
29 #include "../video/SDL_sysvideo.h" 29 #include "../video/SDL_sysvideo.h"
30 30
31 31
32 static int SDL_num_mice = 0; 32 /* Global mouse information */
33 static int SDL_current_mouse = -1; 33
34 static SDL_Mouse **SDL_mice = NULL; 34 typedef struct SDL_Mouse SDL_Mouse;
35
36 struct SDL_Mouse
37 {
38 /* Create a cursor from a surface */
39 SDL_Cursor *(*CreateCursor) (SDL_Surface * surface, int hot_x, int hot_y);
40
41 /* Show the specified cursor, or hide if cursor is NULL */
42 int (*ShowCursor) (SDL_Cursor * cursor);
43
44 /* This is called when a mouse motion event occurs */
45 void (*MoveCursor) (SDL_Cursor * cursor);
46
47 /* Free a window manager cursor */
48 void (*FreeCursor) (SDL_Cursor * cursor);
49
50 /* Warp the mouse to (x,y) */
51 void (*WarpMouse) (SDL_Mouse * mouse, SDL_Window * window, int x, int y);
52
53 /* Data common to all mice */
54 SDL_Window *focus;
55 int x;
56 int y;
57 int xdelta;
58 int ydelta;
59 int last_x, last_y; /* the last reported x and y coordinates */
60 Uint8 buttonstate;
61 SDL_bool relative_mode;
62
63 SDL_Cursor *cursors;
64 SDL_Cursor *def_cursor;
65 SDL_Cursor *cur_cursor;
66 SDL_bool cursor_shown;
67 };
68
69 static SDL_Mouse SDL_mouse;
35 70
36 71
37 /* Public functions */ 72 /* Public functions */
38 int 73 int
39 SDL_MouseInit(void) 74 SDL_MouseInit(void)
40 { 75 {
41 return (0); 76 return (0);
42 } 77 }
43 78
44 SDL_Mouse *
45 SDL_GetMouse(int index)
46 {
47 if (index < 0 || index >= SDL_num_mice) {
48 return NULL;
49 }
50 return SDL_mice[index];
51 }
52
53 static int
54 SDL_GetMouseIndexId(int id)
55 {
56 int index;
57 SDL_Mouse *mouse;
58
59 for (index = 0; index < SDL_num_mice; ++index) {
60 mouse = SDL_GetMouse(index);
61 if (mouse->id == id) {
62 return index;
63 }
64 }
65 return -1;
66 }
67
68 int
69 SDL_AddMouse(const SDL_Mouse * mouse, char *name, int pressure_max,
70 int pressure_min, int ends)
71 {
72 SDL_Mouse **mice;
73 int selected_mouse;
74 int index;
75 size_t length;
76
77 if (SDL_GetMouseIndexId(mouse->id) != -1) {
78 SDL_SetError("Mouse ID already in use");
79 }
80
81 /* Add the mouse to the list of mice */
82 mice = (SDL_Mouse **) SDL_realloc(SDL_mice,
83 (SDL_num_mice + 1) * sizeof(*mice));
84 if (!mice) {
85 SDL_OutOfMemory();
86 return -1;
87 }
88
89 SDL_mice = mice;
90 index = SDL_num_mice++;
91
92 SDL_mice[index] = (SDL_Mouse *) SDL_malloc(sizeof(*SDL_mice[index]));
93 if (!SDL_mice[index]) {
94 SDL_OutOfMemory();
95 return -1;
96 }
97 *SDL_mice[index] = *mouse;
98
99 /* we're setting the mouse properties */
100 length = 0;
101 length = SDL_strlen(name);
102 SDL_mice[index]->focus = 0;
103 SDL_mice[index]->name = SDL_malloc((length + 2) * sizeof(char));
104 SDL_strlcpy(SDL_mice[index]->name, name, length + 1);
105 SDL_mice[index]->pressure_max = pressure_max;
106 SDL_mice[index]->pressure_min = pressure_min;
107 SDL_mice[index]->cursor_shown = SDL_TRUE;
108 selected_mouse = SDL_SelectMouse(index);
109 SDL_mice[index]->cur_cursor = NULL;
110 SDL_mice[index]->def_cursor =
111 SDL_CreateCursor(default_cdata, default_cmask, DEFAULT_CWIDTH,
112 DEFAULT_CHEIGHT, DEFAULT_CHOTX, DEFAULT_CHOTY);
113 SDL_SetCursor(SDL_mice[index]->def_cursor);
114 /* we're assuming that all mice are in the computer sensing zone */
115 SDL_mice[index]->proximity = SDL_TRUE;
116 /* we're assuming that all mice are working in the absolute position mode
117 thanx to that, the users that don't want to use many mice don't have to
118 worry about anything */
119 SDL_mice[index]->relative_mode = SDL_FALSE;
120 SDL_mice[index]->current_end = 0;
121 SDL_mice[index]->total_ends = ends;
122 SDL_SelectMouse(selected_mouse);
123
124 return index;
125 }
126
127 void 79 void
128 SDL_DelMouse(int index) 80 SDL_ResetMouse(void)
129 { 81 {
130 SDL_Mouse *mouse = SDL_GetMouse(index); 82 /* FIXME */
131 83 }
132 if (!mouse) { 84
133 return; 85 SDL_Window *
134 } 86 SDL_GetMouseFocus(void)
135 87 {
136 mouse->def_cursor = NULL; 88 SDL_Mouse *mouse = &SDL_mouse;
137 SDL_free(mouse->name); 89
138 while (mouse->cursors) { 90 return mouse->focus;
139 SDL_FreeCursor(mouse->cursors);
140 }
141
142 if (mouse->FreeMouse) {
143 mouse->FreeMouse(mouse);
144 }
145 SDL_free(mouse);
146
147 SDL_mice[index] = NULL;
148 } 91 }
149 92
150 void 93 void
151 SDL_ResetMouse(int index) 94 SDL_SetMouseFocus(SDL_Window * window)
152 { 95 {
153 SDL_Mouse *mouse = SDL_GetMouse(index); 96 SDL_Mouse *mouse = &SDL_mouse;
154 97
155 if (!mouse) { 98 if (mouse->focus == window) {
156 return;
157 }
158
159 /* FIXME */
160 }
161
162 void
163 SDL_MouseQuit(void)
164 {
165 int i;
166
167 for (i = 0; i < SDL_num_mice; ++i) {
168 SDL_DelMouse(i);
169 }
170 SDL_num_mice = 0;
171 SDL_current_mouse = -1;
172
173 if (SDL_mice) {
174 SDL_free(SDL_mice);
175 SDL_mice = NULL;
176 }
177 }
178
179 int
180 SDL_GetNumMice(void)
181 {
182 return SDL_num_mice;
183 }
184
185 int
186 SDL_SelectMouse(int index)
187 {
188 if (index >= 0 && index < SDL_num_mice) {
189 SDL_current_mouse = index;
190 }
191 return SDL_current_mouse;
192 }
193
194 SDL_Window *
195 SDL_GetMouseFocusWindow(int index)
196 {
197 SDL_Mouse *mouse = SDL_GetMouse(index);
198
199 if (!mouse) {
200 return 0;
201 }
202 return mouse->focus;
203 }
204
205 static int SDLCALL
206 FlushMouseMotion(void *param, SDL_Event * event)
207 {
208 if (event->type == SDL_MOUSEMOTION
209 && event->motion.which == (Uint8) SDL_current_mouse) {
210 return 0;
211 } else {
212 return 1;
213 }
214 }
215
216 int
217 SDL_SetRelativeMouseMode(int index, SDL_bool enabled)
218 {
219 SDL_Mouse *mouse = SDL_GetMouse(index);
220
221 if (!mouse) {
222 return -1;
223 }
224
225 /* Flush pending mouse motion */
226 mouse->flush_motion = SDL_TRUE;
227 SDL_PumpEvents();
228 mouse->flush_motion = SDL_FALSE;
229 SDL_FilterEvents(FlushMouseMotion, mouse);
230
231 /* Set the relative mode */
232 mouse->relative_mode = enabled;
233
234 /* Update cursor visibility */
235 SDL_SetCursor(NULL);
236
237 if (!enabled) {
238 /* Restore the expected mouse position */
239 SDL_WarpMouseInWindow(mouse->focus, mouse->x, mouse->y);
240 }
241 return 0;
242 }
243
244 SDL_bool
245 SDL_GetRelativeMouseMode(int index)
246 {
247 SDL_Mouse *mouse = SDL_GetMouse(index);
248
249 if (!mouse) {
250 return SDL_FALSE;
251 }
252 return mouse->relative_mode;
253 }
254
255 Uint8
256 SDL_GetMouseState(int *x, int *y)
257 {
258 SDL_Mouse *mouse = SDL_GetMouse(SDL_current_mouse);
259
260 if (!mouse) {
261 if (x) {
262 *x = 0;
263 }
264 if (y) {
265 *y = 0;
266 }
267 return 0;
268 }
269
270 if (x) {
271 *x = mouse->x;
272 }
273 if (y) {
274 *y = mouse->y;
275 }
276 return mouse->buttonstate;
277 }
278
279 Uint8
280 SDL_GetRelativeMouseState(int index, int *x, int *y)
281 {
282 SDL_Mouse *mouse = SDL_GetMouse(index);
283
284 if (!mouse) {
285 if (x) {
286 *x = 0;
287 }
288 if (y) {
289 *y = 0;
290 }
291 return 0;
292 }
293
294 if (x) {
295 *x = mouse->xdelta;
296 }
297 if (y) {
298 *y = mouse->ydelta;
299 }
300 mouse->xdelta = 0;
301 mouse->ydelta = 0;
302 return mouse->buttonstate;
303 }
304
305 void
306 SDL_SetMouseFocus(int id, SDL_Window * window)
307 {
308 int index = SDL_GetMouseIndexId(id);
309 SDL_Mouse *mouse = SDL_GetMouse(index);
310 int i;
311 SDL_bool focus;
312
313 if (!mouse || (mouse->focus == window)) {
314 return; 99 return;
315 } 100 }
316 101
317 /* See if the current window has lost focus */ 102 /* See if the current window has lost focus */
318 if (mouse->focus) { 103 if (mouse->focus) {
319 focus = SDL_FALSE; 104 SDL_SendWindowEvent(mouse->focus, SDL_WINDOWEVENT_LEAVE, 0, 0);
320 for (i = 0; i < SDL_num_mice; ++i) {
321 SDL_Mouse *check;
322 if (i != index) {
323 check = SDL_GetMouse(i);
324 if (check && check->focus == mouse->focus) {
325 focus = SDL_TRUE;
326 break;
327 }
328 }
329 }
330 if (!focus) {
331 SDL_SendWindowEvent(mouse->focus, SDL_WINDOWEVENT_LEAVE, 0, 0);
332 }
333 } 105 }
334 106
335 mouse->focus = window; 107 mouse->focus = window;
336 108
337 if (mouse->focus) { 109 if (mouse->focus) {
338 focus = SDL_FALSE; 110 SDL_SendWindowEvent(mouse->focus, SDL_WINDOWEVENT_ENTER, 0, 0);
339 for (i = 0; i < SDL_num_mice; ++i) {
340 SDL_Mouse *check;
341 if (i != index) {
342 check = SDL_GetMouse(i);
343 if (check && check->focus == mouse->focus) {
344 focus = SDL_TRUE;
345 break;
346 }
347 }
348 }
349 if (!focus) {
350 SDL_SendWindowEvent(mouse->focus, SDL_WINDOWEVENT_ENTER, 0, 0);
351 }
352 } 111 }
353 } 112 }
354 113
355 int 114 int
356 SDL_SendProximity(int id, int x, int y, int type) 115 SDL_SendMouseMotion(int relative, int x, int y)
357 { 116 {
358 int index = SDL_GetMouseIndexId(id); 117 SDL_Mouse *mouse = &SDL_mouse;
359 SDL_Mouse *mouse = SDL_GetMouse(index);
360 int posted = 0;
361
362 if (!mouse) {
363 return 0;
364 }
365
366 mouse->last_x = x;
367 mouse->last_y = y;
368 if (SDL_GetEventState(type) == SDL_ENABLE) {
369 SDL_Event event;
370 event.proximity.which = (Uint8) index;
371 event.proximity.x = x;
372 event.proximity.y = y;
373 event.proximity.cursor = mouse->current_end;
374 event.proximity.type = type;
375 /* FIXME: is this right? */
376 event.proximity.windowID = mouse->focus ? mouse->focus->id : 0;
377 posted = (SDL_PushEvent(&event) > 0);
378 if (type == SDL_PROXIMITYIN) {
379 mouse->proximity = SDL_TRUE;
380 } else {
381 mouse->proximity = SDL_FALSE;
382 }
383 }
384 return posted;
385 }
386
387 int
388 SDL_SendMouseMotion(int id, int relative, int x, int y, int pressure)
389 {
390 int index = SDL_GetMouseIndexId(id);
391 SDL_Mouse *mouse = SDL_GetMouse(index);
392 int posted; 118 int posted;
393 int xrel; 119 int xrel;
394 int yrel; 120 int yrel;
395 int x_max = 0, y_max = 0; 121 int x_max = 0, y_max = 0;
396
397 if (!mouse || mouse->flush_motion) {
398 return 0;
399 }
400
401 /* if the mouse is out of proximity we don't to want to have any motion from it */
402 if (mouse->proximity == SDL_FALSE) {
403 mouse->last_x = x;
404 mouse->last_y = y;
405 return 0;
406 }
407 122
408 /* the relative motion is calculated regarding the system cursor last position */ 123 /* the relative motion is calculated regarding the system cursor last position */
409 if (relative) { 124 if (relative) {
410 xrel = x; 125 xrel = x;
411 yrel = y; 126 yrel = y;
449 mouse->y = 0; 164 mouse->y = 0;
450 } 165 }
451 166
452 mouse->xdelta += xrel; 167 mouse->xdelta += xrel;
453 mouse->ydelta += yrel; 168 mouse->ydelta += yrel;
454 mouse->pressure = pressure; 169
455 170 #if 0 /* FIXME */
456 /* Move the mouse cursor, if needed */ 171 /* Move the mouse cursor, if needed */
457 if (mouse->cursor_shown && !mouse->relative_mode && 172 if (mouse->cursor_shown && !mouse->relative_mode &&
458 mouse->MoveCursor && mouse->cur_cursor) { 173 mouse->MoveCursor && mouse->cur_cursor) {
459 mouse->MoveCursor(mouse->cur_cursor); 174 mouse->MoveCursor(mouse->cur_cursor);
460 } 175 }
176 #endif
461 177
462 /* Post the event, if desired */ 178 /* Post the event, if desired */
463 posted = 0; 179 posted = 0;
464 if (SDL_GetEventState(SDL_MOUSEMOTION) == SDL_ENABLE && 180 if (SDL_GetEventState(SDL_MOUSEMOTION) == SDL_ENABLE) {
465 mouse->proximity == SDL_TRUE) {
466 SDL_Event event; 181 SDL_Event event;
467 event.motion.type = SDL_MOUSEMOTION; 182 event.motion.type = SDL_MOUSEMOTION;
468 event.motion.which = (Uint8) index; 183 event.motion.windowID = mouse->focus ? mouse->focus->id : 0;
469 event.motion.state = mouse->buttonstate; 184 event.motion.state = mouse->buttonstate;
470 event.motion.x = mouse->x; 185 event.motion.x = mouse->x;
471 event.motion.y = mouse->y; 186 event.motion.y = mouse->y;
472 event.motion.z = mouse->z;
473 event.motion.pressure = mouse->pressure;
474 event.motion.pressure_max = mouse->pressure_max;
475 event.motion.pressure_min = mouse->pressure_min;
476 event.motion.rotation = 0;
477 event.motion.tilt_x = 0;
478 event.motion.tilt_y = 0;
479 event.motion.cursor = mouse->current_end;
480 event.motion.xrel = xrel; 187 event.motion.xrel = xrel;
481 event.motion.yrel = yrel; 188 event.motion.yrel = yrel;
482 event.motion.windowID = mouse->focus ? mouse->focus->id : 0;
483 posted = (SDL_PushEvent(&event) > 0); 189 posted = (SDL_PushEvent(&event) > 0);
484 } 190 }
485 mouse->last_x = mouse->x; 191 mouse->last_x = mouse->x;
486 mouse->last_y = mouse->y; 192 mouse->last_y = mouse->y;
487 return posted; 193 return posted;
488 } 194 }
489 195
490 int 196 int
491 SDL_SendMouseButton(int id, Uint8 state, Uint8 button) 197 SDL_SendMouseButton(Uint8 state, Uint8 button)
492 { 198 {
493 int index = SDL_GetMouseIndexId(id); 199 SDL_Mouse *mouse = &SDL_mouse;
494 SDL_Mouse *mouse = SDL_GetMouse(index);
495 int posted; 200 int posted;
496 Uint32 type; 201 Uint32 type;
497
498 if (!mouse) {
499 return 0;
500 }
501 202
502 /* Figure out which event to perform */ 203 /* Figure out which event to perform */
503 switch (state) { 204 switch (state) {
504 case SDL_PRESSED: 205 case SDL_PRESSED:
505 if (mouse->buttonstate & SDL_BUTTON(button)) { 206 if (mouse->buttonstate & SDL_BUTTON(button)) {
525 /* Post the event, if desired */ 226 /* Post the event, if desired */
526 posted = 0; 227 posted = 0;
527 if (SDL_GetEventState(type) == SDL_ENABLE) { 228 if (SDL_GetEventState(type) == SDL_ENABLE) {
528 SDL_Event event; 229 SDL_Event event;
529 event.type = type; 230 event.type = type;
530 event.button.which = (Uint8) index;
531 event.button.state = state; 231 event.button.state = state;
532 event.button.button = button; 232 event.button.button = button;
533 event.button.x = mouse->x; 233 event.button.x = mouse->x;
534 event.button.y = mouse->y; 234 event.button.y = mouse->y;
535 event.button.windowID = mouse->focus ? mouse->focus->id : 0; 235 event.button.windowID = mouse->focus ? mouse->focus->id : 0;
537 } 237 }
538 return posted; 238 return posted;
539 } 239 }
540 240
541 int 241 int
542 SDL_SendMouseWheel(int index, int x, int y) 242 SDL_SendMouseWheel(int x, int y)
543 { 243 {
544 SDL_Mouse *mouse = SDL_GetMouse(index); 244 SDL_Mouse *mouse = &SDL_mouse;
545 int posted; 245 int posted;
546 246
547 if (!mouse || (!x && !y)) { 247 if (!x && !y) {
548 return 0; 248 return 0;
549 } 249 }
550 250
551 /* Post the event, if desired */ 251 /* Post the event, if desired */
552 posted = 0; 252 posted = 0;
553 if (SDL_GetEventState(SDL_MOUSEWHEEL) == SDL_ENABLE) { 253 if (SDL_GetEventState(SDL_MOUSEWHEEL) == SDL_ENABLE) {
554 SDL_Event event; 254 SDL_Event event;
555 event.type = SDL_MOUSEWHEEL; 255 event.type = SDL_MOUSEWHEEL;
556 event.wheel.which = (Uint8) index; 256 event.wheel.windowID = mouse->focus ? mouse->focus->id : 0;
557 event.wheel.x = x; 257 event.wheel.x = x;
558 event.wheel.y = y; 258 event.wheel.y = y;
559 event.wheel.windowID = mouse->focus ? mouse->focus->id : 0;
560 posted = (SDL_PushEvent(&event) > 0); 259 posted = (SDL_PushEvent(&event) > 0);
561 } 260 }
562 return posted; 261 return posted;
262 }
263
264 void
265 SDL_MouseQuit(void)
266 {
267 }
268
269 Uint8
270 SDL_GetMouseState(int *x, int *y)
271 {
272 SDL_Mouse *mouse = &SDL_mouse;
273
274 if (x) {
275 *x = mouse->x;
276 }
277 if (y) {
278 *y = mouse->y;
279 }
280 return mouse->buttonstate;
281 }
282
283 Uint8
284 SDL_GetRelativeMouseState(int *x, int *y)
285 {
286 SDL_Mouse *mouse = &SDL_mouse;
287
288 if (x) {
289 *x = mouse->xdelta;
290 }
291 if (y) {
292 *y = mouse->ydelta;
293 }
294 mouse->xdelta = 0;
295 mouse->ydelta = 0;
296 return mouse->buttonstate;
563 } 297 }
564 298
565 void 299 void
566 SDL_WarpMouseInWindow(SDL_Window * window, int x, int y) 300 SDL_WarpMouseInWindow(SDL_Window * window, int x, int y)
567 { 301 {
568 SDL_Mouse *mouse = SDL_GetMouse(SDL_current_mouse); 302 SDL_Mouse *mouse = &SDL_mouse;
569
570 if (!mouse) {
571 return;
572 }
573 303
574 if (mouse->WarpMouse) { 304 if (mouse->WarpMouse) {
575 mouse->WarpMouse(mouse, window, x, y); 305 mouse->WarpMouse(mouse, window, x, y);
576 } else { 306 } else {
577 SDL_SetMouseFocus(SDL_current_mouse, window); 307 SDL_SetMouseFocus(window);
578 SDL_SendMouseMotion(SDL_current_mouse, 0, x, y, 0); 308 SDL_SendMouseMotion(0, x, y);
579 } 309 }
310 }
311
312 int
313 SDL_SetRelativeMouseMode(SDL_bool enabled)
314 {
315 SDL_Mouse *mouse = &SDL_mouse;
316
317 /* Flush pending mouse motion */
318 SDL_FlushEvent(SDL_MOUSEMOTION);
319
320 /* Set the relative mode */
321 mouse->relative_mode = enabled;
322
323 if (!enabled) {
324 /* Restore the expected mouse position */
325 SDL_WarpMouseInWindow(mouse->focus, mouse->x, mouse->y);
326 }
327
328 /* Update cursor visibility */
329 SDL_SetCursor(NULL);
330
331 return 0;
332 }
333
334 SDL_bool
335 SDL_GetRelativeMouseMode()
336 {
337 SDL_Mouse *mouse = &SDL_mouse;
338
339 return mouse->relative_mode;
580 } 340 }
581 341
582 SDL_Cursor * 342 SDL_Cursor *
583 SDL_CreateCursor(const Uint8 * data, const Uint8 * mask, 343 SDL_CreateCursor(const Uint8 * data, const Uint8 * mask,
584 int w, int h, int hot_x, int hot_y) 344 int w, int h, int hot_x, int hot_y)
585 { 345 {
586 SDL_Mouse *mouse = SDL_GetMouse(SDL_current_mouse); 346 SDL_Mouse *mouse = &SDL_mouse;
587 SDL_Surface *surface; 347 SDL_Surface *surface;
588 SDL_Cursor *cursor; 348 SDL_Cursor *cursor;
589 int x, y; 349 int x, y;
590 Uint32 *pixel; 350 Uint32 *pixel;
591 Uint8 datab, maskb; 351 Uint8 datab = 0, maskb = 0;
592 const Uint32 black = 0xFF000000; 352 const Uint32 black = 0xFF000000;
593 const Uint32 white = 0xFFFFFFFF; 353 const Uint32 white = 0xFFFFFFFF;
594 const Uint32 transparent = 0x00000000; 354 const Uint32 transparent = 0x00000000;
595 355
596 if (!mouse) {
597 SDL_SetError("No mice are initialized");
598 return NULL;
599 }
600
601 if (!mouse->CreateCursor) { 356 if (!mouse->CreateCursor) {
602 SDL_SetError("Current mouse doesn't have cursor support"); 357 SDL_SetError("Cursors are not currently supported");
603 return NULL; 358 return NULL;
604 } 359 }
605 360
606 /* Sanity check the hot spot */ 361 /* Sanity check the hot spot */
607 if ((hot_x < 0) || (hot_y < 0) || (hot_x >= w) || (hot_y >= h)) { 362 if ((hot_x < 0) || (hot_y < 0) || (hot_x >= w) || (hot_y >= h)) {
636 } 391 }
637 } 392 }
638 393
639 cursor = mouse->CreateCursor(surface, hot_x, hot_y); 394 cursor = mouse->CreateCursor(surface, hot_x, hot_y);
640 if (cursor) { 395 if (cursor) {
641 cursor->mouse = mouse;
642 cursor->next = mouse->cursors; 396 cursor->next = mouse->cursors;
643 mouse->cursors = cursor; 397 mouse->cursors = cursor;
644 } 398 }
645 399
646 SDL_FreeSurface(surface); 400 SDL_FreeSurface(surface);
653 the video mode and when the SDL window gains the mouse focus. 407 the video mode and when the SDL window gains the mouse focus.
654 */ 408 */
655 void 409 void
656 SDL_SetCursor(SDL_Cursor * cursor) 410 SDL_SetCursor(SDL_Cursor * cursor)
657 { 411 {
658 SDL_Mouse *mouse = SDL_GetMouse(SDL_current_mouse); 412 SDL_Mouse *mouse = &SDL_mouse;
659
660 if (!mouse) {
661 SDL_SetError("No mice are initialized");
662 return;
663 }
664 413
665 /* Set the new cursor */ 414 /* Set the new cursor */
666 if (cursor) { 415 if (cursor) {
667 /* Make sure the cursor is still valid for this mouse */ 416 /* Make sure the cursor is still valid for this mouse */
668 SDL_Cursor *found; 417 SDL_Cursor *found;
692 } 441 }
693 442
694 SDL_Cursor * 443 SDL_Cursor *
695 SDL_GetCursor(void) 444 SDL_GetCursor(void)
696 { 445 {
697 SDL_Mouse *mouse = SDL_GetMouse(SDL_current_mouse); 446 SDL_Mouse *mouse = &SDL_mouse;
698 447
699 if (!mouse) { 448 if (!mouse) {
700 return NULL; 449 return NULL;
701 } 450 }
702 return mouse->cur_cursor; 451 return mouse->cur_cursor;
703 } 452 }
704 453
705 void 454 void
706 SDL_FreeCursor(SDL_Cursor * cursor) 455 SDL_FreeCursor(SDL_Cursor * cursor)
707 { 456 {
708 SDL_Mouse *mouse; 457 SDL_Mouse *mouse = &SDL_mouse;
709 SDL_Cursor *curr, *prev; 458 SDL_Cursor *curr, *prev;
710 459
711 if (!cursor) { 460 if (!cursor) {
712 return; 461 return;
713 } 462 }
714 mouse = cursor->mouse;
715 463
716 if (cursor == mouse->def_cursor) { 464 if (cursor == mouse->def_cursor) {
717 return; 465 return;
718 } 466 }
719 if (cursor == mouse->cur_cursor) { 467 if (cursor == mouse->cur_cursor) {
738 } 486 }
739 487
740 int 488 int
741 SDL_ShowCursor(int toggle) 489 SDL_ShowCursor(int toggle)
742 { 490 {
743 SDL_Mouse *mouse = SDL_GetMouse(SDL_current_mouse); 491 SDL_Mouse *mouse = &SDL_mouse;
744 SDL_bool shown; 492 SDL_bool shown;
745 493
746 if (!mouse) { 494 if (!mouse) {
747 return 0; 495 return 0;
748 } 496 }
759 } 507 }
760 } 508 }
761 return shown; 509 return shown;
762 } 510 }
763 511
764 char *
765 SDL_GetMouseName(int index)
766 {
767 SDL_Mouse *mouse = SDL_GetMouse(index);
768 if (!mouse) {
769 return NULL;
770 }
771 return mouse->name;
772 }
773
774 void
775 SDL_ChangeEnd(int id, int end)
776 {
777 int index = SDL_GetMouseIndexId(id);
778 SDL_Mouse *mouse = SDL_GetMouse(index);
779
780 if (mouse) {
781 mouse->current_end = end;
782 }
783 }
784
785 int
786 SDL_GetCursorsNumber(int index)
787 {
788 SDL_Mouse *mouse = SDL_GetMouse(index);
789
790 if (!mouse) {
791 return -1;
792 }
793 return mouse->total_ends;
794 }
795
796 int
797 SDL_GetCurrentCursor(int index)
798 {
799 SDL_Mouse *mouse = SDL_GetMouse(index);
800
801 if (!mouse) {
802 return -1;
803 }
804 return mouse->current_end;
805 }
806
807 /* vi: set ts=4 sw=4 expandtab: */ 512 /* vi: set ts=4 sw=4 expandtab: */