Relative mode for tablets. Info on wiki. gsoc2008_manymouse
authorSzymon Wilczek <kazeuser@gmail.com>
Thu, 03 Jul 2008 22:03:58 +0000
branchgsoc2008_manymouse
changeset 37642970fcfbdd54
parent 3763 81ea7d9a6624
child 3765 ed9b7fe8f902
Relative mode for tablets. Info on wiki.
include/SDL_mouse.h
src/events/SDL_mouse.c
src/events/SDL_mouse_c.h
src/video/x11/SDL_x11events.c
src/video/x11/SDL_x11video.c
     1.1 --- a/include/SDL_mouse.h	Wed Jul 02 20:29:29 2008 +0000
     1.2 +++ b/include/SDL_mouse.h	Thu Jul 03 22:03:58 2008 +0000
     1.3 @@ -92,7 +92,7 @@
     1.4   *
     1.5   * \sa SDL_GetRelativeMouseMode()
     1.6   */
     1.7 -extern DECLSPEC int SDLCALL SDL_SetRelativeMouseMode(SDL_bool enabled);
     1.8 +extern DECLSPEC int SDLCALL SDL_SetRelativeMouseMode(SDL_bool enabled, int index);
     1.9  
    1.10  /**
    1.11   * \fn SDL_bool SDL_GetRelativeMouseMode()
     2.1 --- a/src/events/SDL_mouse.c	Wed Jul 02 20:29:29 2008 +0000
     2.2 +++ b/src/events/SDL_mouse.c	Thu Jul 03 22:03:58 2008 +0000
     2.3 @@ -33,8 +33,8 @@
     2.4  static SDL_Mouse **SDL_mice;
     2.5  int *SDL_IdIndex;
     2.6  int SDL_highestId;
     2.7 -
     2.8 -
     2.9 +int last_x, last_y;
    2.10 +int x_max, y_max;
    2.11  /* Public functions */
    2.12  int
    2.13  SDL_MouseInit(void)
    2.14 @@ -85,6 +85,8 @@
    2.15          SDL_CreateCursor(default_cdata, default_cmask, DEFAULT_CWIDTH,
    2.16                           DEFAULT_CHEIGHT, DEFAULT_CHOTX, DEFAULT_CHOTY);
    2.17      SDL_SetCursor(SDL_mice[index]->def_cursor);
    2.18 +    SDL_mice[index]->proximity=SDL_TRUE;
    2.19 +    SDL_mice[index]->relative_mode=SDL_FALSE;
    2.20      SDL_SelectMouse(selected_mouse);
    2.21  
    2.22      return index;
    2.23 @@ -180,9 +182,9 @@
    2.24  }
    2.25  
    2.26  int
    2.27 -SDL_SetRelativeMouseMode(SDL_bool enabled)
    2.28 +SDL_SetRelativeMouseMode(SDL_bool enabled, int index)
    2.29  {
    2.30 -    SDL_Mouse *mouse = SDL_GetMouse(SDL_current_mouse);
    2.31 +    SDL_Mouse *mouse = SDL_GetMouse(index);
    2.32  
    2.33      if (!mouse) {
    2.34          return -1;
    2.35 @@ -326,12 +328,20 @@
    2.36      if(SDL_ProcessEvents[type]==SDL_ENABLE)
    2.37      {
    2.38          SDL_Event event;
    2.39 -        event.proximity.which=index;
    2.40 +        event.proximity.which=(Uint8)index;
    2.41          event.proximity.x=x;
    2.42          event.proximity.y=y;
    2.43          event.type=type;
    2.44          event.proximity.type=type;
    2.45          posted = (SDL_PushEvent(&event) > 0);
    2.46 +        if(type==SDL_PROXIMITYIN)
    2.47 +        {
    2.48 +            SDL_mice[index]->proximity=SDL_TRUE;
    2.49 +        }
    2.50 +        else
    2.51 +        {
    2.52 +            SDL_mice[index]->proximity=SDL_FALSE;
    2.53 +        }
    2.54      }
    2.55      return posted;
    2.56  }
    2.57 @@ -348,16 +358,21 @@
    2.58      if (!mouse || mouse->flush_motion) {
    2.59          return 0;
    2.60      }
    2.61 -
    2.62 -    if (relative) {
    2.63 +    if(mouse->proximity==SDL_FALSE)
    2.64 +    {
    2.65 +        last_x=x;
    2.66 +        last_y=y;
    2.67 +        return 0;
    2.68 +    }
    2.69 +    if (mouse->relative_mode==SDL_TRUE && mouse->proximity==SDL_TRUE) {
    2.70          /* Push the cursor around */
    2.71 -        xrel = x;
    2.72 -        yrel = y;
    2.73 -        x = (mouse->x + xrel);
    2.74 -        y = (mouse->y + yrel);
    2.75 +        xrel = x - last_x;
    2.76 +        yrel = y - last_y;
    2.77 +        //x = (mouse->x + xrel);
    2.78 +        //y = (mouse->y + yrel);
    2.79      } else {
    2.80 -        xrel = x - mouse->x;
    2.81 -        yrel = y - mouse->y;
    2.82 +        xrel = x - last_x;
    2.83 +        yrel = y - last_y;
    2.84      }
    2.85  
    2.86      /* Drop events that don't change state */
    2.87 @@ -369,10 +384,37 @@
    2.88      }
    2.89  
    2.90      /* Update internal mouse state */
    2.91 -    if (!mouse->relative_mode) {
    2.92 +    if (mouse->relative_mode==SDL_FALSE) {
    2.93          mouse->x = x;
    2.94          mouse->y = y;
    2.95      }
    2.96 +    else
    2.97 +    {
    2.98 +        if(mouse->x+xrel>x_max)
    2.99 +        {
   2.100 +            mouse->x=x_max;
   2.101 +        }
   2.102 +        else if(mouse->x+xrel<0)
   2.103 +        {
   2.104 +            mouse->x=0;
   2.105 +        }
   2.106 +        else
   2.107 +        {
   2.108 +            mouse->x+=xrel;
   2.109 +        }
   2.110 +        if(mouse->y+yrel>y_max)
   2.111 +        {
   2.112 +            mouse->y=y_max;
   2.113 +        }
   2.114 +        else if(mouse->y+yrel<0)
   2.115 +        {
   2.116 +            mouse->y=0;
   2.117 +        }
   2.118 +        else
   2.119 +        {
   2.120 +            mouse->y+=yrel;
   2.121 +        }
   2.122 +    }
   2.123      mouse->xdelta += xrel;
   2.124      mouse->ydelta += yrel;
   2.125      mouse->z=z;
   2.126 @@ -385,10 +427,10 @@
   2.127  
   2.128      /* Post the event, if desired */
   2.129      posted = 0;
   2.130 -    if (SDL_ProcessEvents[SDL_MOUSEMOTION] == SDL_ENABLE) {
   2.131 +    if (SDL_ProcessEvents[SDL_MOUSEMOTION] == SDL_ENABLE && SDL_mice[index]->proximity==SDL_TRUE) {
   2.132          SDL_Event event;
   2.133          event.motion.type = SDL_MOUSEMOTION;
   2.134 -        event.motion.which = (Uint8) index;
   2.135 +event.motion.which = (Uint8) index;
   2.136          event.motion.state = mouse->buttonstate;
   2.137          event.motion.x = mouse->x;
   2.138          event.motion.y = mouse->y;
   2.139 @@ -398,6 +440,8 @@
   2.140          event.motion.windowID = mouse->focus;
   2.141          posted = (SDL_PushEvent(&event) > 0);
   2.142      }
   2.143 +    last_x=x;
   2.144 +    last_y=y;
   2.145      return posted;
   2.146  }
   2.147  
   2.148 @@ -724,5 +768,9 @@
   2.149      return mouse->name;
   2.150  }
   2.151  
   2.152 -
   2.153 +void SDL_UpdateCoordinates(int x, int y)
   2.154 +{
   2.155 +    x_max=x;
   2.156 +    y_max=y;
   2.157 +}
   2.158  /* vi: set ts=4 sw=4 expandtab: */
     3.1 --- a/src/events/SDL_mouse_c.h	Wed Jul 02 20:29:29 2008 +0000
     3.2 +++ b/src/events/SDL_mouse_c.h	Thu Jul 03 22:03:58 2008 +0000
     3.3 @@ -67,6 +67,7 @@
     3.4      char* name;
     3.5      Uint8 buttonstate;
     3.6      SDL_bool relative_mode;
     3.7 +    SDL_bool proximity;
     3.8      SDL_bool flush_motion;
     3.9  
    3.10      SDL_Cursor *cursors;
    3.11 @@ -118,7 +119,7 @@
    3.12  
    3.13  extern char* SDL_GetMouseName(int index);
    3.14  
    3.15 -
    3.16 +extern void SDL_UpdateCoordinates(int x, int y);
    3.17  
    3.18  #endif /* _SDL_mouse_c_h */
    3.19  
     4.1 --- a/src/video/x11/SDL_x11events.c	Wed Jul 02 20:29:29 2008 +0000
     4.2 +++ b/src/video/x11/SDL_x11events.c	Thu Jul 03 22:03:58 2008 +0000
     4.3 @@ -37,6 +37,7 @@
     4.4  extern int button_released;
     4.5  extern int proximity_in;
     4.6  extern int proximity_out;
     4.7 +extern int x_max,y_max;
     4.8  
     4.9  
    4.10  static void
    4.11 @@ -126,8 +127,8 @@
    4.12                  (xevent.xcrossing.mode != NotifyUngrab) &&
    4.13                  (xevent.xcrossing.detail != NotifyInferior)) {
    4.14  			    XDeviceMotionEvent* move=(XDeviceMotionEvent*)&xevent;
    4.15 -                SDL_SendMouseMotion(move->deviceid, 0,
    4.16 -                                    move->x, move->y,move->axis_data[2]);
    4.17 +                //SDL_SendMouseMotion(move->deviceid, 0,
    4.18 +                //                    move->x, move->y,move->axis_data[2]);
    4.19                  SDL_SetMouseFocus(move->deviceid, 0);
    4.20              }
    4.21          }
    4.22 @@ -297,6 +298,11 @@
    4.23  #ifdef DEBUG_MOTION
    4.24                  printf("X11 motion: %d,%d\n", xevent.xmotion.x, xevent.xmotion.y);
    4.25  #endif
    4.26 +                XWindowAttributes attrib;
    4.27 +                XGetWindowAttributes(videodata->display, ((XAnyEvent*)&xevent)->window, &attrib);
    4.28 +                /*x_max=attrib.width;
    4.29 +                y_max=attrib.height;*/
    4.30 +                SDL_UpdateCoordinates(attrib.width, attrib.height);
    4.31  			    XDeviceMotionEvent* move=(XDeviceMotionEvent*)&xevent;
    4.32                  SDL_SendMouseMotion(move->deviceid, 0, move->x,
    4.33                                  move->y,move->axis_data[2]);
     5.1 --- a/src/video/x11/SDL_x11video.c	Wed Jul 02 20:29:29 2008 +0000
     5.2 +++ b/src/video/x11/SDL_x11video.c	Thu Jul 03 22:03:58 2008 +0000
     5.3 @@ -362,4 +362,9 @@
     5.4      free(SDL_XDevices);
     5.5  }
     5.6  
     5.7 +/*void X11_ForwardWindowCoordinates(int x, int y)
     5.8 +{
     5.9 +    SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
    5.10 +}*/
    5.11 +
    5.12  /* vim: set ts=4 sw=4 expandtab: */