project_files/HedgewarsMobile/Classes/HedgewarsAppDelegate.m
changeset 6822 206db098f8c5
parent 6700 e04da46ee43c
child 6832 fae8fd118da9
equal deleted inserted replaced
6821:d4f75843cf5d 6822:206db098f8c5
    19  */
    19  */
    20 
    20 
    21 
    21 
    22 #import "HedgewarsAppDelegate.h"
    22 #import "HedgewarsAppDelegate.h"
    23 #import "MainMenuViewController.h"
    23 #import "MainMenuViewController.h"
    24 #import "ObjcExports.h"
       
    25 #include <unistd.h>
       
    26 
       
    27 
    24 
    28 @implementation SDLUIKitDelegate (customDelegate)
    25 @implementation SDLUIKitDelegate (customDelegate)
    29 
    26 
       
    27 // hijack the the SDL_UIKitAppDelegate to use the UIApplicationDelegate we implement here
    30 +(NSString *)getAppDelegateClassName {
    28 +(NSString *)getAppDelegateClassName {
    31     return @"HedgewarsAppDelegate";
    29     return @"HedgewarsAppDelegate";
    32 }
    30 }
    33 
    31 
    34 @end
    32 @end
    55 // override the direct execution of SDL_main to allow us to implement our own frontend
    53 // override the direct execution of SDL_main to allow us to implement our own frontend
    56 -(void) postFinishLaunch {
    54 -(void) postFinishLaunch {
    57     [[UIApplication sharedApplication] setStatusBarHidden:YES];
    55     [[UIApplication sharedApplication] setStatusBarHidden:YES];
    58 
    56 
    59     self.uiwindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    57     self.uiwindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
       
    58     self.uiwindow.backgroundColor = [UIColor blackColor];
    60 
    59 
    61     NSString *controllerName = (IS_IPAD() ? @"MainMenuViewController-iPad" : @"MainMenuViewController-iPhone");
    60     NSString *controllerName = (IS_IPAD() ? @"MainMenuViewController-iPad" : @"MainMenuViewController-iPhone");
    62     self.mainViewController = [[MainMenuViewController alloc] initWithNibName:controllerName bundle:nil];
    61     self.mainViewController = [[MainMenuViewController alloc] initWithNibName:controllerName bundle:nil];
    63 
       
    64     [self.uiwindow addSubview:self.mainViewController.view];
    62     [self.uiwindow addSubview:self.mainViewController.view];
    65     [self.mainViewController release];
    63     [self.mainViewController release];
    66     self.uiwindow.backgroundColor = [UIColor blackColor];
    64 
    67     [self.uiwindow makeKeyAndVisible];
    65     [self.uiwindow makeKeyAndVisible];
    68 }
    66 }
    69 
    67 
    70 -(void) applicationDidReceiveMemoryWarning:(UIApplication *)application {
    68 -(void) applicationDidReceiveMemoryWarning:(UIApplication *)application {
    71     [HWUtils releaseCache];
    69     [HWUtils releaseCache];
    76     }
    74     }
    77     MSG_MEMCLEAN();
    75     MSG_MEMCLEAN();
    78     // don't clean mainMenuViewController here!!!
    76     // don't clean mainMenuViewController here!!!
    79 }
    77 }
    80 
    78 
    81 // true multitasking with sdl works only on 4.2 and above; we close the game to avoid a black screen at return
    79 // true multitasking with SDL works only on 4.2 and above; we close the game to avoid a black screen at return
    82 -(void) applicationWillResignActive:(UIApplication *)application {
    80 -(void) applicationWillResignActive:(UIApplication *)application {
    83     if ([HWUtils isGameLaunched] && [[[UIDevice currentDevice] systemVersion] floatValue] < 4.2f)
    81     if ([HWUtils isGameLaunched] && [[[UIDevice currentDevice] systemVersion] floatValue] < 4.2f)
    84          HW_terminate(NO);
    82         HW_terminate(NO);
    85 
    83 
    86     [super applicationWillResignActive:application];
    84     [super applicationWillResignActive:application];
    87 }
    85 }
    88 
    86 
    89 @end
    87 @end