Added touch event definitions. Heavily modified events/SDL_touch*.
authorJim Grandpre <jim.tla@gmail.com>
Thu, 27 May 2010 01:21:37 -0400
changeset 464149a97daea6ec
parent 4640 f068a6dfc858
child 4642 057e8762d2a1
Added touch event definitions. Heavily modified events/SDL_touch*.
include/SDL_events.h
src/events/SDL_touch.c
src/events/SDL_touch_c.h
touchTest/touchPong
touchTest/touchSimp
     1.1 --- a/include/SDL_events.h	Tue May 25 23:23:23 2010 -0400
     1.2 +++ b/include/SDL_events.h	Thu May 27 01:21:37 2010 -0400
     1.3 @@ -86,11 +86,19 @@
     1.4      SDL_JOYBUTTONDOWN,          /**< Joystick button pressed */
     1.5      SDL_JOYBUTTONUP,            /**< Joystick button released */
     1.6  
     1.7 +    /*Touch events - is 0x700 the correct place?*/
     1.8 +    SDL_FINGERDOWN     = 0x700,
     1.9 +    SDL_FINGERUP,
    1.10 +    SDL_FINGERMOTION,
    1.11 +    SDL_TOUCHBUTTONDOWN,
    1.12 +    SDL_TOUCHBUTTONUP,    
    1.13 +
    1.14      /* Obsolete events */
    1.15      SDL_EVENT_COMPAT1 = 0x7000, /**< SDL 1.2 events for compatibility */
    1.16      SDL_EVENT_COMPAT2,
    1.17      SDL_EVENT_COMPAT3,
    1.18  
    1.19 +
    1.20      /** Events ::SDL_USEREVENT through ::SDL_LASTEVENT are for your use,
    1.21       *  and should be allocated with SDL_RegisterEvents()
    1.22       */
    1.23 @@ -289,6 +297,37 @@
    1.24      Uint8 padding1;
    1.25  } SDL_JoyButtonEvent;
    1.26  
    1.27 +
    1.28 +/**
    1.29 + *  \brief Touch finger motion/finger event structure (event.tmotion.*)
    1.30 + */
    1.31 +typedef struct SDL_TouchFingerEvent
    1.32 +{
    1.33 +    Uint32 type;        /**< ::SDL_FINGERMOTION OR 
    1.34 +			   SDL_FINGERDOWN OR SDL_FINGERUP*/
    1.35 +    Uint32 windowID;    /**< The window with mouse focus, if any */
    1.36 +    Uint8 touchId;        /**< The touch device id */
    1.37 +    Uint8 state;        /**< The current button state */
    1.38 +    Uint8 fingerId;
    1.39 +    Uint8 padding1;
    1.40 +} SDL_TouchFingerEvent;
    1.41 +
    1.42 +
    1.43 +/**
    1.44 + *  \brief Touch finger motion/finger event structure (event.tmotion.*)
    1.45 + */
    1.46 +typedef struct SDL_TouchButtonEvent
    1.47 +{
    1.48 +    Uint32 type;        /**< ::SDL_TOUCHBUTTONUP OR SDL_TOUCHBUTTONDOWN */
    1.49 +    Uint32 windowID;    /**< The window with mouse focus, if any */
    1.50 +    Uint8 touchId;        /**< The touch device index */
    1.51 +    Uint8 state;        /**< The current button state */
    1.52 +    Uint8 button;        /**< The button changing state */
    1.53 +    Uint8 padding1;
    1.54 +
    1.55 +} SDL_TouchButtonEvent;
    1.56 +
    1.57 +
    1.58  /**
    1.59   *  \brief The "quit requested" event
    1.60   */
    1.61 @@ -372,6 +411,8 @@
    1.62      SDL_UserEvent user;             /**< Custom event data */
    1.63      SDL_SysWMEvent syswm;           /**< System dependent window event data */
    1.64      SDL_ProximityEvent proximity;   /**< Proximity In or Out event */
    1.65 +    SDL_TouchFingerEvent tfinger;   /**< Touch finger event data */
    1.66 +    SDL_TouchButtonEvent tbutton;   /**< Touch button event data */
    1.67  
    1.68      /** Temporarily here for backwards compatibility */
    1.69      /*@{*/
     2.1 --- a/src/events/SDL_touch.c	Tue May 25 23:23:23 2010 -0400
     2.2 +++ b/src/events/SDL_touch.c	Thu May 27 01:21:37 2010 -0400
     2.3 @@ -29,8 +29,7 @@
     2.4  
     2.5  
     2.6  static int SDL_num_touch = 0;
     2.7 -static int SDL_current_touch = -1;
     2.8 -static SDL_Touch **SDL_touch = NULL;
     2.9 +static SDL_Touch **SDL_touchPads = NULL;
    2.10  
    2.11  
    2.12  /* Public functions */
    2.13 @@ -39,24 +38,43 @@
    2.14  {
    2.15      return (0);
    2.16  }
    2.17 -
    2.18  SDL_Touch *
    2.19 -SDL_GetTouch(int index)
    2.20 +SDL_GetTouch(int id)
    2.21  {
    2.22 +    int index = SDL_GetTouchIndexId(id);
    2.23      if (index < 0 || index >= SDL_num_touch) {
    2.24          return NULL;
    2.25      }
    2.26 -    return SDL_touch[index];
    2.27 +    return SDL_touchPads[index];
    2.28  }
    2.29  
    2.30 -static int
    2.31 +SDL_Finger *
    2.32 +SDL_GetFinger(SDL_Touch* touch,int id)
    2.33 +{
    2.34 +    int index = SDL_GetFingerIndexId(touch,id);
    2.35 +    if(index < 0 || index >= touch->num_fingers)
    2.36 +	return NULL;
    2.37 +    return touch->fingers[index];
    2.38 +}
    2.39 +
    2.40 +int
    2.41 +SDL_GetFingerIndexId(SDL_Touch* touch,int fingerid)
    2.42 +{
    2.43 +    int i;
    2.44 +    for(i = 0;i < touch->num_fingers;i++)
    2.45 +	if(touch->fingers[i]->id == fingerid)
    2.46 +	    return i;
    2.47 +    return -1;
    2.48 +}
    2.49 +
    2.50 +int
    2.51  SDL_GetTouchIndexId(int id)
    2.52  {
    2.53      int index;
    2.54      SDL_Touch *touch;
    2.55  
    2.56      for (index = 0; index < SDL_num_touch; ++index) {
    2.57 -        touch = SDL_GetTouch(index);
    2.58 +        touch = SDL_touchPads[index];
    2.59          if (touch->id == id) {
    2.60              return index;
    2.61          }
    2.62 @@ -68,7 +86,7 @@
    2.63  SDL_AddTouch(const SDL_Touch * touch, char *name, int pressure_max,
    2.64               int pressure_min, int ends)
    2.65  {
    2.66 -    SDL_Touch **touch;
    2.67 +    SDL_Touch **touchPads;
    2.68      int selected_touch;
    2.69      int index;
    2.70      size_t length;
    2.71 @@ -78,58 +96,47 @@
    2.72      }
    2.73  
    2.74      /* Add the touch to the list of touch */
    2.75 -    touch = (SDL_Touch **) SDL_realloc(SDL_touch,
    2.76 +    touchPads = (SDL_Touch **) SDL_realloc(SDL_touchPads,
    2.77                                        (SDL_num_touch + 1) * sizeof(*touch));
    2.78 -    if (!touch) {
    2.79 +    if (!touchPads) {
    2.80          SDL_OutOfMemory();
    2.81          return -1;
    2.82      }
    2.83  
    2.84 -    SDL_touch = touch;
    2.85 +    SDL_touchPads = touchPads;
    2.86      index = SDL_num_touch++;
    2.87  
    2.88 -    SDL_touch[index] = (SDL_Touch *) SDL_malloc(sizeof(*SDL_touch[index]));
    2.89 -    if (!SDL_touch[index]) {
    2.90 +    SDL_touchPads[index] = (SDL_Touch *) SDL_malloc(sizeof(*SDL_touchPads[index]));
    2.91 +    if (!SDL_touchPads[index]) {
    2.92          SDL_OutOfMemory();
    2.93          return -1;
    2.94      }
    2.95 -    *SDL_touch[index] = *touch;
    2.96 +    *SDL_touchPads[index] = *touch;
    2.97  
    2.98      /* we're setting the touch properties */
    2.99      length = 0;
   2.100      length = SDL_strlen(name);
   2.101 -    SDL_touch[index]->focus = 0;
   2.102 -    SDL_touch[index]->name = SDL_malloc((length + 2) * sizeof(char));
   2.103 -    SDL_strlcpy(SDL_touch[index]->name, name, length + 1);
   2.104 -    SDL_touch[index]->pressure_max = pressure_max;
   2.105 -    SDL_touch[index]->pressure_min = pressure_min;
   2.106 -    SDL_touch[index]->cursor_shown = SDL_TRUE;
   2.107 -    selected_touch = SDL_SelectTouch(index);
   2.108 -    SDL_touch[index]->cur_cursor = NULL;
   2.109 -    SDL_touch[index]->def_cursor =
   2.110 -    /* we're assuming that all touch are in the computer sensing zone */
   2.111 -    SDL_touch[index]->proximity = SDL_TRUE;
   2.112 -    /* we're assuming that all touch are working in the absolute position mode
   2.113 -       thanx to that, the users that don't want to use many touch don't have to
   2.114 -       worry about anything */
   2.115 -    SDL_touch[index]->relative_mode = SDL_FALSE;
   2.116 -    SDL_touch[index]->current_end = 0;
   2.117 -    SDL_touch[index]->total_ends = ends;
   2.118 -    SDL_SelectTouch(selected_touch);
   2.119 +    SDL_touchPads[index]->focus = 0;
   2.120 +    SDL_touchPads[index]->name = SDL_malloc((length + 2) * sizeof(char));
   2.121 +    SDL_strlcpy(SDL_touchPads[index]->name, name, length + 1);
   2.122 +    SDL_touchPads[index]->pressure_max = pressure_max;
   2.123 +    SDL_touchPads[index]->pressure_min = pressure_min;
   2.124 +    
   2.125  
   2.126      return index;
   2.127  }
   2.128  
   2.129  void
   2.130 -SDL_DelTouch(int index)
   2.131 +SDL_DelTouch(int id)
   2.132  {
   2.133 -    SDL_Touch *touch = SDL_GetTouch(index);
   2.134 +    int index = SDL_GetTouchIndexId(id);
   2.135 +    SDL_Touch *touch = SDL_GetTouch(id);
   2.136  
   2.137      if (!touch) {
   2.138          return;
   2.139      }
   2.140  
   2.141 -    touch->def_cursor = NULL;
   2.142 +    
   2.143      SDL_free(touch->name);
   2.144   
   2.145      if (touch->FreeTouch) {
   2.146 @@ -137,19 +144,8 @@
   2.147      }
   2.148      SDL_free(touch);
   2.149  
   2.150 -    SDL_touch[index] = NULL;
   2.151 -}
   2.152 -
   2.153 -void
   2.154 -SDL_ResetTouch(int index)
   2.155 -{
   2.156 -    SDL_Touch *touch = SDL_GetTouch(index);
   2.157 -
   2.158 -    if (!touch) {
   2.159 -        return;
   2.160 -    }
   2.161 -
   2.162 -    /* FIXME */
   2.163 +    SDL_num_touch--;
   2.164 +    SDL_touchPads[index] = SDL_touchPads[SDL_num_touch];
   2.165  }
   2.166  
   2.167  void
   2.168 @@ -157,15 +153,14 @@
   2.169  {
   2.170      int i;
   2.171  
   2.172 -    for (i = 0; i < SDL_num_touch; ++i) {
   2.173 +    for (i = SDL_num_touch-1; i > 0 ; --i) {
   2.174          SDL_DelTouch(i);
   2.175      }
   2.176      SDL_num_touch = 0;
   2.177 -    SDL_current_touch = -1;
   2.178  
   2.179 -    if (SDL_touch) {
   2.180 -        SDL_free(SDL_touch);
   2.181 -        SDL_touch = NULL;
   2.182 +    if (SDL_touchPads) {
   2.183 +        SDL_free(SDL_touchPads);
   2.184 +        SDL_touchPads = NULL;
   2.185      }
   2.186  }
   2.187  
   2.188 @@ -174,20 +169,10 @@
   2.189  {
   2.190      return SDL_num_touch;
   2.191  }
   2.192 -
   2.193 -int
   2.194 -SDL_SelectTouch(int index)
   2.195 +SDL_Window *
   2.196 +SDL_GetTouchFocusWindow(int id)
   2.197  {
   2.198 -    if (index >= 0 && index < SDL_num_touch) {
   2.199 -        SDL_current_touch = index;
   2.200 -    }
   2.201 -    return SDL_current_touch;
   2.202 -}
   2.203 -
   2.204 -SDL_Window *
   2.205 -SDL_GetTouchFocusWindow(int index)
   2.206 -{
   2.207 -    SDL_Touch *touch = SDL_GetTouch(index);
   2.208 +    SDL_Touch *touch = SDL_GetTouch(id);
   2.209  
   2.210      if (!touch) {
   2.211          return 0;
   2.212 @@ -195,110 +180,11 @@
   2.213      return touch->focus;
   2.214  }
   2.215  
   2.216 -static int SDLCALL
   2.217 -FlushTouchMotion(void *param, SDL_Event * event)
   2.218 -{
   2.219 -    if (event->type == SDL_TOUCHMOTION
   2.220 -        && event->motion.which == (Uint8) SDL_current_touch) {
   2.221 -        return 0;
   2.222 -    } else {
   2.223 -        return 1;
   2.224 -    }
   2.225 -}
   2.226 -
   2.227 -int
   2.228 -SDL_SetRelativeTouchMode(int index, SDL_bool enabled)
   2.229 -{
   2.230 -    SDL_Touch *touch = SDL_GetTouch(index);
   2.231 -
   2.232 -    if (!touch) {
   2.233 -        return -1;
   2.234 -    }
   2.235 -
   2.236 -    /* Flush pending touch motion */
   2.237 -    touch->flush_motion = SDL_TRUE;
   2.238 -    SDL_PumpEvents();
   2.239 -    touch->flush_motion = SDL_FALSE;
   2.240 -    SDL_FilterEvents(FlushTouchMotion, touch);
   2.241 -
   2.242 -    /* Set the relative mode */
   2.243 -    touch->relative_mode = enabled;
   2.244 -
   2.245 -
   2.246 -
   2.247 -    if (!enabled) {
   2.248 -        /* Restore the expected touch position */
   2.249 -        SDL_WarpTouchInWindow(touch->focus, touch->x, touch->y);
   2.250 -    }
   2.251 -    return 0;
   2.252 -}
   2.253 -
   2.254 -SDL_bool
   2.255 -SDL_GetRelativeTouchMode(int index)
   2.256 -{
   2.257 -    SDL_Touch *touch = SDL_GetTouch(index);
   2.258 -
   2.259 -    if (!touch) {
   2.260 -        return SDL_FALSE;
   2.261 -    }
   2.262 -    return touch->relative_mode;
   2.263 -}
   2.264 -
   2.265 -Uint8
   2.266 -SDL_GetTouchState(int *x, int *y)
   2.267 -{
   2.268 -    SDL_Touch *touch = SDL_GetTouch(SDL_current_touch);
   2.269 -
   2.270 -    if (!touch) {
   2.271 -        if (x) {
   2.272 -            *x = 0;
   2.273 -        }
   2.274 -        if (y) {
   2.275 -            *y = 0;
   2.276 -        }
   2.277 -        return 0;
   2.278 -    }
   2.279 -
   2.280 -    if (x) {
   2.281 -        *x = touch->x;
   2.282 -    }
   2.283 -    if (y) {
   2.284 -        *y = touch->y;
   2.285 -    }
   2.286 -    return touch->buttonstate;
   2.287 -}
   2.288 -
   2.289 -Uint8
   2.290 -SDL_GetRelativeTouchState(int index, int *x, int *y)
   2.291 -{
   2.292 -    SDL_Touch *touch = SDL_GetTouch(index);
   2.293 -
   2.294 -    if (!touch) {
   2.295 -        if (x) {
   2.296 -            *x = 0;
   2.297 -        }
   2.298 -        if (y) {
   2.299 -            *y = 0;
   2.300 -        }
   2.301 -        return 0;
   2.302 -    }
   2.303 -
   2.304 -    if (x) {
   2.305 -        *x = touch->xdelta;
   2.306 -    }
   2.307 -    if (y) {
   2.308 -        *y = touch->ydelta;
   2.309 -    }
   2.310 -    touch->xdelta = 0;
   2.311 -    touch->ydelta = 0;
   2.312 -    return touch->buttonstate;
   2.313 -}
   2.314 -
   2.315  void
   2.316  SDL_SetTouchFocus(int id, SDL_Window * window)
   2.317  {
   2.318      int index = SDL_GetTouchIndexId(id);
   2.319 -    SDL_Touch *touch = SDL_GetTouch(index);
   2.320 +    SDL_Touch *touch = SDL_GetTouch(id);
   2.321      int i;
   2.322      SDL_bool focus;
   2.323  
   2.324 @@ -312,7 +198,7 @@
   2.325          for (i = 0; i < SDL_num_touch; ++i) {
   2.326              SDL_Touch *check;
   2.327              if (i != index) {
   2.328 -                check = SDL_GetTouch(i);
   2.329 +                check = SDL_touchPads[i];
   2.330                  if (check && check->focus == touch->focus) {
   2.331                      focus = SDL_TRUE;
   2.332                      break;
   2.333 @@ -331,7 +217,7 @@
   2.334          for (i = 0; i < SDL_num_touch; ++i) {
   2.335              SDL_Touch *check;
   2.336              if (i != index) {
   2.337 -                check = SDL_GetTouch(i);
   2.338 +                check = SDL_touchPads[i];
   2.339                  if (check && check->focus == touch->focus) {
   2.340                      focus = SDL_TRUE;
   2.341                      break;
   2.342 @@ -344,43 +230,106 @@
   2.343      }
   2.344  }
   2.345  
   2.346 -int
   2.347 -SDL_SendProximity(int id, int x, int y, int type)
   2.348 +int 
   2.349 +SDL_AddFinger(SDL_Touch* touch,SDL_Finger* finger)
   2.350  {
   2.351 -    int index = SDL_GetTouchIndexId(id);
   2.352 -    SDL_Touch *touch = SDL_GetTouch(index);
   2.353 -    int posted = 0;
   2.354 -
   2.355 -    if (!touch) {
   2.356 -        return 0;
   2.357 +    int index;
   2.358 +    SDL_Finger **fingers;
   2.359 +    size_t length;
   2.360 +    
   2.361 +    if (SDL_GetFingerIndexId(touch,finger->id) != -1) {
   2.362 +        SDL_SetError("Finger ID already in use");
   2.363      }
   2.364  
   2.365 -    touch->last_x = x;
   2.366 -    touch->last_y = y;
   2.367 -    if (SDL_GetEventState(type) == SDL_ENABLE) {
   2.368 -        SDL_Event event;
   2.369 -        event.proximity.which = (Uint8) index;
   2.370 -        event.proximity.x = x;
   2.371 -        event.proximity.y = y;
   2.372 -        event.proximity.cursor = touch->current_end;
   2.373 -        event.proximity.type = type;
   2.374 -        /* FIXME: is this right? */
   2.375 -        event.proximity.windowID = touch->focus ? touch->focus->id : 0;
   2.376 -        posted = (SDL_PushEvent(&event) > 0);
   2.377 -        if (type == SDL_PROXIMITYIN) {
   2.378 -            touch->proximity = SDL_TRUE;
   2.379 -        } else {
   2.380 -            touch->proximity = SDL_FALSE;
   2.381 -        }
   2.382 +    /* Add the touch to the list of touch */
   2.383 +    fingers = (SDL_Finger **) SDL_realloc(touch->fingers,
   2.384 +					  (touch->num_fingers + 1) * sizeof(*touch));
   2.385 +    if (!fingers) {
   2.386 +        SDL_OutOfMemory();
   2.387 +        return -1;
   2.388      }
   2.389 -    return posted;
   2.390 +
   2.391 +    touch->fingers = fingers;
   2.392 +    index = SDL_num_touch++;
   2.393 +
   2.394 +    touch->fingers[index] = (SDL_Finger *) SDL_malloc(sizeof(*(touch->fingers[index])));
   2.395 +    if (!touch->fingers[index]) {
   2.396 +        SDL_OutOfMemory();
   2.397 +        return -1;
   2.398 +    }
   2.399 +    *touch->fingers[index] = *finger;    
   2.400 +
   2.401 +    return index;
   2.402  }
   2.403  
   2.404  int
   2.405 -SDL_SendTouchMotion(int id, int relative, int x, int y, int pressure)
   2.406 +SDL_DelFinger(SDL_Touch* touch,int fingerid)
   2.407 +{
   2.408 +    int index = SLD_GetFingerIndexId(touch,fingerid);
   2.409 +    SDL_Finger* finger = SDL_GetFinger(touch,fingerid);
   2.410 +
   2.411 +    if (!finger) {
   2.412 +        return;
   2.413 +    }
   2.414 + 
   2.415 +
   2.416 +    SDL_free(finger);
   2.417 +    touch->num_fingers--;
   2.418 +    touch->fingers[index] = touch->fingers[touch->num_fingers];
   2.419 +}
   2.420 +
   2.421 +
   2.422 +int
   2.423 +SDL_SendFingerDown(int id, int fingerid, SDL_bool down, int x, int y, int pressure)
   2.424 +{
   2.425 +    SDL_Touch* touch = SDL_GetTouch(id);
   2.426 +    if(down) {
   2.427 +	SDL_Finger nf;
   2.428 +	nf.id = id;
   2.429 +	nf.x = x;
   2.430 +	nf.y = y;
   2.431 +	nf.pressure = pressure;
   2.432 +	nf.xdelta = 0;
   2.433 +	nf.ydelta = 0;
   2.434 +	nf.last_x = x;
   2.435 +	nf.last_y = y;
   2.436 +	SDL_AddFinger(touch,&nf);
   2.437 +
   2.438 +	posted = 0;
   2.439 +	if (SDL_GetEventState(SDL_FINGERDOWN) == SDL_ENABLE) {
   2.440 +	    SDL_Event event;
   2.441 +	    event.tfinger.type = SDL_FINGERDOWN;
   2.442 +	    event.tfinger.touchId = (Uint8) id;
   2.443 +	    event.tfinger.state = touch->buttonstate;
   2.444 +	    event.tfinger.windowID = touch->focus ? touch->focus->id : 0;
   2.445 +	    event.fingerId = id;
   2.446 +	    posted = (SDL_PushEvent(&event) > 0);
   2.447 +	}
   2.448 +	return posted;
   2.449 +    }
   2.450 +    else {
   2.451 +	SDL_DelFinger(touch,id);
   2.452 +	posted = 0;
   2.453 +	if (SDL_GetEventState(SDL_FINGERUP) == SDL_ENABLE) {
   2.454 +	    SDL_Event event;
   2.455 +	    event.tfinger.type = SDL_FINGERUP;
   2.456 +	    event.tfinger.touchId = (Uint8) id;
   2.457 +	    event.tfinger.state = touch->buttonstate;
   2.458 +	    event.tfinger.windowID = touch->focus ? touch->focus->id : 0;
   2.459 +	    event.fingerId = id;
   2.460 +	    posted = (SDL_PushEvent(&event) > 0);
   2.461 +	}
   2.462 +	return posted;
   2.463 +    }
   2.464 +}
   2.465 +
   2.466 +int
   2.467 +SDL_SendTouchMotion(int id, int fingerid, int relative, 
   2.468 +		    int x, int y, int pressure)
   2.469  {
   2.470      int index = SDL_GetTouchIndexId(id);
   2.471 -    SDL_Touch *touch = SDL_GetTouch(index);
   2.472 +    SDL_Touch *touch = SDL_GetTouch(id);
   2.473 +    SDL_Finger *finger = SDL_GetFinger(touch,fingerid);
   2.474      int posted;
   2.475      int xrel;
   2.476      int yrel;
   2.477 @@ -390,22 +339,15 @@
   2.478          return 0;
   2.479      }
   2.480  
   2.481 -    /* if the touch is out of proximity we don't to want to have any motion from it */
   2.482 -    if (touch->proximity == SDL_FALSE) {
   2.483 -        touch->last_x = x;
   2.484 -        touch->last_y = y;
   2.485 -        return 0;
   2.486 -    }
   2.487 -
   2.488      /* the relative motion is calculated regarding the system cursor last position */
   2.489      if (relative) {
   2.490          xrel = x;
   2.491          yrel = y;
   2.492 -        x = (touch->last_x + x);
   2.493 -        y = (touch->last_y + y);
   2.494 +        x = (finger->last_x + x);
   2.495 +        y = (finger->last_y + y);
   2.496      } else {
   2.497 -        xrel = x - touch->last_x;
   2.498 -        yrel = y - touch->last_y;
   2.499 +        xrel = x - finger->last_x;
   2.500 +        yrel = y - finger->last_y;
   2.501      }
   2.502  
   2.503      /* Drop events that don't change state */
   2.504 @@ -417,18 +359,16 @@
   2.505      }
   2.506  
   2.507      /* Update internal touch coordinates */
   2.508 -    if (touch->relative_mode == SDL_FALSE) {
   2.509 -        touch->x = x;
   2.510 -        touch->y = y;
   2.511 -    } else {
   2.512 -        touch->x += xrel;
   2.513 -        touch->y += yrel;
   2.514 -    }
   2.515  
   2.516 -    SDL_GetWindowSize(touch->focus, &x_max, &y_max);
   2.517 +    finger->x = x;
   2.518 +    finger->y = y;
   2.519 +
   2.520 +    /*Should scale to window? Normalize? Maintain Aspect?*/
   2.521 +    //SDL_GetWindowSize(touch->focus, &x_max, &y_max);
   2.522  
   2.523      /* make sure that the pointers find themselves inside the windows */
   2.524      /* only check if touch->xmax is set ! */
   2.525 +    /*
   2.526      if (x_max && touch->x > x_max) {
   2.527          touch->x = x_max;
   2.528      } else if (touch->x < 0) {
   2.529 @@ -440,46 +380,32 @@
   2.530      } else if (touch->y < 0) {
   2.531          touch->y = 0;
   2.532      }
   2.533 -
   2.534 -    touch->xdelta += xrel;
   2.535 -    touch->ydelta += yrel;
   2.536 -    touch->pressure = pressure;
   2.537 +    */
   2.538 +    finger->xdelta += xrel;
   2.539 +    finger->ydelta += yrel;
   2.540 +    finger->pressure = pressure;
   2.541  
   2.542  
   2.543  
   2.544      /* Post the event, if desired */
   2.545      posted = 0;
   2.546 -    if (SDL_GetEventState(SDL_TOUCHMOTION) == SDL_ENABLE &&
   2.547 -        touch->proximity == SDL_TRUE) {
   2.548 +    if (SDL_GetEventState(SDL_FINGERMOTION) == SDL_ENABLE) {
   2.549          SDL_Event event;
   2.550 -        event.motion.type = SDL_TOUCHMOTION;
   2.551 -        event.motion.which = (Uint8) index;
   2.552 -        event.motion.state = touch->buttonstate;
   2.553 -        event.motion.x = touch->x;
   2.554 -        event.motion.y = touch->y;
   2.555 -        event.motion.z = touch->z;
   2.556 -        event.motion.pressure = touch->pressure;
   2.557 -        event.motion.pressure_max = touch->pressure_max;
   2.558 -        event.motion.pressure_min = touch->pressure_min;
   2.559 -        event.motion.rotation = 0;
   2.560 -        event.motion.tilt_x = 0;
   2.561 -        event.motion.tilt_y = 0;
   2.562 -        event.motion.cursor = touch->current_end;
   2.563 -        event.motion.xrel = xrel;
   2.564 -        event.motion.yrel = yrel;
   2.565 -        event.motion.windowID = touch->focus ? touch->focus->id : 0;
   2.566 +        event.tfinger.type = SDL_FINGERMOTION;
   2.567 +        event.tfinger.which = (Uint8) index;
   2.568 +        event.tfinger.state = touch->buttonstate;
   2.569 +        event.tfinger.windowID = touch->focus ? touch->focus->id : 0;
   2.570          posted = (SDL_PushEvent(&event) > 0);
   2.571      }
   2.572 -    touch->last_x = touch->x;
   2.573 -    touch->last_y = touch->y;
   2.574 +    finger->last_x = finger->x;
   2.575 +    finger->last_y = finger->y;
   2.576      return posted;
   2.577  }
   2.578  
   2.579  int
   2.580  SDL_SendTouchButton(int id, Uint8 state, Uint8 button)
   2.581  {
   2.582 -    int index = SDL_GetTouchIndexId(id);
   2.583 -    SDL_Touch *touch = SDL_GetTouch(index);
   2.584 +    SDL_Touch *touch = SDL_GetTouch(id);
   2.585      int posted;
   2.586      Uint32 type;
   2.587  
   2.588 @@ -515,61 +441,23 @@
   2.589      if (SDL_GetEventState(type) == SDL_ENABLE) {
   2.590          SDL_Event event;
   2.591          event.type = type;
   2.592 -        event.button.which = (Uint8) index;
   2.593 -        event.button.state = state;
   2.594 -        event.button.button = button;
   2.595 -        event.button.x = touch->x;
   2.596 -        event.button.y = touch->y;
   2.597 -        event.button.windowID = touch->focus ? touch->focus->id : 0;
   2.598 +        event.tbutton.which = (Uint8) index;
   2.599 +        event.tbutton.state = state;
   2.600 +        event.tbutton.button = button;
   2.601 +        event.tbutton.windowID = touch->focus ? touch->focus->id : 0;
   2.602          posted = (SDL_PushEvent(&event) > 0);
   2.603      }
   2.604      return posted;
   2.605  }
   2.606  
   2.607 -int
   2.608 -SDL_SendTouchWheel(int index, int x, int y)
   2.609 +char *
   2.610 +SDL_GetTouchName(int id)
   2.611  {
   2.612 -    SDL_Touch *touch = SDL_GetTouch(index);
   2.613 -    int posted;
   2.614 -
   2.615 -    if (!touch || (!x && !y)) {
   2.616 -        return 0;
   2.617 -    }
   2.618 -
   2.619 -    /* Post the event, if desired */
   2.620 -    posted = 0;
   2.621 -    if (SDL_GetEventState(SDL_TOUCHWHEEL) == SDL_ENABLE) {
   2.622 -        SDL_Event event;
   2.623 -        event.type = SDL_TOUCHWHEEL;
   2.624 -        event.wheel.which = (Uint8) index;
   2.625 -        event.wheel.x = x;
   2.626 -        event.wheel.y = y;
   2.627 -        event.wheel.windowID = touch->focus ? touch->focus->id : 0;
   2.628 -        posted = (SDL_PushEvent(&event) > 0);
   2.629 -    }
   2.630 -    return posted;
   2.631 -}
   2.632 -
   2.633 -
   2.634 -char *
   2.635 -SDL_GetTouchName(int index)
   2.636 -{
   2.637 -    SDL_Touch *touch = SDL_GetTouch(index);
   2.638 +    SDL_Touch *touch = SDL_GetTouch(id);
   2.639      if (!touch) {
   2.640          return NULL;
   2.641      }
   2.642      return touch->name;
   2.643  }
   2.644  
   2.645 -void
   2.646 -SDL_ChangeEnd(int id, int end)
   2.647 -{
   2.648 -    int index = SDL_GetTouchIndexId(id);
   2.649 -    SDL_Touch *touch = SDL_GetTouch(index);
   2.650 -
   2.651 -    if (touch) {
   2.652 -        touch->current_end = end;
   2.653 -    }
   2.654 -}
   2.655 -
   2.656  /* vi: set ts=4 sw=4 expandtab: */
     3.1 --- a/src/events/SDL_touch_c.h	Tue May 25 23:23:23 2010 -0400
     3.2 +++ b/src/events/SDL_touch_c.h	Thu May 27 01:21:37 2010 -0400
     3.3 @@ -25,49 +25,50 @@
     3.4  #define _SDL_touch_c_h
     3.5  
     3.6  typedef struct SDL_Touch SDL_Touch;
     3.7 +typedef struct SDL_Finger SDL_Finger;
     3.8 +
     3.9 +struct SDL_Finger {
    3.10 +  int id;
    3.11 +  int x;
    3.12 +  int y;
    3.13 +  int z;                      /* for future use */
    3.14 +  int xdelta;
    3.15 +  int ydelta;
    3.16 +  int last_x, last_y;         /* the last reported x and y coordinates */
    3.17 +  int pressure;
    3.18 +};
    3.19  
    3.20  
    3.21  struct SDL_Touch
    3.22  {
    3.23 -    /* Warp the touch to (x,y) */
    3.24 -    void (*WarpTouch) (SDL_Touch * touch, SDL_Window * window, int x,
    3.25 -                       int y);
    3.26 +  
    3.27 +  /* Free the touch when it's time */
    3.28 +  void (*FreeTouch) (SDL_Touch * touch);
    3.29 +  
    3.30 +  /* data common for tablets */
    3.31 +  int pressure_max;
    3.32 +  int pressure_min;
    3.33 +  int tilt;                   /* for future use */
    3.34 +  int rotation;               /* for future use */
    3.35 +  
    3.36 +  int total_ends;
    3.37 +  int current_end;
    3.38 +  
    3.39 +  /* Data common to all touch */
    3.40 +  int id;
    3.41 +  SDL_Window *focus;
    3.42 +  
    3.43 +  char *name;
    3.44 +  Uint8 buttonstate;
    3.45 +  SDL_bool relative_mode;
    3.46 +  SDL_bool flush_motion;
    3.47  
    3.48 -    /* Free the touch when it's time */
    3.49 -    void (*FreeTouch) (SDL_Touch * touch);
    3.50 +  int num_fingers;
    3.51 +  SDL_Finger** fingers;
    3.52 +    
    3.53 +  void *driverdata;
    3.54 +};
    3.55  
    3.56 -    /* data common for tablets */
    3.57 -    int pressure;
    3.58 -    int pressure_max;
    3.59 -    int pressure_min;
    3.60 -    int tilt;                   /* for future use */
    3.61 -    int rotation;               /* for future use */
    3.62 -    int total_ends;
    3.63 -    int current_end;
    3.64 -
    3.65 -    /* Data common to all touch */
    3.66 -    int id;
    3.67 -    SDL_Window *focus;
    3.68 -    int which;
    3.69 -    int x;
    3.70 -    int y;
    3.71 -    int z;                      /* for future use */
    3.72 -    int xdelta;
    3.73 -    int ydelta;
    3.74 -    int last_x, last_y;         /* the last reported x and y coordinates */
    3.75 -    char *name;
    3.76 -    Uint8 buttonstate;
    3.77 -    SDL_bool relative_mode;
    3.78 -    SDL_bool proximity;
    3.79 -    SDL_bool flush_motion;
    3.80 -
    3.81 -    SDL_Cursor *cursors;
    3.82 -    SDL_Cursor *def_cursor;
    3.83 -    SDL_Cursor *cur_cursor;
    3.84 -    SDL_bool cursor_shown;
    3.85 -
    3.86 -    void *driverdata;
    3.87 -};
    3.88  
    3.89  /* Initialize the touch subsystem */
    3.90  extern int SDL_TouchInit(void);
    3.91 @@ -84,24 +85,16 @@
    3.92  /* Remove a touch at an index, clearing the slot for later */
    3.93  extern void SDL_DelTouch(int index);
    3.94  
    3.95 -/* Clear the button state of a touch at an index */
    3.96 -extern void SDL_ResetTouch(int index);
    3.97 -
    3.98  /* Set the touch focus window */
    3.99  extern void SDL_SetTouchFocus(int id, SDL_Window * window);
   3.100  
   3.101  /* Send a touch motion event for a touch */
   3.102 -extern int SDL_SendTouchMotion(int id, int relative, int x, int y, int z);
   3.103 +extern int SDL_SendTouchMotion(int id, int fingerid,
   3.104 +			       int relative, int x, int y, int z);
   3.105  
   3.106  /* Send a touch button event for a touch */
   3.107  extern int SDL_SendTouchButton(int id, Uint8 state, Uint8 button);
   3.108  
   3.109 -/* Send a touch wheel event for a touch */
   3.110 -extern int SDL_SendTouchWheel(int id, int x, int y);
   3.111 -
   3.112 -/* Send a proximity event for a touch */
   3.113 -extern int SDL_SendProximity(int id, int x, int y, int type);
   3.114 -
   3.115  /* Shutdown the touch subsystem */
   3.116  extern void SDL_TouchQuit(void);
   3.117  
     4.1 Binary file touchTest/touchPong has changed
     5.1 Binary file touchTest/touchSimp has changed