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 {
453  (SDL_numGestureTouches + 1) *
454  sizeof(SDL_GestureTouch));
455 
456  if (!gestureTouch) {
457  return SDL_OutOfMemory();
458  }
459 
460  SDL_gestureTouch = gestureTouch;
461 
465  return 0;
466 }

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 }

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;
579  dollarNormalize(&inTouch->dollarPath,path);
580  /* PrintPath(path); */
581  if (recordAll) {
583  for (i = 0; i < SDL_numGestureTouches; i++)
584  SDL_gestureTouch[i].recording = SDL_FALSE;
585  }
586  else {
587  index = SDL_AddDollarGesture(inTouch,path);
588  }
589 
590  if (index >= 0) {
591  SDL_SendDollarRecord(inTouch,inTouch->dollarTemplate[index].hash);
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 }

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.

105 {
108 }

References NULL, SDL_free, and SDL_gestureTouch.

Referenced by SDL_TouchQuit().

SDL_zero
#define SDL_zero(x)
Definition: SDL_stdinc.h:416
SDL_GestureTouch::centroid
SDL_FloatPoint centroid
Definition: SDL_gesture.c:64
SDL_FloatPoint::x
float x
Definition: SDL_gesture.c:47
SDL_DollarPath::length
float length
Definition: SDL_gesture.c:51
dollarRecognize
static float dollarRecognize(const SDL_DollarPath *path, int *bestTempl, SDL_GestureTouch *touch)
Definition: SDL_gesture.c:430
SDL_DollarTemplate::hash
unsigned long hash
Definition: SDL_gesture.c:59
NULL
#define NULL
Definition: begin_code.h:167
SDL_DollarPath
Definition: SDL_gesture.c:50
SDL_atan2
#define SDL_atan2
Definition: SDL_dynapi_overrides.h:425
SDL_GestureTouch::dollarTemplate
SDL_DollarTemplate * dollarTemplate
Definition: SDL_gesture.c:69
SDL_realloc
#define SDL_realloc
Definition: SDL_dynapi_overrides.h:376
MAXPATHSIZE
#define MAXPATHSIZE
Definition: SDL_gesture.c:37
SDL_DollarPath::numPoints
int numPoints
Definition: SDL_gesture.c:53
path
GLsizei const GLchar *const * path
Definition: SDL_opengl_glext.h:3730
index
GLuint index
Definition: SDL_opengl_glext.h:660
v
const GLdouble * v
Definition: SDL_opengl.h:2064
SDL_GestureTouch::dollarPath
SDL_DollarPath dollarPath
Definition: SDL_gesture.c:65
SDL_FINGERUP
@ SDL_FINGERUP
Definition: SDL_events.h:129
SDL_GestureTouch::recording
SDL_bool recording
Definition: SDL_gesture.c:71
SDL_FloatPoint
Definition: SDL_gesture.c:46
SDL_memcpy
#define SDL_memcpy
Definition: SDL_dynapi_overrides.h:387
event
struct _cl_event * event
Definition: SDL_opengl_glext.h:2649
SDL_FALSE
@ SDL_FALSE
Definition: SDL_stdinc.h:163
dollarNormalize
static int dollarNormalize(const SDL_DollarPath *path, SDL_FloatPoint *points)
Definition: SDL_gesture.c:338
SDL_GestureTouch::numDownFingers
Uint16 numDownFingers
Definition: SDL_gesture.c:66
SDL_FINGERDOWN
@ SDL_FINGERDOWN
Definition: SDL_events.h:128
x
GLint GLint GLint GLint GLint x
Definition: SDL_opengl.h:1574
SDL_free
#define SDL_free
Definition: SDL_dynapi_overrides.h:377
SDL_FINGERMOTION
@ SDL_FINGERMOTION
Definition: SDL_events.h:130
SDL_gestureTouch
static SDL_GestureTouch * SDL_gestureTouch
Definition: SDL_gesture.c:74
SDL_numGestureTouches
static int SDL_numGestureTouches
Definition: SDL_gesture.c:75
SDL_OutOfMemory
#define SDL_OutOfMemory()
Definition: SDL_error.h:52
y
GLint GLint GLint GLint GLint GLint y
Definition: SDL_opengl.h:1574
SDL_GestureTouch
Definition: SDL_gesture.c:62
DOLLARNPOINTS
#define DOLLARNPOINTS
Definition: SDL_gesture.c:39
SDL_DollarPath::p
SDL_FloatPoint p[MAXPATHSIZE]
Definition: SDL_gesture.c:54
SDL_SendGestureMulti
static int SDL_SendGestureMulti(SDL_GestureTouch *touch, float dTheta, float dDist)
Definition: SDL_gesture.c:501
recordAll
static SDL_bool recordAll
Definition: SDL_gesture.c:76
SDL_sqrt
#define SDL_sqrt
Definition: SDL_dynapi_overrides.h:437
SDL_FloatPoint::y
float y
Definition: SDL_gesture.c:47
SDL_SendDollarRecord
static int SDL_SendDollarRecord(SDL_GestureTouch *touch, SDL_GestureID gestureId)
Definition: SDL_gesture.c:531
SDL_GestureTouch::id
SDL_TouchID id
Definition: SDL_gesture.c:63
SDL_AddDollarGesture
static int SDL_AddDollarGesture(SDL_GestureTouch *inTouch, SDL_FloatPoint *path)
Definition: SDL_gesture.c:209
SDL_SendGestureDollar
static int SDL_SendGestureDollar(SDL_GestureTouch *touch, SDL_GestureID gestureId, float error)
Definition: SDL_gesture.c:515
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:50
SDL_GetGestureTouch
static SDL_GestureTouch * SDL_GetGestureTouch(SDL_TouchID id)
Definition: SDL_gesture.c:490