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;
78 NSString *obligateForBackspace;
84 - (instancetype)initWithSDLWindow:(
SDL_Window *)_window
86 if (
self = [super initWithNibName:nil bundle:nil]) {
87 self.window = _window;
89 #if SDL_IPHONE_KEYBOARD 91 rotatingOrientation =
FALSE;
96 SDL_AppleTVControllerUIHintChanged,
97 (__bridge
void *)
self);
102 SDL_HideHomeIndicatorHintChanged,
103 (__bridge
void *)
self);
111 #if SDL_IPHONE_KEYBOARD 112 [
self deinitKeyboard];
117 SDL_AppleTVControllerUIHintChanged,
118 (__bridge
void *)
self);
123 SDL_HideHomeIndicatorHintChanged,
124 (__bridge
void *)
self);
128 - (
void)setAnimationCallback:(
int)interval
129 callback:(
void (*)(
void*))callback
130 callbackParam:(
void*)callbackParam
132 [
self stopAnimation];
134 animationInterval = interval;
136 animationCallbackParam = callbackParam;
138 if (animationCallback) {
139 [
self startAnimation];
145 displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(doLoop:)];
150 if ([displayLink respondsToSelector:
@selector(preferredFramesPerSecond)]
151 && data != nil && data.
uiwindow != nil
152 && [data.uiwindow.screen respondsToSelector:@selector(maximumFramesPerSecond)]) {
153 displayLink.preferredFramesPerSecond = data.
uiwindow.screen.maximumFramesPerSecond / animationInterval;
157 #if __IPHONE_OS_VERSION_MIN_REQUIRED < 100300 158 [displayLink setFrameInterval:animationInterval];
162 [displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
167 [displayLink invalidate];
171 - (
void)doLoop:(CADisplayLink*)sender
174 if (!UIKit_ShowingMessageBox()) {
178 animationCallback(animationCallbackParam);
189 const CGSize
size =
self.view.bounds.size;
190 int w = (int) size.width;
191 int h = (
int) size.height;
202 #if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_7_0 203 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orient
228 return UIRectEdgeAll;
230 return UIRectEdgeNone;
236 return UIRectEdgeAll;
238 return UIRectEdgeNone;
246 #if SDL_IPHONE_KEYBOARD 248 @synthesize textInputRect;
249 @synthesize keyboardHeight;
250 @synthesize keyboardVisible;
256 obligateForBackspace =
@" ";
257 textField = [[UITextField alloc] initWithFrame:CGRectZero];
258 textField.delegate =
self;
260 textField.text = obligateForBackspace;
263 textField.autocapitalizationType = UITextAutocapitalizationTypeNone;
264 textField.autocorrectionType = UITextAutocorrectionTypeNo;
265 textField.enablesReturnKeyAutomatically = NO;
266 textField.keyboardAppearance = UIKeyboardAppearanceDefault;
267 textField.keyboardType = UIKeyboardTypeDefault;
268 textField.returnKeyType = UIReturnKeyDefault;
269 textField.secureTextEntry = NO;
271 textField.hidden = YES;
272 keyboardVisible = NO;
274 NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
276 [center addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
277 [center addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
279 [center addObserver:self selector:@selector(textFieldTextDidChange:) name:UITextFieldTextDidChangeNotification object:nil];
282 - (
void)setView:(UIView *)view
284 [
super setView:view];
286 [view addSubview:textField];
288 if (keyboardVisible) {
294 #if TARGET_OS_TV || __IPHONE_OS_VERSION_MIN_REQUIRED >= 80000 295 - (
void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(
id<UIViewControllerTransitionCoordinator>)coordinator
297 [
super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
298 rotatingOrientation =
TRUE;
299 [coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) {}
300 completion:^(id<UIViewControllerTransitionCoordinatorContext> context) {
301 rotatingOrientation = FALSE;
305 - (
void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
306 [
super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
307 rotatingOrientation =
TRUE;
310 - (
void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
311 [
super didRotateFromInterfaceOrientation:fromInterfaceOrientation];
312 rotatingOrientation =
FALSE;
316 - (
void)deinitKeyboard
318 NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
320 [center removeObserver:self name:UIKeyboardWillShowNotification object:nil];
321 [center removeObserver:self name:UIKeyboardWillHideNotification object:nil];
323 [center removeObserver:self name:UITextFieldTextDidChangeNotification object:nil];
329 keyboardVisible = YES;
330 if (textField.window) {
331 [textField becomeFirstResponder];
338 keyboardVisible = NO;
339 [textField resignFirstResponder];
342 - (
void)keyboardWillShow:(NSNotification *)notification
345 CGRect kbrect = [[notification userInfo][UIKeyboardFrameEndUserInfoKey] CGRectValue];
349 kbrect = [
self.view convertRect:kbrect fromView:nil];
351 [
self setKeyboardHeight:(int)kbrect.size.height];
355 - (
void)keyboardWillHide:(NSNotification *)notification
357 if (!rotatingOrientation) {
360 [
self setKeyboardHeight:0];
363 - (
void)textFieldTextDidChange:(NSNotification *)notification
365 if (changeText!=nil && textField.markedTextRange == nil)
367 NSUInteger
len = changeText.length;
372 for (i = 0; i <
len; i++) {
373 unichar
c = [changeText characterAtIndex:i];
396 if (mod & KMOD_SHIFT) {
407 - (
void)updateKeyboard
409 CGAffineTransform
t =
self.view.transform;
410 CGPoint
offset = CGPointMake(0.0, 0.0);
411 CGRect
frame = UIKit_ComputeViewFrame(
window,
self.view.window.screen);
413 if (
self.keyboardHeight) {
414 int rectbottom =
self.textInputRect.y + self.textInputRect.
h;
415 int keybottom =
self.view.bounds.size.height - self.keyboardHeight;
416 if (keybottom < rectbottom) {
417 offset.y = keybottom - rectbottom;
425 offset = CGPointApplyAffineTransform(offset, t);
428 frame.origin.x += offset.
x;
429 frame.origin.y += offset.
y;
431 self.view.frame =
frame;
434 - (
void)setKeyboardHeight:(
int)height
436 keyboardVisible = height > 0;
438 [
self updateKeyboard];
442 - (BOOL)textField:(UITextField *)_textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
444 NSUInteger len =
string.length;
447 if (textField.markedTextRange == nil) {
452 if (textField.text.length < 16) {
453 textField.text = obligateForBackspace;
462 - (BOOL)textFieldShouldReturn:(UITextField*)_textField
477 #if SDL_IPHONE_KEYBOARD 493 UIKit_HasScreenKeyboardSupport(
_THIS)
522 return vc.keyboardVisible;
539 vc.textInputRect = *
rect;
541 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
set set set set set set set macro pixldst1 abits if abits op else op endif endm macro pixldst2 abits if abits op else op endif endm macro pixldst4 abits if abits op else op endif endm macro pixldst0 abits op endm macro pixldst3 mem_operand op endm macro pixldst30 mem_operand op endm macro pixldst abits if abits elseif abits elseif abits elseif abits elseif abits pixldst0 abits else pixldst0 abits pixldst0 abits pixldst0 abits pixldst0 abits endif elseif abits else pixldst0 abits pixldst0 abits endif elseif abits else error unsupported bpp *numpix else pixst endif endm macro pixld1_s mem_operand if asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl elseif asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl else error unsupported endif endm macro pixld2_s mem_operand if mov asr add asl add asl mov asr sub UNIT_X add asl mov asr add asl add asl mov asr add UNIT_X add asl else pixld1_s mem_operand pixld1_s mem_operand endif endm macro pixld0_s mem_operand if asr adds SRC_WIDTH_FIXED bpl add asl elseif asr adds SRC_WIDTH_FIXED bpl add asl endif endm macro pixld_s_internal mem_operand if mem_operand pixld2_s mem_operand pixdeinterleave basereg elseif mem_operand elseif mem_operand elseif mem_operand elseif mem_operand pixld0_s mem_operand else pixld0_s mem_operand pixld0_s mem_operand pixld0_s mem_operand pixld0_s mem_operand endif elseif mem_operand else pixld0_s mem_operand pixld0_s mem_operand endif elseif mem_operand else error unsupported mem_operand if bpp mem_operand endif endm macro vuzp8 reg2 vuzp d d ®2 endm macro vzip8 reg2 vzip d d ®2 endm macro pixdeinterleave basereg basereg basereg basereg basereg endif endm macro pixinterleave basereg basereg basereg basereg basereg endif endm macro PF boost_increment endif if endif PF tst PF addne PF subne PF cmp ORIG_W if endif if endif if endif PF subge ORIG_W PF subges if endif if endif if endif endif endm macro cache_preload_simple endif if dst_r_bpp pld [DST_R, #(PREFETCH_DISTANCE_SIMPLE *dst_r_bpp/8)] endif if mask_bpp pld if[MASK, #(PREFETCH_DISTANCE_SIMPLE *mask_bpp/8)] endif endif endm macro fetch_mask_pixblock pixld mask_basereg pixblock_size MASK endm macro ensure_destination_ptr_alignment process_pixblock_tail_head if beq irp local skip1(dst_w_bpp<=(lowbit *8)) &&((lowbit *8)<(pixblock_size *dst_w_bpp)) .if lowbit< 16 tst DST_R
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()