Mercurial > sdl-ios-xcode
comparison src/events/SDL_touch.c @ 4646:eea1bf53effa
Added include/touch.h Now reading in resolution of touch pad.
author | Jim Grandpre <jim.tla@gmail.com> |
---|---|
date | Tue, 01 Jun 2010 02:54:33 -0400 |
parents | 0375d020e7e3 |
children | 0350b634c044 |
comparison
equal
deleted
inserted
replaced
4645:0375d020e7e3 | 4646:eea1bf53effa |
---|---|
131 SDL_touchPads[index]->focus = 0; | 131 SDL_touchPads[index]->focus = 0; |
132 SDL_touchPads[index]->name = SDL_malloc((length + 2) * sizeof(char)); | 132 SDL_touchPads[index]->name = SDL_malloc((length + 2) * sizeof(char)); |
133 SDL_strlcpy(SDL_touchPads[index]->name, name, length + 1); | 133 SDL_strlcpy(SDL_touchPads[index]->name, name, length + 1); |
134 | 134 |
135 SDL_touchPads[index]->num_fingers = 0; | 135 SDL_touchPads[index]->num_fingers = 0; |
136 SDL_touchPads[index]->max_fingers = 0; | 136 SDL_touchPads[index]->max_fingers = 1; |
137 SDL_touchPads[index]->fingers = NULL; | 137 SDL_touchPads[index]->fingers = (SDL_Finger **) SDL_malloc(sizeof(SDL_Finger*)); |
138 | 138 SDL_touchPads[index]->fingers[0] = NULL; |
139 SDL_touchPads[index]->buttonstate = 0; | 139 SDL_touchPads[index]->buttonstate = 0; |
140 SDL_touchPads[index]->relative_mode = SDL_FALSE; | 140 SDL_touchPads[index]->relative_mode = SDL_FALSE; |
141 SDL_touchPads[index]->flush_motion = SDL_FALSE; | 141 SDL_touchPads[index]->flush_motion = SDL_FALSE; |
142 | 142 |
143 return index; | 143 return index; |
251 SDL_AddFinger(SDL_Touch* touch,SDL_Finger* finger) | 251 SDL_AddFinger(SDL_Touch* touch,SDL_Finger* finger) |
252 { | 252 { |
253 int index; | 253 int index; |
254 SDL_Finger **fingers; | 254 SDL_Finger **fingers; |
255 size_t length; | 255 size_t length; |
256 | 256 //printf("Adding Finger...\n"); |
257 if (SDL_GetFingerIndexId(touch,finger->id) != -1) { | 257 if (SDL_GetFingerIndexId(touch,finger->id) != -1) { |
258 SDL_SetError("Finger ID already in use"); | 258 SDL_SetError("Finger ID already in use"); |
259 } | 259 } |
260 | 260 |
261 /* Add the touch to the list of touch */ | 261 /* Add the touch to the list of touch */ |
262 if(touch->num_fingers >= touch->max_fingers){ | 262 if(touch->num_fingers >= touch->max_fingers){ |
263 if(fingers == NULL) { | 263 printf("Making room for it!\n"); |
264 touch->max_fingers = 1; | 264 fingers = (SDL_Finger **) SDL_realloc(touch->fingers, |
265 fingers = (SDL_Finger **) SDL_malloc(sizeof(finger)); | 265 (touch->num_fingers + 1) * sizeof(SDL_Finger *)); |
266 } | |
267 else { | |
268 fingers = (SDL_Finger **) SDL_realloc(touch->fingers, | |
269 (touch->num_fingers + 1) * sizeof(finger)); | |
270 touch->max_fingers = touch->num_fingers+1; | 266 touch->max_fingers = touch->num_fingers+1; |
271 } | 267 if (!fingers) { |
272 | 268 SDL_OutOfMemory(); |
273 } | 269 return -1; |
274 | 270 } |
275 if (!fingers) { | 271 else { |
276 SDL_OutOfMemory(); | 272 touch->max_fingers = touch->num_fingers+1; |
277 return -1; | 273 touch->fingers = fingers; |
278 } | 274 } |
279 | 275 } |
280 touch->fingers = fingers; | 276 |
281 index = touch->num_fingers; | 277 index = touch->num_fingers; |
282 touch->num_fingers++; | 278 //printf("Max_Fingers: %i Index: %i\n",touch->max_fingers,index); |
283 touch->fingers[index] = (SDL_Finger *) SDL_malloc(sizeof(*(touch->fingers[index]))); | 279 |
280 touch->fingers[index] = (SDL_Finger *) SDL_malloc(sizeof(SDL_Finger)); | |
284 if (!touch->fingers[index]) { | 281 if (!touch->fingers[index]) { |
285 SDL_OutOfMemory(); | 282 SDL_OutOfMemory(); |
286 return -1; | 283 return -1; |
287 } | 284 } |
288 *touch->fingers[index] = *finger; | 285 *(touch->fingers[index]) = *finger; |
286 touch->num_fingers++; | |
289 | 287 |
290 return index; | 288 return index; |
291 } | 289 } |
292 | 290 |
293 int | 291 int |
321 nf.pressure = pressure; | 319 nf.pressure = pressure; |
322 nf.xdelta = 0; | 320 nf.xdelta = 0; |
323 nf.ydelta = 0; | 321 nf.ydelta = 0; |
324 nf.last_x = x; | 322 nf.last_x = x; |
325 nf.last_y = y; | 323 nf.last_y = y; |
324 nf.last_pressure = pressure; | |
326 SDL_AddFinger(touch,&nf); | 325 SDL_AddFinger(touch,&nf); |
327 | 326 |
328 posted = 0; | 327 posted = 0; |
329 if (SDL_GetEventState(SDL_FINGERDOWN) == SDL_ENABLE) { | 328 if (SDL_GetEventState(SDL_FINGERDOWN) == SDL_ENABLE) { |
330 SDL_Event event; | 329 SDL_Event event; |
381 x = (finger->last_x + x); | 380 x = (finger->last_x + x); |
382 y = (finger->last_y + y); | 381 y = (finger->last_y + y); |
383 } else { | 382 } else { |
384 if(x < 0) x = finger->last_x; /*If movement is only in one axis,*/ | 383 if(x < 0) x = finger->last_x; /*If movement is only in one axis,*/ |
385 if(y < 0) y = finger->last_y; /*The other is marked as -1*/ | 384 if(y < 0) y = finger->last_y; /*The other is marked as -1*/ |
385 if(pressure < 0) pressure = finger->last_pressure; | |
386 xrel = x - finger->last_x; | 386 xrel = x - finger->last_x; |
387 yrel = y - finger->last_y; | 387 yrel = y - finger->last_y; |
388 } | 388 } |
389 | 389 |
390 /* Drop events that don't change state */ | 390 /* Drop events that don't change state */ |
416 touch->y = y_max; | 416 touch->y = y_max; |
417 } else if (touch->y < 0) { | 417 } else if (touch->y < 0) { |
418 touch->y = 0; | 418 touch->y = 0; |
419 } | 419 } |
420 */ | 420 */ |
421 finger->xdelta += xrel; | 421 finger->xdelta = xrel; |
422 finger->ydelta += yrel; | 422 finger->ydelta = yrel; |
423 finger->pressure = pressure; | 423 finger->pressure = pressure; |
424 | 424 |
425 | 425 |
426 | 426 |
427 /* Post the event, if desired */ | 427 /* Post the event, if desired */ |
438 event.tfinger.windowID = touch->focus ? touch->focus->id : 0; | 438 event.tfinger.windowID = touch->focus ? touch->focus->id : 0; |
439 posted = (SDL_PushEvent(&event) > 0); | 439 posted = (SDL_PushEvent(&event) > 0); |
440 } | 440 } |
441 finger->last_x = finger->x; | 441 finger->last_x = finger->x; |
442 finger->last_y = finger->y; | 442 finger->last_y = finger->y; |
443 finger->last_pressure = finger->pressure; | |
443 return posted; | 444 return posted; |
444 } | 445 } |
445 } | 446 } |
446 int | 447 int |
447 SDL_SendTouchButton(int id, Uint8 state, Uint8 button) | 448 SDL_SendTouchButton(int id, Uint8 state, Uint8 button) |