SDL_uikitvideo.m
Go to the documentation of this file.
/*
Simple DirectMedia Layer
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#if SDL_VIDEO_DRIVER_UIKIT
#import <UIKit/UIKit.h>
#include "SDL_video.h"
#include "SDL_mouse.h"
#include "SDL_hints.h"
#include "../SDL_sysvideo.h"
#include "../SDL_pixels_c.h"
#include "../../events/SDL_events_c.h"
#include "SDL_uikitvideo.h"
#include "SDL_uikitevents.h"
#include "SDL_uikitmodes.h"
#include "SDL_uikitwindow.h"
#include "SDL_uikitopengles.h"
#define UIKITVID_DRIVER_NAME "uikit"
/* Initialization/Query functions */
static int UIKit_VideoInit(_THIS);
static void UIKit_VideoQuit(_THIS);
/* DUMMY driver bootstrap functions */
static int
UIKit_Available(void)
{
return 1;
}
static void UIKit_DeleteDevice(SDL_VideoDevice * device)
{
SDL_free(device);
}
static SDL_VideoDevice *
UIKit_CreateDevice(int devindex)
{
SDL_VideoDevice *device;
/* Initialize all variables that we clean on shutdown */
device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
if (!device) {
SDL_free(device);
SDL_OutOfMemory();
return (0);
}
/* Set the function pointers */
device->VideoInit = UIKit_VideoInit;
device->VideoQuit = UIKit_VideoQuit;
device->GetDisplayModes = UIKit_GetDisplayModes;
device->SetDisplayMode = UIKit_SetDisplayMode;
device->PumpEvents = UIKit_PumpEvents;
device->SuspendScreenSaver = UIKit_SuspendScreenSaver;
device->CreateWindow = UIKit_CreateWindow;
device->SetWindowTitle = UIKit_SetWindowTitle;
device->ShowWindow = UIKit_ShowWindow;
device->HideWindow = UIKit_HideWindow;
device->RaiseWindow = UIKit_RaiseWindow;
device->SetWindowBordered = UIKit_SetWindowBordered;
device->SetWindowFullscreen = UIKit_SetWindowFullscreen;
device->DestroyWindow = UIKit_DestroyWindow;
device->GetWindowWMInfo = UIKit_GetWindowWMInfo;
#if SDL_IPHONE_KEYBOARD
device->HasScreenKeyboardSupport = UIKit_HasScreenKeyboardSupport;
device->ShowScreenKeyboard = UIKit_ShowScreenKeyboard;
device->HideScreenKeyboard = UIKit_HideScreenKeyboard;
device->IsScreenKeyboardShown = UIKit_IsScreenKeyboardShown;
device->SetTextInputRect = UIKit_SetTextInputRect;
#endif
/* OpenGL (ES) functions */
device->GL_MakeCurrent = UIKit_GL_MakeCurrent;
device->GL_GetDrawableSize = UIKit_GL_GetDrawableSize;
device->GL_SwapWindow = UIKit_GL_SwapWindow;
device->GL_CreateContext = UIKit_GL_CreateContext;
device->GL_DeleteContext = UIKit_GL_DeleteContext;
device->GL_GetProcAddress = UIKit_GL_GetProcAddress;
device->GL_LoadLibrary = UIKit_GL_LoadLibrary;
device->free = UIKit_DeleteDevice;
device->gl_config.accelerated = 1;
return device;
}
VideoBootStrap UIKIT_bootstrap = {
UIKITVID_DRIVER_NAME, "SDL UIKit video driver",
UIKit_Available, UIKit_CreateDevice
};
int
UIKit_VideoInit(_THIS)
{
_this->gl_config.driver_loaded = 1;
if (UIKit_InitModes(_this) < 0) {
return -1;
}
return 0;
}
void
UIKit_VideoQuit(_THIS)
{
UIKit_QuitModes(_this);
}
void
UIKit_SuspendScreenSaver(_THIS)
{
@autoreleasepool {
/* Ignore ScreenSaver API calls if the idle timer hint has been set. */
/* FIXME: The idle timer hint should be deprecated for SDL 2.1. */
if (SDL_GetHint(SDL_HINT_IDLE_TIMER_DISABLED) == NULL) {
UIApplication *app = [UIApplication sharedApplication];
/* Prevent the display from dimming and going to sleep. */
app.idleTimerDisabled = (_this->suspend_screensaver != SDL_FALSE);
}
}
}
BOOL
UIKit_IsSystemVersionAtLeast(double version)
{
return [[UIDevice currentDevice].systemVersion doubleValue] >= version;
}
CGRect
UIKit_ComputeViewFrame(SDL_Window *window, UIScreen *screen)
{
BOOL hasiOS7 = UIKit_IsSystemVersionAtLeast(7.0);
if (hasiOS7 || (window->flags & (SDL_WINDOW_BORDERLESS|SDL_WINDOW_FULLSCREEN))) {
/* The view should always show behind the status bar in iOS 7+. */
return screen.bounds;
} else {
return screen.applicationFrame;
}
}
/*
* iOS log support.
*
* This doesn't really have aything to do with the interfaces of the SDL video
* subsystem, but we need to stuff this into an Objective-C source code file.
*/
void SDL_NSLog(const char *text)
{
NSLog(@"%s", text);
}
#endif /* SDL_VIDEO_DRIVER_UIKIT */
/* vi: set ts=4 sw=4 expandtab: */
UIKit_InitModes
int UIKit_InitModes(_THIS)
UIKit_QuitModes
void UIKit_QuitModes(_THIS)
UIKit_ComputeViewFrame
CGRect UIKit_ComputeViewFrame(SDL_Window *window, UIScreen *screen)
UIKit_PumpEvents
void UIKit_PumpEvents(_THIS)
UIKit_SuspendScreenSaver
void UIKit_SuspendScreenSaver(_THIS)
SDL_uikitopengles.h
UIKit_GetWindowWMInfo
SDL_bool UIKit_GetWindowWMInfo(_THIS, SDL_Window *window, struct SDL_SysWMinfo *info)
UIKit_CreateWindow
int UIKit_CreateWindow(_THIS, SDL_Window *window)
UIKit_DestroyWindow
void UIKit_DestroyWindow(_THIS, SDL_Window *window)
SDL_VideoDevice::IsScreenKeyboardShown
SDL_bool(* IsScreenKeyboardShown)(_THIS, SDL_Window *window)
Definition: SDL_sysvideo.h:263
UIKit_GL_DeleteContext
void UIKit_GL_DeleteContext(_THIS, SDL_GLContext context)
window
SDL_Window * window
Definition: testautomation_render.c:26
SDL_VideoDevice::free
void(* free)(_THIS)
Definition: SDL_sysvideo.h:345
UIKit_GL_GetDrawableSize
void UIKit_GL_GetDrawableSize(_THIS, SDL_Window *window, int *w, int *h)
UIKit_IsSystemVersionAtLeast
BOOL UIKit_IsSystemVersionAtLeast(double version)
SDL_VideoDevice::ShowWindow
void(* ShowWindow)(_THIS, SDL_Window *window)
Definition: SDL_sysvideo.h:203
SDL_GetHint
#define SDL_GetHint
Definition: SDL_dynapi_overrides.h:197
SDL_uikitwindow.h
UIKit_SetWindowTitle
void UIKit_SetWindowTitle(_THIS, SDL_Window *window)
UIKit_RaiseWindow
void UIKit_RaiseWindow(_THIS, SDL_Window *window)
SDL_uikitevents.h
UIKit_HideWindow
void UIKit_HideWindow(_THIS, SDL_Window *window)
SDL_VideoDevice::GL_SwapWindow
void(* GL_SwapWindow)(_THIS, SDL_Window *window)
Definition: SDL_sysvideo.h:242
UIKit_SetWindowBordered
void UIKit_SetWindowBordered(_THIS, SDL_Window *window, SDL_bool bordered)
UIKit_GL_LoadLibrary
int UIKit_GL_LoadLibrary(_THIS, const char *path)
UIKit_GetDisplayModes
void UIKit_GetDisplayModes(_THIS, SDL_VideoDisplay *display)
SDL_VideoDevice::GL_LoadLibrary
int(* GL_LoadLibrary)(_THIS, const char *path)
Definition: SDL_sysvideo.h:234
SDL_VideoDevice::SetDisplayMode
int(* SetDisplayMode)(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mode)
Definition: SDL_sysvideo.h:189
SDL_VideoDevice::SetWindowBordered
void(* SetWindowBordered)(_THIS, SDL_Window *window, SDL_bool bordered)
Definition: SDL_sysvideo.h:209
SDL_VideoDevice::GL_GetDrawableSize
void(* GL_GetDrawableSize)(_THIS, SDL_Window *window, int *w, int *h)
Definition: SDL_sysvideo.h:239
_this
static SDL_VideoDevice * _this
Definition: SDL_video.c:114
SDL_VideoDevice::gl_config
struct SDL_VideoDevice::@29 gl_config
SDL_VideoDevice::HideWindow
void(* HideWindow)(_THIS, SDL_Window *window)
Definition: SDL_sysvideo.h:204
SDL_VideoDevice::accelerated
int accelerated
Definition: SDL_sysvideo.h:306
SDL_VideoDevice::RaiseWindow
void(* RaiseWindow)(_THIS, SDL_Window *window)
Definition: SDL_sysvideo.h:205
SDL_VideoDevice::SetTextInputRect
void(* SetTextInputRect)(_THIS, SDL_Rect *rect)
Definition: SDL_sysvideo.h:257
SDL_video.h
SDL_calloc
void * SDL_calloc(size_t nmemb, size_t size)
SDL_VideoDevice::GetWindowWMInfo
SDL_bool(* GetWindowWMInfo)(_THIS, SDL_Window *window, struct SDL_SysWMinfo *info)
Definition: SDL_sysvideo.h:227
SDL_VideoDevice::GL_CreateContext
SDL_GLContext(* GL_CreateContext)(_THIS, SDL_Window *window)
Definition: SDL_sysvideo.h:237
UIKit_SetWindowFullscreen
void UIKit_SetWindowFullscreen(_THIS, SDL_Window *window, SDL_VideoDisplay *display, SDL_bool fullscreen)
_THIS
#define _THIS
Definition: SDL_alsa_audio.h:31
SDL_VideoDevice::GL_MakeCurrent
int(* GL_MakeCurrent)(_THIS, SDL_Window *window, SDL_GLContext context)
Definition: SDL_sysvideo.h:238
SDL_free
void SDL_free(void *mem)
SDL_mouse.h
SDL_VideoDevice::driver_loaded
int driver_loaded
Definition: SDL_sysvideo.h:315
VideoBootStrap
Definition: SDL_sysvideo.h:348
SDL_hints.h
SDL_VideoDevice::DestroyWindow
void(* DestroyWindow)(_THIS, SDL_Window *window)
Definition: SDL_sysvideo.h:214
UIKit_GL_SwapWindow
void UIKit_GL_SwapWindow(_THIS, SDL_Window *window)
SDL_HINT_IDLE_TIMER_DISABLED
#define SDL_HINT_IDLE_TIMER_DISABLED
A variable controlling whether the idle timer is disabled on iOS.
Definition: SDL_hints.h:267
SDL_VideoDevice::HasScreenKeyboardSupport
SDL_bool(* HasScreenKeyboardSupport)(_THIS)
Definition: SDL_sysvideo.h:260
UIKit_GL_CreateContext
SDL_GLContext UIKit_GL_CreateContext(_THIS, SDL_Window *window)
UIKit_GL_GetProcAddress
void * UIKit_GL_GetProcAddress(_THIS, const char *proc)
SDL_VideoDevice::GetDisplayModes
void(* GetDisplayModes)(_THIS, SDL_VideoDisplay *display)
Definition: SDL_sysvideo.h:181
NULL
#define NULL
Definition: begin_code.h:143
SDL_OutOfMemory
#define SDL_OutOfMemory()
Definition: SDL_error.h:52
SDL_VideoDevice::VideoQuit
void(* VideoQuit)(_THIS)
Definition: SDL_sysvideo.h:161
SDL_WINDOW_BORDERLESS
Definition: SDL_video.h:102
text
static char text[MAX_TEXT_LENGTH]
Definition: testime.c:34
SDL_VideoDevice::ShowScreenKeyboard
void(* ShowScreenKeyboard)(_THIS, SDL_Window *window)
Definition: SDL_sysvideo.h:261
SDL_VideoDevice::CreateWindow
int(* CreateWindow)(_THIS, SDL_Window *window)
Definition: SDL_sysvideo.h:195
SDL_Window
The type used to identify a window.
Definition: SDL_sysvideo.h:71
SDL_FALSE
Definition: SDL_stdinc.h:128
SDL_WINDOW_FULLSCREEN
Definition: SDL_video.h:98
SDL_VideoDevice
Definition: SDL_sysvideo.h:142
SDL_VideoDevice::VideoInit
int(* VideoInit)(_THIS)
Definition: SDL_sysvideo.h:155
SDL_VideoDevice::suspend_screensaver
SDL_bool suspend_screensaver
Definition: SDL_sysvideo.h:278
SDL_VideoDevice::SetWindowFullscreen
void(* SetWindowFullscreen)(_THIS, SDL_Window *window, SDL_VideoDisplay *display, SDL_bool fullscreen)
Definition: SDL_sysvideo.h:210
SDL_VideoDevice::GL_DeleteContext
void(* GL_DeleteContext)(_THIS, SDL_GLContext context)
Definition: SDL_sysvideo.h:243
SDL_VideoDevice::SetWindowTitle
void(* SetWindowTitle)(_THIS, SDL_Window *window)
Definition: SDL_sysvideo.h:197
UIKit_ShowWindow
void UIKit_ShowWindow(_THIS, SDL_Window *window)
SDL_Window::flags
Uint32 flags
Definition: SDL_sysvideo.h:81
SDL_uikitmodes.h
screen
SDL_Renderer * screen
Definition: testgamecontroller.c:64
SDL_VideoDevice::SuspendScreenSaver
void(* SuspendScreenSaver)(_THIS)
Definition: SDL_sysvideo.h:252
UIKit_GL_MakeCurrent
int UIKit_GL_MakeCurrent(_THIS, SDL_Window *window, SDL_GLContext context)
SDL_VideoDevice::GL_GetProcAddress
void *(* GL_GetProcAddress)(_THIS, const char *proc)
Definition: SDL_sysvideo.h:235
SDL_VideoDevice::PumpEvents
void(* PumpEvents)(_THIS)
Definition: SDL_sysvideo.h:249
SDL_uikitvideo.h
SDL_VideoDevice::HideScreenKeyboard
void(* HideScreenKeyboard)(_THIS, SDL_Window *window)
Definition: SDL_sysvideo.h:262
UIKit_SetDisplayMode
int UIKit_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mode)