Browse Source

Merge pull request #246 from elementc/osx-and-ios-updates

Fix for IOS 8 rotation
Mike Lilligreen 10 years ago
parent
commit
437a717c69
2 changed files with 52 additions and 40 deletions
  1. 3 3
      engine/source/platformiOS/T2DView.mm
  2. 49 37
      engine/source/platformiOS/iOSWindow.mm

+ 3 - 3
engine/source/platformiOS/T2DView.mm

@@ -105,7 +105,7 @@ void ConvertToRetina(CGPoint *p)
         }
         
         S32 orientation = _iOSGameGetOrientation();
-        if (UIDeviceOrientationIsPortrait(orientation))
+        if (UIDeviceOrientationIsPortrait((UIDeviceOrientation)orientation))
         {
             point.y -= _iOSGetPortraitTouchoffset();
         }
@@ -137,7 +137,7 @@ extern Vector<Event *> TouchMoveEvents;
         }
         
         S32 orientation = _iOSGameGetOrientation();
-        if (UIDeviceOrientationIsPortrait(orientation))
+        if (UIDeviceOrientationIsPortrait((UIDeviceOrientation)orientation))
         {
             point.y -= _iOSGetPortraitTouchoffset();
             prevPoint.y -= _iOSGetPortraitTouchoffset();
@@ -166,7 +166,7 @@ extern Vector<Event *> TouchMoveEvents;
         }
         
         S32 orientation = _iOSGameGetOrientation();
-        if (UIDeviceOrientationIsPortrait(orientation))
+        if (UIDeviceOrientationIsPortrait((UIDeviceOrientation)orientation))
         {
             point.y -= _iOSGetPortraitTouchoffset();
             prevPoint.y -= _iOSGetPortraitTouchoffset();

+ 49 - 37
engine/source/platformiOS/iOSWindow.mm

@@ -381,48 +381,60 @@ bool setScreenOrientation(bool portrait, bool upsidedown)
     bool success = false;
 
     CGPoint point;
-    if (platState.portrait)
-    {
-        point.x = platState.windowSize.x / 2;
-        point.y = platState.windowSize.y / 2;
-    }
-    else
+    
+    // Is the iOS version less than 8?
+    if( [[[UIDevice currentDevice] systemVersion] compare:@"8.0" options:NSNumericSearch] == NSOrderedAscending )
     {
-        point.x = platState.windowSize.y / 2;
-        point.y = platState.windowSize.x / 2;
-    }
-
-
-    [platState.ctx centerOnPoint:point];
-
-    if (portrait)
-    {//normal upright
-        if (upsidedown)
-        {//button on top
-            [platState.ctx rotateToAngle:M_PI + (M_PI / 2.0)];//rotate to 90 degrees
-            platState.application.statusBarOrientation = UIInterfaceOrientationPortraitUpsideDown;
-            success = true;
-        } else
-        {//button on bottom
-            [platState.ctx rotateToAngle:(M_PI / 2.0)];//rotate to 270 degrees
-            platState.application.statusBarOrientation = UIInterfaceOrientationPortrait;
-            success = true;
+        
+        if (platState.portrait)
+        {
+            point.x = platState.windowSize.x / 2;
+            point.y = platState.windowSize.y / 2;
+        }
+        else
+        {
+            point.x = platState.windowSize.y / 2;
+            point.y = platState.windowSize.x / 2;
         }
-    } else
-    {//landscape/ sideways
-        if (upsidedown)
-        {//button on left
-            [platState.ctx rotateToAngle:0];//rotate to -180 (0) degrees
-            platState.application.statusBarOrientation = UIInterfaceOrientationLandscapeLeft;
-            success = true;
+        
+        
+        [platState.ctx centerOnPoint:point];
+        
+        if (portrait)
+        {//normal upright
+            if (upsidedown)
+            {//button on top
+                [platState.ctx rotateToAngle:M_PI + (M_PI / 2.0)];//rotate to 90 degrees
+                platState.application.statusBarOrientation = UIInterfaceOrientationPortraitUpsideDown;
+                success = true;
+            } else
+            {//button on bottom
+                [platState.ctx rotateToAngle:(M_PI / 2.0)];//rotate to 270 degrees
+                platState.application.statusBarOrientation = UIInterfaceOrientationPortrait;
+                success = true;
+            }
         } else
-        {//button on right
-            [platState.ctx rotateToAngle:(M_PI)];//rotate to 180 degrees
-            platState.application.statusBarOrientation = UIInterfaceOrientationLandscapeRight;
-            success = true;
+        {//landscape/ sideways
+            if (upsidedown)
+            {//button on left
+                [platState.ctx rotateToAngle:0];//rotate to -180 (0) degrees
+                platState.application.statusBarOrientation = UIInterfaceOrientationLandscapeLeft;
+                success = true;
+            } else
+            {//button on right
+                [platState.ctx rotateToAngle:(M_PI)];//rotate to 180 degrees
+                platState.application.statusBarOrientation = UIInterfaceOrientationLandscapeRight;
+                success = true;
+            }
         }
     }
-
+    //Set the screen for iOS 8 and latter
+    else
+    {
+        point.x = platState.windowSize.x / 2;
+        point.y = platState.windowSize.y / 2;
+    }
+    
     return success;
 }