src/events/SDL_mouse.c
branchgsoc2008_manymouse
changeset 3760 64f346a83ed3
parent 2152 003c1b5b07da
child 3763 81ea7d9a6624
     1.1 --- a/src/events/SDL_mouse.c	Fri Jun 06 14:50:56 2008 +0000
     1.2 +++ b/src/events/SDL_mouse.c	Fri Jun 06 15:23:29 2008 +0000
     1.3 @@ -31,6 +31,8 @@
     1.4  static int SDL_num_mice;
     1.5  static int SDL_current_mouse;
     1.6  static SDL_Mouse **SDL_mice;
     1.7 +int *SDL_IdIndex;
     1.8 +int SDL_highestId;
     1.9  
    1.10  
    1.11  /* Public functions */
    1.12 @@ -50,11 +52,11 @@
    1.13  }
    1.14  
    1.15  int
    1.16 -SDL_AddMouse(const SDL_Mouse * mouse, int index)
    1.17 +SDL_AddMouse(const SDL_Mouse * mouse, int index, char* name)
    1.18  {
    1.19      SDL_Mouse **mice;
    1.20      int selected_mouse;
    1.21 -
    1.22 +    char* temp_name;
    1.23      /* Add the mouse to the list of mice */
    1.24      if (index < 0 || index >= SDL_num_mice || SDL_mice[index]) {
    1.25          mice =
    1.26 @@ -74,8 +76,8 @@
    1.27          return -1;
    1.28      }
    1.29      *SDL_mice[index] = *mouse;
    1.30 -
    1.31 -    /* Create the default cursor for the mouse */
    1.32 +    SDL_mice[index]->name=SDL_malloc(strlen(name)*sizeof(char));
    1.33 +    strcpy(SDL_mice[index]->name,name);
    1.34      SDL_mice[index]->cursor_shown = SDL_TRUE;
    1.35      selected_mouse = SDL_SelectMouse(index);
    1.36      SDL_mice[index]->cur_cursor = NULL;
    1.37 @@ -98,6 +100,7 @@
    1.38      }
    1.39  
    1.40      mouse->def_cursor = NULL;
    1.41 +    SDL_free(mouse->name);
    1.42      while (mouse->cursors) {
    1.43          SDL_FreeCursor(mouse->cursors);
    1.44      }
    1.45 @@ -266,8 +269,9 @@
    1.46  }
    1.47  
    1.48  void
    1.49 -SDL_SetMouseFocus(int index, SDL_WindowID windowID)
    1.50 +SDL_SetMouseFocus(int id, SDL_WindowID windowID)
    1.51  {
    1.52 +    int index = SDL_GetIndexById(id);
    1.53      SDL_Mouse *mouse = SDL_GetMouse(index);
    1.54      int i;
    1.55      SDL_bool focus;
    1.56 @@ -315,8 +319,9 @@
    1.57  }
    1.58  
    1.59  int
    1.60 -SDL_SendMouseMotion(int index, int relative, int x, int y)
    1.61 +SDL_SendMouseMotion(int id, int relative, int x, int y,int z)
    1.62  {
    1.63 +    int index=SDL_GetIndexById(id);
    1.64      SDL_Mouse *mouse = SDL_GetMouse(index);
    1.65      int posted;
    1.66      int xrel;
    1.67 @@ -352,6 +357,7 @@
    1.68      }
    1.69      mouse->xdelta += xrel;
    1.70      mouse->ydelta += yrel;
    1.71 +    mouse->z=z;
    1.72  
    1.73      /* Move the mouse cursor, if needed */
    1.74      if (mouse->cursor_shown && !mouse->relative_mode &&
    1.75 @@ -368,6 +374,7 @@
    1.76          event.motion.state = mouse->buttonstate;
    1.77          event.motion.x = mouse->x;
    1.78          event.motion.y = mouse->y;
    1.79 +        event.motion.z = mouse->z;
    1.80          event.motion.xrel = xrel;
    1.81          event.motion.yrel = yrel;
    1.82          event.motion.windowID = mouse->focus;
    1.83 @@ -377,8 +384,9 @@
    1.84  }
    1.85  
    1.86  int
    1.87 -SDL_SendMouseButton(int index, Uint8 state, Uint8 button)
    1.88 +SDL_SendMouseButton(int id, Uint8 state, Uint8 button)
    1.89  {
    1.90 +    int index=SDL_GetIndexById(id);
    1.91      SDL_Mouse *mouse = SDL_GetMouse(index);
    1.92      int posted;
    1.93      Uint8 type;
    1.94 @@ -398,10 +406,10 @@
    1.95          mouse->buttonstate |= SDL_BUTTON(button);
    1.96          break;
    1.97      case SDL_RELEASED:
    1.98 -        if (!(mouse->buttonstate & SDL_BUTTON(button))) {
    1.99 -            /* Ignore this event, no state change */
   1.100 -            return 0;
   1.101 -        }
   1.102 +        //if (!(mouse->buttonstate & SDL_BUTTON(button))) {
   1.103 +        //    /* Ignore this event, no state change */
   1.104 +        //    return 0;
   1.105 +        //}*/
   1.106          type = SDL_MOUSEBUTTONUP;
   1.107          mouse->buttonstate &= ~SDL_BUTTON(button);
   1.108          break;
   1.109 @@ -463,7 +471,7 @@
   1.110          mouse->WarpMouse(mouse, windowID, x, y);
   1.111      } else {
   1.112          SDL_SetMouseFocus(SDL_current_mouse, windowID);
   1.113 -        SDL_SendMouseMotion(SDL_current_mouse, 0, x, y);
   1.114 +        SDL_SendMouseMotion(SDL_current_mouse, 0, x, y,0);
   1.115      }
   1.116  }
   1.117  
   1.118 @@ -649,4 +657,54 @@
   1.119      return shown;
   1.120  }
   1.121  
   1.122 +void SDL_SetIndexId(int id, int index)
   1.123 +{
   1.124 +    if(id>SDL_highestId)
   1.125 +    {
   1.126 +        int *indexes;
   1.127 +        indexes =
   1.128 +            (int*) SDL_realloc(SDL_IdIndex,
   1.129 +                                       (id + 1) * sizeof(int));
   1.130 +        if (!indexes) {
   1.131 +            SDL_OutOfMemory();
   1.132 +            return -1;
   1.133 +        }
   1.134 +        SDL_IdIndex=indexes;
   1.135 +        SDL_IdIndex[id]=index;
   1.136 +        SDL_highestId=id;
   1.137 +    }
   1.138 +    else
   1.139 +    {
   1.140 +        SDL_IdIndex[id]=index;
   1.141 +    }
   1.142 +}
   1.143 +
   1.144 +int SDL_GetIndexById(int id)
   1.145 +{
   1.146 +    if(id>SDL_highestId)
   1.147 +    {
   1.148 +        return -1;
   1.149 +    }
   1.150 +    else
   1.151 +    {
   1.152 +        return SDL_IdIndex[id];
   1.153 +    }
   1.154 +}
   1.155 +
   1.156 +int SDL_GetNumOfMice(void)
   1.157 +{
   1.158 +    return SDL_num_mice;
   1.159 +}
   1.160 +
   1.161 +char* SDL_GetMouseName(int index)
   1.162 +{
   1.163 +    SDL_Mouse* mouse = SDL_GetMouse(index);
   1.164 +    if(!mouse)
   1.165 +    {
   1.166 +        return NULL;
   1.167 +    }
   1.168 +    return mouse->name;
   1.169 +}
   1.170 +
   1.171 +
   1.172  /* vi: set ts=4 sw=4 expandtab: */