21 #include "../../SDL_internal.h"
23 #if SDL_VIDEO_DRIVER_UIKIT
27 #include "../SDL_sysvideo.h"
28 #include "../../events/SDL_events_c.h"
37 #if SDL_IPHONE_KEYBOARD
38 #include "keyinfotable.h"
43 SDL_AppleTVControllerUIHintChanged(
void *userdata,
const char *
name,
const char *oldValue,
const char *hint)
47 viewcontroller.controllerUserInteractionEnabled = hint && (*hint !=
'0');
54 SDL_HideHomeIndicatorHintChanged(
void *userdata,
const char *
name,
const char *oldValue,
const char *hint)
59 #pragma clang diagnostic push
60 #pragma clang diagnostic ignored "-Wunguarded-availability-new"
61 if ([viewcontroller respondsToSelector:
@selector(setNeedsUpdateOfHomeIndicatorAutoHidden)]) {
62 [viewcontroller setNeedsUpdateOfHomeIndicatorAutoHidden];
63 [viewcontroller setNeedsUpdateOfScreenEdgesDeferringSystemGestures];
65 #pragma clang diagnostic pop
71 CADisplayLink *displayLink;
72 int animationInterval;
73 void (*animationCallback)(
void*);
74 void *animationCallbackParam;
76 #if SDL_IPHONE_KEYBOARD
77 UITextField *textField;
78 BOOL hardwareKeyboard;
80 BOOL rotatingOrientation;
82 NSString *obligateForBackspace;
88 - (instancetype)initWithSDLWindow:(
SDL_Window *)_window
90 if (
self = [super initWithNibName:nil bundle:nil]) {
91 self.window = _window;
93 #if SDL_IPHONE_KEYBOARD
95 hardwareKeyboard = NO;
97 rotatingOrientation = NO;
102 SDL_AppleTVControllerUIHintChanged,
103 (__bridge
void *)
self);
108 SDL_HideHomeIndicatorHintChanged,
109 (__bridge
void *)
self);
117 #if SDL_IPHONE_KEYBOARD
118 [
self deinitKeyboard];
123 SDL_AppleTVControllerUIHintChanged,
124 (__bridge
void *)
self);
129 SDL_HideHomeIndicatorHintChanged,
130 (__bridge
void *)
self);
134 - (
void)setAnimationCallback:(
int)interval
135 callback:(
void (*)(
void*))callback
136 callbackParam:(
void*)callbackParam
138 [
self stopAnimation];
140 animationInterval = interval;
142 animationCallbackParam = callbackParam;
144 if (animationCallback) {
145 [
self startAnimation];
149 - (
void)startAnimation
151 displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(doLoop:)];
156 if ([displayLink respondsToSelector:
@selector(preferredFramesPerSecond)]
157 &&
data != nil &&
data.uiwindow != nil
158 && [data.uiwindow.screen respondsToSelector:@selector(maximumFramesPerSecond)]) {
159 displayLink.preferredFramesPerSecond =
data.uiwindow.screen.maximumFramesPerSecond / animationInterval;
163 #if __IPHONE_OS_VERSION_MIN_REQUIRED < 100300
164 [displayLink setFrameInterval:animationInterval];
168 [displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
171 - (
void)stopAnimation
173 [displayLink invalidate];
177 - (
void)doLoop:(CADisplayLink*)sender
180 if (!UIKit_ShowingMessageBox()) {
182 #if SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2
183 UIKit_GL_RestoreCurrentContext();
186 animationCallback(animationCallbackParam);
195 - (
void)viewDidLayoutSubviews
197 const CGSize
size =
self.view.bounds.size;
199 int h = (
int)
size.height;
205 - (NSUInteger)supportedInterfaceOrientations
210 #if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_7_0
211 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orient
213 return ([
self supportedInterfaceOrientations] & (1 << orient)) != 0;
217 - (BOOL)prefersStatusBarHidden
223 - (BOOL)prefersHomeIndicatorAutoHidden
226 if (
self.homeIndicatorHidden == 1) {
232 - (UIRectEdge)preferredScreenEdgesDeferringSystemGestures
234 if (
self.homeIndicatorHidden >= 0) {
235 if (
self.homeIndicatorHidden == 2) {
236 return UIRectEdgeAll;
238 return UIRectEdgeNone;
244 return UIRectEdgeAll;
246 return UIRectEdgeNone;
254 #if SDL_IPHONE_KEYBOARD
256 @synthesize textInputRect;
257 @synthesize keyboardHeight;
258 @synthesize keyboardVisible;
264 obligateForBackspace =
@" ";
265 textField = [[UITextField alloc] initWithFrame:CGRectZero];
266 textField.delegate =
self;
268 textField.text = obligateForBackspace;
271 textField.autocapitalizationType = UITextAutocapitalizationTypeNone;
272 textField.autocorrectionType = UITextAutocorrectionTypeNo;
273 textField.enablesReturnKeyAutomatically = NO;
274 textField.keyboardAppearance = UIKeyboardAppearanceDefault;
275 textField.keyboardType = UIKeyboardTypeDefault;
276 textField.returnKeyType = UIReturnKeyDefault;
277 textField.secureTextEntry = NO;
279 textField.hidden = YES;
280 keyboardVisible = NO;
282 NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
284 [center addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
285 [center addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
287 [center addObserver:self selector:@selector(textFieldTextDidChange:) name:UITextFieldTextDidChangeNotification object:nil];
290 - (NSArray *)keyCommands
292 NSMutableArray *
commands = [[NSMutableArray alloc] init];
293 [commands addObject:[UIKeyCommand keyCommandWithInput:UIKeyInputUpArrow modifierFlags:kNilOptions action:@selector(handleCommand:)]];
294 [commands addObject:[UIKeyCommand keyCommandWithInput:UIKeyInputDownArrow modifierFlags:kNilOptions action:@selector(handleCommand:)]];
295 [commands addObject:[UIKeyCommand keyCommandWithInput:UIKeyInputLeftArrow modifierFlags:kNilOptions action:@selector(handleCommand:)]];
296 [commands addObject:[UIKeyCommand keyCommandWithInput:UIKeyInputRightArrow modifierFlags:kNilOptions action:@selector(handleCommand:)]];
297 [commands addObject:[UIKeyCommand keyCommandWithInput:UIKeyInputEscape modifierFlags:kNilOptions action:@selector(handleCommand:)]];
298 return [NSArray arrayWithArray:commands];
301 - (
void)handleCommand:(UIKeyCommand *)keyCommand
304 NSString *
input = keyCommand.input;
306 if (
input == UIKeyInputUpArrow) {
308 }
else if (
input == UIKeyInputDownArrow) {
310 }
else if (
input == UIKeyInputLeftArrow) {
312 }
else if (
input == UIKeyInputRightArrow) {
314 }
else if (
input == UIKeyInputEscape) {
323 - (
void)setView:(UIView *)view
325 [
super setView:view];
327 [view addSubview:textField];
329 if (keyboardVisible) {
335 #if TARGET_OS_TV || __IPHONE_OS_VERSION_MIN_REQUIRED >= 80000
336 - (
void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(
id<UIViewControllerTransitionCoordinator>)coordinator
338 [
super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
339 rotatingOrientation = YES;
340 [coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) {}
341 completion:^(id<UIViewControllerTransitionCoordinatorContext> context) {
342 self->rotatingOrientation = NO;
346 - (
void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
347 [
super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
348 rotatingOrientation = YES;
351 - (
void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
352 [
super didRotateFromInterfaceOrientation:fromInterfaceOrientation];
353 rotatingOrientation = NO;
357 - (
void)deinitKeyboard
359 NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
361 [center removeObserver:self name:UIKeyboardWillShowNotification object:nil];
362 [center removeObserver:self name:UIKeyboardWillHideNotification object:nil];
364 [center removeObserver:self name:UITextFieldTextDidChangeNotification object:nil];
370 keyboardVisible = YES;
371 if (textField.window) {
372 showingKeyboard = YES;
373 [textField becomeFirstResponder];
374 showingKeyboard = NO;
381 keyboardVisible = NO;
382 [textField resignFirstResponder];
385 - (
void)keyboardWillShow:(NSNotification *)notification
388 CGRect kbrect = [[notification userInfo][UIKeyboardFrameEndUserInfoKey] CGRectValue];
392 kbrect = [
self.view convertRect:kbrect fromView:nil];
394 [
self setKeyboardHeight:(int)kbrect.size.height];
398 - (
void)keyboardWillHide:(NSNotification *)notification
400 if (!showingKeyboard && !rotatingOrientation) {
403 [
self setKeyboardHeight:0];
406 - (
void)textFieldTextDidChange:(NSNotification *)notification
408 if (changeText!=nil && textField.markedTextRange == nil)
410 NSUInteger
len = changeText.length;
416 for (
i = 0;
i <
len;
i++) {
417 unichar
c = [changeText characterAtIndex:i];
452 - (
void)updateKeyboard
454 CGAffineTransform
t =
self.view.transform;
455 CGPoint
offset = CGPointMake(0.0, 0.0);
456 CGRect
frame = UIKit_ComputeViewFrame(
window,
self.view.window.screen);
458 if (
self.keyboardHeight) {
459 int rectbottom =
self.textInputRect.y + self.textInputRect.
h;
460 int keybottom =
self.view.bounds.size.height - self.keyboardHeight;
461 if (keybottom < rectbottom) {
462 offset.y = keybottom - rectbottom;
476 self.view.frame =
frame;
479 - (
void)setKeyboardHeight:(
int)height
481 keyboardVisible =
height > 0;
483 [
self updateKeyboard];
487 - (BOOL)textField:(UITextField *)_textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
489 NSUInteger
len =
string.length;
492 if (textField.markedTextRange == nil) {
496 if (textField.text.length < 16) {
497 textField.text = obligateForBackspace;
506 - (BOOL)textFieldShouldReturn:(UITextField*)_textField
509 if (keyboardVisible &&
521 #if SDL_IPHONE_KEYBOARD
537 UIKit_HasScreenKeyboardSupport(
_THIS)
566 return vc.keyboardVisible;
583 vc.textInputRect = *
rect;
585 if (vc.keyboardVisible) {
#define SDL_DelHintCallback
#define SDL_StopTextInput
#define SDL_GetHintBoolean
#define SDL_AddHintCallback
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
#define SDL_InvalidParamError(param)
#define SDL_HINT_APPLE_TV_CONTROLLER_UI_EVENTS
A variable controlling whether controllers used with the Apple TV generate UI events.
#define SDL_HINT_IOS_HIDE_HOME_INDICATOR
A variable controlling whether the home indicator bar on iPhone X should be hidden.
#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...
int SDL_SendKeyboardKeyAutoRelease(SDL_Scancode scancode)
SDL_bool SDL_HardwareKeyboardKeyPressed(void)
int SDL_SendKeyboardText(const char *text)
int SDL_SendKeyboardKey(Uint8 state, SDL_Scancode scancode)
GLint GLint GLint GLint GLint GLint y
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
GLint GLint GLint GLint GLint x
GLint GLint GLsizei GLsizei height
GLsizei const GLubyte * commands
GLuint const GLchar * name
GLenum GLenum GLenum input
GLsizei const GLchar *const * string
GLfloat GLfloat GLfloat GLfloat h
GLubyte GLubyte GLubyte GLubyte w
SDL_Scancode
The SDL keyboard scancode representation.
SDL_Window * SDL_GetFocusWindow(void)
NSUInteger UIKit_GetSupportedOrientations(SDL_Window *window)
@ SDL_WINDOWEVENT_RESIZED
int SDL_SendWindowEvent(SDL_Window *window, Uint8 windowevent, int data1, int data2)
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)
EGLSurface EGLNativeWindowType * window
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 skip1(dst_w_bpp<=(lowbit *8)) &&((lowbit *8)<(pixblock_size *dst_w_bpp)) .if lowbit< 16 tst DST_R
A rectangle, with the origin at the upper left (integer).
SDL_uikitviewcontroller * viewcontroller
The type used to identify a window.
static Uint32 callback(Uint32 interval, void *param)
static UIKitKeyInfo unicharToUIKeyInfoTable[]
typedef int(__stdcall *FARPROC)()