OSDN Git Service

ShouldAutorotateToInterfaceOrientation implemented.
authorChristoph Aschwanden <contact@noblemaster.com>
Thu, 27 Sep 2012 11:27:58 +0000 (20:27 +0900)
committerChristoph Aschwanden <contact@noblemaster.com>
Thu, 27 Sep 2012 11:27:58 +0000 (20:27 +0900)
backends/gdx-backend-iosmonotouch/src/com/badlogic/gdx/backends/ios/IOSApplication.java
backends/gdx-backend-iosmonotouch/src/com/badlogic/gdx/backends/ios/IOSApplicationConfiguration.java
backends/gdx-backend-iosmonotouch/src/com/badlogic/gdx/backends/ios/IOSGraphics.java

index 84107fa..3f6b81b 100644 (file)
@@ -35,6 +35,7 @@ import com.badlogic.gdx.Gdx;
 import com.badlogic.gdx.Graphics;\r
 import com.badlogic.gdx.Input;\r
 import com.badlogic.gdx.Preferences;\r
+import com.badlogic.gdx.backends.ios.IOSApplicationConfiguration.SupportedOrientation;\r
 import com.badlogic.gdx.utils.Clipboard;\r
 \r
 public class IOSApplication extends UIApplicationDelegate implements Application {\r
@@ -50,8 +51,10 @@ public class IOSApplication extends UIApplicationDelegate implements Application
        boolean firstResume;\r
        \r
        /**\r
-        * Should be called in AppDelegate#FinishedLaunching\r
-        * @param uiApp\r
+        * Should be called in AppDelegate#FinishedLaunching.\r
+        * \r
+        * @param listener  Our application (aka game) to run.\r
+        * @param config  The desired iOS configuration.\r
         */\r
        public IOSApplication(ApplicationListener listener, IOSApplicationConfiguration config) {\r
                this.listener = listener;\r
@@ -67,17 +70,28 @@ public class IOSApplication extends UIApplicationDelegate implements Application
                this.uiWindow = new UIWindow(UIScreen.get_MainScreen().get_Bounds());   \r
                UIViewController uiViewController = new UIViewController() {    \r
                        @Override\r
-                       public void DidRotate (UIInterfaceOrientation arg0) {\r
+                       public void DidRotate (UIInterfaceOrientation orientation) {\r
                                // get the view size and update graphics\r
+                               // FIXME: supporting BOTH (landscape+portrait at same time) is currently not working correctly (needs fix)\r
                                RectangleF bounds = getBounds(this);\r
                                graphics.width = (int)bounds.get_Width();\r
                                graphics.height = (int)bounds.get_Height();\r
-                               graphics.MakeCurrent();\r
+                               graphics.MakeCurrent();  // not sure if that's needed?\r
                                listener.resize(graphics.width, graphics.height);\r
                        }\r
                        @Override\r
-                       public boolean ShouldAutorotateToInterfaceOrientation (UIInterfaceOrientation arg0) {\r
-                               return true;  // TODO: need to check if orientation is supported!!!\r
+                       public boolean ShouldAutorotateToInterfaceOrientation (UIInterfaceOrientation orientation) {\r
+                               // we return "true" if we support the orientation\r
+                               switch (orientation.Value) { \r
+                                       case UIInterfaceOrientation.LandscapeLeft: \r
+                                       case UIInterfaceOrientation.LandscapeRight: \r
+                                          return config.supportedOrientation == SupportedOrientation.LANDSCAPE ||\r
+                                                 config.supportedOrientation == SupportedOrientation.BOTH;\r
+                                       default: \r
+                                               // assume portrait\r
+                                          return config.supportedOrientation == SupportedOrientation.PORTRAIT ||\r
+                                       config.supportedOrientation == SupportedOrientation.BOTH;\r
+                               } \r
                        }\r
                };\r
                this.uiWindow.set_RootViewController(uiViewController);\r
@@ -103,7 +117,13 @@ public class IOSApplication extends UIApplicationDelegate implements Application
                return true;\r
        }\r
 \r
-       private RectangleF getBounds(UIViewController viewController) {\r
+       /**\r
+        * Returns our real display dimension based on screen orientation.\r
+        * \r
+        * @param viewController  The view controller.\r
+        * @return  Or real display dimension.\r
+        */\r
+       RectangleF getBounds(UIViewController viewController) {\r
                // or screen size (always portrait)\r
                RectangleF bounds = UIScreen.get_MainScreen().get_Bounds();\r
 \r
index ac95467..a01351f 100644 (file)
@@ -1,6 +1,19 @@
 package com.badlogic.gdx.backends.ios;
 
 public class IOSApplicationConfiguration {
+       
+       /** The orientation the application/game is supporting. */
+       public enum SupportedOrientation {
+               /** Portrait only. */
+               PORTRAIT,
+               /** Landscape only. */
+               LANDSCAPE,
+               /** Both landscape & portrait. */
+               BOTH;
+       }
+       
+       /** The screen orientations the application supports. */
+       public SupportedOrientation supportedOrientation = SupportedOrientation.BOTH;
        /** whether to use the accelerometer **/
        public boolean useAccelerometer = true;
        /** the update interval to poll the accelerometer with, in seconds **/
index be1e37e..1cfdac6 100644 (file)
@@ -80,7 +80,6 @@ public class IOSGraphics extends iPhoneOSGameView implements Graphics {
                super.OnLoad(arg0);
                MakeCurrent();
                app.listener.create();
-               app.listener.resize(0, 0); // FIXME
        }
 
        @Override
@@ -105,10 +104,11 @@ public class IOSGraphics extends iPhoneOSGameView implements Graphics {
        }
 
        @Override
-       protected void OnResize(EventArgs arg0) {
-               super.OnResize(arg0);
-               MakeCurrent();
-               app.listener.resize(0, 0); // FIXME
+       protected void OnResize(EventArgs event) {
+               super.OnResize(event);
+\r
+               // noblemaster: I don't think this method will get called on iOS!? (at least not as of 2012-09-27)\r
+               Gdx.app.error("IOSGraphics", "OnResize(...) is not implement.");
        }
 
        @ExportAttribute.Annotation("layerClass")