1.1 --- a/include/SDL_touch.h Thu Jun 17 03:41:27 2010 -0400
1.2 +++ b/include/SDL_touch.h Fri Jun 18 01:43:02 2010 -0400
1.3 @@ -50,6 +50,7 @@
1.4 int xdelta;
1.5 int ydelta;
1.6 int last_x, last_y,last_pressure; /* the last reported coordinates */
1.7 + SDL_bool down;
1.8 int pressure;
1.9 };
1.10
2.1 --- a/src/events/SDL_touch.c Thu Jun 17 03:41:27 2010 -0400
2.2 +++ b/src/events/SDL_touch.c Fri Jun 18 01:43:02 2010 -0400
2.3 @@ -300,7 +300,7 @@
2.4 SDL_free(finger);
2.5 touch->num_fingers--;
2.6 touch->fingers[index] = touch->fingers[touch->num_fingers];
2.7 - return 0;
2.8 + return 0;
2.9 }
2.10
2.11
2.12 @@ -311,18 +311,24 @@
2.13 SDL_Touch* touch = SDL_GetTouch(id);
2.14
2.15 if(down) {
2.16 - SDL_Finger nf;
2.17 - nf.id = fingerid;
2.18 - nf.x = x;
2.19 - nf.y = y;
2.20 - nf.pressure = pressure;
2.21 - nf.xdelta = 0;
2.22 - nf.ydelta = 0;
2.23 - nf.last_x = x;
2.24 - nf.last_y = y;
2.25 - nf.last_pressure = pressure;
2.26 - SDL_AddFinger(touch,&nf);
2.27 - //if(x < 0 || y < 0) return 0; //should defer if only a partial input
2.28 + SDL_Finger *finger = SDL_GetFinger(touch,fingerid);
2.29 + if(finger == NULL) {
2.30 + SDL_Finger nf;
2.31 + nf.id = fingerid;
2.32 + nf.x = x;
2.33 + nf.y = y;
2.34 + nf.pressure = pressure;
2.35 + nf.xdelta = 0;
2.36 + nf.ydelta = 0;
2.37 + nf.last_x = x;
2.38 + nf.last_y = y;
2.39 + nf.last_pressure = pressure;
2.40 + nf.down = SDL_FALSE;
2.41 + SDL_AddFinger(touch,&nf);
2.42 + finger = &nf;
2.43 + }
2.44 + else if(finger->down) return 0;
2.45 + if(x < 0 || y < 0) return 0; //should defer if only a partial input
2.46 posted = 0;
2.47 if (SDL_GetEventState(SDL_FINGERDOWN) == SDL_ENABLE) {
2.48 SDL_Event event;
2.49 @@ -335,10 +341,11 @@
2.50 event.tfinger.fingerId = fingerid;
2.51 posted = (SDL_PushEvent(&event) > 0);
2.52 }
2.53 + if(posted) finger->down = SDL_TRUE;
2.54 return posted;
2.55 }
2.56 else {
2.57 - SDL_DelFinger(touch,fingerid);
2.58 + if(SDL_DelFinger(touch,fingerid) < 0) return 0;
2.59 posted = 0;
2.60 if (SDL_GetEventState(SDL_FINGERUP) == SDL_ENABLE) {
2.61 SDL_Event event;
2.62 @@ -364,84 +371,84 @@
2.63 int xrel;
2.64 int yrel;
2.65 int x_max = 0, y_max = 0;
2.66 -
2.67 +
2.68 if (!touch || touch->flush_motion) {
2.69 - return 0;
2.70 + return 0;
2.71 }
2.72
2.73 - if(finger == NULL) {
2.74 - return SDL_SendFingerDown(id,fingerid,SDL_TRUE,x,y,pressure);
2.75 + if(finger == NULL || !finger->down) {
2.76 + return SDL_SendFingerDown(id,fingerid,SDL_TRUE,x,y,pressure);
2.77 } else {
2.78 - /* the relative motion is calculated regarding the last position */
2.79 - if (relative) {
2.80 - xrel = x;
2.81 - yrel = y;
2.82 - x = (finger->last_x + x);
2.83 - y = (finger->last_y + y);
2.84 - } else {
2.85 - if(x < 0) x = finger->last_x; /*If movement is only in one axis,*/
2.86 - if(y < 0) y = finger->last_y; /*The other is marked as -1*/
2.87 - if(pressure < 0) pressure = finger->last_pressure;
2.88 - xrel = x - finger->last_x;
2.89 - yrel = y - finger->last_y;
2.90 - }
2.91 -
2.92 - /* Drop events that don't change state */
2.93 - if (!xrel && !yrel) {
2.94 + /* the relative motion is calculated regarding the last position */
2.95 + if (relative) {
2.96 + xrel = x;
2.97 + yrel = y;
2.98 + x = (finger->last_x + x);
2.99 + y = (finger->last_y + y);
2.100 + } else {
2.101 + if(x < 0) x = finger->last_x; /*If movement is only in one axis,*/
2.102 + if(y < 0) y = finger->last_y; /*The other is marked as -1*/
2.103 + if(pressure < 0) pressure = finger->last_pressure;
2.104 + xrel = x - finger->last_x;
2.105 + yrel = y - finger->last_y;
2.106 + }
2.107 +
2.108 + /* Drop events that don't change state */
2.109 + if (!xrel && !yrel) {
2.110 #if 0
2.111 - printf("Touch event didn't change state - dropped!\n");
2.112 + printf("Touch event didn't change state - dropped!\n");
2.113 #endif
2.114 - return 0;
2.115 - }
2.116 -
2.117 - /* Update internal touch coordinates */
2.118 -
2.119 - finger->x = x;
2.120 - finger->y = y;
2.121 -
2.122 - /*Should scale to window? Normalize? Maintain Aspect?*/
2.123 - //SDL_GetWindowSize(touch->focus, &x_max, &y_max);
2.124 -
2.125 - /* make sure that the pointers find themselves inside the windows */
2.126 - /* only check if touch->xmax is set ! */
2.127 - /*
2.128 - if (x_max && touch->x > x_max) {
2.129 - touch->x = x_max;
2.130 - } else if (touch->x < 0) {
2.131 - touch->x = 0;
2.132 - }
2.133 -
2.134 - if (y_max && touch->y > y_max) {
2.135 - touch->y = y_max;
2.136 - } else if (touch->y < 0) {
2.137 - touch->y = 0;
2.138 - }
2.139 - */
2.140 - finger->xdelta = xrel;
2.141 - finger->ydelta = yrel;
2.142 - finger->pressure = pressure;
2.143 -
2.144 -
2.145 -
2.146 - /* Post the event, if desired */
2.147 - posted = 0;
2.148 - if (SDL_GetEventState(SDL_FINGERMOTION) == SDL_ENABLE) {
2.149 - SDL_Event event;
2.150 - event.tfinger.type = SDL_FINGERMOTION;
2.151 - event.tfinger.touchId = (Uint8) id;
2.152 - event.tfinger.fingerId = (Uint8) fingerid;
2.153 - event.tfinger.x = x;
2.154 - event.tfinger.y = y;
2.155 - event.tfinger.pressure = pressure;
2.156 - event.tfinger.state = touch->buttonstate;
2.157 - event.tfinger.windowID = touch->focus ? touch->focus->id : 0;
2.158 - posted = (SDL_PushEvent(&event) > 0);
2.159 - }
2.160 - finger->last_x = finger->x;
2.161 - finger->last_y = finger->y;
2.162 - finger->last_pressure = finger->pressure;
2.163 - return posted;
2.164 + return 0;
2.165 }
2.166 +
2.167 + /* Update internal touch coordinates */
2.168 +
2.169 + finger->x = x;
2.170 + finger->y = y;
2.171 +
2.172 + /*Should scale to window? Normalize? Maintain Aspect?*/
2.173 + //SDL_GetWindowSize(touch->focus, &x_max, &y_max);
2.174 +
2.175 + /* make sure that the pointers find themselves inside the windows */
2.176 + /* only check if touch->xmax is set ! */
2.177 + /*
2.178 + if (x_max && touch->x > x_max) {
2.179 + touch->x = x_max;
2.180 + } else if (touch->x < 0) {
2.181 + touch->x = 0;
2.182 + }
2.183 +
2.184 + if (y_max && touch->y > y_max) {
2.185 + touch->y = y_max;
2.186 + } else if (touch->y < 0) {
2.187 + touch->y = 0;
2.188 + }
2.189 + */
2.190 + finger->xdelta = xrel;
2.191 + finger->ydelta = yrel;
2.192 + finger->pressure = pressure;
2.193 +
2.194 +
2.195 +
2.196 + /* Post the event, if desired */
2.197 + posted = 0;
2.198 + if (SDL_GetEventState(SDL_FINGERMOTION) == SDL_ENABLE) {
2.199 + SDL_Event event;
2.200 + event.tfinger.type = SDL_FINGERMOTION;
2.201 + event.tfinger.touchId = (Uint8) id;
2.202 + event.tfinger.fingerId = (Uint8) fingerid;
2.203 + event.tfinger.x = x;
2.204 + event.tfinger.y = y;
2.205 + event.tfinger.pressure = pressure;
2.206 + event.tfinger.state = touch->buttonstate;
2.207 + event.tfinger.windowID = touch->focus ? touch->focus->id : 0;
2.208 + posted = (SDL_PushEvent(&event) > 0);
2.209 + }
2.210 + finger->last_x = finger->x;
2.211 + finger->last_y = finger->y;
2.212 + finger->last_pressure = finger->pressure;
2.213 + return posted;
2.214 + }
2.215 }
2.216 int
2.217 SDL_SendTouchButton(int id, Uint8 state, Uint8 button)
3.1 --- a/src/video/x11/SDL_x11events.c Thu Jun 17 03:41:27 2010 -0400
3.2 +++ b/src/video/x11/SDL_x11events.c Fri Jun 18 01:43:02 2010 -0400
3.3 @@ -463,14 +463,16 @@
3.4 break;
3.5 case EV_SYN:
3.6 //printf("Id: %i\n",touch->id);
3.7 - if(data->x >= 0 || data->y >= 0)
3.8 - SDL_SendTouchMotion(touch->id,data->finger,
3.9 - SDL_FALSE,data->x,data->y,
3.10 + if(data->up) {
3.11 + SDL_SendFingerDown(touch->id,data->finger,
3.12 + SDL_FALSE,data->x,data->y,
3.13 + data->pressure);
3.14 + }
3.15 + else if(data->x >= 0 || data->y >= 0)
3.16 + SDL_SendTouchMotion(touch->id,data->finger,
3.17 + SDL_FALSE,data->x,data->y,
3.18 data->pressure);
3.19 - if(data->up)
3.20 - SDL_SendFingerDown(touch->id,data->finger,
3.21 - SDL_FALSE,data->x,data->y,
3.22 - data->pressure);
3.23 +
3.24 //printf("Synched: %i tx: %i, ty: %i\n",
3.25 // data->finger,data->x,data->y);
3.26 data->x = -1;
4.1 --- a/touchTest/gestureTest.c Thu Jun 17 03:41:27 2010 -0400
4.2 +++ b/touchTest/gestureTest.c Fri Jun 18 01:43:02 2010 -0400
4.3 @@ -214,11 +214,12 @@
4.4 int i;
4.5
4.6 int k;
4.7 + /*
4.8 for(k = 0;k<DOLLARNPOINTS;k++) {
4.9 printf("(%f,%f)\n",points[k].x,
4.10 points[k].y);
4.11 }
4.12 -
4.13 + */
4.14 drawDollarPath(screen,points,numPoints,-15,0xFF6600);
4.15
4.16 int bestDiff = 10000;
4.17 @@ -367,23 +368,13 @@
4.18
4.19 gestureLine[j].points = 0;
4.20 #endif
4.21 - //ignore last point - probably invalid
4.22 - dollarPath[j].numPoints--;
4.23 -
4.24 -
4.25 - float dx = dollarPath[j].p[dollarPath[j].numPoints].x -
4.26 - dollarPath[j].p[dollarPath[j].numPoints - 1].x;
4.27 - float dy = dollarPath[j].p[dollarPath[j].numPoints].y -
4.28 - dollarPath[j].p[dollarPath[j].numPoints - 1].y;
4.29 - dollarPath[j].length -= sqrt(dx*dx+dy*dy);
4.30
4.31 if(!keystat[32]){ //spacebar
4.32 int bestTempl;
4.33 float error = dollarRecognize(screen,dollarPath[j],&bestTempl);
4.34 - printf("%i\n",bestTempl);
4.35 if(bestTempl >= 0){
4.36 drawDollarPath(screen,dollarTemplate[bestTempl]
4.37 - ,DOLLARNPOINTS,-15,0x0066FF);\
4.38 + ,DOLLARNPOINTS,-15,0x0066FF);
4.39
4.40 printf("ERROR: %f\n",error);
4.41 }
4.42 @@ -475,8 +466,8 @@
4.43 if(gestureLast[j].id < 0) continue; //Finger up. Or some error...
4.44 int k;
4.45 for(k = 0; k < MAXFINGERS;k++) {
4.46 -
4.47 if(gestureLast[k].id < 0) continue;
4.48 + //printf("k = %i, id: %i\n",k,gestureLast[k].id);
4.49 //colors have no alpha, so shouldn't overflow
4.50 unsigned int c = (colors[gestureLast[j].id%7] +
4.51 colors[gestureLast[k].id%7])/2;