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 39 #include "keyinfotable.h" 44 SDL_AppleTVControllerUIHintChanged(
void *userdata,
const char *
name,
const char *oldValue,
const char *hint)
48 viewcontroller.controllerUserInteractionEnabled = hint && (*hint !=
'0');
55 SDL_HideHomeIndicatorHintChanged(
void *userdata,
const char *
name,
const char *oldValue,
const char *hint)
61 [viewcontroller setNeedsUpdateOfHomeIndicatorAutoHidden];
62 [viewcontroller setNeedsUpdateOfScreenEdgesDeferringSystemGestures];
69 CADisplayLink *displayLink;
70 int animationInterval;
71 void (*animationCallback)(
void*);
72 void *animationCallbackParam;
74 #if SDL_IPHONE_KEYBOARD 75 UITextField *textField;
76 BOOL rotatingOrientation;
82 - (instancetype)initWithSDLWindow:(
SDL_Window *)_window
84 if (
self = [super initWithNibName:nil bundle:nil]) {
85 self.window = _window;
87 #if SDL_IPHONE_KEYBOARD 89 rotatingOrientation =
FALSE;
94 SDL_AppleTVControllerUIHintChanged,
95 (__bridge
void *)
self);
100 SDL_HideHomeIndicatorHintChanged,
101 (__bridge
void *)
self);
109 #if SDL_IPHONE_KEYBOARD 110 [
self deinitKeyboard];
115 SDL_AppleTVControllerUIHintChanged,
116 (__bridge
void *)
self);
121 SDL_HideHomeIndicatorHintChanged,
122 (__bridge
void *)
self);
126 - (
void)setAnimationCallback:(
int)interval
127 callback:(
void (*)(
void*))callback
128 callbackParam:(
void*)callbackParam
130 [
self stopAnimation];
132 animationInterval = interval;
134 animationCallbackParam = callbackParam;
136 if (animationCallback) {
137 [
self startAnimation];
143 displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(doLoop:)];
148 if ([displayLink respondsToSelector:
@selector(preferredFramesPerSecond)]
149 && data != nil && data.
uiwindow != nil
150 && [data.uiwindow.screen respondsToSelector:@selector(maximumFramesPerSecond)]) {
151 displayLink.preferredFramesPerSecond = data.
uiwindow.screen.maximumFramesPerSecond / animationInterval;
155 #if __IPHONE_OS_VERSION_MIN_REQUIRED < 100300 156 [displayLink setFrameInterval:animationInterval];
160 [displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
165 [displayLink invalidate];
169 - (
void)doLoop:(CADisplayLink*)sender
172 if (!UIKit_ShowingMessageBox()) {
176 animationCallback(animationCallbackParam);
187 const CGSize
size =
self.view.bounds.size;
188 int w = (int) size.width;
189 int h = (
int) size.height;
200 #if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_7_0 201 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orient
226 return UIRectEdgeAll;
228 return UIRectEdgeNone;
234 return UIRectEdgeAll;
236 return UIRectEdgeNone;
244 #if SDL_IPHONE_KEYBOARD 246 @synthesize textInputRect;
247 @synthesize keyboardHeight;
248 @synthesize keyboardVisible;
253 textField = [[UITextField alloc] initWithFrame:CGRectZero];
254 textField.delegate =
self;
256 textField.text =
@" ";
259 textField.autocapitalizationType = UITextAutocapitalizationTypeNone;
260 textField.autocorrectionType = UITextAutocorrectionTypeNo;
261 textField.enablesReturnKeyAutomatically = NO;
262 textField.keyboardAppearance = UIKeyboardAppearanceDefault;
263 textField.keyboardType = UIKeyboardTypeDefault;
264 textField.returnKeyType = UIReturnKeyDefault;
265 textField.secureTextEntry = NO;
267 textField.hidden = YES;
268 keyboardVisible = NO;
271 NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
272 [center addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
273 [center addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
277 - (
void)setView:(UIView *)view
279 [
super setView:view];
281 [view addSubview:textField];
283 if (keyboardVisible) {
289 #if TARGET_OS_TV || __IPHONE_OS_VERSION_MIN_REQUIRED >= 80000 290 - (
void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(
id<UIViewControllerTransitionCoordinator>)coordinator
292 [
super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
293 rotatingOrientation =
TRUE;
294 [coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) {}
295 completion:^(id<UIViewControllerTransitionCoordinatorContext> context) {
296 rotatingOrientation = FALSE;
300 - (
void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
301 [
super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
302 rotatingOrientation =
TRUE;
305 - (
void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
306 [
super didRotateFromInterfaceOrientation:fromInterfaceOrientation];
307 rotatingOrientation =
FALSE;
311 - (
void)deinitKeyboard
314 NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
315 [center removeObserver:self name:UIKeyboardWillShowNotification object:nil];
316 [center removeObserver:self name:UIKeyboardWillHideNotification object:nil];
323 keyboardVisible = YES;
324 if (textField.window) {
325 [textField becomeFirstResponder];
332 keyboardVisible = NO;
333 [textField resignFirstResponder];
336 - (
void)keyboardWillShow:(NSNotification *)notification
339 CGRect kbrect = [[notification userInfo][UIKeyboardFrameEndUserInfoKey] CGRectValue];
343 kbrect = [
self.view convertRect:kbrect fromView:nil];
345 [
self setKeyboardHeight:(int)kbrect.size.height];
349 - (
void)keyboardWillHide:(NSNotification *)notification
351 if (!rotatingOrientation) {
354 [
self setKeyboardHeight:0];
357 - (
void)updateKeyboard
359 CGAffineTransform
t =
self.view.transform;
360 CGPoint
offset = CGPointMake(0.0, 0.0);
361 CGRect
frame = UIKit_ComputeViewFrame(
window,
self.view.window.screen);
363 if (
self.keyboardHeight) {
364 int rectbottom =
self.textInputRect.y + self.textInputRect.
h;
365 int keybottom =
self.view.bounds.size.height - self.keyboardHeight;
366 if (keybottom < rectbottom) {
367 offset.y = keybottom - rectbottom;
381 self.view.frame =
frame;
384 - (
void)setKeyboardHeight:(
int)height
386 keyboardVisible = height > 0;
388 [
self updateKeyboard];
392 - (BOOL)textField:(UITextField *)_textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
394 NSUInteger
len =
string.length;
404 for (i = 0; i <
len; i++) {
428 if (mod & KMOD_SHIFT) {
441 - (BOOL)textFieldShouldReturn:(UITextField*)_textField
456 #if SDL_IPHONE_KEYBOARD 472 UIKit_HasScreenKeyboardSupport(
_THIS)
501 return vc.isKeyboardVisible;
518 vc.textInputRect = *
rect;
520 if (vc.keyboardVisible) {
UIRectEdge preferredScreenEdgesDeferringSystemGestures()
GLsizei const GLchar *const * string
#define SDL_HINT_RETURN_KEY_HIDES_IME
A variable to control whether the return key on the soft keyboard should hide the soft keyboard on An...
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)
#define SDL_GetHintBoolean
void viewDidLayoutSubviews()
#define SDL_StopTextInput
BOOL prefersStatusBarHidden()
int SDL_SendKeyboardText(const char *text)
SDL_Window * SDL_GetFocusWindow(void)
static UIKitKeyInfo unicharToUIKeyInfoTable[]
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
#define SDL_HINT_IOS_HIDE_HOME_INDICATOR
A variable controlling whether the home indicator bar on iPhone X should be hidden.
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
BOOL prefersHomeIndicatorAutoHidden()
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()