src/video/uikit/SDL_uikitviewcontroller.m
author Sam Lantinga <slouken@libsdl.org>
Sun, 23 Sep 2012 17:15:05 -0700
changeset 6453 f71e3fdba072
parent 6452 1895319021e4
child 6518 42948831d16e
permissions -rwxr-xr-x
Fixed syntax error
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5640
04b5b11985c8 Split off SDL_uikitviewcontroller in its own module
Kees Bakker <kees@tweeler.com>
parents:
diff changeset
     1
/*
6044
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 6011
diff changeset
     2
  Simple DirectMedia Layer
6138
4c64952a58fb Happy New Year!
Sam Lantinga <slouken@libsdl.org>
parents: 6093
diff changeset
     3
  Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org>
6001
3ae3d1e58d59 Cleanup out trailing whitespace in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 5640
diff changeset
     4
6044
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 6011
diff changeset
     5
  This software is provided 'as-is', without any express or implied
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 6011
diff changeset
     6
  warranty.  In no event will the authors be held liable for any damages
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 6011
diff changeset
     7
  arising from the use of this software.
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 6011
diff changeset
     8
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 6011
diff changeset
     9
  Permission is granted to anyone to use this software for any purpose,
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 6011
diff changeset
    10
  including commercial applications, and to alter it and redistribute it
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 6011
diff changeset
    11
  freely, subject to the following restrictions:
6001
3ae3d1e58d59 Cleanup out trailing whitespace in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 5640
diff changeset
    12
6044
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 6011
diff changeset
    13
  1. The origin of this software must not be misrepresented; you must not
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 6011
diff changeset
    14
     claim that you wrote the original software. If you use this software
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 6011
diff changeset
    15
     in a product, an acknowledgment in the product documentation would be
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 6011
diff changeset
    16
     appreciated but is not required.
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 6011
diff changeset
    17
  2. Altered source versions must be plainly marked as such, and must not be
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 6011
diff changeset
    18
     misrepresented as being the original software.
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 6011
diff changeset
    19
  3. This notice may not be removed or altered from any source distribution.
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 6011
diff changeset
    20
*/
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 6011
diff changeset
    21
#include "SDL_config.h"
6001
3ae3d1e58d59 Cleanup out trailing whitespace in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 5640
diff changeset
    22
6044
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 6011
diff changeset
    23
#if SDL_VIDEO_DRIVER_UIKIT
5640
04b5b11985c8 Split off SDL_uikitviewcontroller in its own module
Kees Bakker <kees@tweeler.com>
parents:
diff changeset
    24
04b5b11985c8 Split off SDL_uikitviewcontroller in its own module
Kees Bakker <kees@tweeler.com>
parents:
diff changeset
    25
#include "SDL_video.h"
04b5b11985c8 Split off SDL_uikitviewcontroller in its own module
Kees Bakker <kees@tweeler.com>
parents:
diff changeset
    26
#include "SDL_assert.h"
04b5b11985c8 Split off SDL_uikitviewcontroller in its own module
Kees Bakker <kees@tweeler.com>
parents:
diff changeset
    27
#include "SDL_hints.h"
04b5b11985c8 Split off SDL_uikitviewcontroller in its own module
Kees Bakker <kees@tweeler.com>
parents:
diff changeset
    28
#include "../SDL_sysvideo.h"
04b5b11985c8 Split off SDL_uikitviewcontroller in its own module
Kees Bakker <kees@tweeler.com>
parents:
diff changeset
    29
#include "../../events/SDL_events_c.h"
04b5b11985c8 Split off SDL_uikitviewcontroller in its own module
Kees Bakker <kees@tweeler.com>
parents:
diff changeset
    30
04b5b11985c8 Split off SDL_uikitviewcontroller in its own module
Kees Bakker <kees@tweeler.com>
parents:
diff changeset
    31
#include "SDL_uikitwindow.h"
6093
a8696b259e09 Another iOS 3.1 compatibility fix.
Ryan C. Gordon <icculus@icculus.org>
parents: 6079
diff changeset
    32
#include "SDL_uikitviewcontroller.h"
a8696b259e09 Another iOS 3.1 compatibility fix.
Ryan C. Gordon <icculus@icculus.org>
parents: 6079
diff changeset
    33
#include "SDL_uikitvideo.h"
5640
04b5b11985c8 Split off SDL_uikitviewcontroller in its own module
Kees Bakker <kees@tweeler.com>
parents:
diff changeset
    34
6452
1895319021e4 Added UIInterfaceOrientationMask for building with older iOS SDKs
Sam Lantinga <slouken@libsdl.org>
parents: 6451
diff changeset
    35
#ifndef __IPHONE_6_0
1895319021e4 Added UIInterfaceOrientationMask for building with older iOS SDKs
Sam Lantinga <slouken@libsdl.org>
parents: 6451
diff changeset
    36
// This enum isn't available in older SDKs, but we use it for our own purposes on iOS 5.1 and for the system on iOS 6.0
6453
f71e3fdba072 Fixed syntax error
Sam Lantinga <slouken@libsdl.org>
parents: 6452
diff changeset
    37
enum UIInterfaceOrientationMask
f71e3fdba072 Fixed syntax error
Sam Lantinga <slouken@libsdl.org>
parents: 6452
diff changeset
    38
{
6452
1895319021e4 Added UIInterfaceOrientationMask for building with older iOS SDKs
Sam Lantinga <slouken@libsdl.org>
parents: 6451
diff changeset
    39
    UIInterfaceOrientationMaskPortrait = (1 << UIInterfaceOrientationPortrait),
1895319021e4 Added UIInterfaceOrientationMask for building with older iOS SDKs
Sam Lantinga <slouken@libsdl.org>
parents: 6451
diff changeset
    40
    UIInterfaceOrientationMaskLandscapeLeft = (1 << UIInterfaceOrientationLandscapeLeft),
1895319021e4 Added UIInterfaceOrientationMask for building with older iOS SDKs
Sam Lantinga <slouken@libsdl.org>
parents: 6451
diff changeset
    41
    UIInterfaceOrientationMaskLandscapeRight = (1 << UIInterfaceOrientationLandscapeRight),
1895319021e4 Added UIInterfaceOrientationMask for building with older iOS SDKs
Sam Lantinga <slouken@libsdl.org>
parents: 6451
diff changeset
    42
    UIInterfaceOrientationMaskPortraitUpsideDown = (1 << UIInterfaceOrientationPortraitUpsideDown),
1895319021e4 Added UIInterfaceOrientationMask for building with older iOS SDKs
Sam Lantinga <slouken@libsdl.org>
parents: 6451
diff changeset
    43
    UIInterfaceOrientationMaskLandscape = (UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight),
1895319021e4 Added UIInterfaceOrientationMask for building with older iOS SDKs
Sam Lantinga <slouken@libsdl.org>
parents: 6451
diff changeset
    44
    UIInterfaceOrientationMaskAll = (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskPortraitUpsideDown),
1895319021e4 Added UIInterfaceOrientationMask for building with older iOS SDKs
Sam Lantinga <slouken@libsdl.org>
parents: 6451
diff changeset
    45
    UIInterfaceOrientationMaskAllButUpsideDown = (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight),
1895319021e4 Added UIInterfaceOrientationMask for building with older iOS SDKs
Sam Lantinga <slouken@libsdl.org>
parents: 6451
diff changeset
    46
};
1895319021e4 Added UIInterfaceOrientationMask for building with older iOS SDKs
Sam Lantinga <slouken@libsdl.org>
parents: 6451
diff changeset
    47
#endif // !__IPHONE_6_0
1895319021e4 Added UIInterfaceOrientationMask for building with older iOS SDKs
Sam Lantinga <slouken@libsdl.org>
parents: 6451
diff changeset
    48
1895319021e4 Added UIInterfaceOrientationMask for building with older iOS SDKs
Sam Lantinga <slouken@libsdl.org>
parents: 6451
diff changeset
    49
    
5640
04b5b11985c8 Split off SDL_uikitviewcontroller in its own module
Kees Bakker <kees@tweeler.com>
parents:
diff changeset
    50
@implementation SDL_uikitviewcontroller
04b5b11985c8 Split off SDL_uikitviewcontroller in its own module
Kees Bakker <kees@tweeler.com>
parents:
diff changeset
    51
6011
83a21d3bd5c1 Make SDL_uikitviewcontroller.window a real Objective-C property and synthesize
Kees Bakker <kees@ijzerbout.nl>
parents: 6003
diff changeset
    52
@synthesize window;
83a21d3bd5c1 Make SDL_uikitviewcontroller.window a real Objective-C property and synthesize
Kees Bakker <kees@ijzerbout.nl>
parents: 6003
diff changeset
    53
6003
fddf81967e2d Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 6001
diff changeset
    54
- (id)initWithSDLWindow:(SDL_Window *)_window
fddf81967e2d Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 6001
diff changeset
    55
{
6011
83a21d3bd5c1 Make SDL_uikitviewcontroller.window a real Objective-C property and synthesize
Kees Bakker <kees@ijzerbout.nl>
parents: 6003
diff changeset
    56
    self = [self init];
83a21d3bd5c1 Make SDL_uikitviewcontroller.window a real Objective-C property and synthesize
Kees Bakker <kees@ijzerbout.nl>
parents: 6003
diff changeset
    57
    if (self == nil) {
5640
04b5b11985c8 Split off SDL_uikitviewcontroller in its own module
Kees Bakker <kees@tweeler.com>
parents:
diff changeset
    58
        return nil;
04b5b11985c8 Split off SDL_uikitviewcontroller in its own module
Kees Bakker <kees@tweeler.com>
parents:
diff changeset
    59
    }
6011
83a21d3bd5c1 Make SDL_uikitviewcontroller.window a real Objective-C property and synthesize
Kees Bakker <kees@ijzerbout.nl>
parents: 6003
diff changeset
    60
    self.window = _window;
6440
f0ca76958984 Generate resize event when the status bar changes size (e.g. call in progress, etc.)
Sam Lantinga <slouken@libsdl.org>
parents: 6438
diff changeset
    61
5640
04b5b11985c8 Split off SDL_uikitviewcontroller in its own module
Kees Bakker <kees@tweeler.com>
parents:
diff changeset
    62
    return self;
04b5b11985c8 Split off SDL_uikitviewcontroller in its own module
Kees Bakker <kees@tweeler.com>
parents:
diff changeset
    63
}
04b5b11985c8 Split off SDL_uikitviewcontroller in its own module
Kees Bakker <kees@tweeler.com>
parents:
diff changeset
    64
6440
f0ca76958984 Generate resize event when the status bar changes size (e.g. call in progress, etc.)
Sam Lantinga <slouken@libsdl.org>
parents: 6438
diff changeset
    65
- (void)loadView
f0ca76958984 Generate resize event when the status bar changes size (e.g. call in progress, etc.)
Sam Lantinga <slouken@libsdl.org>
parents: 6438
diff changeset
    66
{
f0ca76958984 Generate resize event when the status bar changes size (e.g. call in progress, etc.)
Sam Lantinga <slouken@libsdl.org>
parents: 6438
diff changeset
    67
    // do nothing.
f0ca76958984 Generate resize event when the status bar changes size (e.g. call in progress, etc.)
Sam Lantinga <slouken@libsdl.org>
parents: 6438
diff changeset
    68
}
f0ca76958984 Generate resize event when the status bar changes size (e.g. call in progress, etc.)
Sam Lantinga <slouken@libsdl.org>
parents: 6438
diff changeset
    69
6451
52e5a05ca795 Fixed autorotate / resize support on iOS 6.0, tested with iPad and iPhone simulators with iOS 5.1 and 6.0
Sam Lantinga <slouken@libsdl.org>
parents: 6440
diff changeset
    70
- (void)viewDidLayoutSubviews
6440
f0ca76958984 Generate resize event when the status bar changes size (e.g. call in progress, etc.)
Sam Lantinga <slouken@libsdl.org>
parents: 6438
diff changeset
    71
{
f0ca76958984 Generate resize event when the status bar changes size (e.g. call in progress, etc.)
Sam Lantinga <slouken@libsdl.org>
parents: 6438
diff changeset
    72
    if (self->window->flags & SDL_WINDOW_RESIZABLE) {
f0ca76958984 Generate resize event when the status bar changes size (e.g. call in progress, etc.)
Sam Lantinga <slouken@libsdl.org>
parents: 6438
diff changeset
    73
        SDL_WindowData *data = self->window->driverdata;
f0ca76958984 Generate resize event when the status bar changes size (e.g. call in progress, etc.)
Sam Lantinga <slouken@libsdl.org>
parents: 6438
diff changeset
    74
        SDL_VideoDisplay *display = SDL_GetDisplayForWindow(self->window);
f0ca76958984 Generate resize event when the status bar changes size (e.g. call in progress, etc.)
Sam Lantinga <slouken@libsdl.org>
parents: 6438
diff changeset
    75
        SDL_DisplayModeData *displaymodedata = (SDL_DisplayModeData *) display->current_mode.driverdata;
f0ca76958984 Generate resize event when the status bar changes size (e.g. call in progress, etc.)
Sam Lantinga <slouken@libsdl.org>
parents: 6438
diff changeset
    76
        const CGSize size = data->view.bounds.size;
f0ca76958984 Generate resize event when the status bar changes size (e.g. call in progress, etc.)
Sam Lantinga <slouken@libsdl.org>
parents: 6438
diff changeset
    77
        int w, h;
6451
52e5a05ca795 Fixed autorotate / resize support on iOS 6.0, tested with iPad and iPhone simulators with iOS 5.1 and 6.0
Sam Lantinga <slouken@libsdl.org>
parents: 6440
diff changeset
    78
        
6440
f0ca76958984 Generate resize event when the status bar changes size (e.g. call in progress, etc.)
Sam Lantinga <slouken@libsdl.org>
parents: 6438
diff changeset
    79
        w = (int)(size.width * displaymodedata->scale);
f0ca76958984 Generate resize event when the status bar changes size (e.g. call in progress, etc.)
Sam Lantinga <slouken@libsdl.org>
parents: 6438
diff changeset
    80
        h = (int)(size.height * displaymodedata->scale);
6451
52e5a05ca795 Fixed autorotate / resize support on iOS 6.0, tested with iPad and iPhone simulators with iOS 5.1 and 6.0
Sam Lantinga <slouken@libsdl.org>
parents: 6440
diff changeset
    81
        
6440
f0ca76958984 Generate resize event when the status bar changes size (e.g. call in progress, etc.)
Sam Lantinga <slouken@libsdl.org>
parents: 6438
diff changeset
    82
        SDL_SendWindowEvent(self->window, SDL_WINDOWEVENT_RESIZED, w, h);
f0ca76958984 Generate resize event when the status bar changes size (e.g. call in progress, etc.)
Sam Lantinga <slouken@libsdl.org>
parents: 6438
diff changeset
    83
    }
f0ca76958984 Generate resize event when the status bar changes size (e.g. call in progress, etc.)
Sam Lantinga <slouken@libsdl.org>
parents: 6438
diff changeset
    84
}
f0ca76958984 Generate resize event when the status bar changes size (e.g. call in progress, etc.)
Sam Lantinga <slouken@libsdl.org>
parents: 6438
diff changeset
    85
6451
52e5a05ca795 Fixed autorotate / resize support on iOS 6.0, tested with iPad and iPhone simulators with iOS 5.1 and 6.0
Sam Lantinga <slouken@libsdl.org>
parents: 6440
diff changeset
    86
- (NSUInteger)supportedInterfaceOrientations
6003
fddf81967e2d Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 6001
diff changeset
    87
{
6451
52e5a05ca795 Fixed autorotate / resize support on iOS 6.0, tested with iPad and iPhone simulators with iOS 5.1 and 6.0
Sam Lantinga <slouken@libsdl.org>
parents: 6440
diff changeset
    88
    NSUInteger orientationMask = 0;
52e5a05ca795 Fixed autorotate / resize support on iOS 6.0, tested with iPad and iPhone simulators with iOS 5.1 and 6.0
Sam Lantinga <slouken@libsdl.org>
parents: 6440
diff changeset
    89
    
5640
04b5b11985c8 Split off SDL_uikitviewcontroller in its own module
Kees Bakker <kees@tweeler.com>
parents:
diff changeset
    90
    const char *orientationsCString;
04b5b11985c8 Split off SDL_uikitviewcontroller in its own module
Kees Bakker <kees@tweeler.com>
parents:
diff changeset
    91
    if ((orientationsCString = SDL_GetHint(SDL_HINT_ORIENTATIONS)) != NULL) {
04b5b11985c8 Split off SDL_uikitviewcontroller in its own module
Kees Bakker <kees@tweeler.com>
parents:
diff changeset
    92
        BOOL rotate = NO;
04b5b11985c8 Split off SDL_uikitviewcontroller in its own module
Kees Bakker <kees@tweeler.com>
parents:
diff changeset
    93
        NSString *orientationsNSString = [NSString stringWithCString:orientationsCString
04b5b11985c8 Split off SDL_uikitviewcontroller in its own module
Kees Bakker <kees@tweeler.com>
parents:
diff changeset
    94
                                                            encoding:NSUTF8StringEncoding];
04b5b11985c8 Split off SDL_uikitviewcontroller in its own module
Kees Bakker <kees@tweeler.com>
parents:
diff changeset
    95
        NSArray *orientations = [orientationsNSString componentsSeparatedByCharactersInSet:
04b5b11985c8 Split off SDL_uikitviewcontroller in its own module
Kees Bakker <kees@tweeler.com>
parents:
diff changeset
    96
                                 [NSCharacterSet characterSetWithCharactersInString:@" "]];
6451
52e5a05ca795 Fixed autorotate / resize support on iOS 6.0, tested with iPad and iPhone simulators with iOS 5.1 and 6.0
Sam Lantinga <slouken@libsdl.org>
parents: 6440
diff changeset
    97
        
52e5a05ca795 Fixed autorotate / resize support on iOS 6.0, tested with iPad and iPhone simulators with iOS 5.1 and 6.0
Sam Lantinga <slouken@libsdl.org>
parents: 6440
diff changeset
    98
        if ([orientations containsObject:@"LandscapeLeft"]) {
52e5a05ca795 Fixed autorotate / resize support on iOS 6.0, tested with iPad and iPhone simulators with iOS 5.1 and 6.0
Sam Lantinga <slouken@libsdl.org>
parents: 6440
diff changeset
    99
            orientationMask |= UIInterfaceOrientationMaskLandscapeLeft;
52e5a05ca795 Fixed autorotate / resize support on iOS 6.0, tested with iPad and iPhone simulators with iOS 5.1 and 6.0
Sam Lantinga <slouken@libsdl.org>
parents: 6440
diff changeset
   100
        }
52e5a05ca795 Fixed autorotate / resize support on iOS 6.0, tested with iPad and iPhone simulators with iOS 5.1 and 6.0
Sam Lantinga <slouken@libsdl.org>
parents: 6440
diff changeset
   101
        if ([orientations containsObject:@"LandscapeRight"]) {
52e5a05ca795 Fixed autorotate / resize support on iOS 6.0, tested with iPad and iPhone simulators with iOS 5.1 and 6.0
Sam Lantinga <slouken@libsdl.org>
parents: 6440
diff changeset
   102
            orientationMask |= UIInterfaceOrientationMaskLandscapeRight;
52e5a05ca795 Fixed autorotate / resize support on iOS 6.0, tested with iPad and iPhone simulators with iOS 5.1 and 6.0
Sam Lantinga <slouken@libsdl.org>
parents: 6440
diff changeset
   103
        }
52e5a05ca795 Fixed autorotate / resize support on iOS 6.0, tested with iPad and iPhone simulators with iOS 5.1 and 6.0
Sam Lantinga <slouken@libsdl.org>
parents: 6440
diff changeset
   104
        if ([orientations containsObject:@"Portrait"]) {
52e5a05ca795 Fixed autorotate / resize support on iOS 6.0, tested with iPad and iPhone simulators with iOS 5.1 and 6.0
Sam Lantinga <slouken@libsdl.org>
parents: 6440
diff changeset
   105
            orientationMask |= UIInterfaceOrientationMaskPortrait;
5640
04b5b11985c8 Split off SDL_uikitviewcontroller in its own module
Kees Bakker <kees@tweeler.com>
parents:
diff changeset
   106
        }
6451
52e5a05ca795 Fixed autorotate / resize support on iOS 6.0, tested with iPad and iPhone simulators with iOS 5.1 and 6.0
Sam Lantinga <slouken@libsdl.org>
parents: 6440
diff changeset
   107
        if ([orientations containsObject:@"PortraitUpsideDown"]) {
52e5a05ca795 Fixed autorotate / resize support on iOS 6.0, tested with iPad and iPhone simulators with iOS 5.1 and 6.0
Sam Lantinga <slouken@libsdl.org>
parents: 6440
diff changeset
   108
            orientationMask |= UIInterfaceOrientationMaskPortraitUpsideDown;
52e5a05ca795 Fixed autorotate / resize support on iOS 6.0, tested with iPad and iPhone simulators with iOS 5.1 and 6.0
Sam Lantinga <slouken@libsdl.org>
parents: 6440
diff changeset
   109
        }
52e5a05ca795 Fixed autorotate / resize support on iOS 6.0, tested with iPad and iPhone simulators with iOS 5.1 and 6.0
Sam Lantinga <slouken@libsdl.org>
parents: 6440
diff changeset
   110
        
52e5a05ca795 Fixed autorotate / resize support on iOS 6.0, tested with iPad and iPhone simulators with iOS 5.1 and 6.0
Sam Lantinga <slouken@libsdl.org>
parents: 6440
diff changeset
   111
    } else if (self->window->flags & SDL_WINDOW_RESIZABLE) {
52e5a05ca795 Fixed autorotate / resize support on iOS 6.0, tested with iPad and iPhone simulators with iOS 5.1 and 6.0
Sam Lantinga <slouken@libsdl.org>
parents: 6440
diff changeset
   112
        orientationMask = UIInterfaceOrientationMaskAll;  // any orientation is okay.
52e5a05ca795 Fixed autorotate / resize support on iOS 6.0, tested with iPad and iPhone simulators with iOS 5.1 and 6.0
Sam Lantinga <slouken@libsdl.org>
parents: 6440
diff changeset
   113
    } else {
52e5a05ca795 Fixed autorotate / resize support on iOS 6.0, tested with iPad and iPhone simulators with iOS 5.1 and 6.0
Sam Lantinga <slouken@libsdl.org>
parents: 6440
diff changeset
   114
        if (self->window->w >= self->window->h) {
52e5a05ca795 Fixed autorotate / resize support on iOS 6.0, tested with iPad and iPhone simulators with iOS 5.1 and 6.0
Sam Lantinga <slouken@libsdl.org>
parents: 6440
diff changeset
   115
            orientationMask |= UIInterfaceOrientationMaskLandscape;
52e5a05ca795 Fixed autorotate / resize support on iOS 6.0, tested with iPad and iPhone simulators with iOS 5.1 and 6.0
Sam Lantinga <slouken@libsdl.org>
parents: 6440
diff changeset
   116
        }
52e5a05ca795 Fixed autorotate / resize support on iOS 6.0, tested with iPad and iPhone simulators with iOS 5.1 and 6.0
Sam Lantinga <slouken@libsdl.org>
parents: 6440
diff changeset
   117
        if (self->window->h >= self->window->w) {
52e5a05ca795 Fixed autorotate / resize support on iOS 6.0, tested with iPad and iPhone simulators with iOS 5.1 and 6.0
Sam Lantinga <slouken@libsdl.org>
parents: 6440
diff changeset
   118
            orientationMask |= (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown);
52e5a05ca795 Fixed autorotate / resize support on iOS 6.0, tested with iPad and iPhone simulators with iOS 5.1 and 6.0
Sam Lantinga <slouken@libsdl.org>
parents: 6440
diff changeset
   119
        }
5640
04b5b11985c8 Split off SDL_uikitviewcontroller in its own module
Kees Bakker <kees@tweeler.com>
parents:
diff changeset
   120
    }
6451
52e5a05ca795 Fixed autorotate / resize support on iOS 6.0, tested with iPad and iPhone simulators with iOS 5.1 and 6.0
Sam Lantinga <slouken@libsdl.org>
parents: 6440
diff changeset
   121
    
52e5a05ca795 Fixed autorotate / resize support on iOS 6.0, tested with iPad and iPhone simulators with iOS 5.1 and 6.0
Sam Lantinga <slouken@libsdl.org>
parents: 6440
diff changeset
   122
    // Don't allow upside-down orientation on the phone, so answering calls is in the natural orientation
52e5a05ca795 Fixed autorotate / resize support on iOS 6.0, tested with iPad and iPhone simulators with iOS 5.1 and 6.0
Sam Lantinga <slouken@libsdl.org>
parents: 6440
diff changeset
   123
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
52e5a05ca795 Fixed autorotate / resize support on iOS 6.0, tested with iPad and iPhone simulators with iOS 5.1 and 6.0
Sam Lantinga <slouken@libsdl.org>
parents: 6440
diff changeset
   124
        orientationMask &= ~UIInterfaceOrientationMaskPortraitUpsideDown;
5640
04b5b11985c8 Split off SDL_uikitviewcontroller in its own module
Kees Bakker <kees@tweeler.com>
parents:
diff changeset
   125
    }
6451
52e5a05ca795 Fixed autorotate / resize support on iOS 6.0, tested with iPad and iPhone simulators with iOS 5.1 and 6.0
Sam Lantinga <slouken@libsdl.org>
parents: 6440
diff changeset
   126
    return orientationMask;
5640
04b5b11985c8 Split off SDL_uikitviewcontroller in its own module
Kees Bakker <kees@tweeler.com>
parents:
diff changeset
   127
}
04b5b11985c8 Split off SDL_uikitviewcontroller in its own module
Kees Bakker <kees@tweeler.com>
parents:
diff changeset
   128
6451
52e5a05ca795 Fixed autorotate / resize support on iOS 6.0, tested with iPad and iPhone simulators with iOS 5.1 and 6.0
Sam Lantinga <slouken@libsdl.org>
parents: 6440
diff changeset
   129
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orient
6003
fddf81967e2d Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 6001
diff changeset
   130
{
6451
52e5a05ca795 Fixed autorotate / resize support on iOS 6.0, tested with iPad and iPhone simulators with iOS 5.1 and 6.0
Sam Lantinga <slouken@libsdl.org>
parents: 6440
diff changeset
   131
    NSUInteger orientationMask = [self supportedInterfaceOrientations];
52e5a05ca795 Fixed autorotate / resize support on iOS 6.0, tested with iPad and iPhone simulators with iOS 5.1 and 6.0
Sam Lantinga <slouken@libsdl.org>
parents: 6440
diff changeset
   132
    return (orientationMask & (1 << orient));
5640
04b5b11985c8 Split off SDL_uikitviewcontroller in its own module
Kees Bakker <kees@tweeler.com>
parents:
diff changeset
   133
}
04b5b11985c8 Split off SDL_uikitviewcontroller in its own module
Kees Bakker <kees@tweeler.com>
parents:
diff changeset
   134
6451
52e5a05ca795 Fixed autorotate / resize support on iOS 6.0, tested with iPad and iPhone simulators with iOS 5.1 and 6.0
Sam Lantinga <slouken@libsdl.org>
parents: 6440
diff changeset
   135
@end
52e5a05ca795 Fixed autorotate / resize support on iOS 6.0, tested with iPad and iPhone simulators with iOS 5.1 and 6.0
Sam Lantinga <slouken@libsdl.org>
parents: 6440
diff changeset
   136
6044
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 6011
diff changeset
   137
#endif /* SDL_VIDEO_DRIVER_UIKIT */
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 6011
diff changeset
   138
6440
f0ca76958984 Generate resize event when the status bar changes size (e.g. call in progress, etc.)
Sam Lantinga <slouken@libsdl.org>
parents: 6438
diff changeset
   139
/* vi: set ts=4 sw=4 expandtab: */