Mercurial > sdl-ios-xcode
diff src/video/uikit/SDL_uikitview.m @ 4694:c24ba2cc9583
Merged Jim's Google Summer of Code work from SDL-gsoc2010_gesture
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sun, 22 Aug 2010 12:07:55 -0700 |
parents | e2d46c5c7483 f8431f66613d |
children | a69e36365766 |
line wrap: on
line diff
--- a/src/video/uikit/SDL_uikitview.m Sun Aug 22 11:56:07 2010 -0700 +++ b/src/video/uikit/SDL_uikitview.m Sun Aug 22 12:07:55 2010 -0700 @@ -24,6 +24,7 @@ #include "../../events/SDL_keyboard_c.h" #include "../../events/SDL_mouse_c.h" +#include "../../events/SDL_touch_c.h" #if SDL_IPHONE_KEYBOARD #import "keyinfotable.h" @@ -48,16 +49,27 @@ [self initializeKeyboard]; #endif -#if FIXME_MULTITOUCH - int i; - for (i=0; i<MAX_SIMULTANEOUS_TOUCHES; i++) { - mice[i].id = i; - mice[i].driverdata = NULL; - SDL_AddMouse(&mice[i], "Mouse", 0, 0, 1); - } - self.multipleTouchEnabled = YES; +#ifdef FIXED_MULTITOUCH + SDL_Touch touch; + touch.id = 0; //TODO: Should be -1? + + //touch.driverdata = SDL_malloc(sizeof(EventTouchData)); + //EventTouchData* data = (EventTouchData*)(touch.driverdata); + + touch.x_min = 0; + touch.x_max = frame.size.width; + touch.native_xres = touch.x_max - touch.x_min; + touch.y_min = 0; + touch.y_max = frame.size.height; + touch.native_yres = touch.y_max - touch.y_min; + touch.pressure_min = 0; + touch.pressure_max = 1; + touch.native_pressureres = touch.pressure_max - touch.pressure_min; + + + touchId = SDL_AddTouch(&touch, "IPHONE SCREEN"); #endif - + return self; } @@ -67,48 +79,8 @@ NSEnumerator *enumerator = [touches objectEnumerator]; UITouch *touch = (UITouch*)[enumerator nextObject]; -#if FIXME_MULTITOUCH - /* associate touches with mice, so long as we have slots */ - int i; - int found = 0; - for(i=0; touch && i < MAX_SIMULTANEOUS_TOUCHES; i++) { + //NSLog("Click"); - /* check if this mouse is already tracking a touch */ - if (mice[i].driverdata != NULL) { - continue; - } - /* - mouse not associated with anything right now, - associate the touch with this mouse - */ - found = 1; - - /* save old mouse so we can switch back */ - int oldMouse = SDL_SelectMouse(-1); - - /* select this slot's mouse */ - SDL_SelectMouse(i); - CGPoint locationInView = [touch locationInView: self]; - - /* set driver data to touch object, we'll use touch object later */ - mice[i].driverdata = [touch retain]; - - /* send moved event */ - SDL_SendMouseMotion(i, 0, locationInView.x, locationInView.y, 0); - - /* send mouse down event */ - SDL_SendMouseButton(i, SDL_PRESSED, SDL_BUTTON_LEFT); - - /* re-calibrate relative mouse motion */ - SDL_GetRelativeMouseState(i, NULL, NULL); - - /* switch back to our old mouse */ - SDL_SelectMouse(oldMouse); - - /* grab next touch */ - touch = (UITouch*)[enumerator nextObject]; - } -#else if (touch) { CGPoint locationInView = [touch locationInView: self]; @@ -118,6 +90,37 @@ /* send mouse down event */ SDL_SendMouseButton(NULL, SDL_PRESSED, SDL_BUTTON_LEFT); } + +#ifdef FIXED_MULTITOUCH + while(touch) { + CGPoint locationInView = [touch locationInView: self]; + + +#ifdef IPHONE_TOUCH_EFFICIENT_DANGEROUS + //FIXME: TODO: Using touch as the fingerId is potentially dangerous + //It is also much more efficient than storing the UITouch pointer + //and comparing it to the incoming event. + SDL_SendFingerDown(touchId,(long)touch, + SDL_TRUE,locationInView.x,locationInView.y, + 1); +#else + int i; + for(i = 0;i < MAX_SIMULTANEOUS_TOUCHES;i++) { + if(finger[i] == NULL) { + finger[i] = touch; + SDL_SendFingerDown(touchId,i, + SDL_TRUE,locationInView.x,locationInView.y, + 1); + break; + } + } +#endif + + + + + touch = (UITouch*)[enumerator nextObject]; + } #endif } @@ -126,30 +129,34 @@ NSEnumerator *enumerator = [touches objectEnumerator]; UITouch *touch = (UITouch*)[enumerator nextObject]; -#if FIXME_MULTITOUCH - while(touch) { - /* search for the mouse slot associated with this touch */ - int i, found = NO; - for (i=0; i<MAX_SIMULTANEOUS_TOUCHES && !found; i++) { - if (mice[i].driverdata == touch) { - /* found the mouse associate with the touch */ - [(UITouch*)(mice[i].driverdata) release]; - mice[i].driverdata = NULL; - /* send mouse up */ - SDL_SendMouseButton(i, SDL_RELEASED, SDL_BUTTON_LEFT); - /* discontinue search for this touch */ - found = YES; - } - } - - /* grab next touch */ - touch = (UITouch*)[enumerator nextObject]; - } -#else if (touch) { /* send mouse up */ SDL_SendMouseButton(NULL, SDL_RELEASED, SDL_BUTTON_LEFT); } + +#ifdef FIXED_MULTITOUCH + while(touch) { + CGPoint locationInView = [touch locationInView: self]; + + +#ifdef IPHONE_TOUCH_EFFICIENT_DANGEROUS + SDL_SendFingerDown(touchId,(long)touch, + SDL_FALSE,locationInView.x,locationInView.y, + 1); +#else + int i; + for(i = 0;i < MAX_SIMULTANEOUS_TOUCHES;i++) { + if(finger[i] == touch) { + SDL_SendFingerDown(touchId,i, + SDL_FALSE,locationInView.x,locationInView.y, + 1); + break; + } + } +#endif + + touch = (UITouch*)[enumerator nextObject]; + } #endif } @@ -167,31 +174,36 @@ NSEnumerator *enumerator = [touches objectEnumerator]; UITouch *touch = (UITouch*)[enumerator nextObject]; -#if FIXME_MULTITOUCH - while(touch) { - /* try to find the mouse associated with this touch */ - int i, found = NO; - for (i=0; i<MAX_SIMULTANEOUS_TOUCHES && !found; i++) { - if (mice[i].driverdata == touch) { - /* found proper mouse */ - CGPoint locationInView = [touch locationInView: self]; - /* send moved event */ - SDL_SendMouseMotion(i, 0, locationInView.x, locationInView.y, 0); - /* discontinue search */ - found = YES; - } - } - - /* grab next touch */ - touch = (UITouch*)[enumerator nextObject]; - } -#else if (touch) { CGPoint locationInView = [touch locationInView: self]; /* send moved event */ SDL_SendMouseMotion(NULL, 0, locationInView.x, locationInView.y); } + +#ifdef FIXED_MULTITOUCH + while(touch) { + CGPoint locationInView = [touch locationInView: self]; + + +#ifdef IPHONE_TOUCH_EFFICIENT_DANGEROUS + SDL_SendTouchMotion(touchId,(long)touch, + SDL_FALSE,locationInView.x,locationInView.y, + 1); +#else + int i; + for(i = 0;i < MAX_SIMULTANEOUS_TOUCHES;i++) { + if(finger[i] == touch) { + SDL_SendTouchMotion(touchId,i, + SDL_FALSE,locationInView.x,locationInView.y, + 1); + break; + } + } +#endif + + touch = (UITouch*)[enumerator nextObject]; + } #endif }