SDL  2.0
SDL_uikitvideo.m
Go to the documentation of this file.
1 /*
2  Simple DirectMedia Layer
3  Copyright (C) 1997-2016 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_hints.h"
30 #include "../SDL_sysvideo.h"
31 #include "../SDL_pixels_c.h"
32 #include "../../events/SDL_events_c.h"
33 
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"
39 
40 #define UIKITVID_DRIVER_NAME "uikit"
41 
42 /* Initialization/Query functions */
43 static int UIKit_VideoInit(_THIS);
44 static void UIKit_VideoQuit(_THIS);
45 
46 /* DUMMY driver bootstrap functions */
47 
48 static int
49 UIKit_Available(void)
50 {
51  return 1;
52 }
53 
54 static void UIKit_DeleteDevice(SDL_VideoDevice * device)
55 {
56  SDL_free(device);
57 }
58 
59 static SDL_VideoDevice *
60 UIKit_CreateDevice(int devindex)
61 {
62  SDL_VideoDevice *device;
63 
64  /* Initialize all variables that we clean on shutdown */
65  device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
66  if (!device) {
67  SDL_free(device);
69  return (0);
70  }
71 
72  /* Set the function pointers */
73  device->VideoInit = UIKit_VideoInit;
74  device->VideoQuit = UIKit_VideoQuit;
77  device->PumpEvents = UIKit_PumpEvents;
81  device->ShowWindow = UIKit_ShowWindow;
82  device->HideWindow = UIKit_HideWindow;
88 
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;
95 #endif
96 
97  /* OpenGL (ES) functions */
105  device->free = UIKit_DeleteDevice;
106 
107  device->gl_config.accelerated = 1;
108 
109  return device;
110 }
111 
112 VideoBootStrap UIKIT_bootstrap = {
113  UIKITVID_DRIVER_NAME, "SDL UIKit video driver",
114  UIKit_Available, UIKit_CreateDevice
115 };
116 
117 
118 int
119 UIKit_VideoInit(_THIS)
120 {
122 
123  if (UIKit_InitModes(_this) < 0) {
124  return -1;
125  }
126  return 0;
127 }
128 
129 void
130 UIKit_VideoQuit(_THIS)
131 {
133 }
134 
135 void
137 {
138  @autoreleasepool {
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. */
142  UIApplication *app = [UIApplication sharedApplication];
143 
144  /* Prevent the display from dimming and going to sleep. */
145  app.idleTimerDisabled = (_this->suspend_screensaver != SDL_FALSE);
146  }
147  }
148 }
149 
150 BOOL
151 UIKit_IsSystemVersionAtLeast(double version)
152 {
153  return [[UIDevice currentDevice].systemVersion doubleValue] >= version;
154 }
155 
156 CGRect
158 {
159  BOOL hasiOS7 = UIKit_IsSystemVersionAtLeast(7.0);
160 
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;
164  } else {
165  return screen.applicationFrame;
166  }
167 }
168 
169 /*
170  * iOS log support.
171  *
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.
174  */
175 
176 void SDL_NSLog(const char *text)
177 {
178  NSLog(@"%s", text);
179 }
180 
181 #endif /* SDL_VIDEO_DRIVER_UIKIT */
182 
183 /* vi: set ts=4 sw=4 expandtab: */
int UIKit_InitModes(_THIS)
void UIKit_QuitModes(_THIS)
CGRect UIKit_ComputeViewFrame(SDL_Window *window, UIScreen *screen)
void UIKit_PumpEvents(_THIS)
void UIKit_SuspendScreenSaver(_THIS)
SDL_bool UIKit_GetWindowWMInfo(_THIS, SDL_Window *window, struct SDL_SysWMinfo *info)
int UIKit_CreateWindow(_THIS, SDL_Window *window)
void UIKit_DestroyWindow(_THIS, SDL_Window *window)
SDL_bool(* IsScreenKeyboardShown)(_THIS, SDL_Window *window)
Definition: SDL_sysvideo.h:263
void UIKit_GL_DeleteContext(_THIS, SDL_GLContext context)
SDL_Window * window
void(* free)(_THIS)
Definition: SDL_sysvideo.h:345
void UIKit_GL_GetDrawableSize(_THIS, SDL_Window *window, int *w, int *h)
BOOL UIKit_IsSystemVersionAtLeast(double version)
void(* ShowWindow)(_THIS, SDL_Window *window)
Definition: SDL_sysvideo.h:203
#define SDL_GetHint
void UIKit_SetWindowTitle(_THIS, SDL_Window *window)
void UIKit_RaiseWindow(_THIS, SDL_Window *window)
void UIKit_HideWindow(_THIS, SDL_Window *window)
void(* GL_SwapWindow)(_THIS, SDL_Window *window)
Definition: SDL_sysvideo.h:242
void UIKit_SetWindowBordered(_THIS, SDL_Window *window, SDL_bool bordered)
int UIKit_GL_LoadLibrary(_THIS, const char *path)
void UIKit_GetDisplayModes(_THIS, SDL_VideoDisplay *display)
int(* GL_LoadLibrary)(_THIS, const char *path)
Definition: SDL_sysvideo.h:234
int(* SetDisplayMode)(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mode)
Definition: SDL_sysvideo.h:189
void(* SetWindowBordered)(_THIS, SDL_Window *window, SDL_bool bordered)
Definition: SDL_sysvideo.h:209
void(* GL_GetDrawableSize)(_THIS, SDL_Window *window, int *w, int *h)
Definition: SDL_sysvideo.h:239
static SDL_VideoDevice * _this
Definition: SDL_video.c:114
void(* HideWindow)(_THIS, SDL_Window *window)
Definition: SDL_sysvideo.h:204
void(* RaiseWindow)(_THIS, SDL_Window *window)
Definition: SDL_sysvideo.h:205
void(* SetTextInputRect)(_THIS, SDL_Rect *rect)
Definition: SDL_sysvideo.h:257
void * SDL_calloc(size_t nmemb, size_t size)
SDL_bool(* GetWindowWMInfo)(_THIS, SDL_Window *window, struct SDL_SysWMinfo *info)
Definition: SDL_sysvideo.h:227
SDL_GLContext(* GL_CreateContext)(_THIS, SDL_Window *window)
Definition: SDL_sysvideo.h:237
void UIKit_SetWindowFullscreen(_THIS, SDL_Window *window, SDL_VideoDisplay *display, SDL_bool fullscreen)
#define _THIS
int(* GL_MakeCurrent)(_THIS, SDL_Window *window, SDL_GLContext context)
Definition: SDL_sysvideo.h:238
void SDL_free(void *mem)
void(* DestroyWindow)(_THIS, SDL_Window *window)
Definition: SDL_sysvideo.h:214
void UIKit_GL_SwapWindow(_THIS, SDL_Window *window)
#define SDL_HINT_IDLE_TIMER_DISABLED
A variable controlling whether the idle timer is disabled on iOS.
Definition: SDL_hints.h:267
SDL_bool(* HasScreenKeyboardSupport)(_THIS)
Definition: SDL_sysvideo.h:260
SDL_GLContext UIKit_GL_CreateContext(_THIS, SDL_Window *window)
struct SDL_VideoDevice::@27 gl_config
void * UIKit_GL_GetProcAddress(_THIS, const char *proc)
void(* GetDisplayModes)(_THIS, SDL_VideoDisplay *display)
Definition: SDL_sysvideo.h:181
#define NULL
Definition: begin_code.h:143
#define SDL_OutOfMemory()
Definition: SDL_error.h:52
void(* VideoQuit)(_THIS)
Definition: SDL_sysvideo.h:161
static char text[MAX_TEXT_LENGTH]
Definition: testime.c:34
void(* ShowScreenKeyboard)(_THIS, SDL_Window *window)
Definition: SDL_sysvideo.h:261
int(* CreateWindow)(_THIS, SDL_Window *window)
Definition: SDL_sysvideo.h:195
The type used to identify a window.
Definition: SDL_sysvideo.h:71
int(* VideoInit)(_THIS)
Definition: SDL_sysvideo.h:155
SDL_bool suspend_screensaver
Definition: SDL_sysvideo.h:278
void(* SetWindowFullscreen)(_THIS, SDL_Window *window, SDL_VideoDisplay *display, SDL_bool fullscreen)
Definition: SDL_sysvideo.h:210
void(* GL_DeleteContext)(_THIS, SDL_GLContext context)
Definition: SDL_sysvideo.h:243
void(* SetWindowTitle)(_THIS, SDL_Window *window)
Definition: SDL_sysvideo.h:197
void UIKit_ShowWindow(_THIS, SDL_Window *window)
Uint32 flags
Definition: SDL_sysvideo.h:81
SDL_Renderer * screen
void(* SuspendScreenSaver)(_THIS)
Definition: SDL_sysvideo.h:252
int UIKit_GL_MakeCurrent(_THIS, SDL_Window *window, SDL_GLContext context)
void *(* GL_GetProcAddress)(_THIS, const char *proc)
Definition: SDL_sysvideo.h:235
void(* PumpEvents)(_THIS)
Definition: SDL_sysvideo.h:249
void(* HideScreenKeyboard)(_THIS, SDL_Window *window)
Definition: SDL_sysvideo.h:262
int UIKit_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mode)