src/events/SDL_mouse.c
branchgsoc2008_manymouse
changeset 3764 2970fcfbdd54
parent 3763 81ea7d9a6624
child 3765 ed9b7fe8f902
     1.1 --- a/src/events/SDL_mouse.c	Wed Jul 02 20:29:29 2008 +0000
     1.2 +++ b/src/events/SDL_mouse.c	Thu Jul 03 22:03:58 2008 +0000
     1.3 @@ -33,8 +33,8 @@
     1.4  static SDL_Mouse **SDL_mice;
     1.5  int *SDL_IdIndex;
     1.6  int SDL_highestId;
     1.7 -
     1.8 -
     1.9 +int last_x, last_y;
    1.10 +int x_max, y_max;
    1.11  /* Public functions */
    1.12  int
    1.13  SDL_MouseInit(void)
    1.14 @@ -85,6 +85,8 @@
    1.15          SDL_CreateCursor(default_cdata, default_cmask, DEFAULT_CWIDTH,
    1.16                           DEFAULT_CHEIGHT, DEFAULT_CHOTX, DEFAULT_CHOTY);
    1.17      SDL_SetCursor(SDL_mice[index]->def_cursor);
    1.18 +    SDL_mice[index]->proximity=SDL_TRUE;
    1.19 +    SDL_mice[index]->relative_mode=SDL_FALSE;
    1.20      SDL_SelectMouse(selected_mouse);
    1.21  
    1.22      return index;
    1.23 @@ -180,9 +182,9 @@
    1.24  }
    1.25  
    1.26  int
    1.27 -SDL_SetRelativeMouseMode(SDL_bool enabled)
    1.28 +SDL_SetRelativeMouseMode(SDL_bool enabled, int index)
    1.29  {
    1.30 -    SDL_Mouse *mouse = SDL_GetMouse(SDL_current_mouse);
    1.31 +    SDL_Mouse *mouse = SDL_GetMouse(index);
    1.32  
    1.33      if (!mouse) {
    1.34          return -1;
    1.35 @@ -326,12 +328,20 @@
    1.36      if(SDL_ProcessEvents[type]==SDL_ENABLE)
    1.37      {
    1.38          SDL_Event event;
    1.39 -        event.proximity.which=index;
    1.40 +        event.proximity.which=(Uint8)index;
    1.41          event.proximity.x=x;
    1.42          event.proximity.y=y;
    1.43          event.type=type;
    1.44          event.proximity.type=type;
    1.45          posted = (SDL_PushEvent(&event) > 0);
    1.46 +        if(type==SDL_PROXIMITYIN)
    1.47 +        {
    1.48 +            SDL_mice[index]->proximity=SDL_TRUE;
    1.49 +        }
    1.50 +        else
    1.51 +        {
    1.52 +            SDL_mice[index]->proximity=SDL_FALSE;
    1.53 +        }
    1.54      }
    1.55      return posted;
    1.56  }
    1.57 @@ -348,16 +358,21 @@
    1.58      if (!mouse || mouse->flush_motion) {
    1.59          return 0;
    1.60      }
    1.61 -
    1.62 -    if (relative) {
    1.63 +    if(mouse->proximity==SDL_FALSE)
    1.64 +    {
    1.65 +        last_x=x;
    1.66 +        last_y=y;
    1.67 +        return 0;
    1.68 +    }
    1.69 +    if (mouse->relative_mode==SDL_TRUE && mouse->proximity==SDL_TRUE) {
    1.70          /* Push the cursor around */
    1.71 -        xrel = x;
    1.72 -        yrel = y;
    1.73 -        x = (mouse->x + xrel);
    1.74 -        y = (mouse->y + yrel);
    1.75 +        xrel = x - last_x;
    1.76 +        yrel = y - last_y;
    1.77 +        //x = (mouse->x + xrel);
    1.78 +        //y = (mouse->y + yrel);
    1.79      } else {
    1.80 -        xrel = x - mouse->x;
    1.81 -        yrel = y - mouse->y;
    1.82 +        xrel = x - last_x;
    1.83 +        yrel = y - last_y;
    1.84      }
    1.85  
    1.86      /* Drop events that don't change state */
    1.87 @@ -369,10 +384,37 @@
    1.88      }
    1.89  
    1.90      /* Update internal mouse state */
    1.91 -    if (!mouse->relative_mode) {
    1.92 +    if (mouse->relative_mode==SDL_FALSE) {
    1.93          mouse->x = x;
    1.94          mouse->y = y;
    1.95      }
    1.96 +    else
    1.97 +    {
    1.98 +        if(mouse->x+xrel>x_max)
    1.99 +        {
   1.100 +            mouse->x=x_max;
   1.101 +        }
   1.102 +        else if(mouse->x+xrel<0)
   1.103 +        {
   1.104 +            mouse->x=0;
   1.105 +        }
   1.106 +        else
   1.107 +        {
   1.108 +            mouse->x+=xrel;
   1.109 +        }
   1.110 +        if(mouse->y+yrel>y_max)
   1.111 +        {
   1.112 +            mouse->y=y_max;
   1.113 +        }
   1.114 +        else if(mouse->y+yrel<0)
   1.115 +        {
   1.116 +            mouse->y=0;
   1.117 +        }
   1.118 +        else
   1.119 +        {
   1.120 +            mouse->y+=yrel;
   1.121 +        }
   1.122 +    }
   1.123      mouse->xdelta += xrel;
   1.124      mouse->ydelta += yrel;
   1.125      mouse->z=z;
   1.126 @@ -385,10 +427,10 @@
   1.127  
   1.128      /* Post the event, if desired */
   1.129      posted = 0;
   1.130 -    if (SDL_ProcessEvents[SDL_MOUSEMOTION] == SDL_ENABLE) {
   1.131 +    if (SDL_ProcessEvents[SDL_MOUSEMOTION] == SDL_ENABLE && SDL_mice[index]->proximity==SDL_TRUE) {
   1.132          SDL_Event event;
   1.133          event.motion.type = SDL_MOUSEMOTION;
   1.134 -        event.motion.which = (Uint8) index;
   1.135 +event.motion.which = (Uint8) index;
   1.136          event.motion.state = mouse->buttonstate;
   1.137          event.motion.x = mouse->x;
   1.138          event.motion.y = mouse->y;
   1.139 @@ -398,6 +440,8 @@
   1.140          event.motion.windowID = mouse->focus;
   1.141          posted = (SDL_PushEvent(&event) > 0);
   1.142      }
   1.143 +    last_x=x;
   1.144 +    last_y=y;
   1.145      return posted;
   1.146  }
   1.147  
   1.148 @@ -724,5 +768,9 @@
   1.149      return mouse->name;
   1.150  }
   1.151  
   1.152 -
   1.153 +void SDL_UpdateCoordinates(int x, int y)
   1.154 +{
   1.155 +    x_max=x;
   1.156 +    y_max=y;
   1.157 +}
   1.158  /* vi: set ts=4 sw=4 expandtab: */