2 Simple DirectMedia Layer
3 Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
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.
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:
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.
21 #include "../../SDL_internal.h"
23 #if SDL_VIDEO_DRIVER_UIKIT
25 #import <UIKit/UIKit.h>
27 #include "SDL_video.h"
28 #include "SDL_mouse.h"
29 #include "SDL_hints.h"
30 #include "../SDL_sysvideo.h"
31 #include "../SDL_pixels_c.h"
32 #include "../../events/SDL_events_c.h"
34 #include "SDL_uikitvideo.h"
35 #include "SDL_uikitevents.h"
36 #include "SDL_uikitmodes.h"
37 #include "SDL_uikitwindow.h"
38 #include "SDL_uikitopengles.h"
40 #define UIKITVID_DRIVER_NAME "uikit"
42 /* Initialization/Query functions */
43 static int UIKit_VideoInit(_THIS);
44 static void UIKit_VideoQuit(_THIS);
46 /* DUMMY driver bootstrap functions */
54 static void UIKit_DeleteDevice(SDL_VideoDevice * device)
59 static SDL_VideoDevice *
60 UIKit_CreateDevice(int devindex)
62 SDL_VideoDevice *device;
64 /* Initialize all variables that we clean on shutdown */
65 device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
72 /* Set the function pointers */
73 device->VideoInit = UIKit_VideoInit;
74 device->VideoQuit = UIKit_VideoQuit;
75 device->GetDisplayModes = UIKit_GetDisplayModes;
76 device->SetDisplayMode = UIKit_SetDisplayMode;
77 device->PumpEvents = UIKit_PumpEvents;
78 device->SuspendScreenSaver = UIKit_SuspendScreenSaver;
79 device->CreateWindow = UIKit_CreateWindow;
80 device->SetWindowTitle = UIKit_SetWindowTitle;
81 device->ShowWindow = UIKit_ShowWindow;
82 device->HideWindow = UIKit_HideWindow;
83 device->RaiseWindow = UIKit_RaiseWindow;
84 device->SetWindowBordered = UIKit_SetWindowBordered;
85 device->SetWindowFullscreen = UIKit_SetWindowFullscreen;
86 device->DestroyWindow = UIKit_DestroyWindow;
87 device->GetWindowWMInfo = UIKit_GetWindowWMInfo;
89 #if SDL_IPHONE_KEYBOARD
90 device->HasScreenKeyboardSupport = UIKit_HasScreenKeyboardSupport;
91 device->ShowScreenKeyboard = UIKit_ShowScreenKeyboard;
92 device->HideScreenKeyboard = UIKit_HideScreenKeyboard;
93 device->IsScreenKeyboardShown = UIKit_IsScreenKeyboardShown;
94 device->SetTextInputRect = UIKit_SetTextInputRect;
97 /* OpenGL (ES) functions */
98 device->GL_MakeCurrent = UIKit_GL_MakeCurrent;
99 device->GL_GetDrawableSize = UIKit_GL_GetDrawableSize;
100 device->GL_SwapWindow = UIKit_GL_SwapWindow;
101 device->GL_CreateContext = UIKit_GL_CreateContext;
102 device->GL_DeleteContext = UIKit_GL_DeleteContext;
103 device->GL_GetProcAddress = UIKit_GL_GetProcAddress;
104 device->GL_LoadLibrary = UIKit_GL_LoadLibrary;
105 device->free = UIKit_DeleteDevice;
107 device->gl_config.accelerated = 1;
112 VideoBootStrap UIKIT_bootstrap = {
113 UIKITVID_DRIVER_NAME, "SDL UIKit video driver",
114 UIKit_Available, UIKit_CreateDevice
119 UIKit_VideoInit(_THIS)
121 _this->gl_config.driver_loaded = 1;
123 if (UIKit_InitModes(_this) < 0) {
130 UIKit_VideoQuit(_THIS)
132 UIKit_QuitModes(_this);
136 UIKit_SuspendScreenSaver(_THIS)
139 /* Ignore ScreenSaver API calls if the idle timer hint has been set. */
140 /* FIXME: The idle timer hint should be deprecated for SDL 2.1. */
141 if (SDL_GetHint(SDL_HINT_IDLE_TIMER_DISABLED) == NULL) {
142 UIApplication *app = [UIApplication sharedApplication];
144 /* Prevent the display from dimming and going to sleep. */
145 app.idleTimerDisabled = (_this->suspend_screensaver != SDL_FALSE);
151 UIKit_IsSystemVersionAtLeast(double version)
153 return [[UIDevice currentDevice].systemVersion doubleValue] >= version;
157 UIKit_ComputeViewFrame(SDL_Window *window, UIScreen *screen)
159 BOOL hasiOS7 = UIKit_IsSystemVersionAtLeast(7.0);
161 if (hasiOS7 || (window->flags & (SDL_WINDOW_BORDERLESS|SDL_WINDOW_FULLSCREEN))) {
162 /* The view should always show behind the status bar in iOS 7+. */
163 return screen.bounds;
165 return screen.applicationFrame;
172 * This doesn't really have aything to do with the interfaces of the SDL video
173 * subsystem, but we need to stuff this into an Objective-C source code file.
176 void SDL_NSLog(const char *text)
181 #endif /* SDL_VIDEO_DRIVER_UIKIT */
183 /* vi: set ts=4 sw=4 expandtab: */