project_files/HedgewarsMobile/Classes/SDL_uikitappdelegate.m
changeset 4454 42bfc1a70968
parent 4356 d1d26f8963a3
child 4504 8906b2409d97
equal deleted inserted replaced
4453:15a483b2558a 4454:42bfc1a70968
    27 #import "../SDL_sysvideo.h"
    27 #import "../SDL_sysvideo.h"
    28 #import "jumphack.h"
    28 #import "jumphack.h"
    29 #import "SDL_video.h"
    29 #import "SDL_video.h"
    30 #import "SDL_mixer.h"
    30 #import "SDL_mixer.h"
    31 #import "PascalImports.h"
    31 #import "PascalImports.h"
       
    32 #import "ObjcExports.h"
    32 #import "CommodityFunctions.h"
    33 #import "CommodityFunctions.h"
    33 #import "GameSetup.h"
    34 #import "GameSetup.h"
    34 #import "MainMenuViewController.h"
    35 #import "MainMenuViewController.h"
    35 #import "OverlayViewController.h"
    36 #import "OverlayViewController.h"
    36 
    37 
   220     MSG_MEMCLEAN();
   221     MSG_MEMCLEAN();
   221     print_free_memory();
   222     print_free_memory();
   222 }
   223 }
   223 
   224 
   224 -(void) applicationWillResignActive:(UIApplication *)application {
   225 -(void) applicationWillResignActive:(UIApplication *)application {
   225     if (self.isInGame) {
   226     UIDevice* device = [UIDevice currentDevice];
   226         HW_pause();
   227     if ([device respondsToSelector:@selector(isMultitaskingSupported)] &&
   227 
   228          device.multitaskingSupported &&
   228         // Send every window on every screen a MINIMIZED event.
   229          self.isInGame) {
   229         SDL_VideoDevice *_this = SDL_GetVideoDevice();
   230         // there is a bug on iphone that presents a sdl view with a black screen, so it returns to frontend
   230         if (!_this)
   231         if (IS_IPAD())
   231             return;
   232             HW_suspend();
   232 
   233         else {
   233         int i;
   234             // while screen is loading you can't call HW_terminate() so we close the app
   234         for (i = 0; i < _this->num_displays; i++) {
   235             if (isGameRunning())
   235             const SDL_VideoDisplay *display = &_this->displays[i];
   236                 HW_terminate(NO);
   236             SDL_Window *window;
   237             else {
   237             for (window = display->windows; window != nil; window = window->next)
   238                 // force app closure
   238                 SDL_SendWindowEvent(window, SDL_WINDOWEVENT_MINIMIZED, 0, 0);
   239                 SDL_SendQuit();
       
   240                 HW_terminate(YES);
       
   241                 longjmp(*(jump_env()), 1);
       
   242             }
   239         }
   243         }
   240     }
   244     }
   241 }
   245 }
   242 
   246 
   243 -(void) applicationDidBecomeActive:(UIApplication *)application {
   247 -(void) applicationDidBecomeActive:(UIApplication *)application {
   244     if (self.isInGame) {
   248     UIDevice* device = [UIDevice currentDevice];
   245         HW_pause();
   249     if ([device respondsToSelector:@selector(isMultitaskingSupported)] &&
   246 
   250          device.multitaskingSupported &&
   247         // Send every window on every screen a RESTORED event.
   251          self.isInGame) {
   248         SDL_VideoDevice *_this = SDL_GetVideoDevice();
   252         HW_resume();
   249         if (!_this)
       
   250             return;
       
   251 
       
   252         int i;
       
   253         for (i = 0; i < _this->num_displays; i++) {
       
   254             const SDL_VideoDisplay *display = &_this->displays[i];
       
   255             SDL_Window *window;
       
   256             for (window = display->windows; window != nil; window = window->next)
       
   257                 SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESTORED, 0, 0);
       
   258         }
       
   259     }
   253     }
   260 }
   254 }
   261 
   255 
   262 @end
   256 @end