21 #include "../../SDL_internal.h" 23 #if SDL_VIDEO_DRIVER_UIKIT 28 #include "../SDL_sysvideo.h" 29 #include "../../events/SDL_events_c.h" 37 #if SDL_IPHONE_KEYBOARD 42 CADisplayLink *displayLink;
43 int animationInterval;
44 void (*animationCallback)(
void*);
45 void *animationCallbackParam;
47 #if SDL_IPHONE_KEYBOARD 48 UITextField *textField;
54 - (instancetype)initWithSDLWindow:(
SDL_Window *)_window
56 if (
self = [super initWithNibName:nil bundle:nil]) {
57 self.window = _window;
59 #if SDL_IPHONE_KEYBOARD 68 #if SDL_IPHONE_KEYBOARD 69 [
self deinitKeyboard];
73 - (
void)setAnimationCallback:(
int)interval
74 callback:(
void (*)(
void*))callback
75 callbackParam:(
void*)callbackParam
79 animationInterval = interval;
81 animationCallbackParam = callbackParam;
83 if (animationCallback) {
84 [
self startAnimation];
90 displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(doLoop:)];
91 [displayLink setFrameInterval:animationInterval];
92 [displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
97 [displayLink invalidate];
101 - (
void)doLoop:(CADisplayLink*)sender
104 if (!UIKit_ShowingMessageBox()) {
105 animationCallback(animationCallbackParam);
116 const CGSize
size =
self.view.bounds.size;
117 int w = (int)
size.width;
118 int h = (
int)
size.height;
128 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orient
141 #if SDL_IPHONE_KEYBOARD 143 @synthesize textInputRect;
144 @synthesize keyboardHeight;
145 @synthesize keyboardVisible;
150 textField = [[UITextField alloc] initWithFrame:CGRectZero];
151 textField.delegate =
self;
153 textField.text =
@" ";
156 textField.autocapitalizationType = UITextAutocapitalizationTypeNone;
157 textField.autocorrectionType = UITextAutocorrectionTypeNo;
158 textField.enablesReturnKeyAutomatically = NO;
159 textField.keyboardAppearance = UIKeyboardAppearanceDefault;
160 textField.keyboardType = UIKeyboardTypeDefault;
161 textField.returnKeyType = UIReturnKeyDefault;
162 textField.secureTextEntry = NO;
164 textField.hidden = YES;
165 keyboardVisible = NO;
167 NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
168 [center addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
169 [center addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
172 - (
void)setView:(UIView *)view
174 [
super setView:view];
176 [view addSubview:textField];
178 if (keyboardVisible) {
183 - (
void)deinitKeyboard
185 NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
186 [center removeObserver:self name:UIKeyboardWillShowNotification object:nil];
187 [center removeObserver:self name:UIKeyboardWillHideNotification object:nil];
193 keyboardVisible = YES;
194 if (textField.window) {
195 [textField becomeFirstResponder];
202 keyboardVisible = NO;
203 [textField resignFirstResponder];
206 - (
void)keyboardWillShow:(NSNotification *)notification
208 CGRect kbrect = [[notification userInfo][UIKeyboardFrameBeginUserInfoKey] CGRectValue];
212 kbrect = [
self.view convertRect:kbrect fromView:nil];
214 [
self setKeyboardHeight:(int)kbrect.size.height];
217 - (
void)keyboardWillHide:(NSNotification *)notification
219 [
self setKeyboardHeight:0];
222 - (
void)updateKeyboard
224 CGAffineTransform
t =
self.view.transform;
225 CGPoint
offset = CGPointMake(0.0, 0.0);
228 if (
self.keyboardHeight) {
229 int rectbottom =
self.textInputRect.y + self.textInputRect.
h;
230 int keybottom =
self.view.bounds.size.height - self.keyboardHeight;
231 if (keybottom < rectbottom) {
232 offset.y = keybottom - rectbottom;
246 self.view.frame =
frame;
249 - (
void)setKeyboardHeight:(
int)height
251 keyboardVisible = height > 0;
253 [
self updateKeyboard];
257 - (BOOL)textField:(UITextField *)_textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
259 NSUInteger
len =
string.length;
269 for (i = 0; i <
len; i++) {
293 if (mod & KMOD_SHIFT) {
306 - (BOOL)textFieldShouldReturn:(UITextField*)_textField
319 #if SDL_IPHONE_KEYBOARD 335 UIKit_HasScreenKeyboardSupport(
_THIS)
364 return vc.isKeyboardVisible;
381 vc.textInputRect = *
rect;
383 if (vc.keyboardVisible) {
CGRect UIKit_ComputeViewFrame(SDL_Window *window, UIScreen *screen)
GLsizei const GLchar *const * string
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)
GLint GLint GLint GLint GLint x
int SDL_SendKeyboardKey(Uint8 state, SDL_Scancode scancode)
void viewDidLayoutSubviews()
#define SDL_StopTextInput
GLint GLint GLsizei GLsizei height
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
GLint GLint GLint GLint GLint GLint y
The type used to identify a window.
uint16_t Uint16
An unsigned 16-bit integer type.
GLubyte GLubyte GLubyte GLubyte w
SDL_Scancode
The SDL keyboard scancode representation.
GLfloat GLfloat GLfloat GLfloat h
A rectangle, with the origin at the upper left.
NSUInteger supportedInterfaceOrientations()