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 448 of file SDL_gesture.c.

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

Referenced by SDL_AddTouch().

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

◆ SDL_GestureDelTouch()

int SDL_GestureDelTouch ( SDL_TouchID  touchId)

Definition at line 466 of file SDL_gesture.c.

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

Referenced by SDL_DelTouch().

467 {
468  int i;
469  for (i = 0; i < SDL_numGestureTouches; i++) {
470  if (SDL_gestureTouch[i].id == touchId) {
471  break;
472  }
473  }
474 
475  if (i == SDL_numGestureTouches) {
476  /* not found */
477  return -1;
478  }
479 
480  SDL_free(SDL_gestureTouch[i].dollarTemplate);
482 
483  SDL_numGestureTouches--;
484  SDL_memcpy(&SDL_gestureTouch[i], &SDL_gestureTouch[SDL_numGestureTouches], sizeof(SDL_gestureTouch[i]));
485  return 0;
486 }
static int SDL_numGestureTouches
Definition: SDL_gesture.c:75
#define SDL_memcpy
#define SDL_free
static SDL_GestureTouch * SDL_gestureTouch
Definition: SDL_gesture.c:74
#define SDL_zero(x)
Definition: SDL_stdinc.h:416
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

◆ SDL_GestureProcessEvent()

void SDL_GestureProcessEvent ( SDL_Event event)

Definition at line 538 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().

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

◆ SDL_GestureQuit()

void SDL_GestureQuit ( void  )

Definition at line 104 of file SDL_gesture.c.

References NULL, and SDL_free.

Referenced by SDL_TouchQuit().

105 {
108 }
#define SDL_free
static SDL_GestureTouch * SDL_gestureTouch
Definition: SDL_gesture.c:74
#define NULL
Definition: begin_code.h:164