Mercurial > sdl-ios-xcode
comparison src/events/SDL_mouse.c @ 3771:8cc36a399a12 gsoc2008_manymouse
comments added and improved code look(windows part)
author | Szymon Wilczek <kazeuser@gmail.com> |
---|---|
date | Sat, 02 Aug 2008 14:02:28 +0000 |
parents | 81b649bad6d2 |
children | 8b5b67000dc0 |
comparison
equal
deleted
inserted
replaced
3770:81b649bad6d2 | 3771:8cc36a399a12 |
---|---|
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; | 34 static int *SDL_IdIndex=NULL; |
35 static int SDL_highestId=-1; | 35 static int SDL_highestId=-1; |
36 static int last_x, last_y; | 36 static int last_x, last_y;/*the last reported x and y coordinates by the system cursor*/ |
37 int x_max, y_max; | 37 int x_max, y_max; /*current window width and height*/ |
38 /* Public functions */ | 38 /* Public functions */ |
39 int | 39 int |
40 SDL_MouseInit(void) | 40 SDL_MouseInit(void) |
41 { | 41 { |
42 return (0); | 42 return (0); |
75 if (!SDL_mice[index]) { | 75 if (!SDL_mice[index]) { |
76 SDL_OutOfMemory(); | 76 SDL_OutOfMemory(); |
77 return -1; | 77 return -1; |
78 } | 78 } |
79 *SDL_mice[index] = *mouse; | 79 *SDL_mice[index] = *mouse; |
80 | |
81 /*we're setting the mouse properties*/ | |
80 length=0; | 82 length=0; |
81 length=SDL_strlen(name); | 83 length=SDL_strlen(name); |
82 SDL_mice[index]->name=SDL_malloc((length+1)*sizeof(char)); | 84 SDL_mice[index]->name=SDL_malloc((length+1)*sizeof(char)); |
83 SDL_strlcpy(SDL_mice[index]->name,name,length); | 85 SDL_strlcpy(SDL_mice[index]->name,name,length); |
84 SDL_mice[index]->pressure_max=pressure_max; | 86 SDL_mice[index]->pressure_max=pressure_max; |
88 SDL_mice[index]->cur_cursor = NULL; | 90 SDL_mice[index]->cur_cursor = NULL; |
89 SDL_mice[index]->def_cursor = | 91 SDL_mice[index]->def_cursor = |
90 SDL_CreateCursor(default_cdata, default_cmask, DEFAULT_CWIDTH, | 92 SDL_CreateCursor(default_cdata, default_cmask, DEFAULT_CWIDTH, |
91 DEFAULT_CHEIGHT, DEFAULT_CHOTX, DEFAULT_CHOTY); | 93 DEFAULT_CHEIGHT, DEFAULT_CHOTX, DEFAULT_CHOTY); |
92 SDL_SetCursor(SDL_mice[index]->def_cursor); | 94 SDL_SetCursor(SDL_mice[index]->def_cursor); |
95 /*we're assuming that all mouses are in the computer sensing zone*/ | |
93 SDL_mice[index]->proximity=SDL_TRUE; | 96 SDL_mice[index]->proximity=SDL_TRUE; |
97 /*we're assuming that all mouses are working in the absolute position mode | |
98 thanx to that, the users that don't want to use many mouses don't have to | |
99 worry about anything*/ | |
94 SDL_mice[index]->relative_mode=SDL_FALSE; | 100 SDL_mice[index]->relative_mode=SDL_FALSE; |
95 SDL_SelectMouse(selected_mouse); | 101 SDL_SelectMouse(selected_mouse); |
96 | 102 |
97 return index; | 103 return index; |
98 } | 104 } |
359 int index=SDL_GetIndexById(id); | 365 int index=SDL_GetIndexById(id); |
360 SDL_Mouse *mouse = SDL_GetMouse(index); | 366 SDL_Mouse *mouse = SDL_GetMouse(index); |
361 int posted; | 367 int posted; |
362 int xrel; | 368 int xrel; |
363 int yrel; | 369 int yrel; |
370 /*while using the relative mode and many windows, we have to be sure, | |
371 that the pointers find themselves inside the windows*/ | |
364 if(x>x_max) | 372 if(x>x_max) |
365 { | 373 { |
366 x=x_max; | 374 x=x_max; |
367 } | 375 } |
368 if(y>y_max) | 376 if(y>y_max) |
369 { | 377 { |
370 y=y_max; | 378 y=y_max; |
371 } | 379 } |
380 | |
372 if (!mouse || mouse->flush_motion) { | 381 if (!mouse || mouse->flush_motion) { |
373 return 0; | 382 return 0; |
374 } | 383 } |
384 | |
385 /*if the mouse is out of proximity we don't to want to have any motion from it*/ | |
375 if(mouse->proximity==SDL_FALSE) | 386 if(mouse->proximity==SDL_FALSE) |
376 { | 387 { |
377 last_x=x; | 388 last_x=x; |
378 last_y=y; | 389 last_y=y; |
379 return 0; | 390 return 0; |
380 } | 391 } |
381 if (mouse->relative_mode==SDL_TRUE && mouse->proximity==SDL_TRUE) { | 392 |
382 /* Push the cursor around */ | 393 /*the relative motion is calculated regarding the system cursor last position*/ |
383 xrel = x - last_x; | 394 |
384 yrel = y - last_y; | 395 xrel = x - last_x; |
385 } else { | 396 yrel = y - last_y; |
386 xrel = x - last_x; | |
387 yrel = y - last_y; | |
388 } | |
389 | 397 |
390 /* Drop events that don't change state */ | 398 /* Drop events that don't change state */ |
391 if (!xrel && !yrel) { | 399 if (!xrel && !yrel) { |
392 #if 0 | 400 #if 0 |
393 printf("Mouse event didn't change state - dropped!\n"); | 401 printf("Mouse event didn't change state - dropped!\n"); |
394 #endif | 402 #endif |
395 return 0; | 403 return 0; |
396 } | 404 } |
397 | 405 |
398 /* Update internal mouse state */ | 406 /* Update internal mouse coordinates */ |
399 if (mouse->relative_mode==SDL_FALSE) { | 407 if (mouse->relative_mode==SDL_FALSE) { |
400 mouse->x = x; | 408 mouse->x = x; |
401 mouse->y = y; | 409 mouse->y = y; |
402 } | 410 } |
403 else | 411 else |