SDL_gesture_c.h File Reference
`#include "../SDL_internal.h"`
Include dependency graph for SDL_gesture_c.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

## Functions

int | SDL_GestureAddTouch (SDL_TouchID touchId)
void | SDL_GestureProcessEvent (SDL_Event *event)
int | SDL_RecordGesture (SDL_TouchID touchId)
| Begin Recording a gesture on the specified touch, or all touches (-1) More...

## Function Documentation

int SDL_GestureAddTouch | ( | SDL_TouchID | touchId | ) |

Definition at line 442 of file SDL_gesture.c.

References SDL_GestureTouch::id, SDL_numGestureTouches, SDL_OutOfMemory, SDL_realloc, and SDL_zero.

Referenced by SDL_AddTouch().

{
SDL_GestureTouch *gestureTouch = (SDL_GestureTouch *)SDL_realloc(SDL_gestureTouch,
(SDL_numGestureTouches + 1) *
sizeof(SDL_GestureTouch));
if (!gestureTouch) {
return SDL_OutOfMemory();
}
SDL_gestureTouch = gestureTouch;
SDL_zero(SDL_gestureTouch[SDL_numGestureTouches]);
SDL_gestureTouch[SDL_numGestureTouches].id = touchId;
SDL_numGestureTouches++;
return 0;
}
SDL_numGestureTouches
int SDL_numGestureTouches
Definition: SDL_gesture.c:75
SDL_realloc
#define SDL_realloc
Definition: SDL_dynapi_overrides.h:382
SDL_GestureTouch
Definition: SDL_gesture.c:62
SDL_gestureTouch
SDL_GestureTouch * SDL_gestureTouch
Definition: SDL_gesture.c:74
SDL_zero
#define SDL_zero(x)
Definition: SDL_stdinc.h:355
SDL_OutOfMemory
#define SDL_OutOfMemory()
Definition: SDL_error.h:52
SDL_GestureTouch::id
SDL_TouchID id
Definition: SDL_gesture.c:63

void SDL_GestureProcessEvent | ( | SDL_Event * | event | ) |

Definition at line 510 of file SDL_gesture.c.

References SDL_GestureTouch::centroid, dollarNormalize(), DOLLARNPOINTS, SDL_GestureTouch::dollarPath, dollarRecognize(), SDL_GestureTouch::dollarTemplate, SDL_DollarTemplate::hash, i, SDL_DollarPath::length, MAXPATHSIZE, NULL, SDL_GestureTouch::numDownFingers, SDL_DollarPath::numPoints, SDL_DollarPath::p, recordAll, SDL_GestureTouch::recording, SDL_AddDollarGesture(), SDL_atan2, SDL_FALSE, SDL_FINGERDOWN, SDL_FINGERMOTION, SDL_FINGERUP, SDL_GetGestureTouch(), SDL_numGestureTouches, SDL_SendDollarRecord(), SDL_SendGestureDollar(), SDL_SendGestureMulti(), SDL_sqrt, SDL_Event::tfinger, SDL_TouchFingerEvent::touchId, SDL_Event::type, SDL_FloatPoint::x, and SDL_FloatPoint::y.

Referenced by SDL_PushEvent().

{
float x,y;
int index;
int i;
float pathDx, pathDy;
SDL_FloatPoint lastP;
SDL_FloatPoint lastCentroid;
float lDist;
float Dist;
float dtheta;
float dDist;
if (event->type == SDL_FINGERMOTION ||
event->type == SDL_FINGERDOWN ||
event->type == SDL_FINGERUP) {
SDL_GestureTouch* inTouch = SDL_GetGestureTouch(event->tfinger.touchId);
/* Shouldn't be possible */
if (inTouch == NULL) return;
x = event->tfinger.x;
y = event->tfinger.y;
/* Finger Up */
if (event->type == SDL_FINGERUP) {
SDL_FloatPoint path[DOLLARNPOINTS];
inTouch->numDownFingers--;
#ifdef ENABLE_DOLLAR
if (inTouch->recording) {
inTouch->recording = SDL_FALSE;
dollarNormalize(&inTouch->dollarPath,path);
/* PrintPath(path); */
if (recordAll) {
index = SDL_AddDollarGesture(NULL,path);
for (i = 0; i < SDL_numGestureTouches; i++)
SDL_gestureTouch[i].recording = SDL_FALSE;
}
else {
index = SDL_AddDollarGesture(inTouch,path);
}
if (index >= 0) {
SDL_SendDollarRecord(inTouch,inTouch->dollarTemplate[index].hash);
}
else {
SDL_SendDollarRecord(inTouch,-1);
}
}
else {
int bestTempl;
float error;
error = dollarRecognize(&inTouch->dollarPath,
&bestTempl,inTouch);
if (bestTempl >= 0){
/* Send Event */
unsigned long gestureId = inTouch->dollarTemplate[bestTempl].hash;
SDL_SendGestureDollar(inTouch,gestureId,error);
/* printf ("%s\n",);("Dollar error: %f\n",error); */
}
}
#endif
/* inTouch->gestureLast[j] = inTouch->gestureLast[inTouch->numDownFingers]; */
if (inTouch->numDownFingers > 0) {
inTouch->centroid.x = (inTouch->centroid.x*(inTouch->numDownFingers+1)-
x)/inTouch->numDownFingers;
inTouch->centroid.y = (inTouch->centroid.y*(inTouch->numDownFingers+1)-
y)/inTouch->numDownFingers;
}
}
else if (event->type == SDL_FINGERMOTION) {
float dx = event->tfinger.dx;
float dy = event->tfinger.dy;
#ifdef ENABLE_DOLLAR
SDL_DollarPath* path = &inTouch->dollarPath;
if (path->numPoints < MAXPATHSIZE) {
path->p[path->numPoints].x = inTouch->centroid.x;
path->p[path->numPoints].y = inTouch->centroid.y;
pathDx =
(path->p[path->numPoints].x-path->p[path->numPoints-1].x);
pathDy =
(path->p[path->numPoints].y-path->p[path->numPoints-1].y);
path->length += (float)SDL_sqrt(pathDx*pathDx + pathDy*pathDy);
path->numPoints++;
}
#endif
lastP.x = x - dx;
lastP.y = y - dy;
lastCentroid = inTouch->centroid;
inTouch->centroid.x += dx/inTouch->numDownFingers;
inTouch->centroid.y += dy/inTouch->numDownFingers;
/* printf("Centrid : (%f,%f)\n",inTouch->centroid.x,inTouch->centroid.y); */
if (inTouch->numDownFingers > 1) {
SDL_FloatPoint lv; /* Vector from centroid to last x,y position */
SDL_FloatPoint v; /* Vector from centroid to current x,y position */
/* lv = inTouch->gestureLast[j].cv; */
lv.x = lastP.x - lastCentroid.x;
lv.y = lastP.y - lastCentroid.y;
lDist = (float)SDL_sqrt(lv.x*lv.x + lv.y*lv.y);
/* printf("lDist = %f\n",lDist); */
v.x = x - inTouch->centroid.x;
v.y = y - inTouch->centroid.y;
/* inTouch->gestureLast[j].cv = v; */
Dist = (float)SDL_sqrt(v.x*v.x+v.y*v.y);
/* SDL_cos(dTheta) = (v . lv)/(|v| * |lv|) */
/* Normalize Vectors to simplify angle calculation */
lv.x/=lDist;
lv.y/=lDist;
v.x/=Dist;
v.y/=Dist;
dtheta = (float)SDL_atan2(lv.x*v.y - lv.y*v.x,lv.x*v.x + lv.y*v.y);
dDist = (Dist - lDist);
if (lDist == 0) {dDist = 0;dtheta = 0;} /* To avoid impossible values */
/* inTouch->gestureLast[j].dDist = dDist;
inTouch->gestureLast[j].dtheta = dtheta;
printf("dDist = %f, dTheta = %f\n",dDist,dtheta);
gdtheta = gdtheta*.9 + dtheta*.1;
gdDist = gdDist*.9 + dDist*.1
knob.r += dDist/numDownFingers;
knob.ang += dtheta;
printf("thetaSum = %f, distSum = %f\n",gdtheta,gdDist);
printf("id: %i dTheta = %f, dDist = %f\n",j,dtheta,dDist); */
SDL_SendGestureMulti(inTouch,dtheta,dDist);
}
else {
/* inTouch->gestureLast[j].dDist = 0;
inTouch->gestureLast[j].dtheta = 0;
inTouch->gestureLast[j].cv.x = 0;
inTouch->gestureLast[j].cv.y = 0; */
}
/* inTouch->gestureLast[j].f.p.x = x;
inTouch->gestureLast[j].f.p.y = y;
break;
pressure? */
}
else if (event->type == SDL_FINGERDOWN) {
inTouch->numDownFingers++;
inTouch->centroid.x = (inTouch->centroid.x*(inTouch->numDownFingers - 1)+
x)/inTouch->numDownFingers;
inTouch->centroid.y = (inTouch->centroid.y*(inTouch->numDownFingers - 1)+
y)/inTouch->numDownFingers;
/* printf("Finger Down: (%f,%f). Centroid: (%f,%f\n",x,y,
inTouch->centroid.x,inTouch->centroid.y); */
#ifdef ENABLE_DOLLAR
inTouch->dollarPath.length = 0;
inTouch->dollarPath.p[0].x = x;
inTouch->dollarPath.p[0].y = y;
inTouch->dollarPath.numPoints = 1;
#endif
}
}
}
SDL_DollarPath::numPoints
int numPoints
Definition: SDL_gesture.c:53
SDL_DollarPath::length
float length
Definition: SDL_gesture.c:51
x
GLint GLint GLint GLint GLint x
Definition: SDL_opengl.h:1567
SDL_DollarTemplate::hash
unsigned long hash
Definition: SDL_gesture.c:59
SDL_DollarPath::p
SDL_FloatPoint p[MAXPATHSIZE]
Definition: SDL_gesture.c:54
SDL_GetGestureTouch
static SDL_GestureTouch * SDL_GetGestureTouch(SDL_TouchID id)
Definition: SDL_gesture.c:460
SDL_SendGestureMulti
int SDL_SendGestureMulti(SDL_GestureTouch *touch, float dTheta, float dDist)
Definition: SDL_gesture.c:471
SDL_atan2
#define SDL_atan2
Definition: SDL_dynapi_overrides.h:431
SDL_numGestureTouches
int SDL_numGestureTouches
Definition: SDL_gesture.c:75
SDL_TouchFingerEvent::touchId
SDL_TouchID touchId
Definition: SDL_events.h:414
SDL_SendDollarRecord
static int SDL_SendDollarRecord(SDL_GestureTouch *touch, SDL_GestureID gestureId)
Definition: SDL_gesture.c:500
DOLLARNPOINTS
#define DOLLARNPOINTS
Definition: SDL_gesture.c:39
SDL_GestureTouch::recording
SDL_bool recording
Definition: SDL_gesture.c:71
SDL_GestureTouch::centroid
SDL_FloatPoint centroid
Definition: SDL_gesture.c:64
SDL_FloatPoint::y
float y
Definition: SDL_gesture.c:47
v
const GLdouble * v
Definition: SDL_opengl.h:2057
SDL_GestureTouch::numDownFingers
Uint16 numDownFingers
Definition: SDL_gesture.c:66
SDL_FINGERDOWN
Definition: SDL_events.h:125
SDL_GestureTouch
Definition: SDL_gesture.c:62
y
GLint GLint GLint GLint GLint GLint y
Definition: SDL_opengl.h:1567
recordAll
SDL_bool recordAll
Definition: SDL_gesture.c:76
SDL_FloatPoint::x
float x
Definition: SDL_gesture.c:47
dollarRecognize
static float dollarRecognize(const SDL_DollarPath *path, int *bestTempl, SDL_GestureTouch *touch)
Definition: SDL_gesture.c:423
SDL_FloatPoint
Definition: SDL_gesture.c:46
SDL_gestureTouch
SDL_GestureTouch * SDL_gestureTouch
Definition: SDL_gesture.c:74
dollarNormalize
static int dollarNormalize(const SDL_DollarPath *path, SDL_FloatPoint *points)
Definition: SDL_gesture.c:331
SDL_FINGERMOTION
Definition: SDL_events.h:127
index
GLuint index
Definition: SDL_opengl_glext.h:660
i
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
Definition: SDL_x11sym.h:42
SDL_SendGestureDollar
static int SDL_SendGestureDollar(SDL_GestureTouch *touch, SDL_GestureID gestureId, float error)
Definition: SDL_gesture.c:484
NULL
#define NULL
Definition: begin_code.h:143
SDL_GestureTouch::dollarTemplate
SDL_DollarTemplate * dollarTemplate
Definition: SDL_gesture.c:69
SDL_DollarPath
Definition: SDL_gesture.c:50
SDL_FINGERUP
Definition: SDL_events.h:126
SDL_AddDollarGesture
static int SDL_AddDollarGesture(SDL_GestureTouch *inTouch, SDL_FloatPoint *path)
Definition: SDL_gesture.c:203
SDL_FALSE
Definition: SDL_stdinc.h:128
SDL_sqrt
#define SDL_sqrt
Definition: SDL_dynapi_overrides.h:443
MAXPATHSIZE
#define MAXPATHSIZE
Definition: SDL_gesture.c:37
path
GLsizei const GLchar *const * path
Definition: SDL_opengl_glext.h:3730
SDL_GestureTouch::dollarPath
SDL_DollarPath dollarPath
Definition: SDL_gesture.c:65
SDL_Event::type
Uint32 type
Definition: SDL_events.h:523
SDL_Event::tfinger
SDL_TouchFingerEvent tfinger
Definition: SDL_events.h:544

int SDL_RecordGesture | ( | SDL_TouchID | touchId | ) |

Begin Recording a gesture on the specified touch, or all touches (-1)

Definition at line 90 of file SDL_gesture.c.

References i, recordAll, SDL_GestureTouch::recording, SDL_numGestureTouches, and SDL_TRUE.

{
int i;
if (touchId < 0) recordAll = SDL_TRUE;
for (i = 0; i < SDL_numGestureTouches; i++) {
if ((touchId < 0) || (SDL_gestureTouch[i].id == touchId)) {
SDL_gestureTouch[i].recording = SDL_TRUE;
if (touchId >= 0)
return 1;
}
}
return (touchId < 0);
}
SDL_numGestureTouches
int SDL_numGestureTouches
Definition: SDL_gesture.c:75
SDL_GestureTouch::recording
SDL_bool recording
Definition: SDL_gesture.c:71
recordAll
SDL_bool recordAll
Definition: SDL_gesture.c:76
SDL_gestureTouch
SDL_GestureTouch * SDL_gestureTouch
Definition: SDL_gesture.c:74
SDL_TRUE
Definition: SDL_stdinc.h:129
i
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
Definition: SDL_x11sym.h:42