Browse Source

Adds Pinch/Tap/Slide to iOS Build

- Note: Mac OS Build only includes Pinch currently
Brandon Slack 13 năm trước cách đây
mục cha
commit
3b02c28f8b

+ 4 - 2
gameplay/gameplay.xcodeproj/project.pbxproj

@@ -1610,7 +1610,7 @@
 		5B2BC7601512514500D176CD /* OpenGL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5B2BC75E1512514500D176CD /* OpenGL.framework */; };
 		5B2BC7621512514D00D176CD /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5B2BC7611512514D00D176CD /* QuartzCore.framework */; };
 		5B2BC7641512516B00D176CD /* libz.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 5B2BC7631512516B00D176CD /* libz.dylib */; };
-		5BAF201F152F2A6D003E2AC3 /* libz.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 5BAF201E152F2A6D003E2AC3 /* libz.dylib */; };
+		5B74915B15F7CC9F00CFD43C /* libz.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 5B74915A15F7CC9F00CFD43C /* libz.dylib */; };
 		5BAF2027152F2AF0003E2AC3 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5BAF2020152F2AF0003E2AC3 /* CoreGraphics.framework */; };
 		5BAF2028152F2AF0003E2AC3 /* CoreMotion.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5BAF2021152F2AF0003E2AC3 /* CoreMotion.framework */; };
 		5BAF2029152F2AF0003E2AC3 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5BAF2022152F2AF0003E2AC3 /* Foundation.framework */; };
@@ -2535,6 +2535,7 @@
 		5B5DB93214C25BA5007755DB /* libvorbis.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libvorbis.a; path = "../external-deps/oggvorbis/lib/ios/armv7/libvorbis.a"; sourceTree = "<group>"; };
 		5B5DB93314C25BA5007755DB /* libvorbisenc.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libvorbisenc.a; path = "../external-deps/oggvorbis/lib/ios/armv7/libvorbisenc.a"; sourceTree = "<group>"; };
 		5B5DB93414C25BA5007755DB /* libvorbisfile.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libvorbisfile.a; path = "../external-deps/oggvorbis/lib/ios/armv7/libvorbisfile.a"; sourceTree = "<group>"; };
+		5B74915A15F7CC9F00CFD43C /* libz.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libz.dylib; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.0.sdk/usr/lib/libz.dylib; sourceTree = DEVELOPER_DIR; };
 		5BAF201E152F2A6D003E2AC3 /* libz.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libz.dylib; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.1.sdk/usr/lib/libz.dylib; sourceTree = DEVELOPER_DIR; };
 		5BAF2020152F2AF0003E2AC3 /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.1.sdk/System/Library/Frameworks/CoreGraphics.framework; sourceTree = DEVELOPER_DIR; };
 		5BAF2021152F2AF0003E2AC3 /* CoreMotion.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreMotion.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.1.sdk/System/Library/Frameworks/CoreMotion.framework; sourceTree = DEVELOPER_DIR; };
@@ -2610,6 +2611,7 @@
 			isa = PBXFrameworksBuildPhase;
 			buildActionMask = 2147483647;
 			files = (
+				5B74915B15F7CC9F00CFD43C /* libz.dylib in Frameworks */,
 				5BAF2027152F2AF0003E2AC3 /* CoreGraphics.framework in Frameworks */,
 				5BAF2028152F2AF0003E2AC3 /* CoreMotion.framework in Frameworks */,
 				5BAF2029152F2AF0003E2AC3 /* Foundation.framework in Frameworks */,
@@ -2617,7 +2619,6 @@
 				5BAF202B152F2AF0003E2AC3 /* OpenGLES.framework in Frameworks */,
 				5BAF202C152F2AF0003E2AC3 /* QuartzCore.framework in Frameworks */,
 				5BAF202D152F2AF0003E2AC3 /* UIKit.framework in Frameworks */,
-				5BAF201F152F2A6D003E2AC3 /* libz.dylib in Frameworks */,
 				5B04C57514BFCFE100EB0071 /* libbullet.a in Frameworks */,
 				5B04C57614BFCFE100EB0071 /* libogg.a in Frameworks */,
 				5B04C57714BFCFE100EB0071 /* libvorbis.a in Frameworks */,
@@ -2634,6 +2635,7 @@
 		4234D98A14686BB6003031B3 = {
 			isa = PBXGroup;
 			children = (
+				5B74915A15F7CC9F00CFD43C /* libz.dylib */,
 				42B7FE7115B080EE002BB8C3 /* lua */,
 				5BC4E7D4150F8C3C00CBE1C0 /* res */,
 				4234D9A314686C52003031B3 /* src */,

+ 7 - 0
gameplay/src/Platform.h

@@ -207,6 +207,13 @@ public:
      */
     static void unregisterGesture(Gesture::GestureEvent evt);
 
+    /**
+     * Tests if the specified gesture is registered for gesture recognition for the specified gesture event
+     *
+     * @param evt The gesture event to register to start recognizing events for.
+     */
+    static bool isGestureRegistered(Gesture::GestureEvent evt);
+    
     /** 
      * Gets the number of gamepad devices connected to the Platform.
      *

+ 5 - 0
gameplay/src/PlatformAndroid.cpp

@@ -1024,6 +1024,11 @@ void Platform::registerGesture(Gesture::GestureEvent evt)
 void Platform::unregisterGesture(Gesture::GestureEvent evt)
 {
 }
+    
+bool Platform::isGestureRegistered(Gesture::GestureEvent evt)
+{
+    return false;
+}
 
 unsigned int Platform::getGamepadsConnected()
 {

+ 16 - 11
gameplay/src/PlatformLinux.cpp

@@ -845,17 +845,22 @@ bool Platform::mouseEventInternal(Mouse::MouseEvent evt, int x, int y, int wheel
     }
 }
 
-bool Platform::isGestureSupported(Gesture::GestureEvent evt)
-{
-    return false;
-}
-
-void Platform::registerGesture(Gesture::GestureEvent evt)
-{
-}
-
-void Platform::unregisterGesture(Gesture::GestureEvent evt)
-{
+bool Platform::isGestureSupported(Gesture::GestureEvent evt)
+{
+    return false;
+}
+
+void Platform::registerGesture(Gesture::GestureEvent evt)
+{
+}
+
+void Platform::unregisterGesture(Gesture::GestureEvent evt)
+{
+}
+    
+bool Platform::isGestureRegistered(Gesture::GestureEvent evt)
+{
+    return false;
 }
 
 unsigned int Platform::getGamepadsConnected()

+ 29 - 23
gameplay/src/PlatformMacOSX.mm

@@ -603,13 +603,20 @@ int getKey(unsigned short keyCode, unsigned int modifierFlags)
 
 
 // Gesture support for Mac OS X Trackpads
-- (void)recognizeGesture:(Gesture::GestureEvent)evt {
-    if(evt == Gesture::GESTURE_NONE) _gestureEvents = 0;
-    else _gestureEvents = (_gestureEvents | evt);
+- (bool)isGestureRegistered: (Gesture::GestureEvent) evt {
+    return ((_gestureEvents & evt) == evt);
 }
+- (void)registerGesture: (Gesture::GestureEvent) evt {
+    _gestureEvents |= evt;
+}
+- (void)unregisterGesture: (Gesture::GestureEvent) evt {
+    _gestureEvents &= (~evt);
+}
+
+
 - (void)magnifyWithEvent:(NSEvent *)event
 {
-    if((_gestureEvents & Gesture::GESTURE_PINCH) == 0) return;
+    if([self isGestureRegistered:Gesture::GESTURE_PINCH] == false) return;
     
     NSSet *touches = [event touchesMatchingPhase:NSTouchPhaseAny  inView:nil];
     // Approximate the center by adding and averageing for now
@@ -627,7 +634,7 @@ int getKey(unsigned short keyCode, unsigned int modifierFlags)
 }
 - (void)swipeWithEvent:(NSEvent *)event
 {
-    if((_gestureEvents & Gesture::GESTURE_SWIPE) == 0) return;
+    if([self isGestureRegistered:Gesture::GESTURE_SWIPE] == false) return;
     /**
      * Gesture callback on Gesture::SWIPE events.
      *
@@ -643,23 +650,6 @@ int getKey(unsigned short keyCode, unsigned int modifierFlags)
     //virtual void gestureSwipeEvent(int x, int y, int direction);
 }
 
-- (void)rotateWithEvent:(NSEvent *)event
-{
-    if((_gestureEvents & Gesture::GESTURE_ROTATE) == 0) return;
-    NSSet *touches = [event touchesMatchingPhase:NSTouchPhaseAny  inView:nil];
-    // Approximate the center by adding and averageing for now
-    // Note this is centroid on the physical device be used for touching, not the display
-    float xavg = 0.0f;
-    float yavg = 0.0f;
-    for(NSTouch *t in touches) {
-        xavg += [t normalizedPosition].x;
-        yavg += [t normalizedPosition].y;
-    }
-    xavg /= [touches count];
-    yavg /= [touches count];
-    _game->gestureRotateEvent((int)xavg, (int)yavg, [event rotation]);
-}
-
 @end
 
 @interface FullscreenWindow : NSWindow
@@ -941,18 +931,34 @@ bool Platform::mouseEventInternal(Mouse::MouseEvent evt, int x, int y, int wheel
 
 bool Platform::isGestureSupported(Gesture::GestureEvent evt)
 {
+    // TODO: Support Swipe and Tap
+    switch(evt)
+    {
+        case Gesture::GESTURE_PINCH:
+            return true;
+        default:
+            break;
+    }
     return false;
 }
 
 void Platform::registerGesture(Gesture::GestureEvent evt)
 {
+    [__view registerGesture:evt];
 }
 
 void Platform::unregisterGesture(Gesture::GestureEvent evt)
 {
-    [__view recognizeGesture:evt];
+    [__view unregisterGesture:evt];
+}
+  
+bool Platform::isGestureRegistered(Gesture::GestureEvent evt)
+{
+     return [__view isGestureRegistered:evt];
 }
 
+    
+
 
 unsigned int Platform::getGamepadsConnected()
 {

+ 5 - 0
gameplay/src/PlatformQNX.cpp

@@ -1312,6 +1312,11 @@ void Platform::unregisterGesture(Gesture::GestureEvent evt)
         break;
     }
 }
+    
+bool Platform::isGestureRegistered(Gesture::GestureEvent evt)
+{
+    return __gestureEventsProcessed.test(evt);
+}
 
 unsigned int Platform::getGamepadsConnected()
 {

+ 5 - 0
gameplay/src/PlatformWin32.cpp

@@ -1036,6 +1036,11 @@ void Platform::registerGesture(Gesture::GestureEvent evt)
 void Platform::unregisterGesture(Gesture::GestureEvent evt)
 {
 }
+    
+bool Platform::isGestureRegistered(Gesture::GestureEvent evt)
+{
+    return false;
+}
 
 unsigned int Platform::getGamepadsConnected()
 {

+ 105 - 1
gameplay/src/PlatformiOS.mm

@@ -61,6 +61,10 @@ int getKey(unichar keyCode);
     NSInteger swapInterval;
     BOOL updating;
     Game* _game;
+    
+    UITapGestureRecognizer *_tapRecognizer;
+    UIPinchGestureRecognizer *_pinchRecognizer;
+    UISwipeGestureRecognizer *_swipeRecognizer;
 }
 
 @property (readonly, nonatomic, getter=isUpdating) BOOL updating;
@@ -384,6 +388,98 @@ int getKey(unichar keyCode);
     }
 }
 
+// Gesture support for Mac OS X Trackpads
+- (bool)isGestureRegistered: (Gesture::GestureEvent) evt
+{
+    switch(evt) {
+        case Gesture::GESTURE_SWIPE:
+            return (_swipeRecognizer != NULL);
+        case Gesture::GESTURE_PINCH:
+            return (_pinchRecognizer != NULL);
+        case Gesture::GESTURE_TAP:
+            return (_tapRecognizer != NULL);
+        default:
+            break;
+    }
+    return false;
+}
+
+- (void)registerGesture: (Gesture::GestureEvent) evt
+{
+    if((evt & Gesture::GESTURE_SWIPE) == Gesture::GESTURE_SWIPE && _swipeRecognizer == NULL)
+    {
+        _swipeRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeGesture:)];
+        [self addGestureRecognizer:_swipeRecognizer];
+    }
+    if((evt & Gesture::GESTURE_PINCH) == Gesture::GESTURE_PINCH && _pinchRecognizer == NULL)
+    {
+        _pinchRecognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(handlePinchGesture:)];
+        [self addGestureRecognizer:_pinchRecognizer];
+    }
+    if((evt & Gesture::GESTURE_TAP) == Gesture::GESTURE_TAP && _tapRecognizer == NULL)
+    {
+        _tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapGesture:)];
+        [self addGestureRecognizer:_swipeRecognizer];
+    }
+}
+
+- (void)unregisterGesture: (Gesture::GestureEvent) evt
+{
+    if((evt & Gesture::GESTURE_SWIPE) == Gesture::GESTURE_SWIPE && _swipeRecognizer != NULL)
+    {
+        [self removeGestureRecognizer:_swipeRecognizer];
+        [_swipeRecognizer release];
+        _swipeRecognizer = NULL;
+    }
+    if((evt & Gesture::GESTURE_PINCH) == Gesture::GESTURE_PINCH && _pinchRecognizer != NULL)
+    {
+        [self removeGestureRecognizer:_pinchRecognizer];
+        [_pinchRecognizer release];
+        _pinchRecognizer = NULL;
+    }
+    if((evt & Gesture::GESTURE_TAP) == Gesture::GESTURE_TAP && _tapRecognizer != NULL)
+    {
+        [self removeGestureRecognizer:_tapRecognizer];
+        [_tapRecognizer release];
+        _tapRecognizer = NULL;
+    }
+}
+
+- (void)handleTapGesture:(UITapGestureRecognizer *)sender
+{
+    CGPoint location = [sender locationInView:self];
+    _game->gestureTapEvent(location.x, location.y);
+}
+
+- (void)handlePinchGesture:(UIPinchGestureRecognizer *)sender
+{
+    CGFloat factor = [sender scale];
+    CGPoint location = [sender locationInView:self];
+    _game->gesturePinchEvent(location.x, location.y, factor);
+}
+
+- (void)handleSwipeGesture:(UISwipeGestureRecognizer *)sender
+{
+    UISwipeGestureRecognizerDirection direction = [sender direction];
+    CGPoint location = [sender locationInView:self];
+    int gameplayDirection = 0;
+    switch(direction) {
+        case UISwipeGestureRecognizerDirectionRight:
+            gameplayDirection = Gesture::SWIPE_DIRECTION_RIGHT;
+            break;
+        case UISwipeGestureRecognizerDirectionLeft:
+            gameplayDirection = Gesture::SWIPE_DIRECTION_LEFT;
+            break;
+        case UISwipeGestureRecognizerDirectionUp:
+            gameplayDirection = Gesture::SWIPE_DIRECTION_UP;
+            break;
+        case UISwipeGestureRecognizerDirectionDown:
+            gameplayDirection = Gesture::SWIPE_DIRECTION_DOWN;
+            break;
+    }
+    _game->gestureSwipeEvent(location.x, location.y, gameplayDirection);
+}
+
 @end
 
 
@@ -990,17 +1086,25 @@ bool Platform::mouseEventInternal(Mouse::MouseEvent evt, int x, int y, int wheel
 
 bool Platform::isGestureSupported(Gesture::GestureEvent evt)
 {
-    return false;
+    return true;
 }
 
 void Platform::registerGesture(Gesture::GestureEvent evt)
 {
+    [__view registerGesture:evt];
 }
 
 void Platform::unregisterGesture(Gesture::GestureEvent evt)
 {
+    [__view unregisterGesture:evt];
 }
 
+bool Platform::isGestureRegistered(Gesture::GestureEvent evt)
+{
+    return [__view isGestureRegistered:evt];
+}
+
+
 unsigned int Platform::getGamepadsConnected()
 {
     return 0;