Mercurial > sdl-ios-xcode
comparison src/events/SDL_mouse.c @ 3760:64f346a83ed3 gsoc2008_manymouse
http://wilku.ravenlord.ws/doku.php?id=documentation for information how things work. Currently implemented: detecting many pointing devices and pressure detection. Still a bug. Each program has to be comipled with a flag -lXi
author | Szymon Wilczek <kazeuser@gmail.com> |
---|---|
date | Fri, 06 Jun 2008 15:23:29 +0000 |
parents | 003c1b5b07da |
children | 81ea7d9a6624 |
comparison
equal
deleted
inserted
replaced
3759:064c178558b7 | 3760:64f346a83ed3 |
---|---|
29 | 29 |
30 | 30 |
31 static int SDL_num_mice; | 31 static int SDL_num_mice; |
32 static int SDL_current_mouse; | 32 static int SDL_current_mouse; |
33 static SDL_Mouse **SDL_mice; | 33 static SDL_Mouse **SDL_mice; |
34 int *SDL_IdIndex; | |
35 int SDL_highestId; | |
34 | 36 |
35 | 37 |
36 /* Public functions */ | 38 /* Public functions */ |
37 int | 39 int |
38 SDL_MouseInit(void) | 40 SDL_MouseInit(void) |
48 } | 50 } |
49 return SDL_mice[index]; | 51 return SDL_mice[index]; |
50 } | 52 } |
51 | 53 |
52 int | 54 int |
53 SDL_AddMouse(const SDL_Mouse * mouse, int index) | 55 SDL_AddMouse(const SDL_Mouse * mouse, int index, char* name) |
54 { | 56 { |
55 SDL_Mouse **mice; | 57 SDL_Mouse **mice; |
56 int selected_mouse; | 58 int selected_mouse; |
57 | 59 char* temp_name; |
58 /* Add the mouse to the list of mice */ | 60 /* Add the mouse to the list of mice */ |
59 if (index < 0 || index >= SDL_num_mice || SDL_mice[index]) { | 61 if (index < 0 || index >= SDL_num_mice || SDL_mice[index]) { |
60 mice = | 62 mice = |
61 (SDL_Mouse **) SDL_realloc(SDL_mice, | 63 (SDL_Mouse **) SDL_realloc(SDL_mice, |
62 (SDL_num_mice + 1) * sizeof(*mice)); | 64 (SDL_num_mice + 1) * sizeof(*mice)); |
72 if (!SDL_mice[index]) { | 74 if (!SDL_mice[index]) { |
73 SDL_OutOfMemory(); | 75 SDL_OutOfMemory(); |
74 return -1; | 76 return -1; |
75 } | 77 } |
76 *SDL_mice[index] = *mouse; | 78 *SDL_mice[index] = *mouse; |
77 | 79 SDL_mice[index]->name=SDL_malloc(strlen(name)*sizeof(char)); |
78 /* Create the default cursor for the mouse */ | 80 strcpy(SDL_mice[index]->name,name); |
79 SDL_mice[index]->cursor_shown = SDL_TRUE; | 81 SDL_mice[index]->cursor_shown = SDL_TRUE; |
80 selected_mouse = SDL_SelectMouse(index); | 82 selected_mouse = SDL_SelectMouse(index); |
81 SDL_mice[index]->cur_cursor = NULL; | 83 SDL_mice[index]->cur_cursor = NULL; |
82 SDL_mice[index]->def_cursor = | 84 SDL_mice[index]->def_cursor = |
83 SDL_CreateCursor(default_cdata, default_cmask, DEFAULT_CWIDTH, | 85 SDL_CreateCursor(default_cdata, default_cmask, DEFAULT_CWIDTH, |
96 if (!mouse) { | 98 if (!mouse) { |
97 return; | 99 return; |
98 } | 100 } |
99 | 101 |
100 mouse->def_cursor = NULL; | 102 mouse->def_cursor = NULL; |
103 SDL_free(mouse->name); | |
101 while (mouse->cursors) { | 104 while (mouse->cursors) { |
102 SDL_FreeCursor(mouse->cursors); | 105 SDL_FreeCursor(mouse->cursors); |
103 } | 106 } |
104 | 107 |
105 if (mouse->FreeMouse) { | 108 if (mouse->FreeMouse) { |
264 mouse->ydelta = 0; | 267 mouse->ydelta = 0; |
265 return mouse->buttonstate; | 268 return mouse->buttonstate; |
266 } | 269 } |
267 | 270 |
268 void | 271 void |
269 SDL_SetMouseFocus(int index, SDL_WindowID windowID) | 272 SDL_SetMouseFocus(int id, SDL_WindowID windowID) |
270 { | 273 { |
274 int index = SDL_GetIndexById(id); | |
271 SDL_Mouse *mouse = SDL_GetMouse(index); | 275 SDL_Mouse *mouse = SDL_GetMouse(index); |
272 int i; | 276 int i; |
273 SDL_bool focus; | 277 SDL_bool focus; |
274 | 278 |
275 if (!mouse || (mouse->focus == windowID)) { | 279 if (!mouse || (mouse->focus == windowID)) { |
313 } | 317 } |
314 } | 318 } |
315 } | 319 } |
316 | 320 |
317 int | 321 int |
318 SDL_SendMouseMotion(int index, int relative, int x, int y) | 322 SDL_SendMouseMotion(int id, int relative, int x, int y,int z) |
319 { | 323 { |
324 int index=SDL_GetIndexById(id); | |
320 SDL_Mouse *mouse = SDL_GetMouse(index); | 325 SDL_Mouse *mouse = SDL_GetMouse(index); |
321 int posted; | 326 int posted; |
322 int xrel; | 327 int xrel; |
323 int yrel; | 328 int yrel; |
324 | 329 |
350 mouse->x = x; | 355 mouse->x = x; |
351 mouse->y = y; | 356 mouse->y = y; |
352 } | 357 } |
353 mouse->xdelta += xrel; | 358 mouse->xdelta += xrel; |
354 mouse->ydelta += yrel; | 359 mouse->ydelta += yrel; |
360 mouse->z=z; | |
355 | 361 |
356 /* Move the mouse cursor, if needed */ | 362 /* Move the mouse cursor, if needed */ |
357 if (mouse->cursor_shown && !mouse->relative_mode && | 363 if (mouse->cursor_shown && !mouse->relative_mode && |
358 mouse->MoveCursor && mouse->cur_cursor) { | 364 mouse->MoveCursor && mouse->cur_cursor) { |
359 mouse->MoveCursor(mouse->cur_cursor); | 365 mouse->MoveCursor(mouse->cur_cursor); |
366 event.motion.type = SDL_MOUSEMOTION; | 372 event.motion.type = SDL_MOUSEMOTION; |
367 event.motion.which = (Uint8) index; | 373 event.motion.which = (Uint8) index; |
368 event.motion.state = mouse->buttonstate; | 374 event.motion.state = mouse->buttonstate; |
369 event.motion.x = mouse->x; | 375 event.motion.x = mouse->x; |
370 event.motion.y = mouse->y; | 376 event.motion.y = mouse->y; |
377 event.motion.z = mouse->z; | |
371 event.motion.xrel = xrel; | 378 event.motion.xrel = xrel; |
372 event.motion.yrel = yrel; | 379 event.motion.yrel = yrel; |
373 event.motion.windowID = mouse->focus; | 380 event.motion.windowID = mouse->focus; |
374 posted = (SDL_PushEvent(&event) > 0); | 381 posted = (SDL_PushEvent(&event) > 0); |
375 } | 382 } |
376 return posted; | 383 return posted; |
377 } | 384 } |
378 | 385 |
379 int | 386 int |
380 SDL_SendMouseButton(int index, Uint8 state, Uint8 button) | 387 SDL_SendMouseButton(int id, Uint8 state, Uint8 button) |
381 { | 388 { |
389 int index=SDL_GetIndexById(id); | |
382 SDL_Mouse *mouse = SDL_GetMouse(index); | 390 SDL_Mouse *mouse = SDL_GetMouse(index); |
383 int posted; | 391 int posted; |
384 Uint8 type; | 392 Uint8 type; |
385 | 393 |
386 if (!mouse) { | 394 if (!mouse) { |
396 } | 404 } |
397 type = SDL_MOUSEBUTTONDOWN; | 405 type = SDL_MOUSEBUTTONDOWN; |
398 mouse->buttonstate |= SDL_BUTTON(button); | 406 mouse->buttonstate |= SDL_BUTTON(button); |
399 break; | 407 break; |
400 case SDL_RELEASED: | 408 case SDL_RELEASED: |
401 if (!(mouse->buttonstate & SDL_BUTTON(button))) { | 409 //if (!(mouse->buttonstate & SDL_BUTTON(button))) { |
402 /* Ignore this event, no state change */ | 410 // /* Ignore this event, no state change */ |
403 return 0; | 411 // return 0; |
404 } | 412 //}*/ |
405 type = SDL_MOUSEBUTTONUP; | 413 type = SDL_MOUSEBUTTONUP; |
406 mouse->buttonstate &= ~SDL_BUTTON(button); | 414 mouse->buttonstate &= ~SDL_BUTTON(button); |
407 break; | 415 break; |
408 default: | 416 default: |
409 /* Invalid state -- bail */ | 417 /* Invalid state -- bail */ |
461 | 469 |
462 if (mouse->WarpMouse) { | 470 if (mouse->WarpMouse) { |
463 mouse->WarpMouse(mouse, windowID, x, y); | 471 mouse->WarpMouse(mouse, windowID, x, y); |
464 } else { | 472 } else { |
465 SDL_SetMouseFocus(SDL_current_mouse, windowID); | 473 SDL_SetMouseFocus(SDL_current_mouse, windowID); |
466 SDL_SendMouseMotion(SDL_current_mouse, 0, x, y); | 474 SDL_SendMouseMotion(SDL_current_mouse, 0, x, y,0); |
467 } | 475 } |
468 } | 476 } |
469 | 477 |
470 SDL_Cursor * | 478 SDL_Cursor * |
471 SDL_CreateCursor(const Uint8 * data, const Uint8 * mask, | 479 SDL_CreateCursor(const Uint8 * data, const Uint8 * mask, |
647 } | 655 } |
648 } | 656 } |
649 return shown; | 657 return shown; |
650 } | 658 } |
651 | 659 |
660 void SDL_SetIndexId(int id, int index) | |
661 { | |
662 if(id>SDL_highestId) | |
663 { | |
664 int *indexes; | |
665 indexes = | |
666 (int*) SDL_realloc(SDL_IdIndex, | |
667 (id + 1) * sizeof(int)); | |
668 if (!indexes) { | |
669 SDL_OutOfMemory(); | |
670 return -1; | |
671 } | |
672 SDL_IdIndex=indexes; | |
673 SDL_IdIndex[id]=index; | |
674 SDL_highestId=id; | |
675 } | |
676 else | |
677 { | |
678 SDL_IdIndex[id]=index; | |
679 } | |
680 } | |
681 | |
682 int SDL_GetIndexById(int id) | |
683 { | |
684 if(id>SDL_highestId) | |
685 { | |
686 return -1; | |
687 } | |
688 else | |
689 { | |
690 return SDL_IdIndex[id]; | |
691 } | |
692 } | |
693 | |
694 int SDL_GetNumOfMice(void) | |
695 { | |
696 return SDL_num_mice; | |
697 } | |
698 | |
699 char* SDL_GetMouseName(int index) | |
700 { | |
701 SDL_Mouse* mouse = SDL_GetMouse(index); | |
702 if(!mouse) | |
703 { | |
704 return NULL; | |
705 } | |
706 return mouse->name; | |
707 } | |
708 | |
709 | |
652 /* vi: set ts=4 sw=4 expandtab: */ | 710 /* vi: set ts=4 sw=4 expandtab: */ |