Mercurial > sdl-ios-xcode
changeset 4644:fb500b3e1717
Added pressure support for touch events.
author | Jim Grandpre <jim.tla@gmail.com> |
---|---|
date | Sat, 29 May 2010 02:09:16 -0400 |
parents | 8806b78988f7 |
children | 0375d020e7e3 |
files | include/SDL_events.h src/events/SDL_touch.c src/video/x11/SDL_x11events.c touchTest/touchPong touchTest/touchSimp touchTest/touchTest.c |
diffstat | 6 files changed, 38 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- a/include/SDL_events.h Sat May 29 01:47:19 2010 -0400 +++ b/include/SDL_events.h Sat May 29 02:09:16 2010 -0400 @@ -312,6 +312,7 @@ Uint8 padding1; int x; int y; + int pressure; } SDL_TouchFingerEvent;
--- a/src/events/SDL_touch.c Sat May 29 01:47:19 2010 -0400 +++ b/src/events/SDL_touch.c Sat May 29 02:09:16 2010 -0400 @@ -424,6 +424,7 @@ 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);
--- a/src/video/x11/SDL_x11events.c Sat May 29 01:47:19 2010 -0400 +++ b/src/video/x11/SDL_x11events.c Sat May 29 02:09:16 2010 -0400 @@ -448,14 +448,21 @@ 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)
--- a/touchTest/touchTest.c Sat May 29 01:47:19 2010 -0400 +++ b/touchTest/touchTest.c Sat May 29 02:09:16 2010 -0400 @@ -22,8 +22,13 @@ 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 @@ { 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 @@ 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 @@ //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; } }