Commit 06e66b92 authored by Jim Grandpre's avatar Jim Grandpre

Fixed bugs in input, cleaned up $1

parent 66e6be2a
...@@ -50,6 +50,7 @@ struct SDL_Finger { ...@@ -50,6 +50,7 @@ struct SDL_Finger {
int xdelta; int xdelta;
int ydelta; int ydelta;
int last_x, last_y,last_pressure; /* the last reported coordinates */ int last_x, last_y,last_pressure; /* the last reported coordinates */
SDL_bool down;
int pressure; int pressure;
}; };
......
...@@ -300,7 +300,7 @@ SDL_DelFinger(SDL_Touch* touch,int fingerid) ...@@ -300,7 +300,7 @@ SDL_DelFinger(SDL_Touch* touch,int fingerid)
SDL_free(finger); SDL_free(finger);
touch->num_fingers--; touch->num_fingers--;
touch->fingers[index] = touch->fingers[touch->num_fingers]; touch->fingers[index] = touch->fingers[touch->num_fingers];
return 0; return 0;
} }
...@@ -311,18 +311,24 @@ SDL_SendFingerDown(int id, int fingerid, SDL_bool down, int x, int y, int pressu ...@@ -311,18 +311,24 @@ SDL_SendFingerDown(int id, int fingerid, SDL_bool down, int x, int y, int pressu
SDL_Touch* touch = SDL_GetTouch(id); SDL_Touch* touch = SDL_GetTouch(id);
if(down) { if(down) {
SDL_Finger nf; SDL_Finger *finger = SDL_GetFinger(touch,fingerid);
nf.id = fingerid; if(finger == NULL) {
nf.x = x; SDL_Finger nf;
nf.y = y; nf.id = fingerid;
nf.pressure = pressure; nf.x = x;
nf.xdelta = 0; nf.y = y;
nf.ydelta = 0; nf.pressure = pressure;
nf.last_x = x; nf.xdelta = 0;
nf.last_y = y; nf.ydelta = 0;
nf.last_pressure = pressure; nf.last_x = x;
SDL_AddFinger(touch,&nf); nf.last_y = y;
//if(x < 0 || y < 0) return 0; //should defer if only a partial input nf.last_pressure = pressure;
nf.down = SDL_FALSE;
SDL_AddFinger(touch,&nf);
finger = &nf;
}
else if(finger->down) return 0;
if(x < 0 || y < 0) return 0; //should defer if only a partial input
posted = 0; posted = 0;
if (SDL_GetEventState(SDL_FINGERDOWN) == SDL_ENABLE) { if (SDL_GetEventState(SDL_FINGERDOWN) == SDL_ENABLE) {
SDL_Event event; SDL_Event event;
...@@ -335,10 +341,11 @@ SDL_SendFingerDown(int id, int fingerid, SDL_bool down, int x, int y, int pressu ...@@ -335,10 +341,11 @@ SDL_SendFingerDown(int id, int fingerid, SDL_bool down, int x, int y, int pressu
event.tfinger.fingerId = fingerid; event.tfinger.fingerId = fingerid;
posted = (SDL_PushEvent(&event) > 0); posted = (SDL_PushEvent(&event) > 0);
} }
if(posted) finger->down = SDL_TRUE;
return posted; return posted;
} }
else { else {
SDL_DelFinger(touch,fingerid); if(SDL_DelFinger(touch,fingerid) < 0) return 0;
posted = 0; posted = 0;
if (SDL_GetEventState(SDL_FINGERUP) == SDL_ENABLE) { if (SDL_GetEventState(SDL_FINGERUP) == SDL_ENABLE) {
SDL_Event event; SDL_Event event;
...@@ -364,84 +371,84 @@ SDL_SendTouchMotion(int id, int fingerid, int relative, ...@@ -364,84 +371,84 @@ SDL_SendTouchMotion(int id, int fingerid, int relative,
int xrel; int xrel;
int yrel; int yrel;
int x_max = 0, y_max = 0; int x_max = 0, y_max = 0;
if (!touch || touch->flush_motion) { if (!touch || touch->flush_motion) {
return 0; return 0;
} }
if(finger == NULL) { if(finger == NULL || !finger->down) {
return SDL_SendFingerDown(id,fingerid,SDL_TRUE,x,y,pressure); return SDL_SendFingerDown(id,fingerid,SDL_TRUE,x,y,pressure);
} else { } else {
/* the relative motion is calculated regarding the last position */ /* the relative motion is calculated regarding the last position */
if (relative) { if (relative) {
xrel = x; xrel = x;
yrel = y; yrel = y;
x = (finger->last_x + x); x = (finger->last_x + x);
y = (finger->last_y + y); y = (finger->last_y + y);
} else { } else {
if(x < 0) x = finger->last_x; /*If movement is only in one axis,*/ if(x < 0) x = finger->last_x; /*If movement is only in one axis,*/
if(y < 0) y = finger->last_y; /*The other is marked as -1*/ if(y < 0) y = finger->last_y; /*The other is marked as -1*/
if(pressure < 0) pressure = finger->last_pressure; if(pressure < 0) pressure = finger->last_pressure;
xrel = x - finger->last_x; xrel = x - finger->last_x;
yrel = y - finger->last_y; yrel = y - finger->last_y;
} }
/* Drop events that don't change state */ /* Drop events that don't change state */
if (!xrel && !yrel) { if (!xrel && !yrel) {
#if 0 #if 0
printf("Touch event didn't change state - dropped!\n"); printf("Touch event didn't change state - dropped!\n");
#endif #endif
return 0; return 0;
}
/* Update internal touch coordinates */
finger->x = x;
finger->y = y;
/*Should scale to window? Normalize? Maintain Aspect?*/
//SDL_GetWindowSize(touch->focus, &x_max, &y_max);
/* make sure that the pointers find themselves inside the windows */
/* only check if touch->xmax is set ! */
/*
if (x_max && touch->x > x_max) {
touch->x = x_max;
} else if (touch->x < 0) {
touch->x = 0;
}
if (y_max && touch->y > y_max) {
touch->y = y_max;
} else if (touch->y < 0) {
touch->y = 0;
}
*/
finger->xdelta = xrel;
finger->ydelta = yrel;
finger->pressure = pressure;
/* Post the event, if desired */
posted = 0;
if (SDL_GetEventState(SDL_FINGERMOTION) == SDL_ENABLE) {
SDL_Event event;
event.tfinger.type = SDL_FINGERMOTION;
event.tfinger.touchId = (Uint8) id;
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);
}
finger->last_x = finger->x;
finger->last_y = finger->y;
finger->last_pressure = finger->pressure;
return posted;
} }
/* Update internal touch coordinates */
finger->x = x;
finger->y = y;
/*Should scale to window? Normalize? Maintain Aspect?*/
//SDL_GetWindowSize(touch->focus, &x_max, &y_max);
/* make sure that the pointers find themselves inside the windows */
/* only check if touch->xmax is set ! */
/*
if (x_max && touch->x > x_max) {
touch->x = x_max;
} else if (touch->x < 0) {
touch->x = 0;
}
if (y_max && touch->y > y_max) {
touch->y = y_max;
} else if (touch->y < 0) {
touch->y = 0;
}
*/
finger->xdelta = xrel;
finger->ydelta = yrel;
finger->pressure = pressure;
/* Post the event, if desired */
posted = 0;
if (SDL_GetEventState(SDL_FINGERMOTION) == SDL_ENABLE) {
SDL_Event event;
event.tfinger.type = SDL_FINGERMOTION;
event.tfinger.touchId = (Uint8) id;
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);
}
finger->last_x = finger->x;
finger->last_y = finger->y;
finger->last_pressure = finger->pressure;
return posted;
}
} }
int int
SDL_SendTouchButton(int id, Uint8 state, Uint8 button) SDL_SendTouchButton(int id, Uint8 state, Uint8 button)
......
...@@ -463,14 +463,16 @@ X11_PumpEvents(_THIS) ...@@ -463,14 +463,16 @@ X11_PumpEvents(_THIS)
break; break;
case EV_SYN: case EV_SYN:
//printf("Id: %i\n",touch->id); //printf("Id: %i\n",touch->id);
if(data->x >= 0 || data->y >= 0) if(data->up) {
SDL_SendTouchMotion(touch->id,data->finger, SDL_SendFingerDown(touch->id,data->finger,
SDL_FALSE,data->x,data->y, SDL_FALSE,data->x,data->y,
data->pressure);
}
else if(data->x >= 0 || data->y >= 0)
SDL_SendTouchMotion(touch->id,data->finger,
SDL_FALSE,data->x,data->y,
data->pressure); data->pressure);
if(data->up)
SDL_SendFingerDown(touch->id,data->finger,
SDL_FALSE,data->x,data->y,
data->pressure);
//printf("Synched: %i tx: %i, ty: %i\n", //printf("Synched: %i tx: %i, ty: %i\n",
// data->finger,data->x,data->y); // data->finger,data->x,data->y);
data->x = -1; data->x = -1;
......
...@@ -214,11 +214,12 @@ float dollarRecognize(SDL_Surface* screen, DollarPath path,int *bestTempl) { ...@@ -214,11 +214,12 @@ float dollarRecognize(SDL_Surface* screen, DollarPath path,int *bestTempl) {
int i; int i;
int k; int k;
/*
for(k = 0;k<DOLLARNPOINTS;k++) { for(k = 0;k<DOLLARNPOINTS;k++) {
printf("(%f,%f)\n",points[k].x, printf("(%f,%f)\n",points[k].x,
points[k].y); points[k].y);
} }
*/
drawDollarPath(screen,points,numPoints,-15,0xFF6600); drawDollarPath(screen,points,numPoints,-15,0xFF6600);
int bestDiff = 10000; int bestDiff = 10000;
...@@ -367,23 +368,13 @@ void DrawScreen(SDL_Surface* screen, int h) ...@@ -367,23 +368,13 @@ void DrawScreen(SDL_Surface* screen, int h)
gestureLine[j].points = 0; gestureLine[j].points = 0;
#endif #endif
//ignore last point - probably invalid
dollarPath[j].numPoints--;
float dx = dollarPath[j].p[dollarPath[j].numPoints].x -
dollarPath[j].p[dollarPath[j].numPoints - 1].x;
float dy = dollarPath[j].p[dollarPath[j].numPoints].y -
dollarPath[j].p[dollarPath[j].numPoints - 1].y;
dollarPath[j].length -= sqrt(dx*dx+dy*dy);
if(!keystat[32]){ //spacebar if(!keystat[32]){ //spacebar
int bestTempl; int bestTempl;
float error = dollarRecognize(screen,dollarPath[j],&bestTempl); float error = dollarRecognize(screen,dollarPath[j],&bestTempl);
printf("%i\n",bestTempl);
if(bestTempl >= 0){ if(bestTempl >= 0){
drawDollarPath(screen,dollarTemplate[bestTempl] drawDollarPath(screen,dollarTemplate[bestTempl]
,DOLLARNPOINTS,-15,0x0066FF);\ ,DOLLARNPOINTS,-15,0x0066FF);
printf("ERROR: %f\n",error); printf("ERROR: %f\n",error);
} }
...@@ -475,8 +466,8 @@ void DrawScreen(SDL_Surface* screen, int h) ...@@ -475,8 +466,8 @@ void DrawScreen(SDL_Surface* screen, int h)
if(gestureLast[j].id < 0) continue; //Finger up. Or some error... if(gestureLast[j].id < 0) continue; //Finger up. Or some error...
int k; int k;
for(k = 0; k < MAXFINGERS;k++) { for(k = 0; k < MAXFINGERS;k++) {
if(gestureLast[k].id < 0) continue; if(gestureLast[k].id < 0) continue;
//printf("k = %i, id: %i\n",k,gestureLast[k].id);
//colors have no alpha, so shouldn't overflow //colors have no alpha, so shouldn't overflow
unsigned int c = (colors[gestureLast[j].id%7] + unsigned int c = (colors[gestureLast[j].id%7] +
colors[gestureLast[k].id%7])/2; colors[gestureLast[k].id%7])/2;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment