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

455 {
457  (SDL_numGestureTouches + 1) *
458  sizeof(SDL_GestureTouch));
459 
460  if (!gestureTouch) {
461  return SDL_OutOfMemory();
462  }
463 
464  SDL_gestureTouch = gestureTouch;
465 
469  return 0;
470 }

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

473 {
474  int i;
475  for (i = 0; i < SDL_numGestureTouches; i++) {
476  if (SDL_gestureTouch[i].id == touchId) {
477  break;
478  }
479  }
480 
481  if (i == SDL_numGestureTouches) {
482  /* not found */
483  return -1;
484  }
485 
486  SDL_free(SDL_gestureTouch[i].dollarTemplate);
488 
491  return 0;
492 }

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

552 {
553  float x,y;
554 #if defined(ENABLE_DOLLAR)
555  int index;
556  int i;
557  float pathDx, pathDy;
558 #endif
559  SDL_FloatPoint lastP;
560  SDL_FloatPoint lastCentroid;
561  float lDist;
562  float Dist;
563  float dtheta;
564  float dDist;
565 
566  if (event->type == SDL_FINGERMOTION ||
567  event->type == SDL_FINGERDOWN ||
568  event->type == SDL_FINGERUP) {
569  SDL_GestureTouch* inTouch = SDL_GetGestureTouch(event->tfinger.touchId);
570 
571  /* Shouldn't be possible */
572  if (inTouch == NULL) return;
573 
574  x = event->tfinger.x;
575  y = event->tfinger.y;
576 
577  /* Finger Up */
578  if (event->type == SDL_FINGERUP) {
579 #if defined(ENABLE_DOLLAR)
581 #endif
582 
583  inTouch->numDownFingers--;
584 
585 #if defined(ENABLE_DOLLAR)
586  if (inTouch->recording) {
587  inTouch->recording = SDL_FALSE;
589  /* PrintPath(path); */
590  if (recordAll) {
592  for (i = 0; i < SDL_numGestureTouches; i++)
593  SDL_gestureTouch[i].recording = SDL_FALSE;
594  }
595  else {
596  index = SDL_AddDollarGesture(inTouch,path);
597  }
598 
599  if (index >= 0) {
600  SDL_SendDollarRecord(inTouch,inTouch->dollarTemplate[index].hash);
601  }
602  else {
603  SDL_SendDollarRecord(inTouch,-1);
604  }
605  }
606  else {
607  int bestTempl;
608  float error;
609  error = dollarRecognize(&inTouch->dollarPath,
610  &bestTempl,inTouch);
611  if (bestTempl >= 0){
612  /* Send Event */
613  unsigned long gestureId = inTouch->dollarTemplate[bestTempl].hash;
614  SDL_SendGestureDollar(inTouch,gestureId,error);
615  /* printf ("%s\n",);("Dollar error: %f\n",error); */
616  }
617  }
618 #endif
619  /* inTouch->gestureLast[j] = inTouch->gestureLast[inTouch->numDownFingers]; */
620  if (inTouch->numDownFingers > 0) {
621  inTouch->centroid.x = (inTouch->centroid.x*(inTouch->numDownFingers+1)-
622  x)/inTouch->numDownFingers;
623  inTouch->centroid.y = (inTouch->centroid.y*(inTouch->numDownFingers+1)-
624  y)/inTouch->numDownFingers;
625  }
626  }
627  else if (event->type == SDL_FINGERMOTION) {
628  float dx = event->tfinger.dx;
629  float dy = event->tfinger.dy;
630 #if defined(ENABLE_DOLLAR)
631  SDL_DollarPath* path = &inTouch->dollarPath;
632  if (path->numPoints < MAXPATHSIZE) {
633  path->p[path->numPoints].x = inTouch->centroid.x;
634  path->p[path->numPoints].y = inTouch->centroid.y;
635  pathDx =
636  (path->p[path->numPoints].x-path->p[path->numPoints-1].x);
637  pathDy =
638  (path->p[path->numPoints].y-path->p[path->numPoints-1].y);
639  path->length += (float)SDL_sqrt(pathDx*pathDx + pathDy*pathDy);
640  path->numPoints++;
641  }
642 #endif
643  lastP.x = x - dx;
644  lastP.y = y - dy;
645  lastCentroid = inTouch->centroid;
646 
647  inTouch->centroid.x += dx/inTouch->numDownFingers;
648  inTouch->centroid.y += dy/inTouch->numDownFingers;
649  /* printf("Centrid : (%f,%f)\n",inTouch->centroid.x,inTouch->centroid.y); */
650  if (inTouch->numDownFingers > 1) {
651  SDL_FloatPoint lv; /* Vector from centroid to last x,y position */
652  SDL_FloatPoint v; /* Vector from centroid to current x,y position */
653  /* lv = inTouch->gestureLast[j].cv; */
654  lv.x = lastP.x - lastCentroid.x;
655  lv.y = lastP.y - lastCentroid.y;
656  lDist = (float)SDL_sqrt(lv.x*lv.x + lv.y*lv.y);
657  /* printf("lDist = %f\n",lDist); */
658  v.x = x - inTouch->centroid.x;
659  v.y = y - inTouch->centroid.y;
660  /* inTouch->gestureLast[j].cv = v; */
661  Dist = (float)SDL_sqrt(v.x*v.x+v.y*v.y);
662  /* SDL_cos(dTheta) = (v . lv)/(|v| * |lv|) */
663 
664  /* Normalize Vectors to simplify angle calculation */
665  lv.x/=lDist;
666  lv.y/=lDist;
667  v.x/=Dist;
668  v.y/=Dist;
669  dtheta = (float)SDL_atan2(lv.x*v.y - lv.y*v.x,lv.x*v.x + lv.y*v.y);
670 
671  dDist = (Dist - lDist);
672  if (lDist == 0) {dDist = 0;dtheta = 0;} /* To avoid impossible values */
673 
674  /* inTouch->gestureLast[j].dDist = dDist;
675  inTouch->gestureLast[j].dtheta = dtheta;
676 
677  printf("dDist = %f, dTheta = %f\n",dDist,dtheta);
678  gdtheta = gdtheta*.9 + dtheta*.1;
679  gdDist = gdDist*.9 + dDist*.1
680  knob.r += dDist/numDownFingers;
681  knob.ang += dtheta;
682  printf("thetaSum = %f, distSum = %f\n",gdtheta,gdDist);
683  printf("id: %i dTheta = %f, dDist = %f\n",j,dtheta,dDist); */
684  SDL_SendGestureMulti(inTouch,dtheta,dDist);
685  }
686  else {
687  /* inTouch->gestureLast[j].dDist = 0;
688  inTouch->gestureLast[j].dtheta = 0;
689  inTouch->gestureLast[j].cv.x = 0;
690  inTouch->gestureLast[j].cv.y = 0; */
691  }
692  /* inTouch->gestureLast[j].f.p.x = x;
693  inTouch->gestureLast[j].f.p.y = y;
694  break;
695  pressure? */
696  }
697  else if (event->type == SDL_FINGERDOWN) {
698 
699  inTouch->numDownFingers++;
700  inTouch->centroid.x = (inTouch->centroid.x*(inTouch->numDownFingers - 1)+
701  x)/inTouch->numDownFingers;
702  inTouch->centroid.y = (inTouch->centroid.y*(inTouch->numDownFingers - 1)+
703  y)/inTouch->numDownFingers;
704  /* printf("Finger Down: (%f,%f). Centroid: (%f,%f\n",x,y,
705  inTouch->centroid.x,inTouch->centroid.y); */
706 
707 #if defined(ENABLE_DOLLAR)
708  inTouch->dollarPath.length = 0;
709  inTouch->dollarPath.p[0].x = x;
710  inTouch->dollarPath.p[0].y = y;
711  inTouch->dollarPath.numPoints = 1;
712 #endif
713  }
714  }
715 }

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_TRUE, SDL_FloatPoint::x, and SDL_FloatPoint::y.

Referenced by SDL_PushEvent().

◆ SDL_GestureQuit()

void SDL_GestureQuit ( void  )

Definition at line 106 of file SDL_gesture.c.

107 {
110 }

References NULL, SDL_free, and SDL_gestureTouch.

Referenced by SDL_TouchQuit().

SDL_zero
#define SDL_zero(x)
Definition: SDL_stdinc.h:418
SDL_GestureTouch::centroid
SDL_FloatPoint centroid
Definition: SDL_gesture.c:66
SDL_FloatPoint::x
float x
Definition: SDL_gesture.c:49
SDL_DollarPath::length
float length
Definition: SDL_gesture.c:53
dollarRecognize
static float dollarRecognize(const SDL_DollarPath *path, int *bestTempl, SDL_GestureTouch *touch)
Definition: SDL_gesture.c:434
SDL_DollarTemplate::hash
unsigned long hash
Definition: SDL_gesture.c:61
NULL
#define NULL
Definition: begin_code.h:167
SDL_DollarPath
Definition: SDL_gesture.c:52
SDL_atan2
#define SDL_atan2
Definition: SDL_dynapi_overrides.h:425
SDL_GestureTouch::dollarTemplate
SDL_DollarTemplate * dollarTemplate
Definition: SDL_gesture.c:71
SDL_SendDollarRecord
static void SDL_SendDollarRecord(SDL_GestureTouch *touch, SDL_GestureID gestureId)
Definition: SDL_gesture.c:538
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:55
path
GLsizei const GLchar *const * path
Definition: SDL_opengl_glext.h:3733
index
GLuint index
Definition: SDL_opengl_glext.h:663
v
const GLdouble * v
Definition: SDL_opengl.h:2064
SDL_GestureTouch::dollarPath
SDL_DollarPath dollarPath
Definition: SDL_gesture.c:67
SDL_FINGERUP
@ SDL_FINGERUP
Definition: SDL_events.h:129
SDL_GestureTouch::recording
SDL_bool recording
Definition: SDL_gesture.c:73
SDL_FloatPoint
Definition: SDL_gesture.c:48
SDL_memcpy
#define SDL_memcpy
Definition: SDL_dynapi_overrides.h:387
event
struct _cl_event * event
Definition: SDL_opengl_glext.h:2652
SDL_FALSE
@ SDL_FALSE
Definition: SDL_stdinc.h:163
SDL_GestureTouch::numDownFingers
Uint16 numDownFingers
Definition: SDL_gesture.c:68
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_SendGestureMulti
static void SDL_SendGestureMulti(SDL_GestureTouch *touch, float dTheta, float dDist)
Definition: SDL_gesture.c:505
SDL_FINGERMOTION
@ SDL_FINGERMOTION
Definition: SDL_events.h:130
SDL_gestureTouch
static SDL_GestureTouch * SDL_gestureTouch
Definition: SDL_gesture.c:76
SDL_numGestureTouches
static int SDL_numGestureTouches
Definition: SDL_gesture.c:77
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:64
DOLLARNPOINTS
#define DOLLARNPOINTS
Definition: SDL_gesture.c:41
SDL_DollarPath::p
SDL_FloatPoint p[MAXPATHSIZE]
Definition: SDL_gesture.c:56
SDL_TRUE
@ SDL_TRUE
Definition: SDL_stdinc.h:164
recordAll
static SDL_bool recordAll
Definition: SDL_gesture.c:78
SDL_sqrt
#define SDL_sqrt
Definition: SDL_dynapi_overrides.h:437
SDL_FloatPoint::y
float y
Definition: SDL_gesture.c:49
dollarNormalize
static int dollarNormalize(const SDL_DollarPath *path, SDL_FloatPoint *points, SDL_bool is_recording)
Definition: SDL_gesture.c:340
SDL_GestureTouch::id
SDL_TouchID id
Definition: SDL_gesture.c:65
SDL_AddDollarGesture
static int SDL_AddDollarGesture(SDL_GestureTouch *inTouch, SDL_FloatPoint *path)
Definition: SDL_gesture.c:211
SDL_GetGestureTouch
static SDL_GestureTouch * SDL_GetGestureTouch(SDL_TouchID id)
Definition: SDL_gesture.c:494
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_SendGestureDollar
static void SDL_SendGestureDollar(SDL_GestureTouch *touch, SDL_GestureID gestureId, float error)
Definition: SDL_gesture.c:521