src/video/uikit/SDL_uikitappdelegate.m
author Sam Lantinga <slouken@libsdl.org>
Sun, 14 Oct 2012 01:05:04 -0700
changeset 6587 4ef7c70295c9
parent 6557 87ba88e3f2a9
child 6885 700f1b25f77f
permissions -rw-r--r--
Implemented drop events in iOS
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     1
/*
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5532
diff changeset
     2
  Simple DirectMedia Layer
6138
4c64952a58fb Happy New Year!
Sam Lantinga <slouken@libsdl.org>
parents: 6090
diff changeset
     3
  Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org>
5262
b530ef003506 Happy 2011! :)
Sam Lantinga <slouken@libsdl.org>
parents: 5251
diff changeset
     4
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5532
diff changeset
     5
  This software is provided 'as-is', without any express or implied
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5532
diff changeset
     6
  warranty.  In no event will the authors be held liable for any damages
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5532
diff changeset
     7
  arising from the use of this software.
5262
b530ef003506 Happy 2011! :)
Sam Lantinga <slouken@libsdl.org>
parents: 5251
diff changeset
     8
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5532
diff changeset
     9
  Permission is granted to anyone to use this software for any purpose,
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5532
diff changeset
    10
  including commercial applications, and to alter it and redistribute it
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5532
diff changeset
    11
  freely, subject to the following restrictions:
5262
b530ef003506 Happy 2011! :)
Sam Lantinga <slouken@libsdl.org>
parents: 5251
diff changeset
    12
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5532
diff changeset
    13
  1. The origin of this software must not be misrepresented; you must not
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5532
diff changeset
    14
     claim that you wrote the original software. If you use this software
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5532
diff changeset
    15
     in a product, an acknowledgment in the product documentation would be
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5532
diff changeset
    16
     appreciated but is not required.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5532
diff changeset
    17
  2. Altered source versions must be plainly marked as such, and must not be
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5532
diff changeset
    18
     misrepresented as being the original software.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5532
diff changeset
    19
  3. This notice may not be removed or altered from any source distribution.
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    20
*/
6044
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 6006
diff changeset
    21
#include "SDL_config.h"
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 6006
diff changeset
    22
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 6006
diff changeset
    23
#if SDL_VIDEO_DRIVER_UIKIT
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    24
6556
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
    25
#include "../SDL_sysvideo.h"
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
    26
#include "SDL_assert.h"
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
    27
#include "SDL_hints.h"
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
    28
#include "../../SDL_hints_c.h"
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
    29
#include "SDL_system.h"
4446
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 3685
diff changeset
    30
6556
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
    31
#include "SDL_uikitappdelegate.h"
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
    32
#include "SDL_uikitmodes.h"
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
    33
#include "../../events/SDL_events_c.h"
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
    34
#include "jumphack.h"
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    35
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    36
#ifdef main
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    37
#undef main
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    38
#endif
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    39
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    40
extern int SDL_main(int argc, char *argv[]);
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    41
static int forward_argc;
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    42
static char **forward_argv;
6006
889d89332de4 Do not exit in (uikit) postFinishLaunch but store the exit status and use that to return from main()
Kees Bakker <kees@ijzerbout.nl>
parents: 6003
diff changeset
    43
static int exit_status;
6556
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
    44
static UIWindow *launch_window;
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    45
6003
fddf81967e2d Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 6001
diff changeset
    46
int main(int argc, char **argv)
fddf81967e2d Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 6001
diff changeset
    47
{
5131
7b7da52e8775 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 4489
diff changeset
    48
    int i;
7b7da52e8775 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 4489
diff changeset
    49
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
6001
3ae3d1e58d59 Cleanup out trailing whitespace in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 5614
diff changeset
    50
5131
7b7da52e8775 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 4489
diff changeset
    51
    /* store arguments */
7b7da52e8775 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 4489
diff changeset
    52
    forward_argc = argc;
7b7da52e8775 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 4489
diff changeset
    53
    forward_argv = (char **)malloc((argc+1) * sizeof(char *));
6003
fddf81967e2d Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 6001
diff changeset
    54
    for (i = 0; i < argc; i++) {
5131
7b7da52e8775 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 4489
diff changeset
    55
        forward_argv[i] = malloc( (strlen(argv[i])+1) * sizeof(char));
7b7da52e8775 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 4489
diff changeset
    56
        strcpy(forward_argv[i], argv[i]);
7b7da52e8775 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 4489
diff changeset
    57
    }
7b7da52e8775 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 4489
diff changeset
    58
    forward_argv[i] = NULL;
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    59
5131
7b7da52e8775 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 4489
diff changeset
    60
    /* Give over control to run loop, SDLUIKitDelegate will handle most things from here */
5532
8a04b596b472 Allow overriding the app delegate on iOS
Sam Lantinga <slouken@libsdl.org>
parents: 5487
diff changeset
    61
    UIApplicationMain(argc, argv, NULL, [SDLUIKitDelegate getAppDelegateClassName]);
6001
3ae3d1e58d59 Cleanup out trailing whitespace in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 5614
diff changeset
    62
6006
889d89332de4 Do not exit in (uikit) postFinishLaunch but store the exit status and use that to return from main()
Kees Bakker <kees@ijzerbout.nl>
parents: 6003
diff changeset
    63
    /* free the memory we used to hold copies of argc and argv */
889d89332de4 Do not exit in (uikit) postFinishLaunch but store the exit status and use that to return from main()
Kees Bakker <kees@ijzerbout.nl>
parents: 6003
diff changeset
    64
    for (i = 0; i < forward_argc; i++) {
889d89332de4 Do not exit in (uikit) postFinishLaunch but store the exit status and use that to return from main()
Kees Bakker <kees@ijzerbout.nl>
parents: 6003
diff changeset
    65
        free(forward_argv[i]);
889d89332de4 Do not exit in (uikit) postFinishLaunch but store the exit status and use that to return from main()
Kees Bakker <kees@ijzerbout.nl>
parents: 6003
diff changeset
    66
    }
889d89332de4 Do not exit in (uikit) postFinishLaunch but store the exit status and use that to return from main()
Kees Bakker <kees@ijzerbout.nl>
parents: 6003
diff changeset
    67
    free(forward_argv);
889d89332de4 Do not exit in (uikit) postFinishLaunch but store the exit status and use that to return from main()
Kees Bakker <kees@ijzerbout.nl>
parents: 6003
diff changeset
    68
5131
7b7da52e8775 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 4489
diff changeset
    69
    [pool release];
6006
889d89332de4 Do not exit in (uikit) postFinishLaunch but store the exit status and use that to return from main()
Kees Bakker <kees@ijzerbout.nl>
parents: 6003
diff changeset
    70
    return exit_status;
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    71
}
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    72
6003
fddf81967e2d Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 6001
diff changeset
    73
static void SDL_IdleTimerDisabledChanged(const char *name, const char *oldValue, const char *newValue)
fddf81967e2d Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 6001
diff changeset
    74
{
5555
3ecad5e5dbe4 * SDL_IOS_IDLE_TIMER_DISABLED hint
Tim Angus <tim@blackcompanystudios.co.uk>
parents: 5535
diff changeset
    75
    SDL_assert(SDL_strcmp(name, SDL_HINT_IDLE_TIMER_DISABLED) == 0);
6001
3ae3d1e58d59 Cleanup out trailing whitespace in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 5614
diff changeset
    76
5555
3ecad5e5dbe4 * SDL_IOS_IDLE_TIMER_DISABLED hint
Tim Angus <tim@blackcompanystudios.co.uk>
parents: 5535
diff changeset
    77
    BOOL disable = (*newValue != '0');
3ecad5e5dbe4 * SDL_IOS_IDLE_TIMER_DISABLED hint
Tim Angus <tim@blackcompanystudios.co.uk>
parents: 5535
diff changeset
    78
    [UIApplication sharedApplication].idleTimerDisabled = disable;
3ecad5e5dbe4 * SDL_IOS_IDLE_TIMER_DISABLED hint
Tim Angus <tim@blackcompanystudios.co.uk>
parents: 5535
diff changeset
    79
}
3ecad5e5dbe4 * SDL_IOS_IDLE_TIMER_DISABLED hint
Tim Angus <tim@blackcompanystudios.co.uk>
parents: 5535
diff changeset
    80
6556
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
    81
@interface SDL_splashviewcontroller : UIViewController {
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
    82
    UIImageView *splash;
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
    83
    UIImage *splashPortrait;
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
    84
    UIImage *splashLandscape;
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
    85
}
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
    86
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
    87
- (void)updateSplashImage:(UIInterfaceOrientation)interfaceOrientation;
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
    88
@end
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
    89
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
    90
@implementation SDL_splashviewcontroller
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
    91
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
    92
- (id)init
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
    93
{
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
    94
    self = [super init];
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
    95
    if (self == nil) {
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
    96
        return nil;
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
    97
    }
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
    98
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
    99
    self->splash = [[UIImageView alloc] init];
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
   100
    [self setView:self->splash];
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
   101
6557
87ba88e3f2a9 Support iPhone 5 launch images
Sam Lantinga <slouken@libsdl.org>
parents: 6556
diff changeset
   102
    CGSize size = [UIScreen mainScreen].bounds.size;
87ba88e3f2a9 Support iPhone 5 launch images
Sam Lantinga <slouken@libsdl.org>
parents: 6556
diff changeset
   103
    float height = SDL_max(size.width, size.height);
87ba88e3f2a9 Support iPhone 5 launch images
Sam Lantinga <slouken@libsdl.org>
parents: 6556
diff changeset
   104
    self->splashPortrait = [UIImage imageNamed:[NSString stringWithFormat:@"Default-%dh.png", (int)height]];
87ba88e3f2a9 Support iPhone 5 launch images
Sam Lantinga <slouken@libsdl.org>
parents: 6556
diff changeset
   105
    if (!self->splashPortrait) {
87ba88e3f2a9 Support iPhone 5 launch images
Sam Lantinga <slouken@libsdl.org>
parents: 6556
diff changeset
   106
        self->splashPortrait = [UIImage imageNamed:@"Default.png"];
87ba88e3f2a9 Support iPhone 5 launch images
Sam Lantinga <slouken@libsdl.org>
parents: 6556
diff changeset
   107
    }
6556
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
   108
    self->splashLandscape = [UIImage imageNamed:@"Default-Landscape.png"];
6557
87ba88e3f2a9 Support iPhone 5 launch images
Sam Lantinga <slouken@libsdl.org>
parents: 6556
diff changeset
   109
    if (!self->splashLandscape && self->splashPortrait) {
6556
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
   110
        self->splashLandscape = [[UIImage alloc] initWithCGImage: self->splashPortrait.CGImage
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
   111
                                                           scale: 1.0
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
   112
                                                     orientation: UIImageOrientationRight];
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
   113
    }
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
   114
    if (self->splashPortrait) {
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
   115
        [self->splashPortrait retain];
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
   116
    }
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
   117
    if (self->splashLandscape) {
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
   118
        [self->splashLandscape retain];
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
   119
    }
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
   120
 
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
   121
    [self updateSplashImage:[[UIApplication sharedApplication] statusBarOrientation]];
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
   122
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
   123
    return self;
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
   124
}
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
   125
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
   126
- (NSUInteger)supportedInterfaceOrientations
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
   127
{
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
   128
    NSUInteger orientationMask = UIInterfaceOrientationMaskAll;
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
   129
    
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
   130
    // Don't allow upside-down orientation on the phone, so answering calls is in the natural orientation
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
   131
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
   132
        orientationMask &= ~UIInterfaceOrientationMaskPortraitUpsideDown;
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
   133
    }
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
   134
    return orientationMask;
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
   135
}
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
   136
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
   137
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orient
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
   138
{
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
   139
    NSUInteger orientationMask = [self supportedInterfaceOrientations];
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
   140
    return (orientationMask & (1 << orient));
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
   141
}
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
   142
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
   143
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
   144
{
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
   145
    [self updateSplashImage:interfaceOrientation];
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
   146
}
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
   147
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
   148
- (void)updateSplashImage:(UIInterfaceOrientation)interfaceOrientation
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
   149
{
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
   150
    UIImage *image;
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
   151
    
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
   152
    if (UIInterfaceOrientationIsLandscape(interfaceOrientation)) {
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
   153
        image = self->splashLandscape;
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
   154
    } else {
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
   155
        image = self->splashPortrait;
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
   156
    }
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
   157
    if (image)
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
   158
    {
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
   159
        splash.image = image;
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
   160
    }
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
   161
}
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
   162
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
   163
@end
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
   164
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
   165
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   166
@implementation SDLUIKitDelegate
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   167
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   168
/* convenience method */
6090
687400b595ab Make +sharedAppDelegate return a generic object instead of a SDLUIKitDelegate.
Ryan C. Gordon <icculus@icculus.org>
parents: 6044
diff changeset
   169
+ (id) sharedAppDelegate
6003
fddf81967e2d Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 6001
diff changeset
   170
{
5131
7b7da52e8775 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 4489
diff changeset
   171
    /* the delegate is set in UIApplicationMain(), which is garaunteed to be called before this method */
6090
687400b595ab Make +sharedAppDelegate return a generic object instead of a SDLUIKitDelegate.
Ryan C. Gordon <icculus@icculus.org>
parents: 6044
diff changeset
   172
    return [[UIApplication sharedApplication] delegate];
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   173
}
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   174
6003
fddf81967e2d Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 6001
diff changeset
   175
+ (NSString *)getAppDelegateClassName
fddf81967e2d Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 6001
diff changeset
   176
{
5532
8a04b596b472 Allow overriding the app delegate on iOS
Sam Lantinga <slouken@libsdl.org>
parents: 5487
diff changeset
   177
    /* subclassing notice: when you subclass this appdelegate, make sure to add a category to override
8a04b596b472 Allow overriding the app delegate on iOS
Sam Lantinga <slouken@libsdl.org>
parents: 5487
diff changeset
   178
       this method and return the actual name of the delegate */
8a04b596b472 Allow overriding the app delegate on iOS
Sam Lantinga <slouken@libsdl.org>
parents: 5487
diff changeset
   179
    return @"SDLUIKitDelegate";
8a04b596b472 Allow overriding the app delegate on iOS
Sam Lantinga <slouken@libsdl.org>
parents: 5487
diff changeset
   180
}
8a04b596b472 Allow overriding the app delegate on iOS
Sam Lantinga <slouken@libsdl.org>
parents: 5487
diff changeset
   181
6003
fddf81967e2d Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 6001
diff changeset
   182
- (id)init
fddf81967e2d Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 6001
diff changeset
   183
{
5131
7b7da52e8775 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 4489
diff changeset
   184
    self = [super init];
7b7da52e8775 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 4489
diff changeset
   185
    return self;
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   186
}
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   187
6003
fddf81967e2d Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 6001
diff changeset
   188
- (void)postFinishLaunch
fddf81967e2d Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 6001
diff changeset
   189
{
5131
7b7da52e8775 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 4489
diff changeset
   190
    /* run the user's application, passing argc and argv */
6346
56871d364efc Disable the SDL event pump after the SDL main routine returns, since events will be dispatched by the Cocoa event loop.
Sam Lantinga <slouken@libsdl.org>
parents: 6342
diff changeset
   191
    SDL_iPhoneSetEventPump(SDL_TRUE);
6006
889d89332de4 Do not exit in (uikit) postFinishLaunch but store the exit status and use that to return from main()
Kees Bakker <kees@ijzerbout.nl>
parents: 6003
diff changeset
   192
    exit_status = SDL_main(forward_argc, forward_argv);
6346
56871d364efc Disable the SDL event pump after the SDL main routine returns, since events will be dispatched by the Cocoa event loop.
Sam Lantinga <slouken@libsdl.org>
parents: 6342
diff changeset
   193
    SDL_iPhoneSetEventPump(SDL_FALSE);
6001
3ae3d1e58d59 Cleanup out trailing whitespace in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 5614
diff changeset
   194
6556
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
   195
    /* If we showed a splash image, clean it up */
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
   196
    if (launch_window) {
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
   197
        [launch_window release];
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
   198
        launch_window = NULL;
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
   199
    }
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
   200
5131
7b7da52e8775 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 4489
diff changeset
   201
    /* exit, passing the return status from the user's application */
6342
ac83b73f0edd Created a header file for system dependent API functions, and added SDL_iPhoneSetAnimationCallback()
Sam Lantinga <slouken@libsdl.org>
parents: 6321
diff changeset
   202
    // We don't actually exit to support applications that do setup in
ac83b73f0edd Created a header file for system dependent API functions, and added SDL_iPhoneSetAnimationCallback()
Sam Lantinga <slouken@libsdl.org>
parents: 6321
diff changeset
   203
    // their main function and then allow the Cocoa event loop to run.
6006
889d89332de4 Do not exit in (uikit) postFinishLaunch but store the exit status and use that to return from main()
Kees Bakker <kees@ijzerbout.nl>
parents: 6003
diff changeset
   204
    // exit(exit_status);
3422
ec4db979dddb Fixed bug #847
Sam Lantinga <slouken@libsdl.org>
parents: 3400
diff changeset
   205
}
ec4db979dddb Fixed bug #847
Sam Lantinga <slouken@libsdl.org>
parents: 3400
diff changeset
   206
6003
fddf81967e2d Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 6001
diff changeset
   207
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
fddf81967e2d Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 6001
diff changeset
   208
{
6556
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
   209
    /* Keep the launch image up until we set a video mode */
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
   210
    launch_window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
   211
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
   212
    UIViewController *splashViewController = [[SDL_splashviewcontroller alloc] init];
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
   213
    launch_window.rootViewController = splashViewController;
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
   214
    [launch_window addSubview:splashViewController.view];
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
   215
    [launch_window makeKeyAndVisible];
d5e854f0d9a9 Keep the launch image up until the application has created an OpenGL view
Sam Lantinga <slouken@libsdl.org>
parents: 6349
diff changeset
   216
5131
7b7da52e8775 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 4489
diff changeset
   217
    /* Set working directory to resource path */
7b7da52e8775 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 4489
diff changeset
   218
    [[NSFileManager defaultManager] changeCurrentDirectoryPath: [[NSBundle mainBundle] resourcePath]];
6001
3ae3d1e58d59 Cleanup out trailing whitespace in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 5614
diff changeset
   219
6349
bc8de0568373 Vittorio Giovara fixed bug 1528: move hint registration from SDLUikitAppDelegate
Sam Lantinga <slouken@libsdl.org>
parents: 6346
diff changeset
   220
    /* register a callback for the idletimer hint */
bc8de0568373 Vittorio Giovara fixed bug 1528: move hint registration from SDLUikitAppDelegate
Sam Lantinga <slouken@libsdl.org>
parents: 6346
diff changeset
   221
    SDL_SetHint(SDL_HINT_IDLE_TIMER_DISABLED, "0");
bc8de0568373 Vittorio Giovara fixed bug 1528: move hint registration from SDLUikitAppDelegate
Sam Lantinga <slouken@libsdl.org>
parents: 6346
diff changeset
   222
    SDL_RegisterHintChangedCb(SDL_HINT_IDLE_TIMER_DISABLED, &SDL_IdleTimerDisabledChanged);
bc8de0568373 Vittorio Giovara fixed bug 1528: move hint registration from SDLUikitAppDelegate
Sam Lantinga <slouken@libsdl.org>
parents: 6346
diff changeset
   223
5532
8a04b596b472 Allow overriding the app delegate on iOS
Sam Lantinga <slouken@libsdl.org>
parents: 5487
diff changeset
   224
    [self performSelector:@selector(postFinishLaunch) withObject:nil afterDelay:0.0];
5487
ad3abbbe0381 Delegate should use application: didFinishLaunchingWithOptions:
Sam Lantinga <slouken@libsdl.org>
parents: 5332
diff changeset
   225
ad3abbbe0381 Delegate should use application: didFinishLaunchingWithOptions:
Sam Lantinga <slouken@libsdl.org>
parents: 5332
diff changeset
   226
    return YES;
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   227
}
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   228
6003
fddf81967e2d Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 6001
diff changeset
   229
- (void)applicationWillTerminate:(UIApplication *)application
fddf81967e2d Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 6001
diff changeset
   230
{
5131
7b7da52e8775 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 4489
diff changeset
   231
    SDL_SendQuit();
7b7da52e8775 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 4489
diff changeset
   232
     /* hack to prevent automatic termination.  See SDL_uikitevents.m for details */
7b7da52e8775 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 4489
diff changeset
   233
    longjmp(*(jump_env()), 1);
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   234
}
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   235
3400
4ec48602f1db iPhone interruption patch / SDL 1.3
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   236
- (void) applicationWillResignActive:(UIApplication*)application
4ec48602f1db iPhone interruption patch / SDL 1.3
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   237
{
4446
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 3685
diff changeset
   238
    //NSLog(@"%@", NSStringFromSelector(_cmd));
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 3685
diff changeset
   239
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 3685
diff changeset
   240
    // Send every window on every screen a MINIMIZED event.
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 3685
diff changeset
   241
    SDL_VideoDevice *_this = SDL_GetVideoDevice();
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 3685
diff changeset
   242
    if (!_this) {
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 3685
diff changeset
   243
        return;
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 3685
diff changeset
   244
    }
6001
3ae3d1e58d59 Cleanup out trailing whitespace in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 5614
diff changeset
   245
5532
8a04b596b472 Allow overriding the app delegate on iOS
Sam Lantinga <slouken@libsdl.org>
parents: 5487
diff changeset
   246
    SDL_Window *window;
5251
1b0de3574c58 Fixed compile in Xcode
Sam Lantinga <slouken@libsdl.org>
parents: 5132
diff changeset
   247
    for (window = _this->windows; window != nil; window = window->next) {
6191
2c0d35b1af4e Made the application activity events consistent between iOS and Android
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   248
        SDL_SendWindowEvent(window, SDL_WINDOWEVENT_FOCUS_LOST, 0, 0);
5251
1b0de3574c58 Fixed compile in Xcode
Sam Lantinga <slouken@libsdl.org>
parents: 5132
diff changeset
   249
        SDL_SendWindowEvent(window, SDL_WINDOWEVENT_MINIMIZED, 0, 0);
4446
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 3685
diff changeset
   250
    }
3400
4ec48602f1db iPhone interruption patch / SDL 1.3
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   251
}
4ec48602f1db iPhone interruption patch / SDL 1.3
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   252
4ec48602f1db iPhone interruption patch / SDL 1.3
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   253
- (void) applicationDidBecomeActive:(UIApplication*)application
4ec48602f1db iPhone interruption patch / SDL 1.3
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   254
{
4446
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 3685
diff changeset
   255
    //NSLog(@"%@", NSStringFromSelector(_cmd));
3400
4ec48602f1db iPhone interruption patch / SDL 1.3
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   256
4446
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 3685
diff changeset
   257
    // Send every window on every screen a RESTORED event.
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 3685
diff changeset
   258
    SDL_VideoDevice *_this = SDL_GetVideoDevice();
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 3685
diff changeset
   259
    if (!_this) {
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 3685
diff changeset
   260
        return;
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 3685
diff changeset
   261
    }
6001
3ae3d1e58d59 Cleanup out trailing whitespace in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 5614
diff changeset
   262
5614
50bf98210aae Convert a few TABs into spaces
Kees Bakker <kees@tweeler.com>
parents: 5555
diff changeset
   263
    SDL_Window *window;
5251
1b0de3574c58 Fixed compile in Xcode
Sam Lantinga <slouken@libsdl.org>
parents: 5132
diff changeset
   264
    for (window = _this->windows; window != nil; window = window->next) {
6191
2c0d35b1af4e Made the application activity events consistent between iOS and Android
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   265
        SDL_SendWindowEvent(window, SDL_WINDOWEVENT_FOCUS_GAINED, 0, 0);
5614
50bf98210aae Convert a few TABs into spaces
Kees Bakker <kees@tweeler.com>
parents: 5555
diff changeset
   266
        SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESTORED, 0, 0);
4446
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 3685
diff changeset
   267
    }
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   268
}
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   269
6587
4ef7c70295c9 Implemented drop events in iOS
Sam Lantinga <slouken@libsdl.org>
parents: 6557
diff changeset
   270
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
4ef7c70295c9 Implemented drop events in iOS
Sam Lantinga <slouken@libsdl.org>
parents: 6557
diff changeset
   271
{
4ef7c70295c9 Implemented drop events in iOS
Sam Lantinga <slouken@libsdl.org>
parents: 6557
diff changeset
   272
    NSURL *fileURL = [url filePathURL];
4ef7c70295c9 Implemented drop events in iOS
Sam Lantinga <slouken@libsdl.org>
parents: 6557
diff changeset
   273
    if (fileURL != nil) {
4ef7c70295c9 Implemented drop events in iOS
Sam Lantinga <slouken@libsdl.org>
parents: 6557
diff changeset
   274
        SDL_SendDropFile([[fileURL path] UTF8String]);
4ef7c70295c9 Implemented drop events in iOS
Sam Lantinga <slouken@libsdl.org>
parents: 6557
diff changeset
   275
    } else {
4ef7c70295c9 Implemented drop events in iOS
Sam Lantinga <slouken@libsdl.org>
parents: 6557
diff changeset
   276
        SDL_SendDropFile([[url absoluteString] UTF8String]);
4ef7c70295c9 Implemented drop events in iOS
Sam Lantinga <slouken@libsdl.org>
parents: 6557
diff changeset
   277
    }
4ef7c70295c9 Implemented drop events in iOS
Sam Lantinga <slouken@libsdl.org>
parents: 6557
diff changeset
   278
    return YES;
4ef7c70295c9 Implemented drop events in iOS
Sam Lantinga <slouken@libsdl.org>
parents: 6557
diff changeset
   279
}
4ef7c70295c9 Implemented drop events in iOS
Sam Lantinga <slouken@libsdl.org>
parents: 6557
diff changeset
   280
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   281
@end
5132
5f09cb749d75 Added vim spacing hints
Sam Lantinga <slouken@libsdl.org>
parents: 5131
diff changeset
   282
6044
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 6006
diff changeset
   283
#endif /* SDL_VIDEO_DRIVER_UIKIT */
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 6006
diff changeset
   284
5132
5f09cb749d75 Added vim spacing hints
Sam Lantinga <slouken@libsdl.org>
parents: 5131
diff changeset
   285
/* vi: set ts=4 sw=4 expandtab: */