src/video/uikit/SDL_uikitwindow.m
author Sam Lantinga <slouken@libsdl.org>
Tue, 08 Nov 2011 00:17:41 -0500
changeset 6064 498e0234dfe6
parent 6044 35448a5ea044
child 6073 9738f2a8eee4
permissions -rw-r--r--
To answer the FIXME, no, we shouldn't force this. The fullscreen flag implies borderless behavior even though the flag isn't set on the window (in case fullscreen is toggled)
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
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5529
diff changeset
     3
  Copyright (C) 1997-2011 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
*/
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    21
#include "SDL_config.h"
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"
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    36
#include "SDL_uikitwindow.h"
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    37
#import "SDL_uikitappdelegate.h"
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    38
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    39
#import "SDL_uikitopenglview.h"
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    40
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    41
#include <Foundation/Foundation.h>
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    42
5520
09b500e0656d Added orientation rotation for iOS.
Ryan C. Gordon <icculus@icculus.org>
parents: 5518
diff changeset
    43
09b500e0656d Added orientation rotation for iOS.
Ryan C. Gordon <icculus@icculus.org>
parents: 5518
diff changeset
    44
09b500e0656d Added orientation rotation for iOS.
Ryan C. Gordon <icculus@icculus.org>
parents: 5518
diff changeset
    45
4446
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 3685
diff changeset
    46
static int SetupWindowData(_THIS, SDL_Window *window, UIWindow *uiwindow, SDL_bool created)
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 3685
diff changeset
    47
{
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
    48
    SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
4446
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 3685
diff changeset
    49
    UIScreen *uiscreen = (UIScreen *) display->driverdata;
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    50
    SDL_WindowData *data;
6001
3ae3d1e58d59 Cleanup out trailing whitespace in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 5640
diff changeset
    51
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    52
    /* Allocate the window data */
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    53
    data = (SDL_WindowData *)SDL_malloc(sizeof(*data));
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    54
    if (!data) {
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    55
        SDL_OutOfMemory();
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    56
        return -1;
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    57
    }
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    58
    data->uiwindow = uiwindow;
5520
09b500e0656d Added orientation rotation for iOS.
Ryan C. Gordon <icculus@icculus.org>
parents: 5518
diff changeset
    59
    data->viewcontroller = nil;
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
    60
    data->view = nil;
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
    61
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    62
    /* 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
    63
    {
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    64
        window->x = 0;
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    65
        window->y = 0;
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    66
        window->w = (int)uiwindow.frame.size.width;
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    67
        window->h = (int)uiwindow.frame.size.height;
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    68
    }
6001
3ae3d1e58d59 Cleanup out trailing whitespace in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 5640
diff changeset
    69
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
    70
    window->driverdata = data;
5520
09b500e0656d Added orientation rotation for iOS.
Ryan C. Gordon <icculus@icculus.org>
parents: 5518
diff changeset
    71
09b500e0656d Added orientation rotation for iOS.
Ryan C. Gordon <icculus@icculus.org>
parents: 5518
diff changeset
    72
    window->flags |= SDL_WINDOW_SHOWN;            /* only one window on iOS, always shown */
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    73
4446
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 3685
diff changeset
    74
    // SDL_WINDOW_BORDERLESS controls whether status bar is hidden.
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 3685
diff changeset
    75
    // This is only set if the window is on the main screen. Other screens
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 3685
diff changeset
    76
    //  just force the window to have the borderless flag.
5518
f84dd424d514 iOS: Report both landscape and portrait orientation as display modes.
Ryan C. Gordon <icculus@icculus.org>
parents: 5262
diff changeset
    77
    if ([UIScreen mainScreen] != uiscreen) {
f84dd424d514 iOS: Report both landscape and portrait orientation as display modes.
Ryan C. Gordon <icculus@icculus.org>
parents: 5262
diff changeset
    78
        window->flags &= ~SDL_WINDOW_RESIZABLE;  // window is NEVER resizeable
f84dd424d514 iOS: Report both landscape and portrait orientation as display modes.
Ryan C. Gordon <icculus@icculus.org>
parents: 5262
diff changeset
    79
        window->flags &= ~SDL_WINDOW_INPUT_FOCUS;  // never has input focus
5520
09b500e0656d Added orientation rotation for iOS.
Ryan C. Gordon <icculus@icculus.org>
parents: 5518
diff changeset
    80
        window->flags |= SDL_WINDOW_BORDERLESS;  // never has a status bar.
5518
f84dd424d514 iOS: Report both landscape and portrait orientation as display modes.
Ryan C. Gordon <icculus@icculus.org>
parents: 5262
diff changeset
    81
    } else {
f84dd424d514 iOS: Report both landscape and portrait orientation as display modes.
Ryan C. Gordon <icculus@icculus.org>
parents: 5262
diff changeset
    82
        window->flags |= SDL_WINDOW_INPUT_FOCUS;  // always has input focus
f84dd424d514 iOS: Report both landscape and portrait orientation as display modes.
Ryan C. Gordon <icculus@icculus.org>
parents: 5262
diff changeset
    83
6064
498e0234dfe6 To answer the FIXME, no, we shouldn't force this. The fullscreen flag implies borderless behavior even though the flag isn't set on the window (in case fullscreen is toggled)
Sam Lantinga <slouken@libsdl.org>
parents: 6044
diff changeset
    84
        if (window->flags & (SDL_WINDOW_FULLSCREEN|SDL_WINDOW_BORDERLESS)) {
4446
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 3685
diff changeset
    85
            [UIApplication sharedApplication].statusBarHidden = YES;
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 3685
diff changeset
    86
        } else {
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 3685
diff changeset
    87
            [UIApplication sharedApplication].statusBarHidden = NO;
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 3685
diff changeset
    88
        }
5518
f84dd424d514 iOS: Report both landscape and portrait orientation as display modes.
Ryan C. Gordon <icculus@icculus.org>
parents: 5262
diff changeset
    89
6044
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 6014
diff changeset
    90
        //const UIDeviceOrientation o = [[UIDevice currentDevice] orientation];
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 6014
diff changeset
    91
        //const BOOL landscape = (o == UIDeviceOrientationLandscapeLeft) ||
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 6014
diff changeset
    92
        //                           (o == UIDeviceOrientationLandscapeRight);
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 6014
diff changeset
    93
        //const BOOL rotate = ( ((window->w > window->h) && (!landscape)) ||
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 6014
diff changeset
    94
        //                      ((window->w < window->h) && (landscape)) );
5518
f84dd424d514 iOS: Report both landscape and portrait orientation as display modes.
Ryan C. Gordon <icculus@icculus.org>
parents: 5262
diff changeset
    95
5529
8c0d15077360 Some more iOS orientation rotation fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 5527
diff changeset
    96
        // The View Controller will handle rotating the view when the
8c0d15077360 Some more iOS orientation rotation fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 5527
diff changeset
    97
        //  device orientation changes. This will trigger resize events, if
8c0d15077360 Some more iOS orientation rotation fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 5527
diff changeset
    98
        //  appropriate.
8c0d15077360 Some more iOS orientation rotation fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 5527
diff changeset
    99
        SDL_uikitviewcontroller *controller;
8c0d15077360 Some more iOS orientation rotation fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 5527
diff changeset
   100
        controller = [SDL_uikitviewcontroller alloc];
8c0d15077360 Some more iOS orientation rotation fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 5527
diff changeset
   101
        data->viewcontroller = [controller initWithSDLWindow:window];
8c0d15077360 Some more iOS orientation rotation fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 5527
diff changeset
   102
        [data->viewcontroller setTitle:@"SDL App"];  // !!! FIXME: hook up SDL_SetWindowTitle()
8c0d15077360 Some more iOS orientation rotation fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 5527
diff changeset
   103
        // !!! FIXME: if (rotate), force a "resize" right at the start
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
   104
    }
5518
f84dd424d514 iOS: Report both landscape and portrait orientation as display modes.
Ryan C. Gordon <icculus@icculus.org>
parents: 5262
diff changeset
   105
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   106
    return 0;
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   107
}
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   108
5056
8b7988f42fcb Added the ability to get the UIKit window through the SDL API.
Sam Lantinga <slouken@libsdl.org>
parents: 4446
diff changeset
   109
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
   110
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
   111
{
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
   112
    SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
4446
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 3685
diff changeset
   113
    UIScreen *uiscreen = (UIScreen *) display->driverdata;
5529
8c0d15077360 Some more iOS orientation rotation fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 5527
diff changeset
   114
    const BOOL external = ([UIScreen mainScreen] != uiscreen);
4446
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 3685
diff changeset
   115
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 3685
diff changeset
   116
    // SDL currently puts this window at the start of display's linked list. We rely on this.
5251
1b0de3574c58 Fixed compile in Xcode
Sam Lantinga <slouken@libsdl.org>
parents: 5249
diff changeset
   117
    SDL_assert(_this->windows == window);
4446
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 3685
diff changeset
   118
5520
09b500e0656d Added orientation rotation for iOS.
Ryan C. Gordon <icculus@icculus.org>
parents: 5518
diff changeset
   119
    /* We currently only handle a single window per display on iOS */
4446
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 3685
diff changeset
   120
    if (window->next != NULL) {
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 3685
diff changeset
   121
        SDL_SetError("Only one window allowed per display.");
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
   122
        return -1;
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
   123
    }
4446
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 3685
diff changeset
   124
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 3685
diff changeset
   125
    // Non-mainscreen windows must be force to borderless, as there's no
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 3685
diff changeset
   126
    //  status bar there, and we want to get the right dimensions later in
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 3685
diff changeset
   127
    //  this function.
5529
8c0d15077360 Some more iOS orientation rotation fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 5527
diff changeset
   128
    if (external) {
4446
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 3685
diff changeset
   129
        window->flags |= SDL_WINDOW_BORDERLESS;
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 3685
diff changeset
   130
    }
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 3685
diff changeset
   131
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 3685
diff changeset
   132
    // If monitor has a resolution of 0x0 (hasn't been explicitly set by the
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 3685
diff changeset
   133
    //  user, so it's in standby), try to force the display to a resolution
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 3685
diff changeset
   134
    //  that most closely matches the desired window size.
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 3685
diff changeset
   135
    if (SDL_UIKit_supports_multiple_displays) {
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 3685
diff changeset
   136
        const CGSize origsize = [[uiscreen currentMode] size];
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 3685
diff changeset
   137
        if ((origsize.width == 0.0f) && (origsize.height == 0.0f)) {
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 3685
diff changeset
   138
            if (display->num_display_modes == 0) {
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 3685
diff changeset
   139
                _this->GetDisplayModes(_this, display);
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 3685
diff changeset
   140
            }
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 3685
diff changeset
   141
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 3685
diff changeset
   142
            int i;
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 3685
diff changeset
   143
            const SDL_DisplayMode *bestmode = NULL;
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 3685
diff changeset
   144
            for (i = display->num_display_modes; i >= 0; i--) {
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 3685
diff changeset
   145
                const SDL_DisplayMode *mode = &display->display_modes[i];
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 3685
diff changeset
   146
                if ((mode->w >= window->w) && (mode->h >= window->h))
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 3685
diff changeset
   147
                    bestmode = mode;
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 3685
diff changeset
   148
            }
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 3685
diff changeset
   149
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 3685
diff changeset
   150
            if (bestmode) {
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 3685
diff changeset
   151
                UIScreenMode *uimode = (UIScreenMode *) bestmode->driverdata;
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 3685
diff changeset
   152
                [uiscreen setCurrentMode:uimode];
5997
69875bbf83d8 Fix up some retain/release issues with UIScreenMode objects.
Ryan C. Gordon <icculus@icculus.org>
parents: 5640
diff changeset
   153
69875bbf83d8 Fix up some retain/release issues with UIScreenMode objects.
Ryan C. Gordon <icculus@icculus.org>
parents: 5640
diff changeset
   154
                // desktop_mode doesn't change here (the higher level will
69875bbf83d8 Fix up some retain/release issues with UIScreenMode objects.
Ryan C. Gordon <icculus@icculus.org>
parents: 5640
diff changeset
   155
                //  use it to set all the screens back to their defaults
69875bbf83d8 Fix up some retain/release issues with UIScreenMode objects.
Ryan C. Gordon <icculus@icculus.org>
parents: 5640
diff changeset
   156
                //  upon window destruction, SDL_Quit(), etc.
69875bbf83d8 Fix up some retain/release issues with UIScreenMode objects.
Ryan C. Gordon <icculus@icculus.org>
parents: 5640
diff changeset
   157
                [((UIScreenMode *) display->current_mode.driverdata) release];
4446
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 3685
diff changeset
   158
                display->current_mode = *bestmode;
5997
69875bbf83d8 Fix up some retain/release issues with UIScreenMode objects.
Ryan C. Gordon <icculus@icculus.org>
parents: 5640
diff changeset
   159
                [((UIScreenMode *) display->current_mode.driverdata) retain];
4446
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 3685
diff changeset
   160
            }
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 3685
diff changeset
   161
        }
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 3685
diff changeset
   162
    }
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 3685
diff changeset
   163
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
   164
    /* ignore the size user requested, and make a fullscreen window */
4446
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 3685
diff changeset
   165
    // !!! FIXME: can we have a smaller view?
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 3685
diff changeset
   166
    UIWindow *uiwindow = [UIWindow alloc];
6064
498e0234dfe6 To answer the FIXME, no, we shouldn't force this. The fullscreen flag implies borderless behavior even though the flag isn't set on the window (in case fullscreen is toggled)
Sam Lantinga <slouken@libsdl.org>
parents: 6044
diff changeset
   167
    if (window->flags & (SDL_WINDOW_FULLSCREEN|SDL_WINDOW_BORDERLESS))
4446
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 3685
diff changeset
   168
        uiwindow = [uiwindow initWithFrame:[uiscreen bounds]];
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 3685
diff changeset
   169
    else
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 3685
diff changeset
   170
        uiwindow = [uiwindow initWithFrame:[uiscreen applicationFrame]];
6001
3ae3d1e58d59 Cleanup out trailing whitespace in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 5640
diff changeset
   171
5529
8c0d15077360 Some more iOS orientation rotation fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 5527
diff changeset
   172
    // put the window on an external display if appropriate. This implicitly
8c0d15077360 Some more iOS orientation rotation fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 5527
diff changeset
   173
    //  does [uiwindow setframe:[uiscreen bounds]], so don't do it on the
8c0d15077360 Some more iOS orientation rotation fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 5527
diff changeset
   174
    //  main display, where we land by default, as that would eat the
8c0d15077360 Some more iOS orientation rotation fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 5527
diff changeset
   175
    //  status bar real estate.
8c0d15077360 Some more iOS orientation rotation fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 5527
diff changeset
   176
    if (external) {
4446
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 3685
diff changeset
   177
        [uiwindow setScreen:uiscreen];
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 3685
diff changeset
   178
    }
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 3685
diff changeset
   179
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
   180
    if (SetupWindowData(_this, window, uiwindow, SDL_TRUE) < 0) {
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   181
        [uiwindow release];
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   182
        return -1;
6001
3ae3d1e58d59 Cleanup out trailing whitespace in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 5640
diff changeset
   183
    }
3ae3d1e58d59 Cleanup out trailing whitespace in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 5640
diff changeset
   184
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
   185
    return 1;
6001
3ae3d1e58d59 Cleanup out trailing whitespace in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 5640
diff changeset
   186
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   187
}
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   188
5056
8b7988f42fcb Added the ability to get the UIKit window through the SDL API.
Sam Lantinga <slouken@libsdl.org>
parents: 4446
diff changeset
   189
void
6003
fddf81967e2d Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 6001
diff changeset
   190
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
   191
{
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
   192
    SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
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
   193
    if (data) {
5520
09b500e0656d Added orientation rotation for iOS.
Ryan C. Gordon <icculus@icculus.org>
parents: 5518
diff changeset
   194
        [data->viewcontroller release];
4446
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 3685
diff changeset
   195
        [data->uiwindow release];
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 3685
diff changeset
   196
        SDL_free(data);
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 3685
diff changeset
   197
        window->driverdata = NULL;
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
   198
    }
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   199
}
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   200
5056
8b7988f42fcb Added the ability to get the UIKit window through the SDL API.
Sam Lantinga <slouken@libsdl.org>
parents: 4446
diff changeset
   201
SDL_bool
8b7988f42fcb Added the ability to get the UIKit window through the SDL API.
Sam Lantinga <slouken@libsdl.org>
parents: 4446
diff changeset
   202
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
   203
{
8b7988f42fcb Added the ability to get the UIKit window through the SDL API.
Sam Lantinga <slouken@libsdl.org>
parents: 4446
diff changeset
   204
    UIWindow *uiwindow = ((SDL_WindowData *) window->driverdata)->uiwindow;
8b7988f42fcb Added the ability to get the UIKit window through the SDL API.
Sam Lantinga <slouken@libsdl.org>
parents: 4446
diff changeset
   205
8b7988f42fcb Added the ability to get the UIKit window through the SDL API.
Sam Lantinga <slouken@libsdl.org>
parents: 4446
diff changeset
   206
    if (info->version.major <= SDL_MAJOR_VERSION) {
8b7988f42fcb Added the ability to get the UIKit window through the SDL API.
Sam Lantinga <slouken@libsdl.org>
parents: 4446
diff changeset
   207
        info->subsystem = SDL_SYSWM_UIKIT;
8b7988f42fcb Added the ability to get the UIKit window through the SDL API.
Sam Lantinga <slouken@libsdl.org>
parents: 4446
diff changeset
   208
        info->info.uikit.window = uiwindow;
8b7988f42fcb Added the ability to get the UIKit window through the SDL API.
Sam Lantinga <slouken@libsdl.org>
parents: 4446
diff changeset
   209
        return SDL_TRUE;
8b7988f42fcb Added the ability to get the UIKit window through the SDL API.
Sam Lantinga <slouken@libsdl.org>
parents: 4446
diff changeset
   210
    } else {
8b7988f42fcb Added the ability to get the UIKit window through the SDL API.
Sam Lantinga <slouken@libsdl.org>
parents: 4446
diff changeset
   211
        SDL_SetError("Application not compiled with SDL %d.%d\n",
8b7988f42fcb Added the ability to get the UIKit window through the SDL API.
Sam Lantinga <slouken@libsdl.org>
parents: 4446
diff changeset
   212
                     SDL_MAJOR_VERSION, SDL_MINOR_VERSION);
8b7988f42fcb Added the ability to get the UIKit window through the SDL API.
Sam Lantinga <slouken@libsdl.org>
parents: 4446
diff changeset
   213
        return SDL_FALSE;
8b7988f42fcb Added the ability to get the UIKit window through the SDL API.
Sam Lantinga <slouken@libsdl.org>
parents: 4446
diff changeset
   214
    }
8b7988f42fcb Added the ability to get the UIKit window through the SDL API.
Sam Lantinga <slouken@libsdl.org>
parents: 4446
diff changeset
   215
}
8b7988f42fcb Added the ability to get the UIKit window through the SDL API.
Sam Lantinga <slouken@libsdl.org>
parents: 4446
diff changeset
   216
6044
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 6014
diff changeset
   217
#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
   218
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   219
/* vi: set ts=4 sw=4 expandtab: */