src/events/SDL_mouse.c
branchgsoc2008_manymouse
changeset 3771 8cc36a399a12
parent 3770 81b649bad6d2
child 3774 8b5b67000dc0
     1.1 --- a/src/events/SDL_mouse.c	Thu Jul 31 14:41:48 2008 +0000
     1.2 +++ b/src/events/SDL_mouse.c	Sat Aug 02 14:02:28 2008 +0000
     1.3 @@ -33,8 +33,8 @@
     1.4  static SDL_Mouse **SDL_mice=NULL;
     1.5  static int *SDL_IdIndex=NULL;
     1.6  static int SDL_highestId=-1;
     1.7 -static int last_x, last_y;
     1.8 -int x_max, y_max;
     1.9 +static int last_x, last_y;/*the last reported x and y coordinates by the system cursor*/
    1.10 +int x_max, y_max; /*current window width and height*/
    1.11  /* Public functions */
    1.12  int
    1.13  SDL_MouseInit(void)
    1.14 @@ -77,6 +77,8 @@
    1.15          return -1;
    1.16      }
    1.17      *SDL_mice[index] = *mouse;
    1.18 +
    1.19 +	/*we're setting the mouse properties*/
    1.20  	length=0;
    1.21  	length=SDL_strlen(name);
    1.22      SDL_mice[index]->name=SDL_malloc((length+1)*sizeof(char));
    1.23 @@ -90,7 +92,11 @@
    1.24          SDL_CreateCursor(default_cdata, default_cmask, DEFAULT_CWIDTH,
    1.25                           DEFAULT_CHEIGHT, DEFAULT_CHOTX, DEFAULT_CHOTY);
    1.26      SDL_SetCursor(SDL_mice[index]->def_cursor);
    1.27 +	/*we're assuming that all mouses are in the computer sensing zone*/
    1.28      SDL_mice[index]->proximity=SDL_TRUE;
    1.29 +	/*we're assuming that all mouses are working in the absolute position mode
    1.30 +	thanx to that, the users that don't want to use many mouses don't have to
    1.31 +	worry about anything*/
    1.32      SDL_mice[index]->relative_mode=SDL_FALSE;
    1.33      SDL_SelectMouse(selected_mouse);
    1.34  
    1.35 @@ -361,6 +367,8 @@
    1.36      int posted;
    1.37      int xrel;
    1.38      int yrel;
    1.39 +	/*while using the relative mode and many windows, we have to be sure,
    1.40 +	that the pointers find themselves inside the windows*/
    1.41  	if(x>x_max)
    1.42  	{
    1.43  		x=x_max;
    1.44 @@ -369,23 +377,23 @@
    1.45  	{
    1.46  		y=y_max;
    1.47  	}
    1.48 +
    1.49      if (!mouse || mouse->flush_motion) {
    1.50          return 0;
    1.51      }
    1.52 +
    1.53 +	/*if the mouse is out of proximity we don't to want to have any motion from it*/
    1.54      if(mouse->proximity==SDL_FALSE)
    1.55      {
    1.56          last_x=x;
    1.57          last_y=y;
    1.58          return 0;
    1.59      }
    1.60 -    if (mouse->relative_mode==SDL_TRUE && mouse->proximity==SDL_TRUE) {
    1.61 -        /* Push the cursor around */
    1.62 -        xrel = x - last_x;
    1.63 -        yrel = y - last_y;
    1.64 -    } else {
    1.65 -        xrel = x - last_x;
    1.66 -        yrel = y - last_y;
    1.67 -    }
    1.68 +
    1.69 +	/*the relative motion is calculated regarding the system cursor last position*/
    1.70 +
    1.71 +    xrel = x - last_x;
    1.72 +    yrel = y - last_y;
    1.73  
    1.74      /* Drop events that don't change state */
    1.75      if (!xrel && !yrel) {
    1.76 @@ -395,7 +403,7 @@
    1.77          return 0;
    1.78      }
    1.79  
    1.80 -    /* Update internal mouse state */
    1.81 +    /* Update internal mouse coordinates */
    1.82      if (mouse->relative_mode==SDL_FALSE) {
    1.83          mouse->x = x;
    1.84          mouse->y = y;