Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Added pressure support for touch events.

  • Loading branch information
jimtla committed May 29, 2010
1 parent 632271c commit ec612e614dde272307b06cd286b994781b30fca4
@@ -312,6 +312,7 @@ typedef struct SDL_TouchFingerEvent
Uint8 padding1;
int x;
int y;
int pressure;
} SDL_TouchFingerEvent;


@@ -424,6 +424,7 @@ SDL_SendTouchMotion(int id, int fingerid, int relative,
event.tfinger.fingerId = (Uint8) fingerid;
event.tfinger.x = x;
event.tfinger.y = y;
event.tfinger.pressure = pressure;
event.tfinger.state = touch->buttonstate;
event.tfinger.windowID = touch->focus ? touch->focus->id : 0;
posted = (SDL_PushEvent(&event) > 0);
@@ -448,14 +448,21 @@ X11_PumpEvents(_THIS)
switch (ev[i].type) {
case EV_ABS:
//printf("Got position x: %i!\n",data->x);
if(ev[i].code == ABS_X)
data->x = ev[i].value;
else if (ev[i].code == ABS_Y)
data->y = ev[i].value;
else if (ev[i].code == ABS_MISC) {
data->up = SDL_TRUE;
data->finger = ev[i].value;
}
switch (ev[i].code) {
case ABS_X:
data->x = ev[i].value;
break;
case ABS_Y:
data->y = ev[i].value;
break;
case ABS_PRESSURE:
data->pressure = ev[i].value;
break;
case ABS_MISC:
data->up = SDL_TRUE;
data->finger = ev[i].value;
break;
}
break;
case EV_MSC:
if(ev[i].code == MSC_SERIAL)
BIN +16 Bytes (100%) touchTest/touchPong
Binary file not shown.
BIN +12 Bytes (100%) touchTest/touchSimp
Binary file not shown.
@@ -22,8 +22,13 @@ typedef struct {
int x,y;
} Point;

typedef struct {
Point p;
int pressure;
} Finger;


Point finger[MAXFINGERS];
Finger finger[MAXFINGERS];

void handler (int sig)
{
@@ -56,9 +61,12 @@ void drawCircle(SDL_Surface* screen,int x,int y,int r,int c)
{

float a;
for(a=0;a<2*PI;a+=1.f/(float)r)
for(a=0;a<PI/2;a+=1.f/(float)r)
{
setpix(screen,(int)(x+r*cos(a)),(int)(y+r*sin(a)),c);
setpix(screen,(int)(x-r*cos(a)),(int)(y+r*sin(a)),c);
setpix(screen,(int)(x+r*cos(a)),(int)(y-r*sin(a)),c);
setpix(screen,(int)(x-r*cos(a)),(int)(y-r*sin(a)),c);
}
}

@@ -85,8 +93,8 @@ void DrawScreen(SDL_Surface* screen, int h)

int i;
for(i=0;i<MAXFINGERS;i++)
if(finger[i].x >= 0 && finger[i].y >= 0)
drawCircle(screen,finger[i].x,finger[i].y,20,0xFF6600);
if(finger[i].p.x >= 0 && finger[i].p.y >= 0)
drawCircle(screen,finger[i].p.x,finger[i].p.y,20,0xFF6600-finger[i].pressure);

if(SDL_MUSTLOCK(screen)) SDL_UnlockSurface(screen);

@@ -157,20 +165,23 @@ int main(int argc, char* argv[])

//printf("Finger: %i,x: %i, y: %i\n",event.tfinger.fingerId,
// event.tfinger.x,event.tfinger.y);
finger[event.tfinger.fingerId].x = event.tfinger.x;
finger[event.tfinger.fingerId].y = event.tfinger.y;
finger[event.tfinger.fingerId].p.x = event.tfinger.x;
finger[event.tfinger.fingerId].p.y = event.tfinger.y;
finger[event.tfinger.fingerId].pressure = event.tfinger.pressure;
printf("Finger: %i, pressure: %i\n",event.tfinger.fingerId,
event.tfinger.pressure);
break;
case SDL_FINGERDOWN:
printf("Figner: %i down - x: %i, y: %i\n",event.tfinger.fingerId,
event.tfinger.x,event.tfinger.y);
finger[event.tfinger.fingerId].x = event.tfinger.x;
finger[event.tfinger.fingerId].y = event.tfinger.y;
finger[event.tfinger.fingerId].p.x = event.tfinger.x;
finger[event.tfinger.fingerId].p.y = event.tfinger.y;
break;
case SDL_FINGERUP:
printf("Figner: %i up - x: %i, y: %i\n",event.tfinger.fingerId,
event.tfinger.x,event.tfinger.y);
finger[event.tfinger.fingerId].x = -1;
finger[event.tfinger.fingerId].y = -1;
finger[event.tfinger.fingerId].p.x = -1;
finger[event.tfinger.fingerId].p.y = -1;
break;
}
}

0 comments on commit ec612e6

Please sign in to comment.