src/video/uikit/SDL_uikitappdelegate.m
author Alex Szpakowski <slime73@gmail.com>
Sun, 12 Apr 2015 01:50:28 -0300
changeset 9552 201f813c650b
parent 9534 5b2b50804caa
child 9619 b94b6d0bff0f
permissions -rw-r--r--
Fixed orientation issues in the iOS extended launch screen.
slouken@2765
     1
/*
slouken@5535
     2
  Simple DirectMedia Layer
slouken@8149
     3
  Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
slouken@5262
     4
slouken@5535
     5
  This software is provided 'as-is', without any express or implied
slouken@5535
     6
  warranty.  In no event will the authors be held liable for any damages
slouken@5535
     7
  arising from the use of this software.
slouken@5262
     8
slouken@5535
     9
  Permission is granted to anyone to use this software for any purpose,
slouken@5535
    10
  including commercial applications, and to alter it and redistribute it
slouken@5535
    11
  freely, subject to the following restrictions:
slouken@5262
    12
slouken@5535
    13
  1. The origin of this software must not be misrepresented; you must not
slouken@5535
    14
     claim that you wrote the original software. If you use this software
slouken@5535
    15
     in a product, an acknowledgment in the product documentation would be
slouken@5535
    16
     appreciated but is not required.
slouken@5535
    17
  2. Altered source versions must be plainly marked as such, and must not be
slouken@5535
    18
     misrepresented as being the original software.
slouken@5535
    19
  3. This notice may not be removed or altered from any source distribution.
slouken@2765
    20
*/
icculus@8093
    21
#include "../../SDL_internal.h"
slouken@6044
    22
slouken@6044
    23
#if SDL_VIDEO_DRIVER_UIKIT
slouken@2765
    24
slouken@6556
    25
#include "../SDL_sysvideo.h"
slouken@6556
    26
#include "SDL_assert.h"
slouken@6556
    27
#include "SDL_hints.h"
slouken@6556
    28
#include "SDL_system.h"
slouken@7283
    29
#include "SDL_main.h"
icculus@4446
    30
slime73@9532
    31
#import "SDL_uikitappdelegate.h"
slime73@9532
    32
#import "SDL_uikitmodes.h"
slime73@9532
    33
#import "SDL_uikitwindow.h"
slime73@9532
    34
slouken@6556
    35
#include "../../events/SDL_events_c.h"
slouken@2765
    36
slouken@2765
    37
#ifdef main
slouken@2765
    38
#undef main
slouken@2765
    39
#endif
slouken@2765
    40
slouken@2765
    41
static int forward_argc;
slouken@2765
    42
static char **forward_argv;
kees@6006
    43
static int exit_status;
slouken@2765
    44
kees@6003
    45
int main(int argc, char **argv)
kees@6003
    46
{
slouken@5131
    47
    int i;
kees@6001
    48
slouken@5131
    49
    /* store arguments */
slouken@5131
    50
    forward_argc = argc;
slouken@5131
    51
    forward_argv = (char **)malloc((argc+1) * sizeof(char *));
kees@6003
    52
    for (i = 0; i < argc; i++) {
slouken@5131
    53
        forward_argv[i] = malloc( (strlen(argv[i])+1) * sizeof(char));
slouken@5131
    54
        strcpy(forward_argv[i], argv[i]);
slouken@5131
    55
    }
slouken@5131
    56
    forward_argv[i] = NULL;
slouken@2765
    57
slouken@5131
    58
    /* Give over control to run loop, SDLUIKitDelegate will handle most things from here */
slime73@9487
    59
    @autoreleasepool {
slime73@9510
    60
        UIApplicationMain(argc, argv, nil, [SDLUIKitDelegate getAppDelegateClassName]);
slime73@9487
    61
    }
kees@6001
    62
kees@6006
    63
    /* free the memory we used to hold copies of argc and argv */
kees@6006
    64
    for (i = 0; i < forward_argc; i++) {
kees@6006
    65
        free(forward_argv[i]);
kees@6006
    66
    }
kees@6006
    67
    free(forward_argv);
kees@6006
    68
kees@6006
    69
    return exit_status;
slouken@2765
    70
}
slouken@2765
    71
slouken@7432
    72
static void
slouken@7432
    73
SDL_IdleTimerDisabledChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
kees@6003
    74
{
slouken@7432
    75
    BOOL disable = (hint && *hint != '0');
tim@5555
    76
    [UIApplication sharedApplication].idleTimerDisabled = disable;
tim@5555
    77
}
tim@5555
    78
slime73@9532
    79
/* Load a launch image using the old UILaunchImageFile-era naming rules. */
slime73@9532
    80
static UIImage *
slime73@9532
    81
SDL_LoadLaunchImageNamed(NSString *name, int screenh)
slime73@9532
    82
{
slime73@9532
    83
    UIInterfaceOrientation curorient = [UIApplication sharedApplication].statusBarOrientation;
slime73@9532
    84
    UIUserInterfaceIdiom idiom = [UIDevice currentDevice].userInterfaceIdiom;
slime73@9532
    85
    UIImage *image = nil;
slime73@9532
    86
slime73@9532
    87
    if (idiom == UIUserInterfaceIdiomPhone && screenh == 568) {
slime73@9532
    88
        /* The image name for the iPhone 5 uses its height as a suffix. */
slime73@9532
    89
        image = [UIImage imageNamed:[NSString stringWithFormat:@"%@-568h", name]];
slime73@9532
    90
    } else if (idiom == UIUserInterfaceIdiomPad) {
slime73@9532
    91
        /* iPad apps can launch in any orientation. */
slime73@9532
    92
        if (UIInterfaceOrientationIsLandscape(curorient)) {
slime73@9532
    93
            if (curorient == UIInterfaceOrientationLandscapeLeft) {
slime73@9532
    94
                image = [UIImage imageNamed:[NSString stringWithFormat:@"%@-LandscapeLeft", name]];
slime73@9532
    95
            } else {
slime73@9532
    96
                image = [UIImage imageNamed:[NSString stringWithFormat:@"%@-LandscapeRight", name]];
slime73@9532
    97
            }
slime73@9532
    98
            if (!image) {
slime73@9532
    99
                image = [UIImage imageNamed:[NSString stringWithFormat:@"%@-Landscape", name]];
slime73@9532
   100
            }
slime73@9532
   101
        } else {
slime73@9532
   102
            if (curorient == UIInterfaceOrientationPortraitUpsideDown) {
slime73@9532
   103
                image = [UIImage imageNamed:[NSString stringWithFormat:@"%@-PortraitUpsideDown", name]];
slime73@9532
   104
            }
slime73@9532
   105
            if (!image) {
slime73@9532
   106
                image = [UIImage imageNamed:[NSString stringWithFormat:@"%@-Portrait", name]];
slime73@9532
   107
            }
slime73@9532
   108
        }
slime73@9532
   109
    }
slime73@9532
   110
slime73@9532
   111
    if (!image) {
slime73@9532
   112
        image = [UIImage imageNamed:name];
slime73@9532
   113
    }
slime73@9532
   114
slime73@9532
   115
    return image;
slime73@9532
   116
}
slime73@9532
   117
slime73@9552
   118
@implementation SDLLaunchScreenController
slime73@9532
   119
slime73@9532
   120
- (instancetype)init
slime73@9532
   121
{
slime73@9532
   122
    if (!(self = [super initWithNibName:nil bundle:nil])) {
slime73@9532
   123
        return nil;
slime73@9532
   124
    }
slime73@9532
   125
slime73@9532
   126
    NSBundle *bundle = [NSBundle mainBundle];
slime73@9532
   127
    NSString *screenname = [bundle objectForInfoDictionaryKey:@"UILaunchStoryboardName"];
slime73@9552
   128
    BOOL atleastiOS8 = UIKit_IsSystemVersionAtLeast(8.0);
slime73@9534
   129
slime73@9532
   130
    /* Launch screens were added in iOS 8. Otherwise we use launch images. */
slime73@9552
   131
    if (screenname && atleastiOS8) {
slime73@9532
   132
        @try {
slime73@9532
   133
            self.view = [bundle loadNibNamed:screenname owner:self options:nil][0];
slime73@9532
   134
        }
slime73@9532
   135
        @catch (NSException *exception) {
slime73@9552
   136
            /* If a launch screen name is specified but it fails to load, iOS
slime73@9552
   137
             * displays a blank screen rather than falling back to an image. */
slime73@9532
   138
            return nil;
slime73@9532
   139
        }
slime73@9532
   140
    }
slime73@9532
   141
slime73@9532
   142
    if (!self.view) {
slime73@9532
   143
        NSArray *launchimages = [bundle objectForInfoDictionaryKey:@"UILaunchImages"];
slime73@9532
   144
        UIInterfaceOrientation curorient = [UIApplication sharedApplication].statusBarOrientation;
slime73@9532
   145
        NSString *imagename = nil;
slime73@9532
   146
        UIImage *image = nil;
slime73@9532
   147
slime73@9532
   148
        int screenw = (int)([UIScreen mainScreen].bounds.size.width + 0.5);
slime73@9532
   149
        int screenh = (int)([UIScreen mainScreen].bounds.size.height + 0.5);
slime73@9532
   150
slime73@9532
   151
        /* We always want portrait-oriented size, to match UILaunchImageSize. */
slime73@9532
   152
        if (screenw > screenh) {
slime73@9532
   153
            int width = screenw;
slime73@9532
   154
            screenw = screenh;
slime73@9532
   155
            screenh = width;
slime73@9532
   156
        }
slime73@9532
   157
slime73@9532
   158
        /* Xcode 5 introduced a dictionary of launch images in Info.plist. */
slime73@9532
   159
        if (launchimages) {
slime73@9532
   160
            for (NSDictionary *dict in launchimages) {
slime73@9532
   161
                UIInterfaceOrientationMask orientmask = UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
slime73@9532
   162
                NSString *minversion   = dict[@"UILaunchImageMinimumOSVersion"];
slime73@9532
   163
                NSString *sizestring   = dict[@"UILaunchImageSize"];
slime73@9532
   164
                NSString *orientstring = dict[@"UILaunchImageOrientation"];
slime73@9532
   165
slime73@9532
   166
                /* Ignore this image if the current version is too low. */
slime73@9532
   167
                if (minversion && !UIKit_IsSystemVersionAtLeast(minversion.doubleValue)) {
slime73@9532
   168
                    continue;
slime73@9532
   169
                }
slime73@9532
   170
slime73@9532
   171
                /* Ignore this image if the size doesn't match. */
slime73@9532
   172
                if (sizestring) {
slime73@9532
   173
                    CGSize size = CGSizeFromString(sizestring);
slime73@9532
   174
                    if ((int)(size.width + 0.5) != screenw || (int)(size.height + 0.5) != screenh) {
slime73@9532
   175
                        continue;
slime73@9532
   176
                    }
slime73@9532
   177
                }
slime73@9532
   178
slime73@9532
   179
                if (orientstring) {
slime73@9532
   180
                    if ([orientstring isEqualToString:@"PortraitUpsideDown"]) {
slime73@9532
   181
                        orientmask = UIInterfaceOrientationMaskPortraitUpsideDown;
slime73@9532
   182
                    } else if ([orientstring isEqualToString:@"Landscape"]) {
slime73@9532
   183
                        orientmask = UIInterfaceOrientationMaskLandscape;
slime73@9532
   184
                    } else if ([orientstring isEqualToString:@"LandscapeLeft"]) {
slime73@9532
   185
                        orientmask = UIInterfaceOrientationMaskLandscapeLeft;
slime73@9532
   186
                    } else if ([orientstring isEqualToString:@"LandscapeRight"]) {
slime73@9532
   187
                        orientmask = UIInterfaceOrientationMaskLandscapeRight;
slime73@9532
   188
                    }
slime73@9532
   189
                }
slime73@9532
   190
slime73@9532
   191
                /* Ignore this image if the orientation doesn't match. */
slime73@9532
   192
                if ((orientmask & (1 << curorient)) == 0) {
slime73@9532
   193
                    continue;
slime73@9532
   194
                }
slime73@9532
   195
slime73@9532
   196
                imagename = dict[@"UILaunchImageName"];
slime73@9532
   197
            }
slime73@9532
   198
slime73@9532
   199
            if (imagename) {
slime73@9532
   200
                image = [UIImage imageNamed:imagename];
slime73@9532
   201
            }
slime73@9532
   202
        } else {
slime73@9532
   203
            imagename = [bundle objectForInfoDictionaryKey:@"UILaunchImageFile"];
slime73@9532
   204
slime73@9532
   205
            if (imagename) {
slime73@9532
   206
                image = SDL_LoadLaunchImageNamed(imagename, screenh);
slime73@9532
   207
            }
slime73@9532
   208
slime73@9532
   209
            if (!image) {
slime73@9532
   210
                image = SDL_LoadLaunchImageNamed(@"Default", screenh);
slime73@9532
   211
            }
slime73@9532
   212
        }
slime73@9532
   213
slime73@9532
   214
        if (image) {
slime73@9552
   215
            UIImageView *view = [[UIImageView alloc] initWithFrame:[UIScreen mainScreen].bounds];
slime73@9552
   216
            UIImageOrientation imageorient = UIImageOrientationUp;
slime73@9552
   217
slime73@9552
   218
            /* Bugs observed / workaround tested in iOS 8.3, 7.1, and 6.1. */
slime73@9552
   219
            if (UIInterfaceOrientationIsLandscape(curorient)) {
slime73@9552
   220
                if (atleastiOS8 && image.size.width < image.size.height) {
slime73@9552
   221
                    /* On iOS 8, portrait launch images displayed in forced-
slime73@9552
   222
                     * landscape mode (e.g. a standard Default.png on an iPhone
slime73@9552
   223
                     * when Info.plist only supports landscape orientations) need
slime73@9552
   224
                     * to be rotated to display in the expected orientation. */
slime73@9552
   225
                    if (curorient == UIInterfaceOrientationLandscapeLeft) {
slime73@9552
   226
                        imageorient = UIImageOrientationRight;
slime73@9552
   227
                    } else if (curorient == UIInterfaceOrientationLandscapeRight) {
slime73@9552
   228
                        imageorient = UIImageOrientationLeft;
slime73@9552
   229
                    }
slime73@9552
   230
                } else if (!atleastiOS8 && image.size.width > image.size.height) {
slime73@9552
   231
                    /* On iOS 7 and below, landscape launch images displayed in
slime73@9552
   232
                     * landscape mode (e.g. landscape iPad launch images) need
slime73@9552
   233
                     * to be rotated to display in the expected orientation. */
slime73@9552
   234
                    if (curorient == UIInterfaceOrientationLandscapeLeft) {
slime73@9552
   235
                        imageorient = UIImageOrientationLeft;
slime73@9552
   236
                    } else if (curorient == UIInterfaceOrientationLandscapeRight) {
slime73@9552
   237
                        imageorient = UIImageOrientationRight;
slime73@9552
   238
                    }
slime73@9552
   239
                }
slime73@9534
   240
            }
slime73@9534
   241
slime73@9552
   242
            /* Create the properly oriented image. */
slime73@9552
   243
            view.image = [[UIImage alloc] initWithCGImage:image.CGImage scale:image.scale orientation:imageorient];
slime73@9552
   244
slime73@9552
   245
            self.view = view;
slime73@9532
   246
        }
slime73@9532
   247
    }
slime73@9532
   248
slime73@9532
   249
    return self;
slime73@9532
   250
}
slime73@9532
   251
slime73@9532
   252
- (void)loadView
slime73@9532
   253
{
slime73@9532
   254
    /* Do nothing. */
slime73@9532
   255
}
slime73@9532
   256
slime73@9552
   257
- (BOOL)shouldAutorotate
slime73@9552
   258
{
slime73@9552
   259
    /* If YES, the launch image will be incorrectly rotated in some cases. */
slime73@9552
   260
    return NO;
slime73@9552
   261
}
slime73@9552
   262
slime73@9532
   263
- (NSUInteger)supportedInterfaceOrientations
slime73@9532
   264
{
slime73@9552
   265
    /* We keep the supported orientations unrestricted to avoid the case where
slime73@9552
   266
     * there are no common orientations between the ones set in Info.plist and
slime73@9552
   267
     * the ones set here (it will cause an exception in that case.) */
slime73@9552
   268
    return UIInterfaceOrientationMaskAll;
slime73@9532
   269
}
slime73@9532
   270
slime73@9532
   271
@end
slime73@9532
   272
slime73@9532
   273
@implementation SDLUIKitDelegate {
slime73@9532
   274
    UIWindow *launchWindow;
slime73@9532
   275
}
slouken@2765
   276
slouken@2765
   277
/* convenience method */
slime73@9532
   278
+ (id)sharedAppDelegate
kees@6003
   279
{
slime73@9532
   280
    /* the delegate is set in UIApplicationMain(), which is guaranteed to be
slime73@9532
   281
     * called before this method */
slime73@9532
   282
    return [UIApplication sharedApplication].delegate;
slouken@2765
   283
}
slouken@2765
   284
kees@6003
   285
+ (NSString *)getAppDelegateClassName
kees@6003
   286
{
slime73@9532
   287
    /* subclassing notice: when you subclass this appdelegate, make sure to add
slime73@9532
   288
     * a category to override this method and return the actual name of the
slime73@9532
   289
     * delegate */
slouken@5532
   290
    return @"SDLUIKitDelegate";
slouken@5532
   291
}
slouken@5532
   292
slime73@9532
   293
- (void)hideLaunchScreen
kees@6003
   294
{
slime73@9532
   295
    UIWindow *window = launchWindow;
slime73@9532
   296
slime73@9532
   297
    if (!window || window.hidden) {
slime73@9532
   298
        return;
slime73@9532
   299
    }
slime73@9532
   300
slime73@9532
   301
    launchWindow = nil;
slime73@9532
   302
slime73@9532
   303
    /* Do a nice animated fade-out (roughly matches the real launch behavior.) */
slime73@9532
   304
    [UIView animateWithDuration:0.2 animations:^{
slime73@9532
   305
        window.alpha = 0.0;
slime73@9532
   306
    } completion:^(BOOL finished) {
slime73@9532
   307
        window.hidden = YES;
slime73@9532
   308
    }];
slouken@2765
   309
}
slouken@2765
   310
kees@6003
   311
- (void)postFinishLaunch
kees@6003
   312
{
slime73@9532
   313
    /* Hide the launch screen the next time the run loop is run. SDL apps will
slime73@9532
   314
     * have a chance to load resources while the launch screen is still up. */
slime73@9532
   315
    [self performSelector:@selector(hideLaunchScreen) withObject:nil afterDelay:0.0];
slime73@9532
   316
slouken@5131
   317
    /* run the user's application, passing argc and argv */
slouken@6346
   318
    SDL_iPhoneSetEventPump(SDL_TRUE);
kees@6006
   319
    exit_status = SDL_main(forward_argc, forward_argv);
slouken@6346
   320
    SDL_iPhoneSetEventPump(SDL_FALSE);
kees@6001
   321
slime73@9532
   322
    if (launchWindow) {
slime73@9532
   323
        launchWindow.hidden = YES;
slime73@9532
   324
        launchWindow = nil;
slime73@9532
   325
    }
slime73@9532
   326
slouken@5131
   327
    /* exit, passing the return status from the user's application */
slime73@9532
   328
    /* We don't actually exit to support applications that do setup in their
slime73@9532
   329
     * main function and then allow the Cocoa event loop to run. */
slouken@7191
   330
    /* exit(exit_status); */
slouken@3422
   331
}
slouken@3422
   332
kees@6003
   333
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
kees@6003
   334
{
slime73@9532
   335
    NSBundle *bundle = [NSBundle mainBundle];
slime73@9532
   336
    NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
slime73@9532
   337
slime73@9532
   338
#if SDL_IPHONE_LAUNCHSCREEN
slime73@9532
   339
    /* The normal launch screen is displayed until didFinishLaunching returns,
slime73@9532
   340
     * but SDL_main is called after that happens and there may be a noticeable
slime73@9532
   341
     * delay between the start of SDL_main and when the first real frame is
slime73@9532
   342
     * displayed (e.g. if resources are loaded before SDL_GL_SwapWindow is
slime73@9532
   343
     * called), so we show the launch screen programmatically until the first
slime73@9532
   344
     * time events are pumped. */
slime73@9532
   345
    UIViewController *viewcontroller = [[SDLLaunchScreenController alloc] init];
slime73@9532
   346
slime73@9532
   347
    if (viewcontroller.view) {
slime73@9532
   348
        launchWindow = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
slime73@9532
   349
slime73@9532
   350
        /* We don't want the launch window immediately hidden when a real SDL
slime73@9532
   351
         * window is shown - we fade it out ourselves when we're ready. */
slime73@9532
   352
        launchWindow.windowLevel = UIWindowLevelNormal + 1.0;
slime73@9532
   353
slime73@9532
   354
        /* Show the window but don't make it key. Events should always go to
slime73@9532
   355
         * other windows when possible. */
slime73@9532
   356
        launchWindow.hidden = NO;
slime73@9532
   357
slime73@9532
   358
        launchWindow.rootViewController = viewcontroller;
slime73@9532
   359
    }
slime73@9532
   360
#endif
slime73@9532
   361
slouken@5131
   362
    /* Set working directory to resource path */
slime73@9532
   363
    [[NSFileManager defaultManager] changeCurrentDirectoryPath:[bundle resourcePath]];
kees@6001
   364
slouken@6349
   365
    /* register a callback for the idletimer hint */
slouken@7432
   366
    SDL_AddHintCallback(SDL_HINT_IDLE_TIMER_DISABLED,
slouken@7432
   367
                        SDL_IdleTimerDisabledChanged, NULL);
slouken@6349
   368
slouken@7355
   369
    SDL_SetMainReady();
slouken@5532
   370
    [self performSelector:@selector(postFinishLaunch) withObject:nil afterDelay:0.0];
slime73@9534
   371
slouken@5487
   372
    return YES;
slouken@2765
   373
}
slouken@2765
   374
kees@6003
   375
- (void)applicationWillTerminate:(UIApplication *)application
kees@6003
   376
{
slouken@7190
   377
    SDL_SendAppEvent(SDL_APP_TERMINATING);
slouken@7190
   378
}
slouken@7190
   379
slouken@7190
   380
- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application
slouken@7190
   381
{
slouken@7190
   382
    SDL_SendAppEvent(SDL_APP_LOWMEMORY);
slouken@2765
   383
}
slouken@2765
   384
slime73@9504
   385
- (void)application:(UIApplication *)application didChangeStatusBarOrientation:(UIInterfaceOrientation)oldStatusBarOrientation
slime73@9504
   386
{
slime73@9505
   387
    BOOL isLandscape = UIInterfaceOrientationIsLandscape(application.statusBarOrientation);
slime73@9504
   388
    SDL_VideoDevice *_this = SDL_GetVideoDevice();
slime73@9504
   389
slime73@9504
   390
    if (_this && _this->num_displays > 0) {
slime73@9505
   391
        SDL_DisplayMode *desktopmode = &_this->displays[0].desktop_mode;
slime73@9505
   392
        SDL_DisplayMode *currentmode = &_this->displays[0].current_mode;
slime73@9504
   393
slime73@9504
   394
        /* The desktop display mode should be kept in sync with the screen
slime73@9504
   395
         * orientation so that updating a window's fullscreen state to
slime73@9504
   396
         * SDL_WINDOW_FULLSCREEN_DESKTOP keeps the window dimensions in the
slime73@9532
   397
         * correct orientation. */
slime73@9505
   398
        if (isLandscape != (desktopmode->w > desktopmode->h)) {
slime73@9505
   399
            int height = desktopmode->w;
slime73@9505
   400
            desktopmode->w = desktopmode->h;
slime73@9505
   401
            desktopmode->h = height;
slime73@9505
   402
        }
slime73@9505
   403
slime73@9505
   404
        /* Same deal with the current mode + SDL_GetCurrentDisplayMode. */
slime73@9505
   405
        if (isLandscape != (currentmode->w > currentmode->h)) {
slime73@9505
   406
            int height = currentmode->w;
slime73@9505
   407
            currentmode->w = currentmode->h;
slime73@9505
   408
            currentmode->h = height;
slime73@9504
   409
        }
slime73@9504
   410
    }
slime73@9504
   411
}
slime73@9504
   412
slime73@9532
   413
- (void)applicationWillResignActive:(UIApplication*)application
slouken@3400
   414
{
slouken@7190
   415
    SDL_VideoDevice *_this = SDL_GetVideoDevice();
slouken@7190
   416
    if (_this) {
slouken@7190
   417
        SDL_Window *window;
slouken@7190
   418
        for (window = _this->windows; window != nil; window = window->next) {
slouken@7190
   419
            SDL_SendWindowEvent(window, SDL_WINDOWEVENT_FOCUS_LOST, 0, 0);
slouken@7190
   420
            SDL_SendWindowEvent(window, SDL_WINDOWEVENT_MINIMIZED, 0, 0);
slouken@7190
   421
        }
slouken@7190
   422
    }
slouken@7190
   423
    SDL_SendAppEvent(SDL_APP_WILLENTERBACKGROUND);
slouken@7190
   424
}
icculus@4446
   425
slime73@9532
   426
- (void)applicationDidEnterBackground:(UIApplication*)application
slouken@7190
   427
{
slouken@7190
   428
    SDL_SendAppEvent(SDL_APP_DIDENTERBACKGROUND);
slouken@7190
   429
}
kees@6001
   430
slime73@9532
   431
- (void)applicationWillEnterForeground:(UIApplication*)application
slouken@7190
   432
{
slouken@7190
   433
    SDL_SendAppEvent(SDL_APP_WILLENTERFOREGROUND);
slouken@3400
   434
}
slouken@3400
   435
slime73@9532
   436
- (void)applicationDidBecomeActive:(UIApplication*)application
slouken@3400
   437
{
slouken@7190
   438
    SDL_SendAppEvent(SDL_APP_DIDENTERFOREGROUND);
slouken@3400
   439
icculus@4446
   440
    SDL_VideoDevice *_this = SDL_GetVideoDevice();
slouken@7190
   441
    if (_this) {
slouken@7190
   442
        SDL_Window *window;
slouken@7190
   443
        for (window = _this->windows; window != nil; window = window->next) {
slouken@7190
   444
            SDL_SendWindowEvent(window, SDL_WINDOWEVENT_FOCUS_GAINED, 0, 0);
slouken@7190
   445
            SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESTORED, 0, 0);
slouken@7190
   446
        }
icculus@4446
   447
    }
slouken@2765
   448
}
slouken@2765
   449
slouken@6587
   450
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
slouken@6587
   451
{
slime73@9532
   452
    NSURL *fileURL = url.filePathURL;
slouken@6587
   453
    if (fileURL != nil) {
slime73@9532
   454
        SDL_SendDropFile([fileURL.path UTF8String]);
slouken@6587
   455
    } else {
slime73@9532
   456
        SDL_SendDropFile([url.absoluteString UTF8String]);
slouken@6587
   457
    }
slouken@6587
   458
    return YES;
slouken@6587
   459
}
slouken@6587
   460
slouken@2765
   461
@end
slouken@5132
   462
slouken@6044
   463
#endif /* SDL_VIDEO_DRIVER_UIKIT */
slouken@6044
   464
slouken@5132
   465
/* vi: set ts=4 sw=4 expandtab: */