From 3bfb68f96cbc96be49251099775ec3390e838e03 Mon Sep 17 00:00:00 2001 From: "techdragon.nguyen@gmail.com" Date: Fri, 16 Dec 2011 11:09:40 +0000 Subject: [PATCH] modified touch interface to be a little more fluid on iOS --- JGE/src/iOS/EAGLView.h | 2 +- JGE/src/iOS/EAGLView.m | 60 +++++++++++++------- projects/mtg/wagic.xcodeproj/project.pbxproj | 4 +- 3 files changed, 41 insertions(+), 25 deletions(-) diff --git a/JGE/src/iOS/EAGLView.h b/JGE/src/iOS/EAGLView.h index 00a683a24..8d648f537 100755 --- a/JGE/src/iOS/EAGLView.h +++ b/JGE/src/iOS/EAGLView.h @@ -8,7 +8,7 @@ // This class wraps the CAEAGLLayer from CoreAnimation into a convenient UIView subclass. // The view content is basically an EAGL surface you render your OpenGL scene into. // Note that setting the view non-opaque will only work if the EAGL surface has an alpha channel. -@interface EAGLView : UIView +@interface EAGLView : UIView { AdWhirlView *adView; //This is a trick, AdMob uses a viewController to display its Ads, trust me, you'll need this diff --git a/JGE/src/iOS/EAGLView.m b/JGE/src/iOS/EAGLView.m index 9356b47ef..486aff0c1 100755 --- a/JGE/src/iOS/EAGLView.m +++ b/JGE/src/iOS/EAGLView.m @@ -23,12 +23,6 @@ static JGameLauncher* g_launcher = NULL; CGFloat lastScale; CGFloat lastRotation; -CGFloat firstX; -CGFloat firstY; - -CGFloat currentX; -CGFloat currentY; - void JGECreateDefaultBindings() { } @@ -109,6 +103,7 @@ static NSString *_MY_AD_WHIRL_APPLICATION_KEY_IPAD = @"2e70e3f3da40408588b9a3170 /* create swipe handlers for single swipe */ + UISwipeGestureRecognizer *singleFlickGestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget: self action: @selector(handleFlickGesture:)]; singleFlickGestureRecognizer.numberOfTouchesRequired = 1; singleFlickGestureRecognizer.direction = UISwipeGestureRecognizerDirectionRight; @@ -230,6 +225,10 @@ static NSString *_MY_AD_WHIRL_APPLICATION_KEY_IPAD = @"2e70e3f3da40408588b9a3170 [self addGestureRecognizer: singleTapRecognizer]; + UIPanGestureRecognizer *panGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget: self action: @selector(handlePanMotion:)]; + [panGestureRecognizer setMaximumNumberOfTouches: 1]; + [self addGestureRecognizer: panGestureRecognizer]; + [panGestureRecognizer release]; /* Use the pinch gesture recognizer to zoom in and out of a location on the screen. @@ -403,6 +402,36 @@ static NSString *_MY_AD_WHIRL_APPLICATION_KEY_IPAD = @"2e70e3f3da40408588b9a3170 #pragma mark Gesture Recognizer callbacks +- (BOOL) gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer +{ + return YES; +} + + +- (void)handlePanMotion: (UIPanGestureRecognizer *) panGesture +{ + [[[panGesture view] layer] removeAllAnimations]; + currentLocation = [panGesture locationInView: self]; + ES2Renderer* es2renderer = (ES2Renderer*)renderer; + + int actualWidth = (int) JRenderer::GetInstance()->GetActualWidth(); + int actualHeight = (int) JRenderer::GetInstance()->GetActualHeight(); + int xOffset = ((currentLocation.x-es2renderer.viewPort.left)*SCREEN_WIDTH)/actualWidth; + int yOffset = ((currentLocation.y-es2renderer.viewPort.top)*SCREEN_HEIGHT)/actualHeight; + CGPoint newLocation = CGPointMake(xOffset, yOffset); + + if (panGesture.state == UIGestureRecognizerStateBegan || panGesture.state == UIGestureRecognizerStateChanged) + { + g_engine->LeftClicked(newLocation.x, newLocation.y); + } + else if ( [panGesture state] == UIGestureRecognizerStateEnded) + { + CGPoint velocity = [panGesture velocityInView:panGesture.view.superview]; + if (!(( ((int)abs( (int) velocity.x)) > 300) || ((int) (abs( (int) velocity.y)) > 300))) + g_engine->HoldKey_NoRepeat( JGE_BTN_OK ); + } +} + - (void)handleSingleTap: (UITapGestureRecognizer *) recognizer { [[[recognizer view] layer] removeAllAnimations]; currentLocation = [recognizer locationInView: self]; @@ -421,18 +450,9 @@ static NSString *_MY_AD_WHIRL_APPLICATION_KEY_IPAD = @"2e70e3f3da40408588b9a3170 int yOffset = ((currentLocation.y-es2renderer.viewPort.top)*SCREEN_HEIGHT)/actualHeight; g_engine->LeftClicked(xOffset, yOffset); - - // doesn't work as expected. Need to figure out correct algorithm. Double tap or double swipe down will execute OK button. - NSInteger xDiff = abs(static_cast(currentX) - xOffset); - NSInteger yDiff = abs(static_cast(currentY) - yOffset); - if (xDiff <= 60 && yDiff <= 60) - { + if ( recognizer.state == UIGestureRecognizerStateEnded ) g_engine->HoldKey_NoRepeat(JGE_BTN_OK); - } - - currentX = xOffset; - currentY = yOffset; } else if(currentLocation.y < es2renderer.viewPort.top) { @@ -471,12 +491,6 @@ static NSString *_MY_AD_WHIRL_APPLICATION_KEY_IPAD = @"2e70e3f3da40408588b9a3170 default: break; } -/* - CGPoint translatedPoint = [recognizer locationInView: self]; - currentX = translatedPoint.x; - currentY = translatedPoint.y; - g_engine->LeftClicked( currentX, currentY); - */ } - (void)handleHand:(UITapGestureRecognizer *)recognizer { @@ -532,6 +546,8 @@ static NSString *_MY_AD_WHIRL_APPLICATION_KEY_IPAD = @"2e70e3f3da40408588b9a3170 } #pragma mark - + + #include "GameOptions.h" #pragma mark Keyboard related methods diff --git a/projects/mtg/wagic.xcodeproj/project.pbxproj b/projects/mtg/wagic.xcodeproj/project.pbxproj index ea5f57219..9dad02b38 100755 --- a/projects/mtg/wagic.xcodeproj/project.pbxproj +++ b/projects/mtg/wagic.xcodeproj/project.pbxproj @@ -2447,7 +2447,7 @@ ./minizip, "iOS/Reachability/Reachability\\ 2.0.4ddg/DDG\\ Reachability/Classes/", ); - INFOPLIST_FILE = "wagic copy-Info.plist"; + INFOPLIST_FILE = "wagic-Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 4.0; LIBRARY_SEARCH_PATHS = ( "$(inherited)", @@ -2492,7 +2492,7 @@ ./minizip, "iOS/Reachability/Reachability\\ 2.0.4ddg/DDG\\ Reachability/Classes/", ); - INFOPLIST_FILE = "wagic copy-Info.plist"; + INFOPLIST_FILE = "wagic-Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 4.0; LIBRARY_SEARCH_PATHS = ( "$(inherited)",