src/video/uikit/SDL_uikitvideo.m
author Sam Lantinga <slouken@libsdl.org>
Tue, 26 May 2015 06:27:46 -0700
changeset 9619 b94b6d0bff0f
parent 9603 8e570fd79352
child 9998 f67cf37e9cd4
permissions -rw-r--r--
Updated the copyright year to 2015
slouken@2765
     1
/*
slouken@5535
     2
  Simple DirectMedia Layer
slouken@9619
     3
  Copyright (C) 1997-2015 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"
slime73@9603
    29
#include "SDL_hints.h"
slouken@2765
    30
#include "../SDL_sysvideo.h"
slouken@2765
    31
#include "../SDL_pixels_c.h"
slouken@2765
    32
#include "../../events/SDL_events_c.h"
slouken@2765
    33
slouken@2765
    34
#include "SDL_uikitvideo.h"
slouken@2765
    35
#include "SDL_uikitevents.h"
slouken@6518
    36
#include "SDL_uikitmodes.h"
slouken@2765
    37
#include "SDL_uikitwindow.h"
slouken@2765
    38
#include "SDL_uikitopengles.h"
slouken@2765
    39
slouken@2765
    40
#define UIKITVID_DRIVER_NAME "uikit"
slouken@2765
    41
slouken@2765
    42
/* Initialization/Query functions */
slouken@2765
    43
static int UIKit_VideoInit(_THIS);
slouken@2765
    44
static void UIKit_VideoQuit(_THIS);
slouken@2765
    45
slouken@2765
    46
/* DUMMY driver bootstrap functions */
slouken@2765
    47
slouken@2765
    48
static int
slouken@2765
    49
UIKit_Available(void)
slouken@2765
    50
{
kees@6003
    51
    return 1;
slouken@2765
    52
}
slouken@2765
    53
slouken@2765
    54
static void UIKit_DeleteDevice(SDL_VideoDevice * device)
slouken@2765
    55
{
slouken@2765
    56
    SDL_free(device);
slouken@2765
    57
}
slouken@2765
    58
slouken@2765
    59
static SDL_VideoDevice *
slouken@2765
    60
UIKit_CreateDevice(int devindex)
slouken@2765
    61
{
slouken@2765
    62
    SDL_VideoDevice *device;
slouken@2765
    63
slouken@2765
    64
    /* Initialize all variables that we clean on shutdown */
slouken@2765
    65
    device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
slouken@2765
    66
    if (!device) {
slouken@7719
    67
        SDL_free(device);
icculus@7037
    68
        SDL_OutOfMemory();
slouken@2765
    69
        return (0);
slouken@2765
    70
    }
slouken@2765
    71
slouken@2765
    72
    /* Set the function pointers */
slouken@2765
    73
    device->VideoInit = UIKit_VideoInit;
slouken@2765
    74
    device->VideoQuit = UIKit_VideoQuit;
icculus@4443
    75
    device->GetDisplayModes = UIKit_GetDisplayModes;
slouken@2765
    76
    device->SetDisplayMode = UIKit_SetDisplayMode;
slouken@2765
    77
    device->PumpEvents = UIKit_PumpEvents;
slime73@9603
    78
    device->SuspendScreenSaver = UIKit_SuspendScreenSaver;
slouken@5131
    79
    device->CreateWindow = UIKit_CreateWindow;
slime73@9529
    80
    device->SetWindowTitle = UIKit_SetWindowTitle;
slouken@6379
    81
    device->ShowWindow = UIKit_ShowWindow;
slouken@6379
    82
    device->HideWindow = UIKit_HideWindow;
icculus@6419
    83
    device->RaiseWindow = UIKit_RaiseWindow;
slime73@9505
    84
    device->SetWindowBordered = UIKit_SetWindowBordered;
slouken@6073
    85
    device->SetWindowFullscreen = UIKit_SetWindowFullscreen;
slouken@5131
    86
    device->DestroyWindow = UIKit_DestroyWindow;
slouken@5056
    87
    device->GetWindowWMInfo = UIKit_GetWindowWMInfo;
kees@6001
    88
urkle@7111
    89
#if SDL_IPHONE_KEYBOARD
philipp@7135
    90
    device->HasScreenKeyboardSupport = UIKit_HasScreenKeyboardSupport;
philipp@7135
    91
    device->ShowScreenKeyboard = UIKit_ShowScreenKeyboard;
philipp@7135
    92
    device->HideScreenKeyboard = UIKit_HideScreenKeyboard;
philipp@7135
    93
    device->IsScreenKeyboardShown = UIKit_IsScreenKeyboardShown;
slouken@7962
    94
    device->SetTextInputRect = UIKit_SetTextInputRect;
urkle@7111
    95
#endif
kees@6001
    96
slouken@5131
    97
    /* OpenGL (ES) functions */
slime73@9488
    98
    device->GL_MakeCurrent      = UIKit_GL_MakeCurrent;
slime73@9488
    99
    device->GL_GetDrawableSize  = UIKit_GL_GetDrawableSize;
slime73@9488
   100
    device->GL_SwapWindow       = UIKit_GL_SwapWindow;
slouken@5131
   101
    device->GL_CreateContext    = UIKit_GL_CreateContext;
slouken@5131
   102
    device->GL_DeleteContext    = UIKit_GL_DeleteContext;
slouken@5131
   103
    device->GL_GetProcAddress   = UIKit_GL_GetProcAddress;
slime73@9488
   104
    device->GL_LoadLibrary      = UIKit_GL_LoadLibrary;
slouken@5131
   105
    device->free = UIKit_DeleteDevice;
slouken@2765
   106
slouken@5131
   107
    device->gl_config.accelerated = 1;
slouken@5131
   108
slouken@2765
   109
    return device;
slouken@2765
   110
}
slouken@2765
   111
slouken@2765
   112
VideoBootStrap UIKIT_bootstrap = {
slouken@2765
   113
    UIKITVID_DRIVER_NAME, "SDL UIKit video driver",
slouken@2765
   114
    UIKit_Available, UIKit_CreateDevice
slouken@2765
   115
};
slouken@2765
   116
slouken@2765
   117
slouken@2765
   118
int
slouken@2765
   119
UIKit_VideoInit(_THIS)
slouken@2765
   120
{
icculus@4443
   121
    _this->gl_config.driver_loaded = 1;
slouken@2765
   122
slouken@6518
   123
    if (UIKit_InitModes(_this) < 0) {
tim@6267
   124
        return -1;
tim@6267
   125
    }
slouken@2765
   126
    return 0;
slouken@2765
   127
}
slouken@2765
   128
slouken@2765
   129
void
slouken@2765
   130
UIKit_VideoQuit(_THIS)
slouken@2765
   131
{
slouken@6518
   132
    UIKit_QuitModes(_this);
slouken@2765
   133
}
slouken@2765
   134
slime73@9603
   135
void
slime73@9603
   136
UIKit_SuspendScreenSaver(_THIS)
slime73@9603
   137
{
slime73@9603
   138
    @autoreleasepool {
slime73@9603
   139
        /* Ignore ScreenSaver API calls if the idle timer hint has been set. */
slime73@9603
   140
        /* FIXME: The idle timer hint should be deprecated for SDL 2.1. */
slime73@9603
   141
        if (SDL_GetHint(SDL_HINT_IDLE_TIMER_DISABLED) == NULL) {
slime73@9603
   142
            UIApplication *app = [UIApplication sharedApplication];
slime73@9603
   143
slime73@9603
   144
            /* Prevent the display from dimming and going to sleep. */
slime73@9603
   145
            app.idleTimerDisabled = (_this->suspend_screensaver != SDL_FALSE);
slime73@9603
   146
        }
slime73@9603
   147
    }
slime73@9603
   148
}
slime73@9603
   149
slime73@9502
   150
BOOL
slime73@9525
   151
UIKit_IsSystemVersionAtLeast(double version)
slime73@9502
   152
{
slime73@9525
   153
    return [[UIDevice currentDevice].systemVersion doubleValue] >= version;
slime73@9502
   154
}
slime73@9502
   155
slime73@9502
   156
CGRect
slime73@9502
   157
UIKit_ComputeViewFrame(SDL_Window *window, UIScreen *screen)
slime73@9502
   158
{
slime73@9525
   159
    BOOL hasiOS7 = UIKit_IsSystemVersionAtLeast(7.0);
slime73@9502
   160
slime73@9502
   161
    if (hasiOS7 || (window->flags & (SDL_WINDOW_BORDERLESS|SDL_WINDOW_FULLSCREEN))) {
slime73@9502
   162
        /* The view should always show behind the status bar in iOS 7+. */
slime73@9502
   163
        return screen.bounds;
slime73@9502
   164
    } else {
slime73@9502
   165
        return screen.applicationFrame;
slime73@9502
   166
    }
slime73@9502
   167
}
slime73@9502
   168
slouken@6616
   169
/*
slouken@6616
   170
 * iOS log support.
slouken@6616
   171
 *
slouken@6616
   172
 * This doesn't really have aything to do with the interfaces of the SDL video
slouken@6616
   173
 *  subsystem, but we need to stuff this into an Objective-C source code file.
slouken@6616
   174
 */
slouken@6616
   175
slouken@6616
   176
void SDL_NSLog(const char *text)
slouken@6616
   177
{
slouken@6714
   178
    NSLog(@"%s", text);
slouken@6616
   179
}
slouken@6616
   180
slouken@6044
   181
#endif /* SDL_VIDEO_DRIVER_UIKIT */
slouken@6044
   182
slouken@2765
   183
/* vi: set ts=4 sw=4 expandtab: */