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
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
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
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
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 **/