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;
66 - (instancetype)initWithSDLWindow:(
SDL_Window *)_window
68 if (
self = [super initWithNibName:nil bundle:nil]) {
69 self.window = _window;
71 #if SDL_IPHONE_KEYBOARD 77 SDL_AppleTVControllerUIHintChanged,
78 (__bridge
void *)
self);
86 #if SDL_IPHONE_KEYBOARD 87 [
self deinitKeyboard];
92 SDL_AppleTVControllerUIHintChanged,
93 (__bridge
void *)
self);
97 - (
void)setAnimationCallback:(
int)interval
98 callback:(
void (*)(
void*))callback
99 callbackParam:(
void*)callbackParam
101 [
self stopAnimation];
103 animationInterval = interval;
105 animationCallbackParam = callbackParam;
107 if (animationCallback) {
108 [
self startAnimation];
114 displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(doLoop:)];
115 [displayLink setFrameInterval:animationInterval];
116 [displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
121 [displayLink invalidate];
125 - (
void)doLoop:(CADisplayLink*)sender
128 if (!UIKit_ShowingMessageBox()) {
132 animationCallback(animationCallbackParam);
143 const CGSize
size =
self.view.bounds.size;
144 int w = (int)
size.width;
145 int h = (
int)
size.height;
156 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orient
170 #if SDL_IPHONE_KEYBOARD 172 @synthesize textInputRect;
173 @synthesize keyboardHeight;
174 @synthesize keyboardVisible;
179 textField = [[UITextField alloc] initWithFrame:CGRectZero];
180 textField.delegate =
self;
182 textField.text =
@" ";
185 textField.autocapitalizationType = UITextAutocapitalizationTypeNone;
186 textField.autocorrectionType = UITextAutocorrectionTypeNo;
187 textField.enablesReturnKeyAutomatically = NO;
188 textField.keyboardAppearance = UIKeyboardAppearanceDefault;
189 textField.keyboardType = UIKeyboardTypeDefault;
190 textField.returnKeyType = UIReturnKeyDefault;
191 textField.secureTextEntry = NO;
193 textField.hidden = YES;
194 keyboardVisible = NO;
197 NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
198 [center addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
199 [center addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
203 - (
void)setView:(UIView *)view
205 [
super setView:view];
207 [view addSubview:textField];
209 if (keyboardVisible) {
214 - (
void)deinitKeyboard
217 NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
218 [center removeObserver:self name:UIKeyboardWillShowNotification object:nil];
219 [center removeObserver:self name:UIKeyboardWillHideNotification object:nil];
226 keyboardVisible = YES;
227 if (textField.window) {
228 [textField becomeFirstResponder];
235 keyboardVisible = NO;
236 [textField resignFirstResponder];
239 - (
void)keyboardWillShow:(NSNotification *)notification
242 CGRect kbrect = [[notification userInfo][UIKeyboardFrameBeginUserInfoKey] CGRectValue];
246 kbrect = [
self.view convertRect:kbrect fromView:nil];
248 [
self setKeyboardHeight:(int)kbrect.size.height];
252 - (
void)keyboardWillHide:(NSNotification *)notification
255 [
self setKeyboardHeight:0];
258 - (
void)updateKeyboard
260 CGAffineTransform
t =
self.view.transform;
261 CGPoint
offset = CGPointMake(0.0, 0.0);
262 CGRect
frame = UIKit_ComputeViewFrame(
window,
self.view.window.screen);
264 if (
self.keyboardHeight) {
265 int rectbottom =
self.textInputRect.y + self.textInputRect.
h;
266 int keybottom =
self.view.bounds.size.height - self.keyboardHeight;
267 if (keybottom < rectbottom) {
268 offset.y = keybottom - rectbottom;
282 self.view.frame =
frame;
285 - (
void)setKeyboardHeight:(
int)height
287 keyboardVisible = height > 0;
289 [
self updateKeyboard];
293 - (BOOL)textField:(UITextField *)_textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
295 NSUInteger
len =
string.length;
305 for (i = 0; i <
len; i++) {
329 if (mod & KMOD_SHIFT) {
342 - (BOOL)textFieldShouldReturn:(UITextField*)_textField
355 #if SDL_IPHONE_KEYBOARD 371 UIKit_HasScreenKeyboardSupport(
_THIS)
400 return vc.isKeyboardVisible;
417 vc.textInputRect = *
rect;
419 if (vc.keyboardVisible) {
GLsizei const GLchar *const * string
GLint GLint GLint GLint GLint x
void UIKit_GL_RestoreCurrentContext()
SDL_uikitviewcontroller * viewcontroller
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
GLuint const GLchar * name
int SDL_SendWindowEvent(SDL_Window *window, Uint8 windowevent, int data1, int data2)
#define SDL_InvalidParamError(param)
GLint GLint GLsizei GLsizei height
NSUInteger UIKit_GetSupportedOrientations(SDL_Window *window)
int SDL_SendKeyboardKey(Uint8 state, SDL_Scancode scancode)
void viewDidLayoutSubviews()
#define SDL_StopTextInput
GLint GLint GLint GLint GLint GLint y
static UIKitKeyInfo unicharToUIKeyInfoTable[]
BOOL prefersStatusBarHidden()
int SDL_SendKeyboardText(const char *text)
SDL_Window * SDL_GetFocusWindow(void)
static Uint32 callback(Uint32 interval, void *param)
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)
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
uint16_t Uint16
An unsigned 16-bit integer type.
GLubyte GLubyte GLubyte GLubyte w
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.
GLfloat GLfloat GLfloat GLfloat h
A rectangle, with the origin at the upper left.
NSUInteger supportedInterfaceOrientations()