src/video/uikit/SDL_uikitvideo.m
author Alex Szpakowski <slime73@gmail.com>
Wed, 23 Jul 2014 21:55:42 -0300
branchiOS-improvements
changeset 9502 933ed557b7c1
parent 9488 f15520430c94
child 9505 6fc615dfc93f
permissions -rw-r--r--
Fixed SDL_SetWindowFullscreen on iOS for the last time, hopefully.

Fixed iOS version checking code.
slouken@2765
     1
/*
slouken@5535
     2
  Simple DirectMedia Layer
slouken@8149
     3
  Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
slouken@2765
     4
slouken@5535
     5
  This software is provided 'as-is', without any express or implied
slouken@5535
     6
  warranty.  In no event will the authors be held liable for any damages
slouken@5535
     7
  arising from the use of this software.
slouken@2765
     8
slouken@5535
     9
  Permission is granted to anyone to use this software for any purpose,
slouken@5535
    10
  including commercial applications, and to alter it and redistribute it
slouken@5535
    11
  freely, subject to the following restrictions:
slouken@2765
    12
slouken@5535
    13
  1. The origin of this software must not be misrepresented; you must not
slouken@5535
    14
     claim that you wrote the original software. If you use this software
slouken@5535
    15
     in a product, an acknowledgment in the product documentation would be
slouken@5535
    16
     appreciated but is not required.
slouken@5535
    17
  2. Altered source versions must be plainly marked as such, and must not be
slouken@5535
    18
     misrepresented as being the original software.
slouken@5535
    19
  3. This notice may not be removed or altered from any source distribution.
slouken@2765
    20
*/
icculus@8093
    21
#include "../../SDL_internal.h"
slouken@6044
    22
slouken@6044
    23
#if SDL_VIDEO_DRIVER_UIKIT
icculus@4443
    24
icculus@4443
    25
#import <UIKit/UIKit.h>
icculus@4443
    26
slouken@2765
    27
#include "SDL_video.h"
slouken@2765
    28
#include "SDL_mouse.h"
slouken@2765
    29
#include "../SDL_sysvideo.h"
slouken@2765
    30
#include "../SDL_pixels_c.h"
slouken@2765
    31
#include "../../events/SDL_events_c.h"
slouken@2765
    32
slouken@2765
    33
#include "SDL_uikitvideo.h"
slouken@2765
    34
#include "SDL_uikitevents.h"
slouken@6518
    35
#include "SDL_uikitmodes.h"
slouken@2765
    36
#include "SDL_uikitwindow.h"
slouken@2765
    37
#include "SDL_uikitopengles.h"
slouken@2765
    38
slouken@2765
    39
#define UIKITVID_DRIVER_NAME "uikit"
slouken@2765
    40
slouken@2765
    41
/* Initialization/Query functions */
slouken@2765
    42
static int UIKit_VideoInit(_THIS);
slouken@2765
    43
static void UIKit_VideoQuit(_THIS);
slouken@2765
    44
slouken@2765
    45
/* DUMMY driver bootstrap functions */
slouken@2765
    46
slouken@2765
    47
static int
slouken@2765
    48
UIKit_Available(void)
slouken@2765
    49
{
kees@6003
    50
    return 1;
slouken@2765
    51
}
slouken@2765
    52
slouken@2765
    53
static void UIKit_DeleteDevice(SDL_VideoDevice * device)
slouken@2765
    54
{
slouken@2765
    55
    SDL_free(device);
slouken@2765
    56
}
slouken@2765
    57
slouken@2765
    58
static SDL_VideoDevice *
slouken@2765
    59
UIKit_CreateDevice(int devindex)
slouken@2765
    60
{
slouken@2765
    61
    SDL_VideoDevice *device;
slouken@2765
    62
slouken@2765
    63
    /* Initialize all variables that we clean on shutdown */
slouken@2765
    64
    device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
slouken@2765
    65
    if (!device) {
slouken@7719
    66
        SDL_free(device);
icculus@7037
    67
        SDL_OutOfMemory();
slouken@2765
    68
        return (0);
slouken@2765
    69
    }
slouken@2765
    70
slouken@2765
    71
    /* Set the function pointers */
slouken@2765
    72
    device->VideoInit = UIKit_VideoInit;
slouken@2765
    73
    device->VideoQuit = UIKit_VideoQuit;
icculus@4443
    74
    device->GetDisplayModes = UIKit_GetDisplayModes;
slouken@2765
    75
    device->SetDisplayMode = UIKit_SetDisplayMode;
slouken@2765
    76
    device->PumpEvents = UIKit_PumpEvents;
slouken@5131
    77
    device->CreateWindow = UIKit_CreateWindow;
slouken@6379
    78
    device->ShowWindow = UIKit_ShowWindow;
slouken@6379
    79
    device->HideWindow = UIKit_HideWindow;
icculus@6419
    80
    device->RaiseWindow = UIKit_RaiseWindow;
slouken@6073
    81
    device->SetWindowFullscreen = UIKit_SetWindowFullscreen;
slouken@5131
    82
    device->DestroyWindow = UIKit_DestroyWindow;
slouken@5056
    83
    device->GetWindowWMInfo = UIKit_GetWindowWMInfo;
kees@6001
    84
icculus@6422
    85
    /* !!! FIXME: implement SetWindowBordered */
icculus@6422
    86
urkle@7111
    87
#if SDL_IPHONE_KEYBOARD
philipp@7135
    88
    device->HasScreenKeyboardSupport = UIKit_HasScreenKeyboardSupport;
philipp@7135
    89
    device->ShowScreenKeyboard = UIKit_ShowScreenKeyboard;
philipp@7135
    90
    device->HideScreenKeyboard = UIKit_HideScreenKeyboard;
philipp@7135
    91
    device->IsScreenKeyboardShown = UIKit_IsScreenKeyboardShown;
slouken@7962
    92
    device->SetTextInputRect = UIKit_SetTextInputRect;
urkle@7111
    93
#endif
kees@6001
    94
slouken@5131
    95
    /* OpenGL (ES) functions */
slime73@9488
    96
    device->GL_MakeCurrent      = UIKit_GL_MakeCurrent;
slime73@9488
    97
    device->GL_GetDrawableSize  = UIKit_GL_GetDrawableSize;
slime73@9488
    98
    device->GL_SwapWindow       = UIKit_GL_SwapWindow;
slouken@5131
    99
    device->GL_CreateContext    = UIKit_GL_CreateContext;
slouken@5131
   100
    device->GL_DeleteContext    = UIKit_GL_DeleteContext;
slouken@5131
   101
    device->GL_GetProcAddress   = UIKit_GL_GetProcAddress;
slime73@9488
   102
    device->GL_LoadLibrary      = UIKit_GL_LoadLibrary;
slouken@5131
   103
    device->free = UIKit_DeleteDevice;
slouken@2765
   104
slouken@5131
   105
    device->gl_config.accelerated = 1;
slouken@5131
   106
slouken@2765
   107
    return device;
slouken@2765
   108
}
slouken@2765
   109
slouken@2765
   110
VideoBootStrap UIKIT_bootstrap = {
slouken@2765
   111
    UIKITVID_DRIVER_NAME, "SDL UIKit video driver",
slouken@2765
   112
    UIKit_Available, UIKit_CreateDevice
slouken@2765
   113
};
slouken@2765
   114
slouken@2765
   115
slouken@2765
   116
int
slouken@2765
   117
UIKit_VideoInit(_THIS)
slouken@2765
   118
{
icculus@4443
   119
    _this->gl_config.driver_loaded = 1;
slouken@2765
   120
slouken@6518
   121
    if (UIKit_InitModes(_this) < 0) {
tim@6267
   122
        return -1;
tim@6267
   123
    }
slouken@2765
   124
    return 0;
slouken@2765
   125
}
slouken@2765
   126
slouken@2765
   127
void
slouken@2765
   128
UIKit_VideoQuit(_THIS)
slouken@2765
   129
{
slouken@6518
   130
    UIKit_QuitModes(_this);
slouken@2765
   131
}
slouken@2765
   132
slime73@9502
   133
BOOL
slime73@9502
   134
UIKit_IsSystemVersionAtLeast(NSString *version)
slime73@9502
   135
{
slime73@9502
   136
    NSString *sysversion = [UIDevice currentDevice].systemVersion;
slime73@9502
   137
    return [sysversion compare:version options:NSNumericSearch] != NSOrderedAscending;
slime73@9502
   138
}
slime73@9502
   139
slime73@9502
   140
CGRect
slime73@9502
   141
UIKit_ComputeViewFrame(SDL_Window *window, UIScreen *screen)
slime73@9502
   142
{
slime73@9502
   143
    BOOL hasiOS7 = UIKit_IsSystemVersionAtLeast(@"7.0");
slime73@9502
   144
slime73@9502
   145
    if (hasiOS7 || (window->flags & (SDL_WINDOW_BORDERLESS|SDL_WINDOW_FULLSCREEN))) {
slime73@9502
   146
        /* The view should always show behind the status bar in iOS 7+. */
slime73@9502
   147
        return screen.bounds;
slime73@9502
   148
    } else {
slime73@9502
   149
        return screen.applicationFrame;
slime73@9502
   150
    }
slime73@9502
   151
}
slime73@9502
   152
slouken@6616
   153
/*
slouken@6616
   154
 * iOS log support.
slouken@6616
   155
 *
slouken@6616
   156
 * This doesn't really have aything to do with the interfaces of the SDL video
slouken@6616
   157
 *  subsystem, but we need to stuff this into an Objective-C source code file.
slouken@6616
   158
 */
slouken@6616
   159
slouken@6616
   160
void SDL_NSLog(const char *text)
slouken@6616
   161
{
slouken@6714
   162
    NSLog(@"%s", text);
slouken@6616
   163
}
slouken@6616
   164
slouken@6044
   165
#endif /* SDL_VIDEO_DRIVER_UIKIT */
slouken@6044
   166
slouken@2765
   167
/* vi: set ts=4 sw=4 expandtab: */