Mercurial > sdl-ios-xcode
comparison src/video/cocoa/SDL_cocoawindow.m @ 4680:229529693289
Fixed sending motion and finger up events
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sat, 31 Jul 2010 20:55:33 -0700 |
parents | 5ee96ba0c01e |
children | 257bdf117af8 |
comparison
equal
deleted
inserted
replaced
4679:5ee96ba0c01e | 4680:229529693289 |
---|---|
289 [self handleTouches:COCOA_TOUCH_CANCELLED withEvent:theEvent]; | 289 [self handleTouches:COCOA_TOUCH_CANCELLED withEvent:theEvent]; |
290 } | 290 } |
291 | 291 |
292 - (void)handleTouches:(cocoaTouchType)type withEvent:(NSEvent *)event | 292 - (void)handleTouches:(cocoaTouchType)type withEvent:(NSEvent *)event |
293 { | 293 { |
294 NSSet *touches = [event touchesMatchingPhase:NSTouchPhaseBegan inView:nil]; | 294 NSSet *touches = 0; |
295 | 295 NSEnumerator *enumerator; |
296 NSEnumerator *enumerator = [touches objectEnumerator]; | 296 NSTouch *touch; |
297 NSTouch *touch = (NSTouch*)[enumerator nextObject]; | 297 |
298 switch (type) { | |
299 case COCOA_TOUCH_DOWN: | |
300 touches = [event touchesMatchingPhase:NSTouchPhaseBegan inView:nil]; | |
301 break; | |
302 case COCOA_TOUCH_UP: | |
303 case COCOA_TOUCH_CANCELLED: | |
304 touches = [event touchesMatchingPhase:NSTouchPhaseEnded inView:nil]; | |
305 break; | |
306 case COCOA_TOUCH_MOVE: | |
307 touches = [event touchesMatchingPhase:NSTouchPhaseMoved inView:nil]; | |
308 break; | |
309 } | |
310 | |
311 enumerator = [touches objectEnumerator]; | |
312 touch = (NSTouch*)[enumerator nextObject]; | |
298 while (touch) { | 313 while (touch) { |
299 long touchId = (long)[touch device]; | 314 SDL_TouchID touchId = (SDL_TouchID)[touch device]; |
300 if (!SDL_GetTouch(touchId)) { | 315 if (!SDL_GetTouch(touchId)) { |
301 printf("Adding touch: %li\n",touchId); | |
302 SDL_Touch touch; | 316 SDL_Touch touch; |
303 | 317 |
304 touch.id = touchId; | 318 touch.id = touchId; |
305 touch.x_min = 0; | 319 touch.x_min = 0; |
306 touch.x_max = 1; | 320 touch.x_max = 1; |
311 touch.pressure_min = 0; | 325 touch.pressure_min = 0; |
312 touch.pressure_max = 1; | 326 touch.pressure_max = 1; |
313 touch.native_pressureres = touch.pressure_max - touch.pressure_min; | 327 touch.native_pressureres = touch.pressure_max - touch.pressure_min; |
314 | 328 |
315 if (SDL_AddTouch(&touch, "") < 0) { | 329 if (SDL_AddTouch(&touch, "") < 0) { |
316 continue; | 330 return; |
317 } | 331 } |
318 printf("Success, added touch: %li\n",touchId); | |
319 } | 332 } |
320 float x = [touch normalizedPosition].x; | 333 float x = [touch normalizedPosition].x; |
321 float y = [touch normalizedPosition].y; | 334 float y = [touch normalizedPosition].y; |
322 long fingerId = (long)[touch identity]; | 335 SDL_FingerID fingerId = (SDL_FingerID)[touch identity]; |
323 switch (type) { | 336 switch (type) { |
324 case COCOA_TOUCH_DOWN: | 337 case COCOA_TOUCH_DOWN: |
325 SDL_SendFingerDown(touchId, fingerId, SDL_TRUE, x, y, 1); | 338 SDL_SendFingerDown(touchId, fingerId, SDL_TRUE, x, y, 1); |
326 break; | 339 break; |
327 case COCOA_TOUCH_UP: | 340 case COCOA_TOUCH_UP: |