comparison src/events/SDL_touch.c @ 4683:15dfe42edbfd

Fixed gestureMulti. Disabled dollar gesture temporarily.
author Jim Grandpre <jim.tla@gmail.com>
date Wed, 04 Aug 2010 23:17:30 -0400
parents 5378f2d0754f
children f9ab8df6d45a
comparison
equal deleted inserted replaced
4682:4ba1048a324c 4683:15dfe42edbfd
316 SDL_Touch* touch = SDL_GetTouch(id); 316 SDL_Touch* touch = SDL_GetTouch(id);
317 317
318 if(!touch) { 318 if(!touch) {
319 return SDL_TouchNotFoundError(id); 319 return SDL_TouchNotFoundError(id);
320 } 320 }
321
322
321 //scale to Integer coordinates 323 //scale to Integer coordinates
322 Uint16 x = (xin+touch->x_min)*(touch->xres)/(touch->native_xres); 324 Uint16 x = (xin+touch->x_min)*(touch->xres)/(touch->native_xres);
323 Uint16 y = (yin+touch->y_min)*(touch->yres)/(touch->native_yres); 325 Uint16 y = (yin+touch->y_min)*(touch->yres)/(touch->native_yres);
324 Uint16 pressure = (yin+touch->pressure_min)*(touch->pressureres)/(touch->native_pressureres); 326 Uint16 pressure = (yin+touch->pressure_min)*(touch->pressureres)/(touch->native_pressureres);
327
328 SDL_Finger *finger = SDL_GetFinger(touch,fingerid);
325 if(down) { 329 if(down) {
326 SDL_Finger *finger = SDL_GetFinger(touch,fingerid);
327 SDL_Finger nf;
328 if(finger == NULL) { 330 if(finger == NULL) {
329 331 SDL_Finger nf;
330 nf.id = fingerid; 332 nf.id = fingerid;
331 nf.x = x; 333 nf.x = x;
332 nf.y = y; 334 nf.y = y;
333 nf.pressure = pressure; 335 nf.pressure = pressure;
334 nf.xdelta = 0; 336 nf.xdelta = 0;
335 nf.ydelta = 0; 337 nf.ydelta = 0;
336 nf.last_x = x; 338 nf.last_x = x;
337 nf.last_y = y; 339 nf.last_y = y;
338 nf.last_pressure = pressure; 340 nf.last_pressure = pressure;
339 nf.down = SDL_FALSE; 341 nf.down = SDL_FALSE;
340 SDL_AddFinger(touch,&nf); 342 if(SDL_AddFinger(touch,&nf) < 0) return 0;
341 finger = &nf; 343 finger = SDL_GetFinger(touch,fingerid);
342 } 344 }
343 else if(finger->down) return 0; 345 else if(finger->down) return 0;
344 if(xin < touch->x_min || yin < touch->y_min) return 0; //should defer if only a partial input 346 if(xin < touch->x_min || yin < touch->y_min) return 0; //should defer if only a partial input
345 posted = 0; 347 posted = 0;
346 if (SDL_GetEventState(SDL_FINGERDOWN) == SDL_ENABLE) { 348 if (SDL_GetEventState(SDL_FINGERDOWN) == SDL_ENABLE) {
356 } 358 }
357 if(posted) finger->down = SDL_TRUE; 359 if(posted) finger->down = SDL_TRUE;
358 return posted; 360 return posted;
359 } 361 }
360 else { 362 else {
361 if(SDL_DelFinger(touch,fingerid) < 0) return 0; 363 if(finger == NULL) {printf("Finger not found...\n");return 0;}
362 posted = 0; 364 posted = 0;
363 if (SDL_GetEventState(SDL_FINGERUP) == SDL_ENABLE) { 365 if (SDL_GetEventState(SDL_FINGERUP) == SDL_ENABLE) {
364 SDL_Event event; 366 SDL_Event event;
365 event.tfinger.type = SDL_FINGERUP; 367 event.tfinger.type = SDL_FINGERUP;
366 event.tfinger.touchId = id; 368 event.tfinger.touchId = id;
367 event.tfinger.state = touch->buttonstate; 369 event.tfinger.state = touch->buttonstate;
368 event.tfinger.windowID = touch->focus ? touch->focus->id : 0; 370 event.tfinger.windowID = touch->focus ? touch->focus->id : 0;
369 event.tfinger.fingerId = fingerid; 371 event.tfinger.fingerId = fingerid;
372 //I don't trust the coordinates passed on fingerUp
373 event.tfinger.x = finger->x;
374 event.tfinger.y = finger->y;
375 event.tfinger.dx = 0;
376 event.tfinger.dy = 0;
377
378 if(SDL_DelFinger(touch,fingerid) < 0) return 0;
370 posted = (SDL_PushEvent(&event) > 0); 379 posted = (SDL_PushEvent(&event) > 0);
371 } 380 }
372 return posted; 381 return posted;
373 } 382 }
374 } 383 }
375 384
376 int 385 int
379 { 388 {
380 int index = SDL_GetTouchIndexId(id); 389 int index = SDL_GetTouchIndexId(id);
381 SDL_Touch *touch = SDL_GetTouch(id); 390 SDL_Touch *touch = SDL_GetTouch(id);
382 SDL_Finger *finger = SDL_GetFinger(touch,fingerid); 391 SDL_Finger *finger = SDL_GetFinger(touch,fingerid);
383 int posted; 392 int posted;
384 float xrel; 393 Sint16 xrel, yrel;
385 float yrel;
386 float x_max = 0, y_max = 0; 394 float x_max = 0, y_max = 0;
387 395
388 if (!touch) { 396 if (!touch) {
389 return SDL_TouchNotFoundError(id); 397 return SDL_TouchNotFoundError(id);
390 } 398 }
396 if(touch->flush_motion) { 404 if(touch->flush_motion) {
397 return 0; 405 return 0;
398 } 406 }
399 407
400 if(finger == NULL || !finger->down) { 408 if(finger == NULL || !finger->down) {
401 return SDL_SendFingerDown(id,fingerid,SDL_TRUE,x,y,pressure); 409 return SDL_SendFingerDown(id,fingerid,SDL_TRUE,xin,yin,pressurein);
402 } else { 410 } else {
403 /* the relative motion is calculated regarding the last position */ 411 /* the relative motion is calculated regarding the last position */
404 if (relative) { 412 if (relative) {
405 xrel = x; 413 xrel = x;
406 yrel = y; 414 yrel = y;
410 if(xin < touch->x_min) x = finger->last_x; /*If movement is only in one axis,*/ 418 if(xin < touch->x_min) x = finger->last_x; /*If movement is only in one axis,*/
411 if(yin < touch->y_min) y = finger->last_y; /*The other is marked as -1*/ 419 if(yin < touch->y_min) y = finger->last_y; /*The other is marked as -1*/
412 if(pressurein < touch->pressure_min) pressure = finger->last_pressure; 420 if(pressurein < touch->pressure_min) pressure = finger->last_pressure;
413 xrel = x - finger->last_x; 421 xrel = x - finger->last_x;
414 yrel = y - finger->last_y; 422 yrel = y - finger->last_y;
423 //printf("xrel,yrel (%i,%i)\n",(int)xrel,(int)yrel);
415 } 424 }
416 425
417 /* Drop events that don't change state */ 426 /* Drop events that don't change state */
418 if (!xrel && !yrel) { 427 if (!xrel && !yrel) {
419 #if 0 428 #if 0
458 event.tfinger.type = SDL_FINGERMOTION; 467 event.tfinger.type = SDL_FINGERMOTION;
459 event.tfinger.touchId = id; 468 event.tfinger.touchId = id;
460 event.tfinger.fingerId = fingerid; 469 event.tfinger.fingerId = fingerid;
461 event.tfinger.x = x; 470 event.tfinger.x = x;
462 event.tfinger.y = y; 471 event.tfinger.y = y;
472 event.tfinger.dx = xrel;
473 event.tfinger.dy = yrel;
474
463 475
464 event.tfinger.pressure = pressure; 476 event.tfinger.pressure = pressure;
465 event.tfinger.state = touch->buttonstate; 477 event.tfinger.state = touch->buttonstate;
466 event.tfinger.windowID = touch->focus ? touch->focus->id : 0; 478 event.tfinger.windowID = touch->focus ? touch->focus->id : 0;
467 posted = (SDL_PushEvent(&event) > 0); 479 posted = (SDL_PushEvent(&event) > 0);