From 128b3ed816d9a64599c02dbab7c26589cc8fd19c Mon Sep 17 00:00:00 2001 From: Mathieu Virbel Date: Mon, 15 Oct 2012 12:40:01 +0200 Subject: [PATCH] read orientations values from the Info.plist --- tools/templates/main.m | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tools/templates/main.m b/tools/templates/main.m index 750b934..72d2b2f 100644 --- a/tools/templates/main.m +++ b/tools/templates/main.m @@ -9,6 +9,8 @@ #include "SDL/SDL_main.h" #include +void export_orientation(); + int main(int argc, char *argv[]) { int ret = 0; @@ -34,6 +36,9 @@ int main(int argc, char *argv[]) { putenv("KIVY_IMAGE=imageio"); putenv("KIVY_AUDIO=sdl"); + // Export orientation preferences for Kivy + export_orientation(); + NSString * resourcePath = [[NSBundle mainBundle] resourcePath]; NSLog(@"PythonHome is: %s", (char *)[resourcePath UTF8String]); Py_SetPythonHome((char *)[resourcePath UTF8String]); @@ -69,3 +74,23 @@ int main(int argc, char *argv[]) { exit(ret); return ret; } + +// This method read available orientations from the Info.plist, and share them +// in an environment variable. Kivy will automatically set the orientation +// according to this environment value, if exist. +void export_orientation() { + NSDictionary *info = [[NSBundle mainBundle] infoDictionary]; + NSArray *orientations = [info objectForKey:@"UISupportedInterfaceOrientations"]; + NSString *result = [[NSString alloc] initWithString:@"KIVY_ORIENTATION="]; + for (int i = 0; i < [orientations count]; i++) { + NSString *item = [orientations objectAtIndex:i]; + item = [item substringFromIndex:22]; + if (i > 0) + result = [result stringByAppendingString:@" "]; + result = [result stringByAppendingString:item]; + } + + putenv([result UTF8String]); + //NSLog(@"Available orientation: %@", result); +} +