Mercurial > sdl-ios-xcode
comparison src/events/SDL_gesture.c @ 4664:317a151b79ad
Bug fixes, now using RWops instead of File pointers.
author | Jim Grandpre <jim.tla@gmail.com> |
---|---|
date | Fri, 16 Jul 2010 20:48:43 -0400 |
parents | 063b9455bd1a |
children | c2493813a2f4 |
comparison
equal
deleted
inserted
replaced
4662:3c4e0130c9b1 | 4664:317a151b79ad |
---|---|
108 hash = ((hash<<5) + hash) + points[i].y; | 108 hash = ((hash<<5) + hash) + points[i].y; |
109 } | 109 } |
110 return hash; | 110 return hash; |
111 } | 111 } |
112 | 112 |
113 int SaveTemplate(DollarTemplate *templ, FILE *fp) { | 113 int SaveTemplate(DollarTemplate *templ, SDL_RWops * src) { |
114 int i; | 114 if(src == NULL) return 0; |
115 fprintf(fp,"%lu ",templ->hash); | 115 int i; |
116 | |
117 //No Longer storing the Hash, rehash on load | |
118 //fprintf(fp,"%lu ",templ->hash); | |
119 //if(SDL_RWops.write(src,&(templ->hash),sizeof(templ->hash),1) != 1) return 0; | |
120 | |
121 /* | |
116 for(i = 0;i < DOLLARNPOINTS;i++) { | 122 for(i = 0;i < DOLLARNPOINTS;i++) { |
117 fprintf(fp,"%i %i ",(int)templ->path[i].x,(int)templ->path[i].y); | 123 fprintf(fp,"%i %i ",(int)templ->path[i].x,(int)templ->path[i].y); |
118 } | 124 } |
119 fprintf(fp,"\n"); | 125 fprintf(fp,"\n"); |
120 } | 126 */ |
121 | 127 if(SDL_RWwrite(src,templ->path,sizeof(templ->path[0]),DOLLARNPOINTS) != DOLLARNPOINTS) return 0; |
122 | 128 return 1; |
123 int SDL_SaveAllDollarTemplates(FILE *fp) { | 129 } |
130 | |
131 | |
132 int SDL_SaveAllDollarTemplates(SDL_RWops *src) { | |
124 int i,j,rtrn = 0; | 133 int i,j,rtrn = 0; |
125 for(i = 0; i < numGestureTouches; i++) { | 134 for(i = 0; i < numGestureTouches; i++) { |
126 GestureTouch* touch = &gestureTouch[i]; | 135 GestureTouch* touch = &gestureTouch[i]; |
127 for(j = 0;j < touch->numDollarTemplates; j++) { | 136 for(j = 0;j < touch->numDollarTemplates; j++) { |
128 rtrn += SaveTemplate(&touch->dollarTemplate[i],fp); | 137 rtrn += SaveTemplate(&touch->dollarTemplate[i],src); |
129 } | 138 } |
130 } | 139 } |
131 return rtrn; | 140 return rtrn; |
132 } | 141 } |
133 | 142 |
134 int SDL_SaveDollarTemplate(unsigned long gestureId, FILE *fp) { | 143 int SDL_SaveDollarTemplate(unsigned long gestureId, SDL_RWops *src) { |
135 int i,j; | 144 int i,j; |
136 for(i = 0; i < numGestureTouches; i++) { | 145 for(i = 0; i < numGestureTouches; i++) { |
137 GestureTouch* touch = &gestureTouch[i]; | 146 GestureTouch* touch = &gestureTouch[i]; |
138 for(j = 0;j < touch->numDollarTemplates; j++) { | 147 for(j = 0;j < touch->numDollarTemplates; j++) { |
139 if(touch->dollarTemplate[i].hash == gestureId) { | 148 if(touch->dollarTemplate[i].hash == gestureId) { |
140 return SaveTemplate(&touch->dollarTemplate[i],fp); | 149 return SaveTemplate(&touch->dollarTemplate[i],src); |
141 } | 150 } |
142 } | 151 } |
143 } | 152 } |
144 } | 153 } |
145 | 154 |
146 int SDL_LoadDollarTemplates(int touchId, FILE *fp) { | 155 int SDL_LoadDollarTemplates(int touchId, SDL_RWops *src) { |
156 if(src == NULL) return 0; | |
147 int i,loaded = 0; | 157 int i,loaded = 0; |
148 GestureTouch *touch = NULL; | 158 GestureTouch *touch = NULL; |
149 if(touchId >= 0) { | 159 if(touchId >= 0) { |
150 for(i = 0;i < numGestureTouches; i++) | 160 for(i = 0;i < numGestureTouches; i++) |
151 if(gestureTouch[i].id == touchId) | 161 if(gestureTouch[i].id == touchId) |
152 touch = &gestureTouch[i]; | 162 touch = &gestureTouch[i]; |
153 if(touch == NULL) return -1; | 163 if(touch == NULL) return -1; |
154 } | 164 } |
155 | 165 |
156 while(!feof(fp)) { | 166 while(1) { |
157 DollarTemplate templ; | 167 DollarTemplate templ; |
158 fscanf(fp,"%lu ",&templ.hash); | 168 //fscanf(fp,"%lu ",&templ.hash); |
169 /* | |
159 for(i = 0;i < DOLLARNPOINTS; i++) { | 170 for(i = 0;i < DOLLARNPOINTS; i++) { |
160 int x,y; | 171 int x,y; |
161 if(fscanf(fp,"%i %i ",&x,&y) != 2) break; | 172 if(fscanf(fp,"%i %i ",&x,&y) != 2) break; |
162 templ.path[i].x = x; | 173 templ.path[i].x = x; |
163 templ.path[i].y = y; | 174 templ.path[i].y = y; |
164 } | 175 } |
165 fscanf(fp,"\n"); | 176 fscanf(fp,"\n"); |
177 */ | |
178 if(SDL_RWread(src,templ.path,sizeof(templ.path[0]),DOLLARNPOINTS) < DOLLARNPOINTS) break; | |
166 | 179 |
167 if(touchId >= 0) { | 180 if(touchId >= 0) { |
168 if(SDL_AddDollarGesture(touch,templ)) loaded++; | 181 printf("Adding loaded gesture to 1 touch\n"); |
182 if(SDL_AddDollarGesture(touch,templ.path)) loaded++; | |
169 } | 183 } |
170 else { | 184 else { |
185 printf("Adding to: %i touches\n",numGestureTouches); | |
171 for(i = 0;i < numGestureTouches; i++) { | 186 for(i = 0;i < numGestureTouches; i++) { |
172 if(gestureTouch[i].id == touchId) { | 187 touch = &gestureTouch[i]; |
173 touch = &gestureTouch[i]; | 188 printf("Adding loaded gesture to + touches\n"); |
174 SDL_AddDollarGesture(touch,templ); | 189 //TODO: What if this fails? |
175 } | 190 SDL_AddDollarGesture(touch,templ.path); |
176 } | 191 } |
177 loaded++; | 192 loaded++; |
178 } | 193 } |
179 } | 194 } |
180 | 195 |
181 return 1; | 196 return loaded; |
182 } | 197 } |
183 | 198 |
184 | 199 |
185 //path is an already sampled set of points | 200 //path is an already sampled set of points |
186 //Returns the index of the gesture on success, or -1 | 201 //Returns the index of the gesture on success, or -1 |