src/video/uikit/SDL_uikitvideo.m
author Sam Lantinga
Fri, 27 Jan 2017 06:05:50 -0800
changeset 10856 486aa38c6a88
parent 10737 3406a0f8b041
child 11306 45fbdef6a227
permissions -rw-r--r--
Added Thrustmaster Wheel FFB entry to the list of wheels
slouken@2765
     1
/*
slouken@5535
     2
  Simple DirectMedia Layer
slouken@10737
     3
  Copyright (C) 1997-2017 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"
slime73@10062
    39
#include "SDL_uikitclipboard.h"
slouken@2765
    40
slouken@2765
    41
#define UIKITVID_DRIVER_NAME "uikit"
slouken@2765
    42
slime73@10062
    43
@implementation SDL_VideoData
slime73@10062
    44
slime73@10062
    45
@end
slime73@10062
    46
slouken@2765
    47
/* Initialization/Query functions */
slouken@2765
    48
static int UIKit_VideoInit(_THIS);
slouken@2765
    49
static void UIKit_VideoQuit(_THIS);
slouken@2765
    50
slouken@2765
    51
/* DUMMY driver bootstrap functions */
slouken@2765
    52
slouken@2765
    53
static int
slouken@2765
    54
UIKit_Available(void)
slouken@2765
    55
{
kees@6003
    56
    return 1;
slouken@2765
    57
}
slouken@2765
    58
slouken@2765
    59
static void UIKit_DeleteDevice(SDL_VideoDevice * device)
slouken@2765
    60
{
slime73@10062
    61
    @autoreleasepool {
slime73@10062
    62
        CFRelease(device->driverdata);
slime73@10062
    63
        SDL_free(device);
slime73@10062
    64
    }
slouken@2765
    65
}
slouken@2765
    66
slouken@2765
    67
static SDL_VideoDevice *
slouken@2765
    68
UIKit_CreateDevice(int devindex)
slouken@2765
    69
{
slime73@10062
    70
    @autoreleasepool {
slime73@10062
    71
        SDL_VideoDevice *device;
slime73@10062
    72
        SDL_VideoData *data;
slouken@2765
    73
slime73@10062
    74
        /* Initialize all variables that we clean on shutdown */
slime73@10062
    75
        device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
slime73@10062
    76
        if (device) {
slime73@10062
    77
            data = [SDL_VideoData new];
slime73@10062
    78
        } else {
slime73@10062
    79
            SDL_free(device);
slime73@10062
    80
            SDL_OutOfMemory();
slime73@10062
    81
            return (0);
slime73@10062
    82
        }
slime73@10062
    83
slime73@10062
    84
        device->driverdata = (void *) CFBridgingRetain(data);
slouken@2765
    85
slime73@10062
    86
        /* Set the function pointers */
slime73@10062
    87
        device->VideoInit = UIKit_VideoInit;
slime73@10062
    88
        device->VideoQuit = UIKit_VideoQuit;
slime73@10062
    89
        device->GetDisplayModes = UIKit_GetDisplayModes;
slime73@10062
    90
        device->SetDisplayMode = UIKit_SetDisplayMode;
slime73@10062
    91
        device->PumpEvents = UIKit_PumpEvents;
slime73@10062
    92
        device->SuspendScreenSaver = UIKit_SuspendScreenSaver;
slime73@10062
    93
        device->CreateWindow = UIKit_CreateWindow;
slime73@10062
    94
        device->SetWindowTitle = UIKit_SetWindowTitle;
slime73@10062
    95
        device->ShowWindow = UIKit_ShowWindow;
slime73@10062
    96
        device->HideWindow = UIKit_HideWindow;
slime73@10062
    97
        device->RaiseWindow = UIKit_RaiseWindow;
slime73@10062
    98
        device->SetWindowBordered = UIKit_SetWindowBordered;
slime73@10062
    99
        device->SetWindowFullscreen = UIKit_SetWindowFullscreen;
slime73@10062
   100
        device->DestroyWindow = UIKit_DestroyWindow;
slime73@10062
   101
        device->GetWindowWMInfo = UIKit_GetWindowWMInfo;
slime73@10062
   102
        device->GetDisplayUsableBounds = UIKit_GetDisplayUsableBounds;
kees@6001
   103
slime73@10062
   104
    #if SDL_IPHONE_KEYBOARD
slime73@10062
   105
        device->HasScreenKeyboardSupport = UIKit_HasScreenKeyboardSupport;
slime73@10062
   106
        device->ShowScreenKeyboard = UIKit_ShowScreenKeyboard;
slime73@10062
   107
        device->HideScreenKeyboard = UIKit_HideScreenKeyboard;
slime73@10062
   108
        device->IsScreenKeyboardShown = UIKit_IsScreenKeyboardShown;
slime73@10062
   109
        device->SetTextInputRect = UIKit_SetTextInputRect;
slime73@10062
   110
    #endif
slime73@10062
   111
slime73@10062
   112
        device->SetClipboardText = UIKit_SetClipboardText;
slime73@10062
   113
        device->GetClipboardText = UIKit_GetClipboardText;
slime73@10062
   114
        device->HasClipboardText = UIKit_HasClipboardText;
kees@6001
   115
slime73@10062
   116
        /* OpenGL (ES) functions */
slime73@10062
   117
        device->GL_MakeCurrent      = UIKit_GL_MakeCurrent;
slime73@10062
   118
        device->GL_GetDrawableSize  = UIKit_GL_GetDrawableSize;
slime73@10062
   119
        device->GL_SwapWindow       = UIKit_GL_SwapWindow;
slime73@10062
   120
        device->GL_CreateContext    = UIKit_GL_CreateContext;
slime73@10062
   121
        device->GL_DeleteContext    = UIKit_GL_DeleteContext;
slime73@10062
   122
        device->GL_GetProcAddress   = UIKit_GL_GetProcAddress;
slime73@10062
   123
        device->GL_LoadLibrary      = UIKit_GL_LoadLibrary;
slime73@10062
   124
        device->free = UIKit_DeleteDevice;
slouken@2765
   125
slime73@10062
   126
        device->gl_config.accelerated = 1;
slouken@5131
   127
slime73@10062
   128
        return device;
slime73@10062
   129
    }
slouken@2765
   130
}
slouken@2765
   131
slouken@2765
   132
VideoBootStrap UIKIT_bootstrap = {
slouken@2765
   133
    UIKITVID_DRIVER_NAME, "SDL UIKit video driver",
slouken@2765
   134
    UIKit_Available, UIKit_CreateDevice
slouken@2765
   135
};
slouken@2765
   136
slouken@2765
   137
slouken@2765
   138
int
slouken@2765
   139
UIKit_VideoInit(_THIS)
slouken@2765
   140
{
icculus@4443
   141
    _this->gl_config.driver_loaded = 1;
slouken@2765
   142
slouken@6518
   143
    if (UIKit_InitModes(_this) < 0) {
tim@6267
   144
        return -1;
tim@6267
   145
    }
slouken@2765
   146
    return 0;
slouken@2765
   147
}
slouken@2765
   148
slouken@2765
   149
void
slouken@2765
   150
UIKit_VideoQuit(_THIS)
slouken@2765
   151
{
slouken@6518
   152
    UIKit_QuitModes(_this);
slouken@2765
   153
}
slouken@2765
   154
slime73@9603
   155
void
slime73@9603
   156
UIKit_SuspendScreenSaver(_THIS)
slime73@9603
   157
{
slime73@9603
   158
    @autoreleasepool {
slime73@9603
   159
        /* Ignore ScreenSaver API calls if the idle timer hint has been set. */
slime73@9603
   160
        /* FIXME: The idle timer hint should be deprecated for SDL 2.1. */
slouken@10499
   161
        if (!SDL_GetHintBoolean(SDL_HINT_IDLE_TIMER_DISABLED, SDL_FALSE)) {
slime73@9603
   162
            UIApplication *app = [UIApplication sharedApplication];
slime73@9603
   163
slime73@9603
   164
            /* Prevent the display from dimming and going to sleep. */
slime73@9603
   165
            app.idleTimerDisabled = (_this->suspend_screensaver != SDL_FALSE);
slime73@9603
   166
        }
slime73@9603
   167
    }
slime73@9603
   168
}
slime73@9603
   169
slime73@10372
   170
SDL_bool
slime73@9525
   171
UIKit_IsSystemVersionAtLeast(double version)
slime73@9502
   172
{
slime73@9525
   173
    return [[UIDevice currentDevice].systemVersion doubleValue] >= version;
slime73@9502
   174
}
slime73@9502
   175
slime73@9502
   176
CGRect
slime73@9502
   177
UIKit_ComputeViewFrame(SDL_Window *window, UIScreen *screen)
slime73@9502
   178
{
slime73@10340
   179
#if !TARGET_OS_TV && (__IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_7_0)
slime73@9525
   180
    BOOL hasiOS7 = UIKit_IsSystemVersionAtLeast(7.0);
slime73@9502
   181
slime73@9502
   182
    if (hasiOS7 || (window->flags & (SDL_WINDOW_BORDERLESS|SDL_WINDOW_FULLSCREEN))) {
slime73@9502
   183
        /* The view should always show behind the status bar in iOS 7+. */
slime73@9502
   184
        return screen.bounds;
slime73@9502
   185
    } else {
slime73@9502
   186
        return screen.applicationFrame;
slime73@9502
   187
    }
slime73@10340
   188
#else
slime73@10340
   189
    return screen.bounds;
slime73@10340
   190
#endif
slime73@9502
   191
}
slime73@9502
   192
slouken@6616
   193
/*
slouken@6616
   194
 * iOS log support.
slouken@6616
   195
 *
slouken@6616
   196
 * This doesn't really have aything to do with the interfaces of the SDL video
slouken@6616
   197
 *  subsystem, but we need to stuff this into an Objective-C source code file.
slouken@6616
   198
 */
slouken@6616
   199
slouken@6616
   200
void SDL_NSLog(const char *text)
slouken@6616
   201
{
slouken@6714
   202
    NSLog(@"%s", text);
slouken@6616
   203
}
slouken@6616
   204
slouken@6044
   205
#endif /* SDL_VIDEO_DRIVER_UIKIT */
slouken@6044
   206
slouken@2765
   207
/* vi: set ts=4 sw=4 expandtab: */