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);
106 unsigned long hash = 5381;
109 hash = ((hash<<5) + hash) + (
unsigned long)points[i].
x;
110 hash = ((hash<<5) + hash) + (
unsigned long)points[i].
y;
125 #if SDL_BYTEORDER == SDL_LIL_ENDIAN 141 sizeof(copy.
path[0]),DOLLARNPOINTS) != DOLLARNPOINTS) {
190 if (!dollarTemplate) {
207 if (inTouch ==
NULL) {
210 inTouch = &SDL_gestureTouch[
i];
225 if (src ==
NULL)
return 0;
228 if (SDL_gestureTouch[i].
id == touchId) {
229 touch = &SDL_gestureTouch[
i];
242 return SDL_SetError(
"could not read any dollar gesture from rwops");
247 #if SDL_BYTEORDER != SDL_LIL_ENDIAN 263 touch = &SDL_gestureTouch[
i];
286 (p.
y-templ[i].
y)*(p.
y-templ[
i].
y)));
301 float x1 = (float)(
PHI*ta + (1-
PHI)*tb);
303 float x2 = (float)((1-
PHI)*ta +
PHI*tb);
310 x1 = (float)(
PHI*ta + (1-
PHI)*tb);
317 x2 = (float)((1-
PHI)*ta +
PHI*tb);
338 float xmin,xmax,ymin,ymax;
346 float dx = path->
p[
i ].
x - path->
p[i-1].
x;
347 float dy = path->
p[
i ].
y - path->
p[i-1].
y;
348 length += (float)(
SDL_sqrt(dx*dx+dy*dy));
356 centroid.
x = 0;centroid.
y = 0;
360 float d = (float)(
SDL_sqrt((path->
p[i-1].
x-path->
p[i].
x)*(path->
p[i-1].
x-path->
p[
i].
x)+
361 (path->
p[i-1].
y-path->
p[i].
y)*(path->
p[i-1].
y-path->
p[
i].
y)));
363 while (dist + d > interval) {
364 points[numPoints].
x = path->
p[i-1].
x +
365 ((interval-dist)/d)*(path->
p[
i].
x-path->
p[i-1].
x);
366 points[numPoints].
y = path->
p[i-1].
y +
367 ((interval-dist)/d)*(path->
p[
i].
y-path->
p[i-1].
y);
368 centroid.
x += points[numPoints].
x;
369 centroid.
y += points[numPoints].
y;
384 centroid.
x /= numPoints;
385 centroid.
y /= numPoints;
395 centroid.
x - points[0].
x));
397 for (i = 0; i<numPoints; i++) {
398 float px = points[
i].
x;
399 float py = points[
i].
y;
400 points[
i].
x = (float)((px - centroid.
x)*
SDL_cos(ang) -
401 (py - centroid.
y)*
SDL_sin(ang) + centroid.
x);
402 points[
i].
y = (float)((px - centroid.
x)*
SDL_sin(ang) +
403 (py - centroid.
y)*
SDL_cos(ang) + centroid.
y);
406 if (points[i].
x < xmin) xmin = points[
i].
x;
407 if (points[i].
x > xmax) xmax = points[
i].
x;
408 if (points[i].
y < ymin) ymin = points[
i].
y;
409 if (points[i].
y > ymax) ymax = points[
i].
y;
416 for (i=0; i<numPoints; i++) {
427 float bestDiff = 10000;
437 if (diff < bestDiff) {bestDiff = diff; *bestTempl =
i;}
452 SDL_gestureTouch = gestureTouch;
456 SDL_numGestureTouches++;
465 if (SDL_gestureTouch[i].
id ==
id)
466 return &SDL_gestureTouch[
i];
475 event.mgesture.touchId = touch->
id;
478 event.mgesture.dTheta = dTheta;
479 event.mgesture.dDist = dDist;
489 event.dgesture.touchId = touch->
id;
492 event.dgesture.gestureId = gestureId;
493 event.dgesture.error = error;
504 event.dgesture.touchId = touch->
id;
505 event.dgesture.gestureId = gestureId;
515 float pathDx, pathDy;
529 if (inTouch ==
NULL)
return;
531 x =
event->tfinger.x;
532 y =
event->tfinger.y;
548 SDL_gestureTouch[i].recording =
SDL_FALSE;
583 float dx =
event->tfinger.dx;
584 float dy =
event->tfinger.dy;
609 lv.
x = lastP.
x - lastCentroid.
x;
610 lv.
y = lastP.
y - lastCentroid.
y;
626 dDist = (Dist - lDist);
627 if (lDist == 0) {dDist = 0;dtheta = 0;}
GLuint GLfloat GLfloat GLfloat x1
static unsigned long SDL_HashDollar(SDL_FloatPoint *points)
SDL_FloatPoint path[DOLLARNPOINTS]
#define SDL_RWwrite(ctx, ptr, size, n)
GLint GLint GLint GLint GLint x
static int SDL_AddDollarGesture_one(SDL_GestureTouch *inTouch, SDL_FloatPoint *path)
SDL_FloatPoint p[MAXPATHSIZE]
static SDL_GestureTouch * SDL_GetGestureTouch(SDL_TouchID id)
int SDL_SendGestureMulti(SDL_GestureTouch *touch, float dTheta, float dDist)
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)
GLint GLint GLint GLint GLint GLint y
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
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)
SDL_GestureTouch * SDL_gestureTouch
static int dollarNormalize(const SDL_DollarPath *path, SDL_FloatPoint *points)
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)
uint16_t Uint16
An unsigned 16-bit integer type.
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
GLubyte GLubyte GLubyte GLubyte w
GLuint GLsizei GLsizei * length
GLfloat GLfloat GLfloat GLfloat h
SDL_DollarPath dollarPath
SDL_TouchFingerEvent tfinger