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 #include "SDL_uikitclipboard.h"
40 
41 #define UIKITVID_DRIVER_NAME "uikit"
42 
43 @implementation SDL_VideoData
44 
45 @end
46 
47 /* Initialization/Query functions */
48 static int UIKit_VideoInit(_THIS);
49 static void UIKit_VideoQuit(_THIS);
50 
51 /* DUMMY driver bootstrap functions */
52 
53 static int
54 UIKit_Available(void)
55 {
56  return 1;
57 }
58 
59 static void UIKit_DeleteDevice(SDL_VideoDevice * device)
60 {
61  @autoreleasepool {
62  CFRelease(device->driverdata);
63  SDL_free(device);
64  }
65 }
66 
67 static SDL_VideoDevice *
68 UIKit_CreateDevice(int devindex)
69 {
70  @autoreleasepool {
71  SDL_VideoDevice *device;
73 
74  /* Initialize all variables that we clean on shutdown */
75  device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
76  if (device) {
77  data = [SDL_VideoData new];
78  } else {
79  SDL_free(device);
81  return (0);
82  }
83 
84  device->driverdata = (void *) CFBridgingRetain(data);
85 
86  /* Set the function pointers */
87  device->VideoInit = UIKit_VideoInit;
88  device->VideoQuit = UIKit_VideoQuit;
91  device->PumpEvents = UIKit_PumpEvents;
95  device->ShowWindow = UIKit_ShowWindow;
96  device->HideWindow = UIKit_HideWindow;
103 
104  #if SDL_IPHONE_KEYBOARD
105  device->HasScreenKeyboardSupport = UIKit_HasScreenKeyboardSupport;
106  device->ShowScreenKeyboard = UIKit_ShowScreenKeyboard;
107  device->HideScreenKeyboard = UIKit_HideScreenKeyboard;
108  device->IsScreenKeyboardShown = UIKit_IsScreenKeyboardShown;
109  device->SetTextInputRect = UIKit_SetTextInputRect;
110  #endif
111 
115 
116  /* OpenGL (ES) functions */
124  device->free = UIKit_DeleteDevice;
125 
126  device->gl_config.accelerated = 1;
127 
128  return device;
129  }
130 }
131 
132 VideoBootStrap UIKIT_bootstrap = {
133  UIKITVID_DRIVER_NAME, "SDL UIKit video driver",
134  UIKit_Available, UIKit_CreateDevice
135 };
136 
137 
138 int
139 UIKit_VideoInit(_THIS)
140 {
142 
143  if (UIKit_InitModes(_this) < 0) {
144  return -1;
145  }
146  return 0;
147 }
148 
149 void
150 UIKit_VideoQuit(_THIS)
151 {
153 }
154 
155 void
157 {
158  @autoreleasepool {
159  /* Ignore ScreenSaver API calls if the idle timer hint has been set. */
160  /* FIXME: The idle timer hint should be deprecated for SDL 2.1. */
162  UIApplication *app = [UIApplication sharedApplication];
163 
164  /* Prevent the display from dimming and going to sleep. */
165  app.idleTimerDisabled = (_this->suspend_screensaver != SDL_FALSE);
166  }
167  }
168 }
169 
170 SDL_bool
171 UIKit_IsSystemVersionAtLeast(double version)
172 {
173  return [[UIDevice currentDevice].systemVersion doubleValue] >= version;
174 }
175 
176 CGRect
177 UIKit_ComputeViewFrame(SDL_Window *window, UIScreen *screen)
178 {
179 #if !TARGET_OS_TV && (__IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_7_0)
180  BOOL hasiOS7 = UIKit_IsSystemVersionAtLeast(7.0);
181 
182  if (hasiOS7 || (window->flags & (SDL_WINDOW_BORDERLESS|SDL_WINDOW_FULLSCREEN))) {
183  /* The view should always show behind the status bar in iOS 7+. */
184  return screen.bounds;
185  } else {
186  return screen.applicationFrame;
187  }
188 #else
189  return screen.bounds;
190 #endif
191 }
192 
193 /*
194  * iOS log support.
195  *
196  * This doesn't really have aything to do with the interfaces of the SDL video
197  * subsystem, but we need to stuff this into an Objective-C source code file.
198  */
199 
200 void SDL_NSLog(const char *text)
201 {
202  NSLog(@"%s", text);
203 }
204 
205 #endif /* SDL_VIDEO_DRIVER_UIKIT */
206 
207 /* vi: set ts=4 sw=4 expandtab: */
int UIKit_InitModes(_THIS)
SDL_bool UIKit_IsSystemVersionAtLeast(double version)
void UIKit_QuitModes(_THIS)
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:276
void UIKit_GL_DeleteContext(_THIS, SDL_GLContext context)
static SDL_Window * window
void(* free)(_THIS)
Definition: SDL_sysvideo.h:358
void UIKit_GL_GetDrawableSize(_THIS, SDL_Window *window, int *w, int *h)
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: SDL_opengl.h:1967
void(* ShowWindow)(_THIS, SDL_Window *window)
Definition: SDL_sysvideo.h:215
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:255
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:247
int(* SetDisplayMode)(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mode)
Definition: SDL_sysvideo.h:197
#define SDL_GetHintBoolean
void(* SetWindowBordered)(_THIS, SDL_Window *window, SDL_bool bordered)
Definition: SDL_sysvideo.h:221
void(* GL_GetDrawableSize)(_THIS, SDL_Window *window, int *w, int *h)
Definition: SDL_sysvideo.h:252
static SDL_VideoDevice * _this
Definition: SDL_video.c:118
struct SDL_VideoDevice::@29 gl_config
void(* HideWindow)(_THIS, SDL_Window *window)
Definition: SDL_sysvideo.h:216
void(* RaiseWindow)(_THIS, SDL_Window *window)
Definition: SDL_sysvideo.h:217
void(* SetTextInputRect)(_THIS, SDL_Rect *rect)
Definition: SDL_sysvideo.h:270
void * SDL_calloc(size_t nmemb, size_t size)
SDL_bool(* GetWindowWMInfo)(_THIS, SDL_Window *window, struct SDL_SysWMinfo *info)
Definition: SDL_sysvideo.h:240
SDL_GLContext(* GL_CreateContext)(_THIS, SDL_Window *window)
Definition: SDL_sysvideo.h:250
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:251
void SDL_free(void *mem)
void(* DestroyWindow)(_THIS, SDL_Window *window)
Definition: SDL_sysvideo.h:227
void UIKit_GL_SwapWindow(_THIS, SDL_Window *window)
BOOL(WINAPI *CloseTouchInputHandle)(HTOUCHINPUT)
#define SDL_HINT_IDLE_TIMER_DISABLED
A variable controlling whether the idle timer is disabled on iOS.
Definition: SDL_hints.h:278
SDL_bool(* HasScreenKeyboardSupport)(_THIS)
Definition: SDL_sysvideo.h:273
SDL_GLContext UIKit_GL_CreateContext(_THIS, SDL_Window *window)
void * UIKit_GL_GetProcAddress(_THIS, const char *proc)
void(* GetDisplayModes)(_THIS, SDL_VideoDisplay *display)
Definition: SDL_sysvideo.h:189
int UIKit_GetDisplayUsableBounds(_THIS, SDL_VideoDisplay *display, SDL_Rect *rect)
#define SDL_OutOfMemory()
Definition: SDL_error.h:52
SDL_bool
Definition: SDL_stdinc.h:130
void(* VideoQuit)(_THIS)
Definition: SDL_sysvideo.h:164
static char text[MAX_TEXT_LENGTH]
Definition: testime.c:47
void(* ShowScreenKeyboard)(_THIS, SDL_Window *window)
Definition: SDL_sysvideo.h:274
int(* CreateWindow)(_THIS, SDL_Window *window)
Definition: SDL_sysvideo.h:203
The type used to identify a window.
Definition: SDL_sysvideo.h:71
SDL_bool(* HasClipboardText)(_THIS)
Definition: SDL_sysvideo.h:281
int(* VideoInit)(_THIS)
Definition: SDL_sysvideo.h:158
SDL_bool suspend_screensaver
Definition: SDL_sysvideo.h:291
void(* SetWindowFullscreen)(_THIS, SDL_Window *window, SDL_VideoDisplay *display, SDL_bool fullscreen)
Definition: SDL_sysvideo.h:223
void(* GL_DeleteContext)(_THIS, SDL_GLContext context)
Definition: SDL_sysvideo.h:256
char *(* GetClipboardText)(_THIS)
Definition: SDL_sysvideo.h:280
void(* SetWindowTitle)(_THIS, SDL_Window *window)
Definition: SDL_sysvideo.h:205
int(* GetDisplayUsableBounds)(_THIS, SDL_VideoDisplay *display, SDL_Rect *rect)
Definition: SDL_sysvideo.h:184
int(* SetClipboardText)(_THIS, const char *text)
Definition: SDL_sysvideo.h:279
void UIKit_ShowWindow(_THIS, SDL_Window *window)
Uint32 flags
Definition: SDL_sysvideo.h:81
SDL_Renderer * screen
void(* SuspendScreenSaver)(_THIS)
Definition: SDL_sysvideo.h:265
int UIKit_GL_MakeCurrent(_THIS, SDL_Window *window, SDL_GLContext context)
int UIKit_SetClipboardText(_THIS, const char *text)
void *(* GL_GetProcAddress)(_THIS, const char *proc)
Definition: SDL_sysvideo.h:248
void(* PumpEvents)(_THIS)
Definition: SDL_sysvideo.h:262
void(* HideScreenKeyboard)(_THIS, SDL_Window *window)
Definition: SDL_sysvideo.h:275
char * UIKit_GetClipboardText(_THIS)
int UIKit_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mode)
SDL_bool UIKit_HasClipboardText(_THIS)