comparison src/events/SDL_mouse.c @ 2794:f7872b7a8732

Fixed mouse coordinate range on Mac OS X
author Sam Lantinga <slouken@libsdl.org>
date Thu, 27 Nov 2008 21:53:18 +0000
parents f55c87ae336b
children 97ba0be8b565
comparison
equal deleted inserted replaced
2793:b14f672b2857 2794:f7872b7a8732
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; /* the last reported x and y coordinates by the system cursor */ 36 static int last_x, last_y; /* the last reported x and y coordinates by the system cursor */
37 int x_max, y_max; /* current window width and height */
38 37
39 38
40 /* Public functions */ 39 /* Public functions */
41 int 40 int
42 SDL_MouseInit(void) 41 SDL_MouseInit(void)
363 } 362 }
364 } 363 }
365 if (!focus) { 364 if (!focus) {
366 SDL_SendWindowEvent(mouse->focus, SDL_WINDOWEVENT_ENTER, 0, 0); 365 SDL_SendWindowEvent(mouse->focus, SDL_WINDOWEVENT_ENTER, 0, 0);
367 } 366 }
367 SDL_GetWindowSize(windowID, &mouse->x_max, &mouse->y_max);
368 }
369 }
370
371 void
372 SDL_SetMouseFocusSize(SDL_WindowID windowID, int w, int h)
373 {
374 int i;
375
376 for (i = 0; i < SDL_num_mice; ++i) {
377 SDL_Mouse *mouse = SDL_GetMouse(i);
378 if (mouse && mouse->focus == windowID) {
379 mouse->x_max = w;
380 mouse->y_max = h;
381 }
368 } 382 }
369 } 383 }
370 384
371 int 385 int
372 SDL_SendProximity(int id, int x, int y, int type) 386 SDL_SendProximity(int id, int x, int y, int type)
405 SDL_Mouse *mouse = SDL_GetMouse(index); 419 SDL_Mouse *mouse = SDL_GetMouse(index);
406 int posted; 420 int posted;
407 int xrel; 421 int xrel;
408 int yrel; 422 int yrel;
409 423
410 /* while using the relative mode and many windows, we have to be sure,
411 that the pointers find themselves inside the windows */
412 if (x > x_max) {
413 x = x_max;
414 }
415 if (y > y_max) {
416 y = y_max;
417 }
418
419 if (!mouse || mouse->flush_motion) { 424 if (!mouse || mouse->flush_motion) {
420 return 0; 425 return 0;
421 } 426 }
422 427
423 /* if the mouse is out of proximity we don't to want to have any motion from it */ 428 /* if the mouse is out of proximity we don't to want to have any motion from it */
443 /* Update internal mouse coordinates */ 448 /* Update internal mouse coordinates */
444 if (mouse->relative_mode == SDL_FALSE) { 449 if (mouse->relative_mode == SDL_FALSE) {
445 mouse->x = x; 450 mouse->x = x;
446 mouse->y = y; 451 mouse->y = y;
447 } else { 452 } else {
448 if (mouse->x + xrel > x_max) { 453 /* while using the relative mode and many windows, we have to be
449 mouse->x = x_max; 454 sure that the pointers find themselves inside the windows */
455 if (mouse->x + xrel > mouse->x_max) {
456 mouse->x = mouse->x_max;
450 } else if (mouse->x + xrel < 0) { 457 } else if (mouse->x + xrel < 0) {
451 mouse->x = 0; 458 mouse->x = 0;
452 } else { 459 } else {
453 mouse->x += xrel; 460 mouse->x += xrel;
454 } 461 }
455 if (mouse->y + yrel > y_max) { 462 if (mouse->y + yrel > mouse->y_max) {
456 mouse->y = y_max; 463 mouse->y = mouse->y_max;
457 } else if (mouse->y + yrel < 0) { 464 } else if (mouse->y + yrel < 0) {
458 mouse->y = 0; 465 mouse->y = 0;
459 } else { 466 } else {
460 mouse->y += yrel; 467 mouse->y += yrel;
461 } 468 }
777 } 784 }
778 return mouse->name; 785 return mouse->name;
779 } 786 }
780 787
781 void 788 void
782 SDL_UpdateCoordinates(int x, int y)
783 {
784 x_max = x;
785 y_max = y;
786 }
787
788 void
789 SDL_ChangeEnd(int id, int end) 789 SDL_ChangeEnd(int id, int end)
790 { 790 {
791 int index = SDL_GetMouseIndexId(id); 791 int index = SDL_GetMouseIndexId(id);
792 SDL_Mouse *mouse = SDL_GetMouse(index); 792 SDL_Mouse *mouse = SDL_GetMouse(index);
793 793