src/video/uikit/SDL_uikitwindow.m
author Alex Szpakowski <slime73@gmail.com>
Sun, 23 Nov 2014 23:29:24 -0400
branchiOS-improvements
changeset 9528 6915f7db6791
parent 9523 9cbd69cac7ed
child 9529 4bf9830d8153
permissions -rw-r--r--
Removed an ugly hack to make windows rotate properly on iOS 8+. Recent commits apparently resolved the issue that made the hack necessary.
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: 5529
diff changeset
     2
  Simple DirectMedia Layer
8149
681eb46b8ac4 Fixed bug 2374 - Update copyright for 2014...
Sam Lantinga <slouken@libsdl.org>
parents: 8093
diff changeset
     3
  Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     4
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5529
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: 5529
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: 5529
diff changeset
     7
  arising from the use of this software.
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     8
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5529
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: 5529
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: 5529
diff changeset
    11
  freely, subject to the following restrictions:
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    12
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5529
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: 5529
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: 5529
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: 5529
diff changeset
    16
     appreciated but is not required.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5529
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: 5529
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: 5529
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
*/
8093
b43765095a6f Make internal SDL sources include SDL_internal.h instead of SDL_config.h
Ryan C. Gordon <icculus@icculus.org>
parents: 7862
diff changeset
    21
#include "../../SDL_internal.h"
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    22
6044
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 6014
diff changeset
    23
#if SDL_VIDEO_DRIVER_UIKIT
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 6014
diff changeset
    24
5056
8b7988f42fcb Added the ability to get the UIKit window through the SDL API.
Sam Lantinga <slouken@libsdl.org>
parents: 4446
diff changeset
    25
#include "SDL_syswm.h"
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    26
#include "SDL_video.h"
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    27
#include "SDL_mouse.h"
4446
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 3685
diff changeset
    28
#include "SDL_assert.h"
5554
4b4258be8699 * SDL_IOS_ORIENTATIONS hint
Tim Angus <tim@blackcompanystudios.co.uk>
parents: 5535
diff changeset
    29
#include "SDL_hints.h"
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    30
#include "../SDL_sysvideo.h"
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    31
#include "../SDL_pixels_c.h"
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    32
#include "../../events/SDL_events_c.h"
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    33
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    34
#include "SDL_uikitvideo.h"
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    35
#include "SDL_uikitevents.h"
6518
42948831d16e Refactored the UIKit mode code into a separate file so it's cleaner and more consistent with other backends
Sam Lantinga <slouken@libsdl.org>
parents: 6511
diff changeset
    36
#include "SDL_uikitmodes.h"
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    37
#include "SDL_uikitwindow.h"
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    38
#import "SDL_uikitappdelegate.h"
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
#import "SDL_uikitopenglview.h"
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    41
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    42
#include <Foundation/Foundation.h>
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    43
9510
e19faa3b5d88 Updated the iOS backend code to use Objective-C's automatic reference counting (ARC).
Alex Szpakowski <slime73@gmail.com>
parents: 9506
diff changeset
    44
@implementation SDL_WindowData
e19faa3b5d88 Updated the iOS backend code to use Objective-C's automatic reference counting (ARC).
Alex Szpakowski <slime73@gmail.com>
parents: 9506
diff changeset
    45
e19faa3b5d88 Updated the iOS backend code to use Objective-C's automatic reference counting (ARC).
Alex Szpakowski <slime73@gmail.com>
parents: 9506
diff changeset
    46
@synthesize uiwindow;
e19faa3b5d88 Updated the iOS backend code to use Objective-C's automatic reference counting (ARC).
Alex Szpakowski <slime73@gmail.com>
parents: 9506
diff changeset
    47
@synthesize view;
e19faa3b5d88 Updated the iOS backend code to use Objective-C's automatic reference counting (ARC).
Alex Szpakowski <slime73@gmail.com>
parents: 9506
diff changeset
    48
@synthesize viewcontroller;
e19faa3b5d88 Updated the iOS backend code to use Objective-C's automatic reference counting (ARC).
Alex Szpakowski <slime73@gmail.com>
parents: 9506
diff changeset
    49
e19faa3b5d88 Updated the iOS backend code to use Objective-C's automatic reference counting (ARC).
Alex Szpakowski <slime73@gmail.com>
parents: 9506
diff changeset
    50
@end
e19faa3b5d88 Updated the iOS backend code to use Objective-C's automatic reference counting (ARC).
Alex Szpakowski <slime73@gmail.com>
parents: 9506
diff changeset
    51
9505
6fc615dfc93f Added support for SDL_SetWindowBordered on iOS. Worked around a bug with rotating the device on iOS 8.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
    52
9528
6915f7db6791 Removed an ugly hack to make windows rotate properly on iOS 8+.
Alex Szpakowski <slime73@gmail.com>
parents: 9523
diff changeset
    53
static int SetupWindowData(_THIS, SDL_Window *window, UIWindow *uiwindow, SDL_bool created)
4446
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 3685
diff changeset
    54
{
5246
58265e606e4e Window coordinates are in the global space and windows are not tied to a particular display.
Sam Lantinga <slouken@libsdl.org>
parents: 5154
diff changeset
    55
    SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
9510
e19faa3b5d88 Updated the iOS backend code to use Objective-C's automatic reference counting (ARC).
Alex Szpakowski <slime73@gmail.com>
parents: 9506
diff changeset
    56
    SDL_DisplayData *displaydata = (__bridge SDL_DisplayData *) display->driverdata;
6001
3ae3d1e58d59 Cleanup out trailing whitespace in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 5640
diff changeset
    57
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    58
    /* Allocate the window data */
9510
e19faa3b5d88 Updated the iOS backend code to use Objective-C's automatic reference counting (ARC).
Alex Szpakowski <slime73@gmail.com>
parents: 9506
diff changeset
    59
    SDL_WindowData *data = [[SDL_WindowData alloc] init];
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    60
    if (!data) {
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6885
diff changeset
    61
        return SDL_OutOfMemory();
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    62
    }
9510
e19faa3b5d88 Updated the iOS backend code to use Objective-C's automatic reference counting (ARC).
Alex Szpakowski <slime73@gmail.com>
parents: 9506
diff changeset
    63
e19faa3b5d88 Updated the iOS backend code to use Objective-C's automatic reference counting (ARC).
Alex Szpakowski <slime73@gmail.com>
parents: 9506
diff changeset
    64
    data.uiwindow = uiwindow;
3685
64ce267332c6 Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents: 3400
diff changeset
    65
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    66
    /* Fill in the SDL window with the window data */
3685
64ce267332c6 Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents: 3400
diff changeset
    67
    {
9510
e19faa3b5d88 Updated the iOS backend code to use Objective-C's automatic reference counting (ARC).
Alex Szpakowski <slime73@gmail.com>
parents: 9506
diff changeset
    68
        CGRect frame = UIKit_ComputeViewFrame(window, displaydata.uiscreen);
6437
3e52c17e2a07 Fixed window/view bounds management with autorotation.
Sam Lantinga <slouken@libsdl.org>
parents: 6419
diff changeset
    69
9488
f15520430c94 Changed the way retina resolutions are handled in iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 8978
diff changeset
    70
        /* Get frame dimensions */
9502
933ed557b7c1 Fixed SDL_SetWindowFullscreen on iOS for the last time, hopefully.
Alex Szpakowski <slime73@gmail.com>
parents: 9501
diff changeset
    71
        int width = (int) frame.size.width;
933ed557b7c1 Fixed SDL_SetWindowFullscreen on iOS for the last time, hopefully.
Alex Szpakowski <slime73@gmail.com>
parents: 9501
diff changeset
    72
        int height = (int) frame.size.height;
6520
7a7726af31c1 Make sure mode width/height and status bar orientation match
Sam Lantinga <slouken@libsdl.org>
parents: 6518
diff changeset
    73
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7159
diff changeset
    74
        /* Make sure the width/height are oriented correctly */
9510
e19faa3b5d88 Updated the iOS backend code to use Objective-C's automatic reference counting (ARC).
Alex Szpakowski <slime73@gmail.com>
parents: 9506
diff changeset
    75
        if (UIKit_IsDisplayLandscape(displaydata.uiscreen) != (width > height)) {
6520
7a7726af31c1 Make sure mode width/height and status bar orientation match
Sam Lantinga <slouken@libsdl.org>
parents: 6518
diff changeset
    76
            int temp = width;
7a7726af31c1 Make sure mode width/height and status bar orientation match
Sam Lantinga <slouken@libsdl.org>
parents: 6518
diff changeset
    77
            width = height;
7a7726af31c1 Make sure mode width/height and status bar orientation match
Sam Lantinga <slouken@libsdl.org>
parents: 6518
diff changeset
    78
            height = temp;
6077
ee00e4b80f79 Work in progress fixing support for rotated video modes
Sam Lantinga <slouken@libsdl.org>
parents: 6073
diff changeset
    79
        }
6520
7a7726af31c1 Make sure mode width/height and status bar orientation match
Sam Lantinga <slouken@libsdl.org>
parents: 6518
diff changeset
    80
9523
9cbd69cac7ed Fixed mismatching orientations for the window width and height on iOS when the window is created or the app is brought to the foreground, when SDL_HINT_ORIENTATIONS or SDL_WINDOW_FULLSCREEN is used.
Alex Szpakowski <slime73@gmail.com>
parents: 9510
diff changeset
    81
        window->x = 0;
9cbd69cac7ed Fixed mismatching orientations for the window width and height on iOS when the window is created or the app is brought to the foreground, when SDL_HINT_ORIENTATIONS or SDL_WINDOW_FULLSCREEN is used.
Alex Szpakowski <slime73@gmail.com>
parents: 9510
diff changeset
    82
        window->y = 0;
6520
7a7726af31c1 Make sure mode width/height and status bar orientation match
Sam Lantinga <slouken@libsdl.org>
parents: 6518
diff changeset
    83
        window->w = width;
7a7726af31c1 Make sure mode width/height and status bar orientation match
Sam Lantinga <slouken@libsdl.org>
parents: 6518
diff changeset
    84
        window->h = height;
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    85
    }
6001
3ae3d1e58d59 Cleanup out trailing whitespace in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 5640
diff changeset
    86
9510
e19faa3b5d88 Updated the iOS backend code to use Objective-C's automatic reference counting (ARC).
Alex Szpakowski <slime73@gmail.com>
parents: 9506
diff changeset
    87
    window->driverdata = (void *) CFBridgingRetain(data);
5520
09b500e0656d Added orientation rotation for iOS.
Ryan C. Gordon <icculus@icculus.org>
parents: 5518
diff changeset
    88
6262
47d6b41996e4 Fixed setting the window visibility on iOS and Android
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
    89
    /* only one window on iOS, always shown */
47d6b41996e4 Fixed setting the window visibility on iOS and Android
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
    90
    window->flags &= ~SDL_WINDOW_HIDDEN;
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    91
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7159
diff changeset
    92
    /* SDL_WINDOW_BORDERLESS controls whether status bar is hidden.
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7159
diff changeset
    93
     * This is only set if the window is on the main screen. Other screens
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7159
diff changeset
    94
     *  just force the window to have the borderless flag.
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7159
diff changeset
    95
     */
9510
e19faa3b5d88 Updated the iOS backend code to use Objective-C's automatic reference counting (ARC).
Alex Szpakowski <slime73@gmail.com>
parents: 9506
diff changeset
    96
    if (displaydata.uiscreen == [UIScreen mainScreen]) {
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7159
diff changeset
    97
        window->flags |= SDL_WINDOW_INPUT_FOCUS;  /* always has input focus */
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7159
diff changeset
    98
7862
d20e37f08533 Fixed the status bar visibility in iOS 7
Sam Lantinga <slouken@libsdl.org>
parents: 7192
diff changeset
    99
        /* This was setup earlier for our window, and in iOS 7 is controlled by the view, not the application
6520
7a7726af31c1 Make sure mode width/height and status bar orientation match
Sam Lantinga <slouken@libsdl.org>
parents: 6518
diff changeset
   100
        if ([UIApplication sharedApplication].statusBarHidden) {
7a7726af31c1 Make sure mode width/height and status bar orientation match
Sam Lantinga <slouken@libsdl.org>
parents: 6518
diff changeset
   101
            window->flags |= SDL_WINDOW_BORDERLESS;
4446
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 3685
diff changeset
   102
        } else {
6520
7a7726af31c1 Make sure mode width/height and status bar orientation match
Sam Lantinga <slouken@libsdl.org>
parents: 6518
diff changeset
   103
            window->flags &= ~SDL_WINDOW_BORDERLESS;
4446
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 3685
diff changeset
   104
        }
7862
d20e37f08533 Fixed the status bar visibility in iOS 7
Sam Lantinga <slouken@libsdl.org>
parents: 7192
diff changeset
   105
        */
6511
41253d43a2cf Updated support for external video output on the iPad
Sam Lantinga <slouken@libsdl.org>
parents: 6437
diff changeset
   106
    } else {
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7159
diff changeset
   107
        window->flags &= ~SDL_WINDOW_RESIZABLE;  /* window is NEVER resizeable */
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7159
diff changeset
   108
        window->flags &= ~SDL_WINDOW_INPUT_FOCUS;  /* never has input focus */
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7159
diff changeset
   109
        window->flags |= SDL_WINDOW_BORDERLESS;  /* never has a status bar. */
6511
41253d43a2cf Updated support for external video output on the iPad
Sam Lantinga <slouken@libsdl.org>
parents: 6437
diff changeset
   110
    }
5518
f84dd424d514 iOS: Report both landscape and portrait orientation as display modes.
Ryan C. Gordon <icculus@icculus.org>
parents: 5262
diff changeset
   111
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7159
diff changeset
   112
    /* The View Controller will handle rotating the view when the
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7159
diff changeset
   113
     * device orientation changes. This will trigger resize events, if
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7159
diff changeset
   114
     * appropriate.
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7159
diff changeset
   115
     */
9510
e19faa3b5d88 Updated the iOS backend code to use Objective-C's automatic reference counting (ARC).
Alex Szpakowski <slime73@gmail.com>
parents: 9506
diff changeset
   116
    data.viewcontroller = [[SDL_uikitviewcontroller alloc] initWithSDLWindow:window];
e19faa3b5d88 Updated the iOS backend code to use Objective-C's automatic reference counting (ARC).
Alex Szpakowski <slime73@gmail.com>
parents: 9506
diff changeset
   117
    data.viewcontroller.title = @"SDL App";  /* !!! FIXME: hook up SDL_SetWindowTitle() */
5518
f84dd424d514 iOS: Report both landscape and portrait orientation as display modes.
Ryan C. Gordon <icculus@icculus.org>
parents: 5262
diff changeset
   118
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   119
    return 0;
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   120
}
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   121
5056
8b7988f42fcb Added the ability to get the UIKit window through the SDL API.
Sam Lantinga <slouken@libsdl.org>
parents: 4446
diff changeset
   122
int
5246
58265e606e4e Window coordinates are in the global space and windows are not tied to a particular display.
Sam Lantinga <slouken@libsdl.org>
parents: 5154
diff changeset
   123
UIKit_CreateWindow(_THIS, SDL_Window *window)
58265e606e4e Window coordinates are in the global space and windows are not tied to a particular display.
Sam Lantinga <slouken@libsdl.org>
parents: 5154
diff changeset
   124
{
9506
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9505
diff changeset
   125
    @autoreleasepool {
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9505
diff changeset
   126
        SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
9510
e19faa3b5d88 Updated the iOS backend code to use Objective-C's automatic reference counting (ARC).
Alex Szpakowski <slime73@gmail.com>
parents: 9506
diff changeset
   127
        SDL_DisplayData *data = (__bridge SDL_DisplayData *) display->driverdata;
e19faa3b5d88 Updated the iOS backend code to use Objective-C's automatic reference counting (ARC).
Alex Szpakowski <slime73@gmail.com>
parents: 9506
diff changeset
   128
        const BOOL external = ([UIScreen mainScreen] != data.uiscreen);
e19faa3b5d88 Updated the iOS backend code to use Objective-C's automatic reference counting (ARC).
Alex Szpakowski <slime73@gmail.com>
parents: 9506
diff changeset
   129
        const CGSize origsize = [[data.uiscreen currentMode] size];
4446
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 3685
diff changeset
   130
9506
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9505
diff changeset
   131
        /* SDL currently puts this window at the start of display's linked list. We rely on this. */
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9505
diff changeset
   132
        SDL_assert(_this->windows == window);
4446
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 3685
diff changeset
   133
9506
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9505
diff changeset
   134
        /* We currently only handle a single window per display on iOS */
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9505
diff changeset
   135
        if (window->next != NULL) {
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9505
diff changeset
   136
            return SDL_SetError("Only one window allowed per display.");
8891
7b6472f1b7ba Fixed bug 2563 - Remove obsolete code for supporting iOS < 5
Sam Lantinga <slouken@libsdl.org>
parents: 8583
diff changeset
   137
        }
4446
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 3685
diff changeset
   138
9506
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9505
diff changeset
   139
        /* If monitor has a resolution of 0x0 (hasn't been explicitly set by the
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9505
diff changeset
   140
         * user, so it's in standby), try to force the display to a resolution
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9505
diff changeset
   141
         * that most closely matches the desired window size.
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9505
diff changeset
   142
         */
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9505
diff changeset
   143
        if ((origsize.width == 0.0f) && (origsize.height == 0.0f)) {
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9505
diff changeset
   144
            if (display->num_display_modes == 0) {
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9505
diff changeset
   145
                _this->GetDisplayModes(_this, display);
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9505
diff changeset
   146
            }
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7159
diff changeset
   147
9506
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9505
diff changeset
   148
            int i;
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9505
diff changeset
   149
            const SDL_DisplayMode *bestmode = NULL;
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9505
diff changeset
   150
            for (i = display->num_display_modes; i >= 0; i--) {
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9505
diff changeset
   151
                const SDL_DisplayMode *mode = &display->display_modes[i];
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9505
diff changeset
   152
                if ((mode->w >= window->w) && (mode->h >= window->h))
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9505
diff changeset
   153
                    bestmode = mode;
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9505
diff changeset
   154
            }
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7159
diff changeset
   155
9506
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9505
diff changeset
   156
            if (bestmode) {
9510
e19faa3b5d88 Updated the iOS backend code to use Objective-C's automatic reference counting (ARC).
Alex Szpakowski <slime73@gmail.com>
parents: 9506
diff changeset
   157
                SDL_DisplayModeData *modedata = (__bridge SDL_DisplayModeData *)bestmode->driverdata;
e19faa3b5d88 Updated the iOS backend code to use Objective-C's automatic reference counting (ARC).
Alex Szpakowski <slime73@gmail.com>
parents: 9506
diff changeset
   158
                [data.uiscreen setCurrentMode:modedata.uiscreenmode];
9506
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9505
diff changeset
   159
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9505
diff changeset
   160
                /* desktop_mode doesn't change here (the higher level will
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9505
diff changeset
   161
                 * use it to set all the screens back to their defaults
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9505
diff changeset
   162
                 * upon window destruction, SDL_Quit(), etc.
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9505
diff changeset
   163
                 */
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9505
diff changeset
   164
                display->current_mode = *bestmode;
6520
7a7726af31c1 Make sure mode width/height and status bar orientation match
Sam Lantinga <slouken@libsdl.org>
parents: 6518
diff changeset
   165
            }
7a7726af31c1 Make sure mode width/height and status bar orientation match
Sam Lantinga <slouken@libsdl.org>
parents: 6518
diff changeset
   166
        }
4446
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 3685
diff changeset
   167
9510
e19faa3b5d88 Updated the iOS backend code to use Objective-C's automatic reference counting (ARC).
Alex Szpakowski <slime73@gmail.com>
parents: 9506
diff changeset
   168
        if (data.uiscreen == [UIScreen mainScreen]) {
9523
9cbd69cac7ed Fixed mismatching orientations for the window width and height on iOS when the window is created or the app is brought to the foreground, when SDL_HINT_ORIENTATIONS or SDL_WINDOW_FULLSCREEN is used.
Alex Szpakowski <slime73@gmail.com>
parents: 9510
diff changeset
   169
            NSUInteger orientations = UIKit_GetSupportedOrientations(window);
9cbd69cac7ed Fixed mismatching orientations for the window width and height on iOS when the window is created or the app is brought to the foreground, when SDL_HINT_ORIENTATIONS or SDL_WINDOW_FULLSCREEN is used.
Alex Szpakowski <slime73@gmail.com>
parents: 9510
diff changeset
   170
            UIApplication *app = [UIApplication sharedApplication];
9cbd69cac7ed Fixed mismatching orientations for the window width and height on iOS when the window is created or the app is brought to the foreground, when SDL_HINT_ORIENTATIONS or SDL_WINDOW_FULLSCREEN is used.
Alex Szpakowski <slime73@gmail.com>
parents: 9510
diff changeset
   171
9506
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9505
diff changeset
   172
            if (window->flags & (SDL_WINDOW_FULLSCREEN|SDL_WINDOW_BORDERLESS)) {
9523
9cbd69cac7ed Fixed mismatching orientations for the window width and height on iOS when the window is created or the app is brought to the foreground, when SDL_HINT_ORIENTATIONS or SDL_WINDOW_FULLSCREEN is used.
Alex Szpakowski <slime73@gmail.com>
parents: 9510
diff changeset
   173
                app.statusBarHidden = YES;
9506
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9505
diff changeset
   174
            } else {
9523
9cbd69cac7ed Fixed mismatching orientations for the window width and height on iOS when the window is created or the app is brought to the foreground, when SDL_HINT_ORIENTATIONS or SDL_WINDOW_FULLSCREEN is used.
Alex Szpakowski <slime73@gmail.com>
parents: 9510
diff changeset
   175
                app.statusBarHidden = NO;
9506
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9505
diff changeset
   176
            }
6001
3ae3d1e58d59 Cleanup out trailing whitespace in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 5640
diff changeset
   177
9523
9cbd69cac7ed Fixed mismatching orientations for the window width and height on iOS when the window is created or the app is brought to the foreground, when SDL_HINT_ORIENTATIONS or SDL_WINDOW_FULLSCREEN is used.
Alex Szpakowski <slime73@gmail.com>
parents: 9510
diff changeset
   178
            /* Make sure the screen is using a supported orientation. We do it
9cbd69cac7ed Fixed mismatching orientations for the window width and height on iOS when the window is created or the app is brought to the foreground, when SDL_HINT_ORIENTATIONS or SDL_WINDOW_FULLSCREEN is used.
Alex Szpakowski <slime73@gmail.com>
parents: 9510
diff changeset
   179
             * now so that SetupWindowData assigns the properly oriented width
9cbd69cac7ed Fixed mismatching orientations for the window width and height on iOS when the window is created or the app is brought to the foreground, when SDL_HINT_ORIENTATIONS or SDL_WINDOW_FULLSCREEN is used.
Alex Szpakowski <slime73@gmail.com>
parents: 9510
diff changeset
   180
             * and height to the window's w and h variables.
9cbd69cac7ed Fixed mismatching orientations for the window width and height on iOS when the window is created or the app is brought to the foreground, when SDL_HINT_ORIENTATIONS or SDL_WINDOW_FULLSCREEN is used.
Alex Szpakowski <slime73@gmail.com>
parents: 9510
diff changeset
   181
             */
9cbd69cac7ed Fixed mismatching orientations for the window width and height on iOS when the window is created or the app is brought to the foreground, when SDL_HINT_ORIENTATIONS or SDL_WINDOW_FULLSCREEN is used.
Alex Szpakowski <slime73@gmail.com>
parents: 9510
diff changeset
   182
            if (UIKit_IsDisplayLandscape(data.uiscreen)) {
9cbd69cac7ed Fixed mismatching orientations for the window width and height on iOS when the window is created or the app is brought to the foreground, when SDL_HINT_ORIENTATIONS or SDL_WINDOW_FULLSCREEN is used.
Alex Szpakowski <slime73@gmail.com>
parents: 9510
diff changeset
   183
                if (!(orientations & UIInterfaceOrientationMaskLandscape)) {
9cbd69cac7ed Fixed mismatching orientations for the window width and height on iOS when the window is created or the app is brought to the foreground, when SDL_HINT_ORIENTATIONS or SDL_WINDOW_FULLSCREEN is used.
Alex Szpakowski <slime73@gmail.com>
parents: 9510
diff changeset
   184
                    [app setStatusBarOrientation:UIInterfaceOrientationPortrait animated:NO];
9506
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9505
diff changeset
   185
                }
9523
9cbd69cac7ed Fixed mismatching orientations for the window width and height on iOS when the window is created or the app is brought to the foreground, when SDL_HINT_ORIENTATIONS or SDL_WINDOW_FULLSCREEN is used.
Alex Szpakowski <slime73@gmail.com>
parents: 9510
diff changeset
   186
            } else {
9cbd69cac7ed Fixed mismatching orientations for the window width and height on iOS when the window is created or the app is brought to the foreground, when SDL_HINT_ORIENTATIONS or SDL_WINDOW_FULLSCREEN is used.
Alex Szpakowski <slime73@gmail.com>
parents: 9510
diff changeset
   187
                if (!(orientations & (UIInterfaceOrientationMaskPortrait|UIInterfaceOrientationMaskPortraitUpsideDown))) {
9cbd69cac7ed Fixed mismatching orientations for the window width and height on iOS when the window is created or the app is brought to the foreground, when SDL_HINT_ORIENTATIONS or SDL_WINDOW_FULLSCREEN is used.
Alex Szpakowski <slime73@gmail.com>
parents: 9510
diff changeset
   188
                    UIInterfaceOrientation orient = UIInterfaceOrientationLandscapeLeft;
9cbd69cac7ed Fixed mismatching orientations for the window width and height on iOS when the window is created or the app is brought to the foreground, when SDL_HINT_ORIENTATIONS or SDL_WINDOW_FULLSCREEN is used.
Alex Szpakowski <slime73@gmail.com>
parents: 9510
diff changeset
   189
9cbd69cac7ed Fixed mismatching orientations for the window width and height on iOS when the window is created or the app is brought to the foreground, when SDL_HINT_ORIENTATIONS or SDL_WINDOW_FULLSCREEN is used.
Alex Szpakowski <slime73@gmail.com>
parents: 9510
diff changeset
   190
                    if (orientations & UIInterfaceOrientationMaskLandscapeRight) {
9cbd69cac7ed Fixed mismatching orientations for the window width and height on iOS when the window is created or the app is brought to the foreground, when SDL_HINT_ORIENTATIONS or SDL_WINDOW_FULLSCREEN is used.
Alex Szpakowski <slime73@gmail.com>
parents: 9510
diff changeset
   191
                        orient = UIInterfaceOrientationLandscapeRight;
9cbd69cac7ed Fixed mismatching orientations for the window width and height on iOS when the window is created or the app is brought to the foreground, when SDL_HINT_ORIENTATIONS or SDL_WINDOW_FULLSCREEN is used.
Alex Szpakowski <slime73@gmail.com>
parents: 9510
diff changeset
   192
                    }
9cbd69cac7ed Fixed mismatching orientations for the window width and height on iOS when the window is created or the app is brought to the foreground, when SDL_HINT_ORIENTATIONS or SDL_WINDOW_FULLSCREEN is used.
Alex Szpakowski <slime73@gmail.com>
parents: 9510
diff changeset
   193
9cbd69cac7ed Fixed mismatching orientations for the window width and height on iOS when the window is created or the app is brought to the foreground, when SDL_HINT_ORIENTATIONS or SDL_WINDOW_FULLSCREEN is used.
Alex Szpakowski <slime73@gmail.com>
parents: 9510
diff changeset
   194
                    [app setStatusBarOrientation:orient animated:NO];
9506
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9505
diff changeset
   195
                }
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9505
diff changeset
   196
            }
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9505
diff changeset
   197
        }
4446
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 3685
diff changeset
   198
9506
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9505
diff changeset
   199
        /* ignore the size user requested, and make a fullscreen window */
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9505
diff changeset
   200
        /* !!! FIXME: can we have a smaller view? */
9528
6915f7db6791 Removed an ugly hack to make windows rotate properly on iOS 8+.
Alex Szpakowski <slime73@gmail.com>
parents: 9523
diff changeset
   201
        UIWindow *uiwindow = [[UIWindow alloc] initWithFrame:data.uiscreen.bounds];
9506
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9505
diff changeset
   202
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9505
diff changeset
   203
        /* put the window on an external display if appropriate. This implicitly
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9505
diff changeset
   204
         * does [uiwindow setframe:[uiscreen bounds]], so don't do it on the
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9505
diff changeset
   205
         * main display, where we land by default, as that would eat the
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9505
diff changeset
   206
         * status bar real estate.
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9505
diff changeset
   207
         */
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9505
diff changeset
   208
        if (external) {
9510
e19faa3b5d88 Updated the iOS backend code to use Objective-C's automatic reference counting (ARC).
Alex Szpakowski <slime73@gmail.com>
parents: 9506
diff changeset
   209
            [uiwindow setScreen:data.uiscreen];
9506
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9505
diff changeset
   210
        }
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9505
diff changeset
   211
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9505
diff changeset
   212
        if (SetupWindowData(_this, window, uiwindow, SDL_TRUE) < 0) {
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9505
diff changeset
   213
            return -1;
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9505
diff changeset
   214
        }
9510
e19faa3b5d88 Updated the iOS backend code to use Objective-C's automatic reference counting (ARC).
Alex Szpakowski <slime73@gmail.com>
parents: 9506
diff changeset
   215
6001
3ae3d1e58d59 Cleanup out trailing whitespace in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 5640
diff changeset
   216
    }
3ae3d1e58d59 Cleanup out trailing whitespace in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 5640
diff changeset
   217
3685
64ce267332c6 Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents: 3400
diff changeset
   218
    return 1;
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   219
}
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   220
5056
8b7988f42fcb Added the ability to get the UIKit window through the SDL API.
Sam Lantinga <slouken@libsdl.org>
parents: 4446
diff changeset
   221
void
6379
8f224d0762ab Fix for the Game Center status window always being behind the SDL window (untested!)
Sam Lantinga <slouken@libsdl.org>
parents: 6342
diff changeset
   222
UIKit_ShowWindow(_THIS, SDL_Window * window)
8f224d0762ab Fix for the Game Center status window always being behind the SDL window (untested!)
Sam Lantinga <slouken@libsdl.org>
parents: 6342
diff changeset
   223
{
9506
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9505
diff changeset
   224
    @autoreleasepool {
9510
e19faa3b5d88 Updated the iOS backend code to use Objective-C's automatic reference counting (ARC).
Alex Szpakowski <slime73@gmail.com>
parents: 9506
diff changeset
   225
        UIWindow *uiwindow = ((__bridge SDL_WindowData *) window->driverdata).uiwindow;
9506
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9505
diff changeset
   226
        [uiwindow makeKeyAndVisible];
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9505
diff changeset
   227
    }
6379
8f224d0762ab Fix for the Game Center status window always being behind the SDL window (untested!)
Sam Lantinga <slouken@libsdl.org>
parents: 6342
diff changeset
   228
}
8f224d0762ab Fix for the Game Center status window always being behind the SDL window (untested!)
Sam Lantinga <slouken@libsdl.org>
parents: 6342
diff changeset
   229
8f224d0762ab Fix for the Game Center status window always being behind the SDL window (untested!)
Sam Lantinga <slouken@libsdl.org>
parents: 6342
diff changeset
   230
void
8f224d0762ab Fix for the Game Center status window always being behind the SDL window (untested!)
Sam Lantinga <slouken@libsdl.org>
parents: 6342
diff changeset
   231
UIKit_HideWindow(_THIS, SDL_Window * window)
8f224d0762ab Fix for the Game Center status window always being behind the SDL window (untested!)
Sam Lantinga <slouken@libsdl.org>
parents: 6342
diff changeset
   232
{
9506
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9505
diff changeset
   233
    @autoreleasepool {
9510
e19faa3b5d88 Updated the iOS backend code to use Objective-C's automatic reference counting (ARC).
Alex Szpakowski <slime73@gmail.com>
parents: 9506
diff changeset
   234
        UIWindow *uiwindow = ((__bridge SDL_WindowData *) window->driverdata).uiwindow;
9506
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9505
diff changeset
   235
        uiwindow.hidden = YES;
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9505
diff changeset
   236
    }
6379
8f224d0762ab Fix for the Game Center status window always being behind the SDL window (untested!)
Sam Lantinga <slouken@libsdl.org>
parents: 6342
diff changeset
   237
}
8f224d0762ab Fix for the Game Center status window always being behind the SDL window (untested!)
Sam Lantinga <slouken@libsdl.org>
parents: 6342
diff changeset
   238
8f224d0762ab Fix for the Game Center status window always being behind the SDL window (untested!)
Sam Lantinga <slouken@libsdl.org>
parents: 6342
diff changeset
   239
void
6419
b75e82af5ef1 Moved iOS-specific code into uikit target. Fixes crashes in X11 target.
Ryan C. Gordon <icculus@icculus.org>
parents: 6381
diff changeset
   240
UIKit_RaiseWindow(_THIS, SDL_Window * window)
b75e82af5ef1 Moved iOS-specific code into uikit target. Fixes crashes in X11 target.
Ryan C. Gordon <icculus@icculus.org>
parents: 6381
diff changeset
   241
{
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7159
diff changeset
   242
    /* We don't currently offer a concept of "raising" the SDL window, since
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7159
diff changeset
   243
     *  we only allow one per display, in the iOS fashion.
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7159
diff changeset
   244
     * However, we use this entry point to rebind the context to the view
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7159
diff changeset
   245
     *  during OnWindowRestored processing.
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7159
diff changeset
   246
     */
6419
b75e82af5ef1 Moved iOS-specific code into uikit target. Fixes crashes in X11 target.
Ryan C. Gordon <icculus@icculus.org>
parents: 6381
diff changeset
   247
    _this->GL_MakeCurrent(_this, _this->current_glwin, _this->current_glctx);
b75e82af5ef1 Moved iOS-specific code into uikit target. Fixes crashes in X11 target.
Ryan C. Gordon <icculus@icculus.org>
parents: 6381
diff changeset
   248
}
b75e82af5ef1 Moved iOS-specific code into uikit target. Fixes crashes in X11 target.
Ryan C. Gordon <icculus@icculus.org>
parents: 6381
diff changeset
   249
9505
6fc615dfc93f Added support for SDL_SetWindowBordered on iOS. Worked around a bug with rotating the device on iOS 8.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
   250
static void
6fc615dfc93f Added support for SDL_SetWindowBordered on iOS. Worked around a bug with rotating the device on iOS 8.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
   251
UIKit_UpdateWindowBorder(_THIS, SDL_Window * window)
6073
9738f2a8eee4 Fixed creating a fullscreen window on iOS
Sam Lantinga <slouken@libsdl.org>
parents: 6064
diff changeset
   252
{
9510
e19faa3b5d88 Updated the iOS backend code to use Objective-C's automatic reference counting (ARC).
Alex Szpakowski <slime73@gmail.com>
parents: 9506
diff changeset
   253
    SDL_WindowData *windowdata = (__bridge SDL_WindowData *) window->driverdata;
e19faa3b5d88 Updated the iOS backend code to use Objective-C's automatic reference counting (ARC).
Alex Szpakowski <slime73@gmail.com>
parents: 9506
diff changeset
   254
    SDL_uikitviewcontroller *viewcontroller = windowdata.viewcontroller;
9502
933ed557b7c1 Fixed SDL_SetWindowFullscreen on iOS for the last time, hopefully.
Alex Szpakowski <slime73@gmail.com>
parents: 9501
diff changeset
   255
    CGRect frame;
6073
9738f2a8eee4 Fixed creating a fullscreen window on iOS
Sam Lantinga <slouken@libsdl.org>
parents: 6064
diff changeset
   256
9510
e19faa3b5d88 Updated the iOS backend code to use Objective-C's automatic reference counting (ARC).
Alex Szpakowski <slime73@gmail.com>
parents: 9506
diff changeset
   257
    if (windowdata.uiwindow.screen == [UIScreen mainScreen]) {
9505
6fc615dfc93f Added support for SDL_SetWindowBordered on iOS. Worked around a bug with rotating the device on iOS 8.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
   258
        if (window->flags & (SDL_WINDOW_FULLSCREEN | SDL_WINDOW_BORDERLESS)) {
6fc615dfc93f Added support for SDL_SetWindowBordered on iOS. Worked around a bug with rotating the device on iOS 8.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
   259
            [UIApplication sharedApplication].statusBarHidden = YES;
6fc615dfc93f Added support for SDL_SetWindowBordered on iOS. Worked around a bug with rotating the device on iOS 8.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
   260
        } else {
6fc615dfc93f Added support for SDL_SetWindowBordered on iOS. Worked around a bug with rotating the device on iOS 8.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
   261
            [UIApplication sharedApplication].statusBarHidden = NO;
6fc615dfc93f Added support for SDL_SetWindowBordered on iOS. Worked around a bug with rotating the device on iOS 8.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
   262
        }
6437
3e52c17e2a07 Fixed window/view bounds management with autorotation.
Sam Lantinga <slouken@libsdl.org>
parents: 6419
diff changeset
   263
9505
6fc615dfc93f Added support for SDL_SetWindowBordered on iOS. Worked around a bug with rotating the device on iOS 8.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
   264
        /* iOS 7+ won't update the status bar until we tell it to. */
6fc615dfc93f Added support for SDL_SetWindowBordered on iOS. Worked around a bug with rotating the device on iOS 8.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
   265
        if ([viewcontroller respondsToSelector:@selector(setNeedsStatusBarAppearanceUpdate)]) {
6fc615dfc93f Added support for SDL_SetWindowBordered on iOS. Worked around a bug with rotating the device on iOS 8.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
   266
            [viewcontroller setNeedsStatusBarAppearanceUpdate];
6fc615dfc93f Added support for SDL_SetWindowBordered on iOS. Worked around a bug with rotating the device on iOS 8.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
   267
        }
9491
c652f2655d2a Fixed SDL_SetWindowFullscreen not properly updating the status bar visibility in iOS 7+
Alex Szpakowski <slime73@gmail.com>
parents: 9488
diff changeset
   268
    }
c652f2655d2a Fixed SDL_SetWindowFullscreen not properly updating the status bar visibility in iOS 7+
Alex Szpakowski <slime73@gmail.com>
parents: 9488
diff changeset
   269
9497
fa0f79fc320d Fixed SDL_SetWindowFullscreen on iOS to properly update the view's frame.
Alex Szpakowski <slime73@gmail.com>
parents: 9495
diff changeset
   270
    /* Update the view's frame to account for the status bar change. */
9510
e19faa3b5d88 Updated the iOS backend code to use Objective-C's automatic reference counting (ARC).
Alex Szpakowski <slime73@gmail.com>
parents: 9506
diff changeset
   271
    frame = UIKit_ComputeViewFrame(window, windowdata.uiwindow.screen);
9505
6fc615dfc93f Added support for SDL_SetWindowBordered on iOS. Worked around a bug with rotating the device on iOS 8.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
   272
9510
e19faa3b5d88 Updated the iOS backend code to use Objective-C's automatic reference counting (ARC).
Alex Szpakowski <slime73@gmail.com>
parents: 9506
diff changeset
   273
    windowdata.view.frame = frame;
e19faa3b5d88 Updated the iOS backend code to use Objective-C's automatic reference counting (ARC).
Alex Szpakowski <slime73@gmail.com>
parents: 9506
diff changeset
   274
    [windowdata.view setNeedsLayout];
e19faa3b5d88 Updated the iOS backend code to use Objective-C's automatic reference counting (ARC).
Alex Szpakowski <slime73@gmail.com>
parents: 9506
diff changeset
   275
    [windowdata.view layoutIfNeeded];
9497
fa0f79fc320d Fixed SDL_SetWindowFullscreen on iOS to properly update the view's frame.
Alex Szpakowski <slime73@gmail.com>
parents: 9495
diff changeset
   276
9488
f15520430c94 Changed the way retina resolutions are handled in iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 8978
diff changeset
   277
    /* Get frame dimensions */
9505
6fc615dfc93f Added support for SDL_SetWindowBordered on iOS. Worked around a bug with rotating the device on iOS 8.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
   278
    int width  = (int) frame.size.width;
9502
933ed557b7c1 Fixed SDL_SetWindowFullscreen on iOS for the last time, hopefully.
Alex Szpakowski <slime73@gmail.com>
parents: 9501
diff changeset
   279
    int height = (int) frame.size.height;
6267
ed2cf4669e55 * On iOS, fix support for the case where [UIScreen scale] is not 1.0 (retina)
Tim Angus <tim@blackcompanystudios.co.uk>
parents: 6262
diff changeset
   280
6077
ee00e4b80f79 Work in progress fixing support for rotated video modes
Sam Lantinga <slouken@libsdl.org>
parents: 6073
diff changeset
   281
    /* We can pick either width or height here and we'll rotate the
9505
6fc615dfc93f Added support for SDL_SetWindowBordered on iOS. Worked around a bug with rotating the device on iOS 8.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
   282
     screen to match, so we pick the closest to what we wanted.
6077
ee00e4b80f79 Work in progress fixing support for rotated video modes
Sam Lantinga <slouken@libsdl.org>
parents: 6073
diff changeset
   283
     */
ee00e4b80f79 Work in progress fixing support for rotated video modes
Sam Lantinga <slouken@libsdl.org>
parents: 6073
diff changeset
   284
    if (window->w >= window->h) {
9505
6fc615dfc93f Added support for SDL_SetWindowBordered on iOS. Worked around a bug with rotating the device on iOS 8.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
   285
        SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, SDL_max(width, height), SDL_min(width, height));
6077
ee00e4b80f79 Work in progress fixing support for rotated video modes
Sam Lantinga <slouken@libsdl.org>
parents: 6073
diff changeset
   286
    } else {
9505
6fc615dfc93f Added support for SDL_SetWindowBordered on iOS. Worked around a bug with rotating the device on iOS 8.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
   287
        SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, SDL_min(width, height), SDL_max(width, height));
6077
ee00e4b80f79 Work in progress fixing support for rotated video modes
Sam Lantinga <slouken@libsdl.org>
parents: 6073
diff changeset
   288
    }
6073
9738f2a8eee4 Fixed creating a fullscreen window on iOS
Sam Lantinga <slouken@libsdl.org>
parents: 6064
diff changeset
   289
}
9738f2a8eee4 Fixed creating a fullscreen window on iOS
Sam Lantinga <slouken@libsdl.org>
parents: 6064
diff changeset
   290
9738f2a8eee4 Fixed creating a fullscreen window on iOS
Sam Lantinga <slouken@libsdl.org>
parents: 6064
diff changeset
   291
void
9505
6fc615dfc93f Added support for SDL_SetWindowBordered on iOS. Worked around a bug with rotating the device on iOS 8.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
   292
UIKit_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered)
6fc615dfc93f Added support for SDL_SetWindowBordered on iOS. Worked around a bug with rotating the device on iOS 8.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
   293
{
9506
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9505
diff changeset
   294
    @autoreleasepool {
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9505
diff changeset
   295
        UIKit_UpdateWindowBorder(_this, window);
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9505
diff changeset
   296
    }
9505
6fc615dfc93f Added support for SDL_SetWindowBordered on iOS. Worked around a bug with rotating the device on iOS 8.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
   297
}
6fc615dfc93f Added support for SDL_SetWindowBordered on iOS. Worked around a bug with rotating the device on iOS 8.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
   298
6fc615dfc93f Added support for SDL_SetWindowBordered on iOS. Worked around a bug with rotating the device on iOS 8.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
   299
void
6fc615dfc93f Added support for SDL_SetWindowBordered on iOS. Worked around a bug with rotating the device on iOS 8.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
   300
UIKit_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen)
6fc615dfc93f Added support for SDL_SetWindowBordered on iOS. Worked around a bug with rotating the device on iOS 8.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
   301
{
9506
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9505
diff changeset
   302
    @autoreleasepool {
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9505
diff changeset
   303
        UIKit_UpdateWindowBorder(_this, window);
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9505
diff changeset
   304
    }
9505
6fc615dfc93f Added support for SDL_SetWindowBordered on iOS. Worked around a bug with rotating the device on iOS 8.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
   305
}
6fc615dfc93f Added support for SDL_SetWindowBordered on iOS. Worked around a bug with rotating the device on iOS 8.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
   306
6fc615dfc93f Added support for SDL_SetWindowBordered on iOS. Worked around a bug with rotating the device on iOS 8.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
   307
void
6003
fddf81967e2d Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 6001
diff changeset
   308
UIKit_DestroyWindow(_THIS, SDL_Window * window)
fddf81967e2d Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 6001
diff changeset
   309
{
9506
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9505
diff changeset
   310
    @autoreleasepool {
9510
e19faa3b5d88 Updated the iOS backend code to use Objective-C's automatic reference counting (ARC).
Alex Szpakowski <slime73@gmail.com>
parents: 9506
diff changeset
   311
        if (window->driverdata != NULL) {
e19faa3b5d88 Updated the iOS backend code to use Objective-C's automatic reference counting (ARC).
Alex Szpakowski <slime73@gmail.com>
parents: 9506
diff changeset
   312
            CFRelease(window->driverdata);
9506
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9505
diff changeset
   313
        }
3685
64ce267332c6 Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents: 3400
diff changeset
   314
    }
9506
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9505
diff changeset
   315
8978
7753e4fd3d1d Fixed bug 2629 - Mac: crash when calling SDL_DestroyWindow with an active OpenGL context
Sam Lantinga <slouken@libsdl.org>
parents: 8905
diff changeset
   316
    window->driverdata = NULL;
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   317
}
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   318
5056
8b7988f42fcb Added the ability to get the UIKit window through the SDL API.
Sam Lantinga <slouken@libsdl.org>
parents: 4446
diff changeset
   319
SDL_bool
8b7988f42fcb Added the ability to get the UIKit window through the SDL API.
Sam Lantinga <slouken@libsdl.org>
parents: 4446
diff changeset
   320
UIKit_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info)
8b7988f42fcb Added the ability to get the UIKit window through the SDL API.
Sam Lantinga <slouken@libsdl.org>
parents: 4446
diff changeset
   321
{
9506
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9505
diff changeset
   322
    @autoreleasepool {
9510
e19faa3b5d88 Updated the iOS backend code to use Objective-C's automatic reference counting (ARC).
Alex Szpakowski <slime73@gmail.com>
parents: 9506
diff changeset
   323
        UIWindow *uiwindow = ((__bridge SDL_WindowData *) window->driverdata).uiwindow;
5056
8b7988f42fcb Added the ability to get the UIKit window through the SDL API.
Sam Lantinga <slouken@libsdl.org>
parents: 4446
diff changeset
   324
9506
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9505
diff changeset
   325
        if (info->version.major <= SDL_MAJOR_VERSION) {
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9505
diff changeset
   326
            info->subsystem = SDL_SYSWM_UIKIT;
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9505
diff changeset
   327
            info->info.uikit.window = uiwindow;
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9505
diff changeset
   328
            return SDL_TRUE;
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9505
diff changeset
   329
        } else {
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9505
diff changeset
   330
            SDL_SetError("Application not compiled with SDL %d.%d\n",
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9505
diff changeset
   331
                         SDL_MAJOR_VERSION, SDL_MINOR_VERSION);
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9505
diff changeset
   332
            return SDL_FALSE;
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9505
diff changeset
   333
        }
5056
8b7988f42fcb Added the ability to get the UIKit window through the SDL API.
Sam Lantinga <slouken@libsdl.org>
parents: 4446
diff changeset
   334
    }
8b7988f42fcb Added the ability to get the UIKit window through the SDL API.
Sam Lantinga <slouken@libsdl.org>
parents: 4446
diff changeset
   335
}
8b7988f42fcb Added the ability to get the UIKit window through the SDL API.
Sam Lantinga <slouken@libsdl.org>
parents: 4446
diff changeset
   336
9523
9cbd69cac7ed Fixed mismatching orientations for the window width and height on iOS when the window is created or the app is brought to the foreground, when SDL_HINT_ORIENTATIONS or SDL_WINDOW_FULLSCREEN is used.
Alex Szpakowski <slime73@gmail.com>
parents: 9510
diff changeset
   337
NSUInteger
9cbd69cac7ed Fixed mismatching orientations for the window width and height on iOS when the window is created or the app is brought to the foreground, when SDL_HINT_ORIENTATIONS or SDL_WINDOW_FULLSCREEN is used.
Alex Szpakowski <slime73@gmail.com>
parents: 9510
diff changeset
   338
UIKit_GetSupportedOrientations(SDL_Window * window)
9cbd69cac7ed Fixed mismatching orientations for the window width and height on iOS when the window is created or the app is brought to the foreground, when SDL_HINT_ORIENTATIONS or SDL_WINDOW_FULLSCREEN is used.
Alex Szpakowski <slime73@gmail.com>
parents: 9510
diff changeset
   339
{
9cbd69cac7ed Fixed mismatching orientations for the window width and height on iOS when the window is created or the app is brought to the foreground, when SDL_HINT_ORIENTATIONS or SDL_WINDOW_FULLSCREEN is used.
Alex Szpakowski <slime73@gmail.com>
parents: 9510
diff changeset
   340
    const char *hint = SDL_GetHint(SDL_HINT_ORIENTATIONS);
9cbd69cac7ed Fixed mismatching orientations for the window width and height on iOS when the window is created or the app is brought to the foreground, when SDL_HINT_ORIENTATIONS or SDL_WINDOW_FULLSCREEN is used.
Alex Szpakowski <slime73@gmail.com>
parents: 9510
diff changeset
   341
    NSUInteger orientationMask = 0;
9cbd69cac7ed Fixed mismatching orientations for the window width and height on iOS when the window is created or the app is brought to the foreground, when SDL_HINT_ORIENTATIONS or SDL_WINDOW_FULLSCREEN is used.
Alex Szpakowski <slime73@gmail.com>
parents: 9510
diff changeset
   342
9cbd69cac7ed Fixed mismatching orientations for the window width and height on iOS when the window is created or the app is brought to the foreground, when SDL_HINT_ORIENTATIONS or SDL_WINDOW_FULLSCREEN is used.
Alex Szpakowski <slime73@gmail.com>
parents: 9510
diff changeset
   343
    @autoreleasepool {
9cbd69cac7ed Fixed mismatching orientations for the window width and height on iOS when the window is created or the app is brought to the foreground, when SDL_HINT_ORIENTATIONS or SDL_WINDOW_FULLSCREEN is used.
Alex Szpakowski <slime73@gmail.com>
parents: 9510
diff changeset
   344
        if (hint != NULL) {
9cbd69cac7ed Fixed mismatching orientations for the window width and height on iOS when the window is created or the app is brought to the foreground, when SDL_HINT_ORIENTATIONS or SDL_WINDOW_FULLSCREEN is used.
Alex Szpakowski <slime73@gmail.com>
parents: 9510
diff changeset
   345
            NSArray *orientations = [@(hint) componentsSeparatedByString:@" "];
9cbd69cac7ed Fixed mismatching orientations for the window width and height on iOS when the window is created or the app is brought to the foreground, when SDL_HINT_ORIENTATIONS or SDL_WINDOW_FULLSCREEN is used.
Alex Szpakowski <slime73@gmail.com>
parents: 9510
diff changeset
   346
9cbd69cac7ed Fixed mismatching orientations for the window width and height on iOS when the window is created or the app is brought to the foreground, when SDL_HINT_ORIENTATIONS or SDL_WINDOW_FULLSCREEN is used.
Alex Szpakowski <slime73@gmail.com>
parents: 9510
diff changeset
   347
            if ([orientations containsObject:@"LandscapeLeft"]) {
9cbd69cac7ed Fixed mismatching orientations for the window width and height on iOS when the window is created or the app is brought to the foreground, when SDL_HINT_ORIENTATIONS or SDL_WINDOW_FULLSCREEN is used.
Alex Szpakowski <slime73@gmail.com>
parents: 9510
diff changeset
   348
                orientationMask |= UIInterfaceOrientationMaskLandscapeLeft;
9cbd69cac7ed Fixed mismatching orientations for the window width and height on iOS when the window is created or the app is brought to the foreground, when SDL_HINT_ORIENTATIONS or SDL_WINDOW_FULLSCREEN is used.
Alex Szpakowski <slime73@gmail.com>
parents: 9510
diff changeset
   349
            }
9cbd69cac7ed Fixed mismatching orientations for the window width and height on iOS when the window is created or the app is brought to the foreground, when SDL_HINT_ORIENTATIONS or SDL_WINDOW_FULLSCREEN is used.
Alex Szpakowski <slime73@gmail.com>
parents: 9510
diff changeset
   350
            if ([orientations containsObject:@"LandscapeRight"]) {
9cbd69cac7ed Fixed mismatching orientations for the window width and height on iOS when the window is created or the app is brought to the foreground, when SDL_HINT_ORIENTATIONS or SDL_WINDOW_FULLSCREEN is used.
Alex Szpakowski <slime73@gmail.com>
parents: 9510
diff changeset
   351
                orientationMask |= UIInterfaceOrientationMaskLandscapeRight;
9cbd69cac7ed Fixed mismatching orientations for the window width and height on iOS when the window is created or the app is brought to the foreground, when SDL_HINT_ORIENTATIONS or SDL_WINDOW_FULLSCREEN is used.
Alex Szpakowski <slime73@gmail.com>
parents: 9510
diff changeset
   352
            }
9cbd69cac7ed Fixed mismatching orientations for the window width and height on iOS when the window is created or the app is brought to the foreground, when SDL_HINT_ORIENTATIONS or SDL_WINDOW_FULLSCREEN is used.
Alex Szpakowski <slime73@gmail.com>
parents: 9510
diff changeset
   353
            if ([orientations containsObject:@"Portrait"]) {
9cbd69cac7ed Fixed mismatching orientations for the window width and height on iOS when the window is created or the app is brought to the foreground, when SDL_HINT_ORIENTATIONS or SDL_WINDOW_FULLSCREEN is used.
Alex Szpakowski <slime73@gmail.com>
parents: 9510
diff changeset
   354
                orientationMask |= UIInterfaceOrientationMaskPortrait;
9cbd69cac7ed Fixed mismatching orientations for the window width and height on iOS when the window is created or the app is brought to the foreground, when SDL_HINT_ORIENTATIONS or SDL_WINDOW_FULLSCREEN is used.
Alex Szpakowski <slime73@gmail.com>
parents: 9510
diff changeset
   355
            }
9cbd69cac7ed Fixed mismatching orientations for the window width and height on iOS when the window is created or the app is brought to the foreground, when SDL_HINT_ORIENTATIONS or SDL_WINDOW_FULLSCREEN is used.
Alex Szpakowski <slime73@gmail.com>
parents: 9510
diff changeset
   356
            if ([orientations containsObject:@"PortraitUpsideDown"]) {
9cbd69cac7ed Fixed mismatching orientations for the window width and height on iOS when the window is created or the app is brought to the foreground, when SDL_HINT_ORIENTATIONS or SDL_WINDOW_FULLSCREEN is used.
Alex Szpakowski <slime73@gmail.com>
parents: 9510
diff changeset
   357
                orientationMask |= UIInterfaceOrientationMaskPortraitUpsideDown;
9cbd69cac7ed Fixed mismatching orientations for the window width and height on iOS when the window is created or the app is brought to the foreground, when SDL_HINT_ORIENTATIONS or SDL_WINDOW_FULLSCREEN is used.
Alex Szpakowski <slime73@gmail.com>
parents: 9510
diff changeset
   358
            }
9cbd69cac7ed Fixed mismatching orientations for the window width and height on iOS when the window is created or the app is brought to the foreground, when SDL_HINT_ORIENTATIONS or SDL_WINDOW_FULLSCREEN is used.
Alex Szpakowski <slime73@gmail.com>
parents: 9510
diff changeset
   359
        }
9cbd69cac7ed Fixed mismatching orientations for the window width and height on iOS when the window is created or the app is brought to the foreground, when SDL_HINT_ORIENTATIONS or SDL_WINDOW_FULLSCREEN is used.
Alex Szpakowski <slime73@gmail.com>
parents: 9510
diff changeset
   360
9cbd69cac7ed Fixed mismatching orientations for the window width and height on iOS when the window is created or the app is brought to the foreground, when SDL_HINT_ORIENTATIONS or SDL_WINDOW_FULLSCREEN is used.
Alex Szpakowski <slime73@gmail.com>
parents: 9510
diff changeset
   361
        if (orientationMask == 0 && (window->flags & SDL_WINDOW_RESIZABLE)) {
9cbd69cac7ed Fixed mismatching orientations for the window width and height on iOS when the window is created or the app is brought to the foreground, when SDL_HINT_ORIENTATIONS or SDL_WINDOW_FULLSCREEN is used.
Alex Szpakowski <slime73@gmail.com>
parents: 9510
diff changeset
   362
            /* any orientation is okay. */
9cbd69cac7ed Fixed mismatching orientations for the window width and height on iOS when the window is created or the app is brought to the foreground, when SDL_HINT_ORIENTATIONS or SDL_WINDOW_FULLSCREEN is used.
Alex Szpakowski <slime73@gmail.com>
parents: 9510
diff changeset
   363
            orientationMask = UIInterfaceOrientationMaskAll;
9cbd69cac7ed Fixed mismatching orientations for the window width and height on iOS when the window is created or the app is brought to the foreground, when SDL_HINT_ORIENTATIONS or SDL_WINDOW_FULLSCREEN is used.
Alex Szpakowski <slime73@gmail.com>
parents: 9510
diff changeset
   364
        }
9cbd69cac7ed Fixed mismatching orientations for the window width and height on iOS when the window is created or the app is brought to the foreground, when SDL_HINT_ORIENTATIONS or SDL_WINDOW_FULLSCREEN is used.
Alex Szpakowski <slime73@gmail.com>
parents: 9510
diff changeset
   365
9cbd69cac7ed Fixed mismatching orientations for the window width and height on iOS when the window is created or the app is brought to the foreground, when SDL_HINT_ORIENTATIONS or SDL_WINDOW_FULLSCREEN is used.
Alex Szpakowski <slime73@gmail.com>
parents: 9510
diff changeset
   366
        if (orientationMask == 0) {
9cbd69cac7ed Fixed mismatching orientations for the window width and height on iOS when the window is created or the app is brought to the foreground, when SDL_HINT_ORIENTATIONS or SDL_WINDOW_FULLSCREEN is used.
Alex Szpakowski <slime73@gmail.com>
parents: 9510
diff changeset
   367
            if (window->w >= window->h) {
9cbd69cac7ed Fixed mismatching orientations for the window width and height on iOS when the window is created or the app is brought to the foreground, when SDL_HINT_ORIENTATIONS or SDL_WINDOW_FULLSCREEN is used.
Alex Szpakowski <slime73@gmail.com>
parents: 9510
diff changeset
   368
                orientationMask |= UIInterfaceOrientationMaskLandscape;
9cbd69cac7ed Fixed mismatching orientations for the window width and height on iOS when the window is created or the app is brought to the foreground, when SDL_HINT_ORIENTATIONS or SDL_WINDOW_FULLSCREEN is used.
Alex Szpakowski <slime73@gmail.com>
parents: 9510
diff changeset
   369
            }
9cbd69cac7ed Fixed mismatching orientations for the window width and height on iOS when the window is created or the app is brought to the foreground, when SDL_HINT_ORIENTATIONS or SDL_WINDOW_FULLSCREEN is used.
Alex Szpakowski <slime73@gmail.com>
parents: 9510
diff changeset
   370
            if (window->h >= window->w) {
9cbd69cac7ed Fixed mismatching orientations for the window width and height on iOS when the window is created or the app is brought to the foreground, when SDL_HINT_ORIENTATIONS or SDL_WINDOW_FULLSCREEN is used.
Alex Szpakowski <slime73@gmail.com>
parents: 9510
diff changeset
   371
                orientationMask |= (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown);
9cbd69cac7ed Fixed mismatching orientations for the window width and height on iOS when the window is created or the app is brought to the foreground, when SDL_HINT_ORIENTATIONS or SDL_WINDOW_FULLSCREEN is used.
Alex Szpakowski <slime73@gmail.com>
parents: 9510
diff changeset
   372
            }
9cbd69cac7ed Fixed mismatching orientations for the window width and height on iOS when the window is created or the app is brought to the foreground, when SDL_HINT_ORIENTATIONS or SDL_WINDOW_FULLSCREEN is used.
Alex Szpakowski <slime73@gmail.com>
parents: 9510
diff changeset
   373
        }
9cbd69cac7ed Fixed mismatching orientations for the window width and height on iOS when the window is created or the app is brought to the foreground, when SDL_HINT_ORIENTATIONS or SDL_WINDOW_FULLSCREEN is used.
Alex Szpakowski <slime73@gmail.com>
parents: 9510
diff changeset
   374
9cbd69cac7ed Fixed mismatching orientations for the window width and height on iOS when the window is created or the app is brought to the foreground, when SDL_HINT_ORIENTATIONS or SDL_WINDOW_FULLSCREEN is used.
Alex Szpakowski <slime73@gmail.com>
parents: 9510
diff changeset
   375
        /* Don't allow upside-down orientation on the phone, so answering calls is in the natural orientation */
9cbd69cac7ed Fixed mismatching orientations for the window width and height on iOS when the window is created or the app is brought to the foreground, when SDL_HINT_ORIENTATIONS or SDL_WINDOW_FULLSCREEN is used.
Alex Szpakowski <slime73@gmail.com>
parents: 9510
diff changeset
   376
        if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
9cbd69cac7ed Fixed mismatching orientations for the window width and height on iOS when the window is created or the app is brought to the foreground, when SDL_HINT_ORIENTATIONS or SDL_WINDOW_FULLSCREEN is used.
Alex Szpakowski <slime73@gmail.com>
parents: 9510
diff changeset
   377
            orientationMask &= ~UIInterfaceOrientationMaskPortraitUpsideDown;
9cbd69cac7ed Fixed mismatching orientations for the window width and height on iOS when the window is created or the app is brought to the foreground, when SDL_HINT_ORIENTATIONS or SDL_WINDOW_FULLSCREEN is used.
Alex Szpakowski <slime73@gmail.com>
parents: 9510
diff changeset
   378
        }
9cbd69cac7ed Fixed mismatching orientations for the window width and height on iOS when the window is created or the app is brought to the foreground, when SDL_HINT_ORIENTATIONS or SDL_WINDOW_FULLSCREEN is used.
Alex Szpakowski <slime73@gmail.com>
parents: 9510
diff changeset
   379
    }
9cbd69cac7ed Fixed mismatching orientations for the window width and height on iOS when the window is created or the app is brought to the foreground, when SDL_HINT_ORIENTATIONS or SDL_WINDOW_FULLSCREEN is used.
Alex Szpakowski <slime73@gmail.com>
parents: 9510
diff changeset
   380
9cbd69cac7ed Fixed mismatching orientations for the window width and height on iOS when the window is created or the app is brought to the foreground, when SDL_HINT_ORIENTATIONS or SDL_WINDOW_FULLSCREEN is used.
Alex Szpakowski <slime73@gmail.com>
parents: 9510
diff changeset
   381
    return orientationMask;
9cbd69cac7ed Fixed mismatching orientations for the window width and height on iOS when the window is created or the app is brought to the foreground, when SDL_HINT_ORIENTATIONS or SDL_WINDOW_FULLSCREEN is used.
Alex Szpakowski <slime73@gmail.com>
parents: 9510
diff changeset
   382
}
9cbd69cac7ed Fixed mismatching orientations for the window width and height on iOS when the window is created or the app is brought to the foreground, when SDL_HINT_ORIENTATIONS or SDL_WINDOW_FULLSCREEN is used.
Alex Szpakowski <slime73@gmail.com>
parents: 9510
diff changeset
   383
6342
ac83b73f0edd Created a header file for system dependent API functions, and added SDL_iPhoneSetAnimationCallback()
Sam Lantinga <slouken@libsdl.org>
parents: 6292
diff changeset
   384
int
ac83b73f0edd Created a header file for system dependent API functions, and added SDL_iPhoneSetAnimationCallback()
Sam Lantinga <slouken@libsdl.org>
parents: 6292
diff changeset
   385
SDL_iPhoneSetAnimationCallback(SDL_Window * window, int interval, void (*callback)(void*), void *callbackParam)
ac83b73f0edd Created a header file for system dependent API functions, and added SDL_iPhoneSetAnimationCallback()
Sam Lantinga <slouken@libsdl.org>
parents: 6292
diff changeset
   386
{
9510
e19faa3b5d88 Updated the iOS backend code to use Objective-C's automatic reference counting (ARC).
Alex Szpakowski <slime73@gmail.com>
parents: 9506
diff changeset
   387
    @autoreleasepool {
e19faa3b5d88 Updated the iOS backend code to use Objective-C's automatic reference counting (ARC).
Alex Szpakowski <slime73@gmail.com>
parents: 9506
diff changeset
   388
        SDL_WindowData *data = window ? (__bridge SDL_WindowData *)window->driverdata : nil;
6342
ac83b73f0edd Created a header file for system dependent API functions, and added SDL_iPhoneSetAnimationCallback()
Sam Lantinga <slouken@libsdl.org>
parents: 6292
diff changeset
   389
9510
e19faa3b5d88 Updated the iOS backend code to use Objective-C's automatic reference counting (ARC).
Alex Szpakowski <slime73@gmail.com>
parents: 9506
diff changeset
   390
        if (!data || !data.view) {
e19faa3b5d88 Updated the iOS backend code to use Objective-C's automatic reference counting (ARC).
Alex Szpakowski <slime73@gmail.com>
parents: 9506
diff changeset
   391
            return SDL_SetError("Invalid window or view not set");
e19faa3b5d88 Updated the iOS backend code to use Objective-C's automatic reference counting (ARC).
Alex Szpakowski <slime73@gmail.com>
parents: 9506
diff changeset
   392
        }
6342
ac83b73f0edd Created a header file for system dependent API functions, and added SDL_iPhoneSetAnimationCallback()
Sam Lantinga <slouken@libsdl.org>
parents: 6292
diff changeset
   393
9510
e19faa3b5d88 Updated the iOS backend code to use Objective-C's automatic reference counting (ARC).
Alex Szpakowski <slime73@gmail.com>
parents: 9506
diff changeset
   394
        [data.view setAnimationCallback:interval callback:callback callbackParam:callbackParam];
9506
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9505
diff changeset
   395
    }
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9505
diff changeset
   396
6342
ac83b73f0edd Created a header file for system dependent API functions, and added SDL_iPhoneSetAnimationCallback()
Sam Lantinga <slouken@libsdl.org>
parents: 6292
diff changeset
   397
    return 0;
ac83b73f0edd Created a header file for system dependent API functions, and added SDL_iPhoneSetAnimationCallback()
Sam Lantinga <slouken@libsdl.org>
parents: 6292
diff changeset
   398
}
ac83b73f0edd Created a header file for system dependent API functions, and added SDL_iPhoneSetAnimationCallback()
Sam Lantinga <slouken@libsdl.org>
parents: 6292
diff changeset
   399
6044
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 6014
diff changeset
   400
#endif /* SDL_VIDEO_DRIVER_UIKIT */
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 6014
diff changeset
   401
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   402
/* vi: set ts=4 sw=4 expandtab: */