comparison src/events/SDL_mouse.c @ 2860:6ce28e5287e9

Date: Sun, 07 Dec 2008 13:35:23 +0100 From: Couriersud Subject: SDL: Mouse last_x, last_y into SDL_Mouse the attached diff moves the static vars last_x and last_y into SDL_Mouse. These, as far as I understand it, should be tied to the individual mouse. The patch also makes the code check for out of window conditions of mouse->x,y when relative movements are passed to MouseSendMotion. Also attached is the latest DirectFB code (dfb20081208) supporting multiple mice and keyboards. This works quite well with sdlmame now. It however needs more testing with different directfb configurations.
author Sam Lantinga <slouken@libsdl.org>
date Mon, 08 Dec 2008 00:52:12 +0000
parents 99210400e8b9
children b93965a16fe0
comparison
equal deleted inserted replaced
2859:99210400e8b9 2860:6ce28e5287e9
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; /* the last reported x and y coordinates by the system cursor */
37 36
38 37
39 /* Public functions */ 38 /* Public functions */
40 int 39 int
41 SDL_MouseInit(void) 40 SDL_MouseInit(void)
59 SDL_SetError("Invalid Mouse ID"); 58 SDL_SetError("Invalid Mouse ID");
60 return -1; 59 return -1;
61 } 60 }
62 if (id > SDL_highestId) { 61 if (id > SDL_highestId) {
63 int *indexes; 62 int *indexes;
63 int i;
64 indexes = (int *) SDL_realloc(SDL_IdIndex, (id + 1) * sizeof(int)); 64 indexes = (int *) SDL_realloc(SDL_IdIndex, (id + 1) * sizeof(int));
65 if (!indexes) { 65 if (!indexes) {
66 SDL_OutOfMemory(); 66 SDL_OutOfMemory();
67 return -1; 67 return -1;
68 } 68 }
69 SDL_IdIndex = indexes; 69 SDL_IdIndex = indexes;
70 for (i = SDL_highestId + 1; i <= id; i++)
71 SDL_IdIndex[i] = -1;
70 SDL_IdIndex[id] = index; 72 SDL_IdIndex[id] = index;
71 SDL_highestId = id; 73 SDL_highestId = id;
72 } else { 74 } else {
73 SDL_IdIndex[id] = index; 75 SDL_IdIndex[id] = index;
74 } 76 }
376 378
377 if (!mouse) { 379 if (!mouse) {
378 return 0; 380 return 0;
379 } 381 }
380 382
381 last_x = x; 383 mouse->last_x = x;
382 last_y = y; 384 mouse->last_y = y;
383 if (SDL_ProcessEvents[type] == SDL_ENABLE) { 385 if (SDL_ProcessEvents[type] == SDL_ENABLE) {
384 SDL_Event event; 386 SDL_Event event;
385 event.proximity.which = (Uint8) index; 387 event.proximity.which = (Uint8) index;
386 event.proximity.x = x; 388 event.proximity.x = x;
387 event.proximity.y = y; 389 event.proximity.y = y;
403 int index = SDL_GetMouseIndexId(id); 405 int index = SDL_GetMouseIndexId(id);
404 SDL_Mouse *mouse = SDL_GetMouse(index); 406 SDL_Mouse *mouse = SDL_GetMouse(index);
405 int posted; 407 int posted;
406 int xrel; 408 int xrel;
407 int yrel; 409 int yrel;
410 int x_max = 0, y_max = 0;
408 411
409 if (!mouse || mouse->flush_motion) { 412 if (!mouse || mouse->flush_motion) {
410 return 0; 413 return 0;
411 } 414 }
412 415
413 /* if the mouse is out of proximity we don't to want to have any motion from it */ 416 /* if the mouse is out of proximity we don't to want to have any motion from it */
414 if (mouse->proximity == SDL_FALSE) { 417 if (mouse->proximity == SDL_FALSE) {
415 last_x = x; 418 mouse->last_x = x;
416 last_y = y; 419 mouse->last_y = y;
417 return 0; 420 return 0;
418 } 421 }
419 422
420 /* the relative motion is calculated regarding the system cursor last position */ 423 /* the relative motion is calculated regarding the system cursor last position */
421 if (relative) { 424 if (relative) {
422 xrel = x; 425 xrel = x;
423 yrel = y; 426 yrel = y;
424 x = (last_x + x); 427 x = (mouse->last_x + x);
425 y = (last_y + y); 428 y = (mouse->last_y + y);
426 } else { 429 } else {
427 xrel = x - last_x; 430 xrel = x - mouse->last_x;
428 yrel = y - last_y; 431 yrel = y - mouse->last_y;
429 } 432 }
430 433
431 /* Drop events that don't change state */ 434 /* Drop events that don't change state */
432 if (!xrel && !yrel) { 435 if (!xrel && !yrel) {
433 #if 0 436 #if 0
439 /* Update internal mouse coordinates */ 442 /* Update internal mouse coordinates */
440 if (mouse->relative_mode == SDL_FALSE) { 443 if (mouse->relative_mode == SDL_FALSE) {
441 mouse->x = x; 444 mouse->x = x;
442 mouse->y = y; 445 mouse->y = y;
443 } else { 446 } else {
444 /* while using the relative mode and many windows, we have to be 447 mouse->x += xrel;
445 sure that the pointers find themselves inside the windows */ 448 mouse->y += yrel;
446 int x_max, y_max; 449 }
447 450
448 SDL_GetWindowSize(mouse->focus, &x_max, &y_max); 451 SDL_GetWindowSize(mouse->focus, &x_max, &y_max);
449 452
450 if (mouse->x + xrel > x_max) { 453 /* make sure that the pointers find themselves inside the windows */
451 mouse->x = x_max; 454 /* only check if mouse->xmax is set ! */
452 } else if (mouse->x + xrel < 0) { 455 if (x_max && mouse->x > x_max) {
453 mouse->x = 0; 456 mouse->x = x_max;
454 } else { 457 } else if (mouse->x < 0) {
455 mouse->x += xrel; 458 mouse->x = 0;
456 } 459 }
457 if (mouse->y + yrel > y_max) { 460
458 mouse->y = y_max; 461 if (y_max && mouse->y > y_max) {
459 } else if (mouse->y + yrel < 0) { 462 mouse->y = y_max;
460 mouse->y = 0; 463 } else if (mouse->y < 0) {
461 } else { 464 mouse->y = 0;
462 mouse->y += yrel; 465 }
463 } 466
464 }
465 mouse->xdelta += xrel; 467 mouse->xdelta += xrel;
466 mouse->ydelta += yrel; 468 mouse->ydelta += yrel;
467 mouse->pressure = pressure; 469 mouse->pressure = pressure;
468 470
469 /* Move the mouse cursor, if needed */ 471 /* Move the mouse cursor, if needed */
489 event.motion.pressure_max = mouse->pressure_max; 491 event.motion.pressure_max = mouse->pressure_max;
490 event.motion.pressure_min = mouse->pressure_min; 492 event.motion.pressure_min = mouse->pressure_min;
491 event.motion.cursor = mouse->current_end; 493 event.motion.cursor = mouse->current_end;
492 posted = (SDL_PushEvent(&event) > 0); 494 posted = (SDL_PushEvent(&event) > 0);
493 } 495 }
494 last_x = x; 496 mouse->last_x = x;
495 last_y = y; 497 mouse->last_y = y;
496 return posted; 498 return posted;
497 } 499 }
498 500
499 int 501 int
500 SDL_SendMouseButton(int id, Uint8 state, Uint8 button) 502 SDL_SendMouseButton(int id, Uint8 state, Uint8 button)