22 #include "../SDL_internal.h" 37 #define MAXPATHSIZE 1024 39 #define DOLLARNPOINTS 64 40 #define DOLLARSIZE 256 44 #define PHI 0.618033989 84 printf(
" (%f,%f)",path[i].
x,path[i].
y);
95 if ((touchId < 0) || (SDL_gestureTouch[i].
id == touchId)) {
101 return (touchId < 0);
107 SDL_gestureTouch =
NULL;
112 unsigned long hash = 5381;
115 hash = ((hash<<5) + hash) + (
unsigned long)points[i].
x;
116 hash = ((hash<<5) + hash) + (
unsigned long)points[i].
y;
131 #if SDL_BYTEORDER == SDL_LIL_ENDIAN 147 sizeof(copy.
path[0]),DOLLARNPOINTS) != DOLLARNPOINTS) {
196 if (!dollarTemplate) {
213 if (inTouch ==
NULL) {
216 inTouch = &SDL_gestureTouch[
i];
231 if (src ==
NULL)
return 0;
234 if (SDL_gestureTouch[i].
id == touchId) {
235 touch = &SDL_gestureTouch[
i];
248 return SDL_SetError(
"could not read any dollar gesture from rwops");
253 #if SDL_BYTEORDER != SDL_LIL_ENDIAN 269 touch = &SDL_gestureTouch[
i];
292 (p.
y-templ[i].
y)*(p.
y-templ[
i].
y)));
307 float x1 = (float)(
PHI*ta + (1-
PHI)*tb);
309 float x2 = (float)((1-
PHI)*ta +
PHI*tb);
316 x1 = (float)(
PHI*ta + (1-
PHI)*tb);
323 x2 = (float)((1-
PHI)*ta +
PHI*tb);
344 float xmin,xmax,ymin,ymax;
352 float dx = path->
p[
i ].
x - path->
p[i-1].
x;
353 float dy = path->
p[
i ].
y - path->
p[i-1].
y;
354 length += (float)(
SDL_sqrt(dx*dx+dy*dy));
362 centroid.
x = 0;centroid.
y = 0;
366 float d = (float)(
SDL_sqrt((path->
p[i-1].
x-path->
p[i].
x)*(path->
p[i-1].
x-path->
p[
i].
x)+
367 (path->
p[i-1].
y-path->
p[i].
y)*(path->
p[i-1].
y-path->
p[
i].
y)));
369 while (dist + d > interval) {
370 points[numPoints].
x = path->
p[i-1].
x +
371 ((interval-dist)/d)*(path->
p[
i].
x-path->
p[i-1].
x);
372 points[numPoints].
y = path->
p[i-1].
y +
373 ((interval-dist)/d)*(path->
p[
i].
y-path->
p[i-1].
y);
374 centroid.
x += points[numPoints].
x;
375 centroid.
y += points[numPoints].
y;
390 centroid.
x /= numPoints;
391 centroid.
y /= numPoints;
401 centroid.
x - points[0].
x));
403 for (i = 0; i<numPoints; i++) {
404 float px = points[
i].
x;
405 float py = points[
i].
y;
406 points[
i].
x = (float)((px - centroid.
x)*
SDL_cos(ang) -
407 (py - centroid.
y)*
SDL_sin(ang) + centroid.
x);
408 points[
i].
y = (float)((px - centroid.
x)*
SDL_sin(ang) +
409 (py - centroid.
y)*
SDL_cos(ang) + centroid.
y);
412 if (points[i].
x < xmin) xmin = points[
i].
x;
413 if (points[i].
x > xmax) xmax = points[
i].
x;
414 if (points[i].
y < ymin) ymin = points[
i].
y;
415 if (points[i].
y > ymax) ymax = points[
i].
y;
422 for (i=0; i<numPoints; i++) {
433 float bestDiff = 10000;
443 if (diff < bestDiff) {bestDiff = diff; *bestTempl =
i;}
458 SDL_gestureTouch = gestureTouch;
462 SDL_numGestureTouches++;
470 if (SDL_gestureTouch[i].
id == touchId) {
475 if (i == SDL_numGestureTouches) {
480 SDL_free(SDL_gestureTouch[i].dollarTemplate);
483 SDL_numGestureTouches--;
484 SDL_memcpy(&SDL_gestureTouch[i], &SDL_gestureTouch[SDL_numGestureTouches],
sizeof(SDL_gestureTouch[i]));
493 if (SDL_gestureTouch[i].
id ==
id)
494 return &SDL_gestureTouch[
i];
503 event.mgesture.touchId = touch->
id;
506 event.mgesture.dTheta = dTheta;
507 event.mgesture.dDist = dDist;
517 event.dgesture.touchId = touch->
id;
520 event.dgesture.gestureId = gestureId;
521 event.dgesture.error = error;
532 event.dgesture.touchId = touch->
id;
533 event.dgesture.gestureId = gestureId;
543 float pathDx, pathDy;
557 if (inTouch ==
NULL)
return;
559 x =
event->tfinger.x;
560 y =
event->tfinger.y;
576 SDL_gestureTouch[i].recording =
SDL_FALSE;
611 float dx =
event->tfinger.dx;
612 float dy =
event->tfinger.dy;
637 lv.
x = lastP.
x - lastCentroid.
x;
638 lv.
y = lastP.
y - lastCentroid.
y;
654 dDist = (Dist - lDist);
655 if (lDist == 0) {dDist = 0;dtheta = 0;}
GLuint GLfloat GLfloat GLfloat x1
static unsigned long SDL_HashDollar(SDL_FloatPoint *points)
int SDL_GestureDelTouch(SDL_TouchID touchId)
SDL_FloatPoint path[DOLLARNPOINTS]
GLint GLint GLint GLint GLint x
#define SDL_RWwrite(ctx, ptr, size, n)
static int SDL_SendGestureMulti(SDL_GestureTouch *touch, float dTheta, float dDist)
static int SDL_AddDollarGesture_one(SDL_GestureTouch *inTouch, SDL_FloatPoint *path)
SDL_FloatPoint p[MAXPATHSIZE]
static SDL_GestureTouch * SDL_GetGestureTouch(SDL_TouchID id)
GLfloat GLfloat GLfloat GLfloat h
static int SDL_numGestureTouches
#define SDL_RWread(ctx, ptr, size, n)
static int SDL_SendDollarRecord(SDL_GestureTouch *touch, SDL_GestureID gestureId)
#define SDL_SwapFloatLE(X)
static float bestDollarDifference(SDL_FloatPoint *points, SDL_FloatPoint *templ)
GLfixed GLfixed GLint GLint GLfixed points
void SDL_GestureProcessEvent(SDL_Event *event)
int SDL_GestureAddTouch(SDL_TouchID touchId)
SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char const char SDL_SCANF_FORMAT_STRING const char return SDL_ThreadFunction const char void return Uint32 return Uint32 SDL_AssertionHandler void SDL_SpinLock SDL_atomic_t int int return SDL_atomic_t return void void void return void return int return SDL_AudioSpec SDL_AudioSpec return int int return return int SDL_RWops int SDL_AudioSpec Uint8 ** d
static SDL_bool recordAll
int SDL_SaveAllDollarTemplates(SDL_RWops *dst)
Save all currently loaded Dollar Gesture templates.
static float dollarRecognize(const SDL_DollarPath *path, int *bestTempl, SDL_GestureTouch *touch)
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 int in j)
int SDL_RecordGesture(SDL_TouchID touchId)
Begin Recording a gesture on the specified touch, or all touches (-1)
GLubyte GLubyte GLubyte GLubyte w
static SDL_GestureTouch * SDL_gestureTouch
static int dollarNormalize(const SDL_DollarPath *path, SDL_FloatPoint *points)
GLint GLint GLint GLint GLint GLint y
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)
static int SDL_SendGestureDollar(SDL_GestureTouch *touch, SDL_GestureID gestureId, float error)
int SDL_SaveDollarTemplate(SDL_GestureID gestureId, SDL_RWops *dst)
Save a currently loaded Dollar Gesture template.
#define SDL_OutOfMemory()
SDL_DollarTemplate * dollarTemplate
int SDL_LoadDollarTemplates(SDL_TouchID touchId, SDL_RWops *src)
Load Dollar Gesture templates from a file.
static int SDL_AddDollarGesture(SDL_GestureTouch *inTouch, SDL_FloatPoint *path)
static int SaveTemplate(SDL_DollarTemplate *templ, SDL_RWops *dst)
static float dollarDifference(SDL_FloatPoint *points, SDL_FloatPoint *templ, float ang)
GLsizei const GLchar *const * path
GLuint GLsizei GLsizei * length
SDL_DollarPath dollarPath
SDL_TouchFingerEvent tfinger