Merged changes
authorJim Grandpre <jim.tla@gmail.com>
Fri, 16 Jul 2010 20:53:44 -0400
changeset 4665c2493813a2f4
parent 4664 317a151b79ad
parent 4663 56a2d70de945
child 4666 52e871f486b8
child 4667 0ecdbabdd7e7
Merged changes
src/events/SDL_gesture.c
     1.1 --- a/Xcode-iPhoneOS/SDL/SDLiPhoneOS.xcodeproj/project.pbxproj	Fri Jul 16 20:48:43 2010 -0400
     1.2 +++ b/Xcode-iPhoneOS/SDL/SDLiPhoneOS.xcodeproj/project.pbxproj	Fri Jul 16 20:53:44 2010 -0400
     1.3 @@ -95,6 +95,12 @@
     1.4  		04B2ECEE1025CE4800F9BC5F /* SDL_revision.h in Headers */ = {isa = PBXBuildFile; fileRef = 04B2ECE81025CE4800F9BC5F /* SDL_revision.h */; settings = {ATTRIBUTES = (Public, ); }; };
     1.5  		04B2ECFF1025CEB900F9BC5F /* SDL_atomic.c in Sources */ = {isa = PBXBuildFile; fileRef = 04B2ECF11025CEB900F9BC5F /* SDL_atomic.c */; };
     1.6  		04B2ED081025CF9E00F9BC5F /* SDL_config.h in Headers */ = {isa = PBXBuildFile; fileRef = 04B2ED061025CF9E00F9BC5F /* SDL_config.h */; settings = {ATTRIBUTES = (Public, ); }; };
     1.7 +		04BA9D6311EF474A00B60E01 /* SDL_gesture_c.h in Headers */ = {isa = PBXBuildFile; fileRef = 04BA9D5F11EF474A00B60E01 /* SDL_gesture_c.h */; };
     1.8 +		04BA9D6411EF474A00B60E01 /* SDL_gesture.c in Sources */ = {isa = PBXBuildFile; fileRef = 04BA9D6011EF474A00B60E01 /* SDL_gesture.c */; };
     1.9 +		04BA9D6511EF474A00B60E01 /* SDL_touch_c.h in Headers */ = {isa = PBXBuildFile; fileRef = 04BA9D6111EF474A00B60E01 /* SDL_touch_c.h */; };
    1.10 +		04BA9D6611EF474A00B60E01 /* SDL_touch.c in Sources */ = {isa = PBXBuildFile; fileRef = 04BA9D6211EF474A00B60E01 /* SDL_touch.c */; };
    1.11 +		04BA9D7D11EF497E00B60E01 /* SDL_gesture.h in Headers */ = {isa = PBXBuildFile; fileRef = 04BA9D7B11EF497E00B60E01 /* SDL_gesture.h */; };
    1.12 +		04BA9D7E11EF497E00B60E01 /* SDL_touch.h in Headers */ = {isa = PBXBuildFile; fileRef = 04BA9D7C11EF497E00B60E01 /* SDL_touch.h */; };
    1.13  		04EC8B521025D12900431D42 /* SDL_config_iphoneos.h in Headers */ = {isa = PBXBuildFile; fileRef = 04EC8B501025D12900431D42 /* SDL_config_iphoneos.h */; };
    1.14  		04F2AF541104ABC300D6DDF7 /* SDL_assert.h in Headers */ = {isa = PBXBuildFile; fileRef = 04F2AF531104ABC300D6DDF7 /* SDL_assert.h */; };
    1.15  		04F2AF561104ABD200D6DDF7 /* SDL_assert.c in Sources */ = {isa = PBXBuildFile; fileRef = 04F2AF551104ABD200D6DDF7 /* SDL_assert.c */; };
    1.16 @@ -346,6 +352,12 @@
    1.17  		04B2ECE81025CE4800F9BC5F /* SDL_revision.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SDL_revision.h; path = ../../include/SDL_revision.h; sourceTree = SOURCE_ROOT; };
    1.18  		04B2ECF11025CEB900F9BC5F /* SDL_atomic.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_atomic.c; sourceTree = "<group>"; };
    1.19  		04B2ED061025CF9E00F9BC5F /* SDL_config.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SDL_config.h; path = ../../include/SDL_config.h; sourceTree = SOURCE_ROOT; };
    1.20 +		04BA9D5F11EF474A00B60E01 /* SDL_gesture_c.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_gesture_c.h; sourceTree = "<group>"; };
    1.21 +		04BA9D6011EF474A00B60E01 /* SDL_gesture.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_gesture.c; sourceTree = "<group>"; };
    1.22 +		04BA9D6111EF474A00B60E01 /* SDL_touch_c.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_touch_c.h; sourceTree = "<group>"; };
    1.23 +		04BA9D6211EF474A00B60E01 /* SDL_touch.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_touch.c; sourceTree = "<group>"; };
    1.24 +		04BA9D7B11EF497E00B60E01 /* SDL_gesture.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SDL_gesture.h; path = ../../include/SDL_gesture.h; sourceTree = SOURCE_ROOT; };
    1.25 +		04BA9D7C11EF497E00B60E01 /* SDL_touch.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SDL_touch.h; path = ../../include/SDL_touch.h; sourceTree = SOURCE_ROOT; };
    1.26  		04EC8B501025D12900431D42 /* SDL_config_iphoneos.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SDL_config_iphoneos.h; path = ../../include/SDL_config_iphoneos.h; sourceTree = SOURCE_ROOT; };
    1.27  		04F2AF531104ABC300D6DDF7 /* SDL_assert.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SDL_assert.h; path = ../../include/SDL_assert.h; sourceTree = SOURCE_ROOT; };
    1.28  		04F2AF551104ABD200D6DDF7 /* SDL_assert.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = SDL_assert.c; path = ../../src/SDL_assert.c; sourceTree = SOURCE_ROOT; };
    1.29 @@ -851,6 +863,7 @@
    1.30  				FD99B8F60DD52EB400FB1D6B /* SDL_endian.h */,
    1.31  				FD99B8DC0DD52EB400FB1D6B /* SDL_error.h */,
    1.32  				FD99B8DD0DD52EB400FB1D6B /* SDL_events.h */,
    1.33 +				04BA9D7B11EF497E00B60E01 /* SDL_gesture.h */,
    1.34  				04461DED0EA76BA3006C462D /* SDL_haptic.h */,
    1.35  				044E5FB411E6069F0076F181 /* SDL_input.h */,
    1.36  				FD99B8DE0DD52EB400FB1D6B /* SDL_joystick.h */,
    1.37 @@ -876,6 +889,7 @@
    1.38  				FD99B8EF0DD52EB400FB1D6B /* SDL_syswm.h */,
    1.39  				FD99B8F00DD52EB400FB1D6B /* SDL_thread.h */,
    1.40  				FD99B8F10DD52EB400FB1D6B /* SDL_timer.h */,
    1.41 +				04BA9D7C11EF497E00B60E01 /* SDL_touch.h */,
    1.42  				FD99B8F20DD52EB400FB1D6B /* SDL_types.h */,
    1.43  				FD99B8F30DD52EB400FB1D6B /* SDL_version.h */,
    1.44  				FD99B8F40DD52EB400FB1D6B /* SDL_video.h */,
    1.45 @@ -956,6 +970,10 @@
    1.46  		FD99B98C0DD52EDC00FB1D6B /* events */ = {
    1.47  			isa = PBXGroup;
    1.48  			children = (
    1.49 +				04BA9D5F11EF474A00B60E01 /* SDL_gesture_c.h */,
    1.50 +				04BA9D6011EF474A00B60E01 /* SDL_gesture.c */,
    1.51 +				04BA9D6111EF474A00B60E01 /* SDL_touch_c.h */,
    1.52 +				04BA9D6211EF474A00B60E01 /* SDL_touch.c */,
    1.53  				FD99B98D0DD52EDC00FB1D6B /* blank_cursor.h */,
    1.54  				FD99B98E0DD52EDC00FB1D6B /* default_cursor.h */,
    1.55  				FD99B98F0DD52EDC00FB1D6B /* scancodes_darwin.h */,
    1.56 @@ -1191,6 +1209,10 @@
    1.57  				044E5FB511E6069F0076F181 /* SDL_clipboard.h in Headers */,
    1.58  				044E5FB611E6069F0076F181 /* SDL_input.h in Headers */,
    1.59  				0420497011E6F03D007E7EC9 /* SDL_clipboardevents_c.h in Headers */,
    1.60 +				04BA9D6311EF474A00B60E01 /* SDL_gesture_c.h in Headers */,
    1.61 +				04BA9D6511EF474A00B60E01 /* SDL_touch_c.h in Headers */,
    1.62 +				04BA9D7D11EF497E00B60E01 /* SDL_gesture.h in Headers */,
    1.63 +				04BA9D7E11EF497E00B60E01 /* SDL_touch.h in Headers */,
    1.64  			);
    1.65  			runOnlyForDeploymentPostprocessing = 0;
    1.66  		};
    1.67 @@ -1431,6 +1453,8 @@
    1.68  				006E9889119552DD001DE610 /* SDL_rwopsbundlesupport.m in Sources */,
    1.69  				044E5FB811E606EB0076F181 /* SDL_clipboard.c in Sources */,
    1.70  				0420497111E6F03D007E7EC9 /* SDL_clipboardevents.c in Sources */,
    1.71 +				04BA9D6411EF474A00B60E01 /* SDL_gesture.c in Sources */,
    1.72 +				04BA9D6611EF474A00B60E01 /* SDL_touch.c in Sources */,
    1.73  			);
    1.74  			runOnlyForDeploymentPostprocessing = 0;
    1.75  		};
     2.1 --- a/src/events/SDL_gesture.c	Fri Jul 16 20:48:43 2010 -0400
     2.2 +++ b/src/events/SDL_gesture.c	Fri Jul 16 20:53:44 2010 -0400
     2.3 @@ -110,8 +110,10 @@
     2.4    return hash;
     2.5  }
     2.6  
     2.7 -int SaveTemplate(DollarTemplate *templ, SDL_RWops * src) {
     2.8 +
     2.9 +static int SaveTemplate(DollarTemplate *templ, SDL_RWops * src) {
    2.10    if(src == NULL) return 0;
    2.11 +
    2.12    int i;
    2.13    
    2.14    //No Longer storing the Hash, rehash on load
    2.15 @@ -123,6 +125,7 @@
    2.16      fprintf(fp,"%i %i ",(int)templ->path[i].x,(int)templ->path[i].y);
    2.17    }
    2.18    fprintf(fp,"\n");
    2.19 +
    2.20    */
    2.21    if(SDL_RWwrite(src,templ->path,sizeof(templ->path[0]),DOLLARNPOINTS) != DOLLARNPOINTS) return 0;
    2.22    return 1;
    2.23 @@ -150,6 +153,36 @@
    2.24        }
    2.25      }
    2.26    }
    2.27 +  SDL_SetError("Unknown gestureId");
    2.28 +  return -1;
    2.29 +}
    2.30 +
    2.31 +//path is an already sampled set of points
    2.32 +//Returns the index of the gesture on success, or -1
    2.33 +static int SDL_AddDollarGesture(GestureTouch* inTouch,Point* path) {
    2.34 +  if(inTouch == NULL) {
    2.35 +    if(numGestureTouches == 0) return -1;
    2.36 +    int i = 0;
    2.37 +    for(i = 0;i < numGestureTouches; i++) {
    2.38 +      inTouch = &gestureTouch[i];
    2.39 +      if(inTouch->numDollarTemplates < MAXTEMPLATES) {
    2.40 +	DollarTemplate *templ = 
    2.41 +	  &inTouch->dollarTemplate[inTouch->numDollarTemplates];
    2.42 +	memcpy(templ->path,path,DOLLARNPOINTS*sizeof(Point));
    2.43 +	templ->hash = SDL_HashDollar(templ->path);
    2.44 +	inTouch->numDollarTemplates++;
    2.45 +      }
    2.46 +    }
    2.47 +    return inTouch->numDollarTemplates - 1;
    2.48 +  }else if(inTouch->numDollarTemplates < MAXTEMPLATES) {
    2.49 +    DollarTemplate *templ = 
    2.50 +      &inTouch->dollarTemplate[inTouch->numDollarTemplates];
    2.51 +    memcpy(templ->path,path,DOLLARNPOINTS*sizeof(Point));
    2.52 +    templ->hash = SDL_HashDollar(templ->path);
    2.53 +    inTouch->numDollarTemplates++;
    2.54 +    return inTouch->numDollarTemplates - 1;
    2.55 +  }
    2.56 +  return -1;
    2.57  }
    2.58  
    2.59  int SDL_LoadDollarTemplates(int touchId, SDL_RWops *src) {
    2.60 @@ -197,37 +230,6 @@
    2.61  }
    2.62  
    2.63  
    2.64 -//path is an already sampled set of points
    2.65 -//Returns the index of the gesture on success, or -1
    2.66 -int SDL_AddDollarGesture(GestureTouch* inTouch,Point* path) {
    2.67 -  if(inTouch == NULL) {
    2.68 -    if(numGestureTouches == 0) return -1;
    2.69 -    int i = 0;
    2.70 -    for(i = 0;i < numGestureTouches; i++) {
    2.71 -      inTouch = &gestureTouch[i];
    2.72 -      if(inTouch->numDollarTemplates < MAXTEMPLATES) {
    2.73 -	DollarTemplate *templ = 
    2.74 -	  &inTouch->dollarTemplate[inTouch->numDollarTemplates];
    2.75 -	memcpy(templ->path,path,DOLLARNPOINTS*sizeof(Point));
    2.76 -	templ->hash = SDL_HashDollar(templ->path);
    2.77 -	inTouch->numDollarTemplates++;
    2.78 -      }
    2.79 -    }
    2.80 -    return inTouch->numDollarTemplates - 1;
    2.81 -  }else if(inTouch->numDollarTemplates < MAXTEMPLATES) {
    2.82 -    DollarTemplate *templ = 
    2.83 -      &inTouch->dollarTemplate[inTouch->numDollarTemplates];
    2.84 -    memcpy(templ->path,path,DOLLARNPOINTS*sizeof(Point));
    2.85 -    templ->hash = SDL_HashDollar(templ->path);
    2.86 -    inTouch->numDollarTemplates++;
    2.87 -    return inTouch->numDollarTemplates - 1;
    2.88 -  }
    2.89 -  return -1;
    2.90 -}
    2.91 -
    2.92 -
    2.93 -
    2.94 -
    2.95  float dollarDifference(Point* points,Point* templ,float ang) {
    2.96    //  Point p[DOLLARNPOINTS];
    2.97    float dist = 0;
    2.98 @@ -279,21 +281,6 @@
    2.99    return SDL_min(f1,f2);  
   2.100  }
   2.101  
   2.102 -float dollarRecognize(DollarPath path,int *bestTempl,GestureTouch* touch) {
   2.103 -
   2.104 -  Point points[DOLLARNPOINTS];
   2.105 -  int numPoints = dollarNormalize(path,points);
   2.106 -  int i;
   2.107 - 
   2.108 -  int bestDiff = 10000;
   2.109 -  *bestTempl = -1;
   2.110 -  for(i = 0;i < touch->numDollarTemplates;i++) {
   2.111 -    int diff = bestDollarDifference(points,touch->dollarTemplate[i].path);
   2.112 -    if(diff < bestDiff) {bestDiff = diff; *bestTempl = i;}
   2.113 -  }
   2.114 -  return bestDiff;
   2.115 -}
   2.116 -
   2.117  //DollarPath contains raw points, plus (possibly) the calculated length
   2.118  int dollarNormalize(DollarPath path,Point *points) {
   2.119    int i;
   2.120 @@ -374,6 +361,21 @@
   2.121    return numPoints;
   2.122  }
   2.123  
   2.124 +float dollarRecognize(DollarPath path,int *bestTempl,GestureTouch* touch) {
   2.125 +	
   2.126 +	Point points[DOLLARNPOINTS];
   2.127 +	int numPoints = dollarNormalize(path,points);
   2.128 +	int i;
   2.129 +	
   2.130 +	int bestDiff = 10000;
   2.131 +	*bestTempl = -1;
   2.132 +	for(i = 0;i < touch->numDollarTemplates;i++) {
   2.133 +		int diff = bestDollarDifference(points,touch->dollarTemplate[i].path);
   2.134 +		if(diff < bestDiff) {bestDiff = diff; *bestTempl = i;}
   2.135 +	}
   2.136 +	return bestDiff;
   2.137 +}
   2.138 +
   2.139  int SDL_GestureAddTouch(SDL_Touch* touch) { 
   2.140    if(numGestureTouches >= MAXTOUCHES) return -1;
   2.141