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