21 #include "../../SDL_internal.h" 23 #if SDL_VIDEO_DRIVER_UIKIT 28 #include "../SDL_sysvideo.h" 29 #include "../../events/SDL_events_c.h" 38 #if SDL_IPHONE_KEYBOARD 44 SDL_AppleTVControllerUIHintChanged(
void *userdata,
const char *
name,
const char *oldValue,
const char *hint)
48 viewcontroller.controllerUserInteractionEnabled = hint && (*hint !=
'0');
54 CADisplayLink *displayLink;
55 int animationInterval;
56 void (*animationCallback)(
void*);
57 void *animationCallbackParam;
59 #if SDL_IPHONE_KEYBOARD 60 UITextField *textField;
61 BOOL rotatingOrientation;
67 - (instancetype)initWithSDLWindow:(
SDL_Window *)_window
69 if (
self = [super initWithNibName:nil bundle:nil]) {
70 self.window = _window;
72 #if SDL_IPHONE_KEYBOARD 74 rotatingOrientation =
FALSE;
79 SDL_AppleTVControllerUIHintChanged,
80 (__bridge
void *)
self);
88 #if SDL_IPHONE_KEYBOARD 89 [
self deinitKeyboard];
94 SDL_AppleTVControllerUIHintChanged,
95 (__bridge
void *)
self);
99 - (
void)setAnimationCallback:(
int)interval
100 callback:(
void (*)(
void*))callback
101 callbackParam:(
void*)callbackParam
103 [
self stopAnimation];
105 animationInterval = interval;
107 animationCallbackParam = callbackParam;
109 if (animationCallback) {
110 [
self startAnimation];
116 displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(doLoop:)];
121 if ([displayLink respondsToSelector:
@selector(preferredFramesPerSecond)]
122 && data != nil && data.
uiwindow != nil
123 && [data.uiwindow.screen respondsToSelector:@selector(maximumFramesPerSecond)]) {
124 displayLink.preferredFramesPerSecond = data.
uiwindow.screen.maximumFramesPerSecond / animationInterval;
128 #if __IPHONE_OS_VERSION_MIN_REQUIRED < 100300 129 [displayLink setFrameInterval:animationInterval];
133 [displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
138 [displayLink invalidate];
142 - (
void)doLoop:(CADisplayLink*)sender
145 if (!UIKit_ShowingMessageBox()) {
149 animationCallback(animationCallbackParam);
160 const CGSize
size =
self.view.bounds.size;
161 int w = (int) size.width;
162 int h = (
int) size.height;
173 #if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_7_0 174 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orient
189 #if SDL_IPHONE_KEYBOARD 191 @synthesize textInputRect;
192 @synthesize keyboardHeight;
193 @synthesize keyboardVisible;
198 textField = [[UITextField alloc] initWithFrame:CGRectZero];
199 textField.delegate =
self;
201 textField.text =
@" ";
204 textField.autocapitalizationType = UITextAutocapitalizationTypeNone;
205 textField.autocorrectionType = UITextAutocorrectionTypeNo;
206 textField.enablesReturnKeyAutomatically = NO;
207 textField.keyboardAppearance = UIKeyboardAppearanceDefault;
208 textField.keyboardType = UIKeyboardTypeDefault;
209 textField.returnKeyType = UIReturnKeyDefault;
210 textField.secureTextEntry = NO;
212 textField.hidden = YES;
213 keyboardVisible = NO;
216 NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
217 [center addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
218 [center addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
222 - (
void)setView:(UIView *)view
224 [
super setView:view];
226 [view addSubview:textField];
228 if (keyboardVisible) {
234 #if TARGET_OS_TV || __IPHONE_OS_VERSION_MIN_REQUIRED >= 80000 235 - (
void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(
id<UIViewControllerTransitionCoordinator>)coordinator
237 [
super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
238 rotatingOrientation =
TRUE;
239 [coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) {}
240 completion:^(id<UIViewControllerTransitionCoordinatorContext> context) {
241 rotatingOrientation = FALSE;
245 - (
void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
246 [
super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
247 rotatingOrientation =
TRUE;
250 - (
void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
251 [
super didRotateFromInterfaceOrientation:fromInterfaceOrientation];
252 rotatingOrientation =
FALSE;
256 - (
void)deinitKeyboard
259 NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
260 [center removeObserver:self name:UIKeyboardWillShowNotification object:nil];
261 [center removeObserver:self name:UIKeyboardWillHideNotification object:nil];
268 keyboardVisible = YES;
269 if (textField.window) {
270 [textField becomeFirstResponder];
277 keyboardVisible = NO;
278 [textField resignFirstResponder];
281 - (
void)keyboardWillShow:(NSNotification *)notification
284 CGRect kbrect = [[notification userInfo][UIKeyboardFrameEndUserInfoKey] CGRectValue];
288 kbrect = [
self.view convertRect:kbrect fromView:nil];
290 [
self setKeyboardHeight:(int)kbrect.size.height];
294 - (
void)keyboardWillHide:(NSNotification *)notification
296 if (!rotatingOrientation) {
299 [
self setKeyboardHeight:0];
302 - (
void)updateKeyboard
304 CGAffineTransform
t =
self.view.transform;
305 CGPoint
offset = CGPointMake(0.0, 0.0);
306 CGRect
frame = UIKit_ComputeViewFrame(
window,
self.view.window.screen);
308 if (
self.keyboardHeight) {
309 int rectbottom =
self.textInputRect.y + self.textInputRect.
h;
310 int keybottom =
self.view.bounds.size.height - self.keyboardHeight;
311 if (keybottom < rectbottom) {
312 offset.y = keybottom - rectbottom;
326 self.view.frame =
frame;
329 - (
void)setKeyboardHeight:(
int)height
331 keyboardVisible = height > 0;
333 [
self updateKeyboard];
337 - (BOOL)textField:(UITextField *)_textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
339 NSUInteger
len =
string.length;
349 for (i = 0; i <
len; i++) {
373 if (mod & KMOD_SHIFT) {
386 - (BOOL)textFieldShouldReturn:(UITextField*)_textField
399 #if SDL_IPHONE_KEYBOARD 415 UIKit_HasScreenKeyboardSupport(
_THIS)
444 return vc.isKeyboardVisible;
461 vc.textInputRect = *
rect;
463 if (vc.keyboardVisible) {
GLsizei const GLchar *const * string
GLint GLint GLint GLint GLint x
GLfloat GLfloat GLfloat GLfloat h
SDL_uikitviewcontroller * viewcontroller
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
int SDL_SendWindowEvent(SDL_Window *window, Uint8 windowevent, int data1, int data2)
#define SDL_InvalidParamError(param)
NSUInteger UIKit_GetSupportedOrientations(SDL_Window *window)
GLuint const GLchar * name
void UIKit_GL_RestoreCurrentContext(void)
int SDL_SendKeyboardKey(Uint8 state, SDL_Scancode scancode)
void viewDidLayoutSubviews()
#define SDL_StopTextInput
static UIKitKeyInfo unicharToUIKeyInfoTable[]
BOOL prefersStatusBarHidden()
int SDL_SendKeyboardText(const char *text)
SDL_Window * SDL_GetFocusWindow(void)
GLubyte GLubyte GLubyte GLubyte w
static Uint32 callback(Uint32 interval, void *param)
GLint GLint GLint GLint GLint GLint y
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
GLint GLint GLsizei GLsizei height
EGLSurface EGLNativeWindowType * window
SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char const char SDL_SCANF_FORMAT_STRING const char return SDL_ThreadFunction const char void return Uint32 return Uint32 void
The type used to identify a window.
#define SDL_AddHintCallback
#define SDL_DelHintCallback
SDL_Scancode
The SDL keyboard scancode representation.
#define SDL_HINT_APPLE_TV_CONTROLLER_UI_EVENTS
A variable controlling whether controllers used with the Apple TV generate UI events.
A rectangle, with the origin at the upper left.
NSUInteger supportedInterfaceOrientations()