SDL 2.0
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)
 
int SDL_GestureDelTouch (SDL_TouchID touchId)
 
void SDL_GestureProcessEvent (SDL_Event *event)
 
void SDL_GestureQuit (void)
 

Function Documentation

◆ SDL_GestureAddTouch()

int SDL_GestureAddTouch ( SDL_TouchID  touchId)

Definition at line 450 of file SDL_gesture.c.

451{
454 sizeof(SDL_GestureTouch));
455
456 if (!gestureTouch) {
457 return SDL_OutOfMemory();
458 }
459
460 SDL_gestureTouch = gestureTouch;
461
465 return 0;
466}
#define SDL_realloc
#define SDL_OutOfMemory()
Definition: SDL_error.h:52
static SDL_GestureTouch * SDL_gestureTouch
Definition: SDL_gesture.c:74
static int SDL_numGestureTouches
Definition: SDL_gesture.c:75
#define SDL_zero(x)
Definition: SDL_stdinc.h:416
SDL_TouchID id
Definition: SDL_gesture.c:63

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

Referenced by SDL_AddTouch().

◆ SDL_GestureDelTouch()

int SDL_GestureDelTouch ( SDL_TouchID  touchId)

Definition at line 468 of file SDL_gesture.c.

469{
470 int i;
471 for (i = 0; i < SDL_numGestureTouches; i++) {
472 if (SDL_gestureTouch[i].id == touchId) {
473 break;
474 }
475 }
476
477 if (i == SDL_numGestureTouches) {
478 /* not found */
479 return -1;
480 }
481
482 SDL_free(SDL_gestureTouch[i].dollarTemplate);
484
487 return 0;
488}
#define SDL_free
#define SDL_memcpy
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:50

References i, SDL_free, SDL_gestureTouch, SDL_memcpy, SDL_numGestureTouches, and SDL_zero.

Referenced by SDL_DelTouch().

◆ SDL_GestureProcessEvent()

void SDL_GestureProcessEvent ( SDL_Event event)

Definition at line 542 of file SDL_gesture.c.

543{
544 float x,y;
545#if defined(ENABLE_DOLLAR)
546 int index;
547 int i;
548 float pathDx, pathDy;
549#endif
550 SDL_FloatPoint lastP;
551 SDL_FloatPoint lastCentroid;
552 float lDist;
553 float Dist;
554 float dtheta;
555 float dDist;
556
557 if (event->type == SDL_FINGERMOTION ||
558 event->type == SDL_FINGERDOWN ||
559 event->type == SDL_FINGERUP) {
560 SDL_GestureTouch* inTouch = SDL_GetGestureTouch(event->tfinger.touchId);
561
562 /* Shouldn't be possible */
563 if (inTouch == NULL) return;
564
565 x = event->tfinger.x;
566 y = event->tfinger.y;
567
568 /* Finger Up */
569 if (event->type == SDL_FINGERUP) {
570#if defined(ENABLE_DOLLAR)
572#endif
573
574 inTouch->numDownFingers--;
575
576#if defined(ENABLE_DOLLAR)
577 if (inTouch->recording) {
578 inTouch->recording = SDL_FALSE;
580 /* PrintPath(path); */
581 if (recordAll) {
583 for (i = 0; i < SDL_numGestureTouches; i++)
584 SDL_gestureTouch[i].recording = SDL_FALSE;
585 }
586 else {
588 }
589
590 if (index >= 0) {
592 }
593 else {
594 SDL_SendDollarRecord(inTouch,-1);
595 }
596 }
597 else {
598 int bestTempl;
599 float error;
600 error = dollarRecognize(&inTouch->dollarPath,
601 &bestTempl,inTouch);
602 if (bestTempl >= 0){
603 /* Send Event */
604 unsigned long gestureId = inTouch->dollarTemplate[bestTempl].hash;
605 SDL_SendGestureDollar(inTouch,gestureId,error);
606 /* printf ("%s\n",);("Dollar error: %f\n",error); */
607 }
608 }
609#endif
610 /* inTouch->gestureLast[j] = inTouch->gestureLast[inTouch->numDownFingers]; */
611 if (inTouch->numDownFingers > 0) {
612 inTouch->centroid.x = (inTouch->centroid.x*(inTouch->numDownFingers+1)-
613 x)/inTouch->numDownFingers;
614 inTouch->centroid.y = (inTouch->centroid.y*(inTouch->numDownFingers+1)-
615 y)/inTouch->numDownFingers;
616 }
617 }
618 else if (event->type == SDL_FINGERMOTION) {
619 float dx = event->tfinger.dx;
620 float dy = event->tfinger.dy;
621#if defined(ENABLE_DOLLAR)
622 SDL_DollarPath* path = &inTouch->dollarPath;
623 if (path->numPoints < MAXPATHSIZE) {
624 path->p[path->numPoints].x = inTouch->centroid.x;
625 path->p[path->numPoints].y = inTouch->centroid.y;
626 pathDx =
627 (path->p[path->numPoints].x-path->p[path->numPoints-1].x);
628 pathDy =
629 (path->p[path->numPoints].y-path->p[path->numPoints-1].y);
630 path->length += (float)SDL_sqrt(pathDx*pathDx + pathDy*pathDy);
631 path->numPoints++;
632 }
633#endif
634 lastP.x = x - dx;
635 lastP.y = y - dy;
636 lastCentroid = inTouch->centroid;
637
638 inTouch->centroid.x += dx/inTouch->numDownFingers;
639 inTouch->centroid.y += dy/inTouch->numDownFingers;
640 /* printf("Centrid : (%f,%f)\n",inTouch->centroid.x,inTouch->centroid.y); */
641 if (inTouch->numDownFingers > 1) {
642 SDL_FloatPoint lv; /* Vector from centroid to last x,y position */
643 SDL_FloatPoint v; /* Vector from centroid to current x,y position */
644 /* lv = inTouch->gestureLast[j].cv; */
645 lv.x = lastP.x - lastCentroid.x;
646 lv.y = lastP.y - lastCentroid.y;
647 lDist = (float)SDL_sqrt(lv.x*lv.x + lv.y*lv.y);
648 /* printf("lDist = %f\n",lDist); */
649 v.x = x - inTouch->centroid.x;
650 v.y = y - inTouch->centroid.y;
651 /* inTouch->gestureLast[j].cv = v; */
652 Dist = (float)SDL_sqrt(v.x*v.x+v.y*v.y);
653 /* SDL_cos(dTheta) = (v . lv)/(|v| * |lv|) */
654
655 /* Normalize Vectors to simplify angle calculation */
656 lv.x/=lDist;
657 lv.y/=lDist;
658 v.x/=Dist;
659 v.y/=Dist;
660 dtheta = (float)SDL_atan2(lv.x*v.y - lv.y*v.x,lv.x*v.x + lv.y*v.y);
661
662 dDist = (Dist - lDist);
663 if (lDist == 0) {dDist = 0;dtheta = 0;} /* To avoid impossible values */
664
665 /* inTouch->gestureLast[j].dDist = dDist;
666 inTouch->gestureLast[j].dtheta = dtheta;
667
668 printf("dDist = %f, dTheta = %f\n",dDist,dtheta);
669 gdtheta = gdtheta*.9 + dtheta*.1;
670 gdDist = gdDist*.9 + dDist*.1
671 knob.r += dDist/numDownFingers;
672 knob.ang += dtheta;
673 printf("thetaSum = %f, distSum = %f\n",gdtheta,gdDist);
674 printf("id: %i dTheta = %f, dDist = %f\n",j,dtheta,dDist); */
675 SDL_SendGestureMulti(inTouch,dtheta,dDist);
676 }
677 else {
678 /* inTouch->gestureLast[j].dDist = 0;
679 inTouch->gestureLast[j].dtheta = 0;
680 inTouch->gestureLast[j].cv.x = 0;
681 inTouch->gestureLast[j].cv.y = 0; */
682 }
683 /* inTouch->gestureLast[j].f.p.x = x;
684 inTouch->gestureLast[j].f.p.y = y;
685 break;
686 pressure? */
687 }
688 else if (event->type == SDL_FINGERDOWN) {
689
690 inTouch->numDownFingers++;
691 inTouch->centroid.x = (inTouch->centroid.x*(inTouch->numDownFingers - 1)+
692 x)/inTouch->numDownFingers;
693 inTouch->centroid.y = (inTouch->centroid.y*(inTouch->numDownFingers - 1)+
694 y)/inTouch->numDownFingers;
695 /* printf("Finger Down: (%f,%f). Centroid: (%f,%f\n",x,y,
696 inTouch->centroid.x,inTouch->centroid.y); */
697
698#if defined(ENABLE_DOLLAR)
699 inTouch->dollarPath.length = 0;
700 inTouch->dollarPath.p[0].x = x;
701 inTouch->dollarPath.p[0].y = y;
702 inTouch->dollarPath.numPoints = 1;
703#endif
704 }
705 }
706}
#define SDL_sqrt
#define SDL_atan2
@ SDL_FINGERMOTION
Definition: SDL_events.h:130
@ SDL_FINGERUP
Definition: SDL_events.h:129
@ SDL_FINGERDOWN
Definition: SDL_events.h:128
static int SDL_SendGestureDollar(SDL_GestureTouch *touch, SDL_GestureID gestureId, float error)
Definition: SDL_gesture.c:515
static float dollarRecognize(const SDL_DollarPath *path, int *bestTempl, SDL_GestureTouch *touch)
Definition: SDL_gesture.c:430
#define DOLLARNPOINTS
Definition: SDL_gesture.c:39
static SDL_GestureTouch * SDL_GetGestureTouch(SDL_TouchID id)
Definition: SDL_gesture.c:490
#define MAXPATHSIZE
Definition: SDL_gesture.c:37
static int SDL_SendDollarRecord(SDL_GestureTouch *touch, SDL_GestureID gestureId)
Definition: SDL_gesture.c:531
static int SDL_SendGestureMulti(SDL_GestureTouch *touch, float dTheta, float dDist)
Definition: SDL_gesture.c:501
static SDL_bool recordAll
Definition: SDL_gesture.c:76
static int SDL_AddDollarGesture(SDL_GestureTouch *inTouch, SDL_FloatPoint *path)
Definition: SDL_gesture.c:209
static int dollarNormalize(const SDL_DollarPath *path, SDL_FloatPoint *points)
Definition: SDL_gesture.c:338
GLint GLint GLint GLint GLint GLint y
Definition: SDL_opengl.h:1574
const GLdouble * v
Definition: SDL_opengl.h:2064
GLint GLint GLint GLint GLint x
Definition: SDL_opengl.h:1574
struct _cl_event * event
GLuint index
GLsizei const GLchar *const * path
@ SDL_FALSE
Definition: SDL_stdinc.h:163
#define NULL
Definition: begin_code.h:167
SDL_FloatPoint p[MAXPATHSIZE]
Definition: SDL_gesture.c:54
unsigned long hash
Definition: SDL_gesture.c:59
SDL_DollarTemplate * dollarTemplate
Definition: SDL_gesture.c:69
Uint16 numDownFingers
Definition: SDL_gesture.c:66
SDL_DollarPath dollarPath
Definition: SDL_gesture.c:65
SDL_FloatPoint centroid
Definition: SDL_gesture.c:64
SDL_bool recording
Definition: SDL_gesture.c:71

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_gestureTouch, SDL_GetGestureTouch(), SDL_numGestureTouches, SDL_SendDollarRecord(), SDL_SendGestureDollar(), SDL_SendGestureMulti(), SDL_sqrt, SDL_FloatPoint::x, and SDL_FloatPoint::y.

Referenced by SDL_PushEvent().

◆ SDL_GestureQuit()

void SDL_GestureQuit ( void  )

Definition at line 104 of file SDL_gesture.c.

References NULL, SDL_free, and SDL_gestureTouch.

Referenced by SDL_TouchQuit().