Added pressure support for touch events.
authorJim Grandpre <jim.tla@gmail.com>
Sat, 29 May 2010 02:09:16 -0400
changeset 4644fb500b3e1717
parent 4643 8806b78988f7
child 4645 0375d020e7e3
Added pressure support for touch events.
include/SDL_events.h
src/events/SDL_touch.c
src/video/x11/SDL_x11events.c
touchTest/touchPong
touchTest/touchSimp
touchTest/touchTest.c
     1.1 --- a/include/SDL_events.h	Sat May 29 01:47:19 2010 -0400
     1.2 +++ b/include/SDL_events.h	Sat May 29 02:09:16 2010 -0400
     1.3 @@ -312,6 +312,7 @@
     1.4      Uint8 padding1;
     1.5      int x;
     1.6      int y;
     1.7 +    int pressure;
     1.8  } SDL_TouchFingerEvent;
     1.9  
    1.10  
     2.1 --- a/src/events/SDL_touch.c	Sat May 29 01:47:19 2010 -0400
     2.2 +++ b/src/events/SDL_touch.c	Sat May 29 02:09:16 2010 -0400
     2.3 @@ -424,6 +424,7 @@
     2.4  	    event.tfinger.fingerId = (Uint8) fingerid;
     2.5  	    event.tfinger.x = x;
     2.6  	    event.tfinger.y = y;
     2.7 +	    event.tfinger.pressure = pressure;
     2.8  	    event.tfinger.state = touch->buttonstate;
     2.9  	    event.tfinger.windowID = touch->focus ? touch->focus->id : 0;
    2.10  	    posted = (SDL_PushEvent(&event) > 0);
     3.1 --- a/src/video/x11/SDL_x11events.c	Sat May 29 01:47:19 2010 -0400
     3.2 +++ b/src/video/x11/SDL_x11events.c	Sat May 29 02:09:16 2010 -0400
     3.3 @@ -448,14 +448,21 @@
     3.4  		switch (ev[i].type) {
     3.5  		case EV_ABS:
     3.6  		    //printf("Got position x: %i!\n",data->x);
     3.7 -		    if(ev[i].code == ABS_X)
     3.8 -			data->x = ev[i].value;
     3.9 -		    else if (ev[i].code == ABS_Y)
    3.10 -			data->y = ev[i].value;
    3.11 -		    else if (ev[i].code == ABS_MISC) {
    3.12 -			data->up = SDL_TRUE;
    3.13 -			data->finger = ev[i].value;
    3.14 -		    }
    3.15 +		    switch (ev[i].code) {
    3.16 +			case ABS_X:
    3.17 +			    data->x = ev[i].value;
    3.18 +			    break;
    3.19 +			case ABS_Y:
    3.20 +			    data->y = ev[i].value;
    3.21 +			    break;
    3.22 +			case ABS_PRESSURE:
    3.23 +			    data->pressure = ev[i].value;
    3.24 +			    break;
    3.25 +			case ABS_MISC:
    3.26 +			    data->up = SDL_TRUE;
    3.27 +			    data->finger = ev[i].value;
    3.28 +			    break;
    3.29 +			}
    3.30  		    break;
    3.31  		case EV_MSC:
    3.32  		    if(ev[i].code == MSC_SERIAL)
     4.1 Binary file touchTest/touchPong has changed
     5.1 Binary file touchTest/touchSimp has changed
     6.1 --- a/touchTest/touchTest.c	Sat May 29 01:47:19 2010 -0400
     6.2 +++ b/touchTest/touchTest.c	Sat May 29 02:09:16 2010 -0400
     6.3 @@ -22,8 +22,13 @@
     6.4    int x,y;
     6.5  } Point;
     6.6  
     6.7 +typedef struct {
     6.8 +  Point p;
     6.9 +  int pressure;
    6.10 +} Finger;
    6.11  
    6.12 -Point finger[MAXFINGERS];
    6.13 +
    6.14 +Finger finger[MAXFINGERS];
    6.15  
    6.16  void handler (int sig)
    6.17  {
    6.18 @@ -56,9 +61,12 @@
    6.19  {
    6.20  
    6.21    float a;
    6.22 -  for(a=0;a<2*PI;a+=1.f/(float)r)
    6.23 +  for(a=0;a<PI/2;a+=1.f/(float)r)
    6.24    {
    6.25      setpix(screen,(int)(x+r*cos(a)),(int)(y+r*sin(a)),c);
    6.26 +    setpix(screen,(int)(x-r*cos(a)),(int)(y+r*sin(a)),c);
    6.27 +    setpix(screen,(int)(x+r*cos(a)),(int)(y-r*sin(a)),c);
    6.28 +    setpix(screen,(int)(x-r*cos(a)),(int)(y-r*sin(a)),c);
    6.29    }
    6.30  }
    6.31  
    6.32 @@ -85,8 +93,8 @@
    6.33    
    6.34    int i;
    6.35    for(i=0;i<MAXFINGERS;i++)
    6.36 -    if(finger[i].x >= 0 && finger[i].y >= 0)
    6.37 -      drawCircle(screen,finger[i].x,finger[i].y,20,0xFF6600);
    6.38 +    if(finger[i].p.x >= 0 && finger[i].p.y >= 0)
    6.39 +      drawCircle(screen,finger[i].p.x,finger[i].p.y,20,0xFF6600-finger[i].pressure);
    6.40    
    6.41    if(SDL_MUSTLOCK(screen)) SDL_UnlockSurface(screen);
    6.42    
    6.43 @@ -157,20 +165,23 @@
    6.44  	    
    6.45  	    //printf("Finger: %i,x: %i, y: %i\n",event.tfinger.fingerId,
    6.46  	    //	   event.tfinger.x,event.tfinger.y);
    6.47 -	    finger[event.tfinger.fingerId].x = event.tfinger.x;
    6.48 -	    finger[event.tfinger.fingerId].y = event.tfinger.y;
    6.49 +	    finger[event.tfinger.fingerId].p.x = event.tfinger.x;
    6.50 +	    finger[event.tfinger.fingerId].p.y = event.tfinger.y;
    6.51 +	    finger[event.tfinger.fingerId].pressure = event.tfinger.pressure;
    6.52 +	    printf("Finger: %i, pressure: %i\n",event.tfinger.fingerId,
    6.53 +		   event.tfinger.pressure);
    6.54  	    break;	    
    6.55  	  case SDL_FINGERDOWN:
    6.56  	    printf("Figner: %i down - x: %i, y: %i\n",event.tfinger.fingerId,
    6.57  		   event.tfinger.x,event.tfinger.y);
    6.58 -	    finger[event.tfinger.fingerId].x = event.tfinger.x;
    6.59 -	    finger[event.tfinger.fingerId].y = event.tfinger.y;
    6.60 +	    finger[event.tfinger.fingerId].p.x = event.tfinger.x;
    6.61 +	    finger[event.tfinger.fingerId].p.y = event.tfinger.y;
    6.62  	    break;
    6.63  	  case SDL_FINGERUP:
    6.64  	    printf("Figner: %i up - x: %i, y: %i\n",event.tfinger.fingerId,
    6.65  		   event.tfinger.x,event.tfinger.y);
    6.66 -	    finger[event.tfinger.fingerId].x = -1;
    6.67 -	    finger[event.tfinger.fingerId].y = -1;
    6.68 +	    finger[event.tfinger.fingerId].p.x = -1;
    6.69 +	    finger[event.tfinger.fingerId].p.y = -1;
    6.70  	    break;
    6.71  	  }
    6.72        }