slouken@6079
|
1 |
/*
|
slouken@5535
|
2 |
Simple DirectMedia Layer
|
slouken@8149
|
3 |
Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
|
slouken@5262
|
4 |
|
slouken@5535
|
5 |
This software is provided 'as-is', without any express or implied
|
slouken@5535
|
6 |
warranty. In no event will the authors be held liable for any damages
|
slouken@5535
|
7 |
arising from the use of this software.
|
slouken@5262
|
8 |
|
slouken@5535
|
9 |
Permission is granted to anyone to use this software for any purpose,
|
slouken@5535
|
10 |
including commercial applications, and to alter it and redistribute it
|
slouken@5535
|
11 |
freely, subject to the following restrictions:
|
slouken@5262
|
12 |
|
slouken@5535
|
13 |
1. The origin of this software must not be misrepresented; you must not
|
slouken@5535
|
14 |
claim that you wrote the original software. If you use this software
|
slouken@5535
|
15 |
in a product, an acknowledgment in the product documentation would be
|
slouken@5535
|
16 |
appreciated but is not required.
|
slouken@5535
|
17 |
2. Altered source versions must be plainly marked as such, and must not be
|
slouken@5535
|
18 |
misrepresented as being the original software.
|
slouken@5535
|
19 |
3. This notice may not be removed or altered from any source distribution.
|
slouken@5262
|
20 |
*/
|
icculus@8093
|
21 |
#include "../../SDL_internal.h"
|
slouken@6044
|
22 |
|
slouken@6044
|
23 |
#if SDL_VIDEO_DRIVER_UIKIT
|
slouken@2765
|
24 |
|
slouken@6518
|
25 |
#include "SDL_uikitview.h"
|
slouken@2765
|
26 |
|
slouken@4490
|
27 |
#include "../../events/SDL_keyboard_c.h"
|
slouken@4490
|
28 |
#include "../../events/SDL_mouse_c.h"
|
jimtla@4677
|
29 |
#include "../../events/SDL_touch_c.h"
|
slouken@4490
|
30 |
|
slouken@2765
|
31 |
#if SDL_IPHONE_KEYBOARD
|
slouken@6518
|
32 |
#include "keyinfotable.h"
|
urkle@7111
|
33 |
#endif
|
slouken@6518
|
34 |
#include "SDL_uikitappdelegate.h"
|
slouken@6518
|
35 |
#include "SDL_uikitmodes.h"
|
slouken@6518
|
36 |
#include "SDL_uikitwindow.h"
|
slouken@2765
|
37 |
|
slouken@7962
|
38 |
void _uikit_keyboard_init() ;
|
slouken@7962
|
39 |
|
slouken@2765
|
40 |
@implementation SDL_uikitview
|
slouken@2765
|
41 |
|
kees@6003
|
42 |
- (void)dealloc
|
kees@6003
|
43 |
{
|
slouken@5131
|
44 |
[super dealloc];
|
slouken@2765
|
45 |
}
|
slouken@2765
|
46 |
|
kees@6003
|
47 |
- (id)initWithFrame:(CGRect)frame
|
kees@6003
|
48 |
{
|
slouken@5131
|
49 |
self = [super initWithFrame: frame];
|
kees@6001
|
50 |
|
slouken@2765
|
51 |
#if SDL_IPHONE_KEYBOARD
|
slouken@5131
|
52 |
[self initializeKeyboard];
|
kees@6001
|
53 |
#endif
|
slouken@2765
|
54 |
|
slouken@5445
|
55 |
self.multipleTouchEnabled = YES;
|
slouken@5445
|
56 |
|
slouken@6951
|
57 |
touchId = 1;
|
slouken@6951
|
58 |
SDL_AddTouch(touchId, "");
|
slouken@4661
|
59 |
|
slouken@5131
|
60 |
return self;
|
slouken@2765
|
61 |
|
slouken@2765
|
62 |
}
|
slouken@2765
|
63 |
|
slouken@6436
|
64 |
- (CGPoint)touchLocation:(UITouch *)touch shouldNormalize:(BOOL)normalize
|
slouken@6079
|
65 |
{
|
slouken@6079
|
66 |
CGPoint point = [touch locationInView: self];
|
slouken@6436
|
67 |
|
slouken@7191
|
68 |
/* Get the display scale and apply that to the input coordinates */
|
slouken@6436
|
69 |
SDL_Window *window = self->viewcontroller.window;
|
slouken@6436
|
70 |
SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
|
slouken@6436
|
71 |
SDL_DisplayModeData *displaymodedata = (SDL_DisplayModeData *) display->current_mode.driverdata;
|
slouken@7191
|
72 |
|
slouken@6436
|
73 |
if (normalize) {
|
slouken@6439
|
74 |
CGRect bounds = [self bounds];
|
slouken@6439
|
75 |
point.x /= bounds.size.width;
|
slouken@6439
|
76 |
point.y /= bounds.size.height;
|
slouken@6519
|
77 |
} else {
|
slouken@6519
|
78 |
point.x *= displaymodedata->scale;
|
slouken@6519
|
79 |
point.y *= displaymodedata->scale;
|
slouken@6436
|
80 |
}
|
slouken@6079
|
81 |
return point;
|
slouken@6079
|
82 |
}
|
slouken@6079
|
83 |
|
kees@6003
|
84 |
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
|
kees@6003
|
85 |
{
|
slouken@5131
|
86 |
NSEnumerator *enumerator = [touches objectEnumerator];
|
slouken@5131
|
87 |
UITouch *touch = (UITouch*)[enumerator nextObject];
|
slouken@5459
|
88 |
|
slouken@6597
|
89 |
while (touch) {
|
slouken@6597
|
90 |
if (!leftFingerDown) {
|
slouken@6597
|
91 |
CGPoint locationInView = [self touchLocation:touch shouldNormalize:NO];
|
kees@6001
|
92 |
|
slouken@6597
|
93 |
/* send moved event */
|
slouken@6950
|
94 |
SDL_SendMouseMotion(NULL, SDL_TOUCH_MOUSEID, 0, locationInView.x, locationInView.y);
|
slouken@4488
|
95 |
|
slouken@6597
|
96 |
/* send mouse down event */
|
slouken@6950
|
97 |
SDL_SendMouseButton(NULL, SDL_TOUCH_MOUSEID, SDL_PRESSED, SDL_BUTTON_LEFT);
|
jim@4660
|
98 |
|
icculus@7050
|
99 |
leftFingerDown = touch;
|
slouken@6597
|
100 |
}
|
slouken@6597
|
101 |
|
slouken@6436
|
102 |
CGPoint locationInView = [self touchLocation:touch shouldNormalize:YES];
|
jim@4662
|
103 |
#ifdef IPHONE_TOUCH_EFFICIENT_DANGEROUS
|
slouken@7191
|
104 |
/* FIXME: TODO: Using touch as the fingerId is potentially dangerous
|
slouken@7191
|
105 |
* It is also much more efficient than storing the UITouch pointer
|
slouken@7191
|
106 |
* and comparing it to the incoming event.
|
slouken@7191
|
107 |
*/
|
icculus@7050
|
108 |
SDL_SendTouch(touchId, (SDL_FingerID)((size_t)touch),
|
slouken@6951
|
109 |
SDL_TRUE, locationInView.x, locationInView.y, 1.0f);
|
jim@4662
|
110 |
#else
|
kees@6003
|
111 |
int i;
|
kees@6003
|
112 |
for(i = 0; i < MAX_SIMULTANEOUS_TOUCHES; i++) {
|
kees@6003
|
113 |
if (finger[i] == NULL) {
|
kees@6003
|
114 |
finger[i] = touch;
|
slouken@6951
|
115 |
SDL_SendTouch(touchId, i,
|
slouken@6951
|
116 |
SDL_TRUE, locationInView.x, locationInView.y, 1.0f);
|
kees@6003
|
117 |
break;
|
kees@6003
|
118 |
}
|
slouken@5131
|
119 |
}
|
jim@4662
|
120 |
#endif
|
kees@6003
|
121 |
touch = (UITouch*)[enumerator nextObject];
|
slouken@5131
|
122 |
}
|
slouken@2765
|
123 |
}
|
slouken@2765
|
124 |
|
kees@6003
|
125 |
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
|
kees@6003
|
126 |
{
|
slouken@5131
|
127 |
NSEnumerator *enumerator = [touches objectEnumerator];
|
slouken@5131
|
128 |
UITouch *touch = (UITouch*)[enumerator nextObject];
|
kees@6001
|
129 |
|
slouken@6597
|
130 |
while(touch) {
|
icculus@7050
|
131 |
if (touch == leftFingerDown) {
|
slouken@6597
|
132 |
/* send mouse up */
|
slouken@6950
|
133 |
SDL_SendMouseButton(NULL, SDL_TOUCH_MOUSEID, SDL_RELEASED, SDL_BUTTON_LEFT);
|
icculus@7050
|
134 |
leftFingerDown = nil;
|
slouken@6597
|
135 |
}
|
slouken@4661
|
136 |
|
slouken@6436
|
137 |
CGPoint locationInView = [self touchLocation:touch shouldNormalize:YES];
|
jim@4662
|
138 |
#ifdef IPHONE_TOUCH_EFFICIENT_DANGEROUS
|
slouken@6951
|
139 |
SDL_SendTouch(touchId, (long)touch,
|
slouken@6951
|
140 |
SDL_FALSE, locationInView.x, locationInView.y, 1.0f);
|
jim@4662
|
141 |
#else
|
kees@6003
|
142 |
int i;
|
kees@6003
|
143 |
for (i = 0; i < MAX_SIMULTANEOUS_TOUCHES; i++) {
|
kees@6003
|
144 |
if (finger[i] == touch) {
|
slouken@6951
|
145 |
SDL_SendTouch(touchId, i,
|
slouken@6951
|
146 |
SDL_FALSE, locationInView.x, locationInView.y, 1.0f);
|
kees@6003
|
147 |
finger[i] = NULL;
|
kees@6003
|
148 |
break;
|
kees@6003
|
149 |
}
|
slouken@5131
|
150 |
}
|
jim@4662
|
151 |
#endif
|
kees@6003
|
152 |
touch = (UITouch*)[enumerator nextObject];
|
slouken@5131
|
153 |
}
|
slouken@2765
|
154 |
}
|
slouken@2765
|
155 |
|
kees@6003
|
156 |
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
|
kees@6003
|
157 |
{
|
slouken@5131
|
158 |
/*
|
slouken@5131
|
159 |
this can happen if the user puts more than 5 touches on the screen
|
slouken@5131
|
160 |
at once, or perhaps in other circumstances. Usually (it seems)
|
slouken@5131
|
161 |
all active touches are canceled.
|
slouken@5131
|
162 |
*/
|
slouken@5131
|
163 |
[self touchesEnded: touches withEvent: event];
|
slouken@2765
|
164 |
}
|
slouken@2765
|
165 |
|
kees@6003
|
166 |
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
|
kees@6003
|
167 |
{
|
slouken@5131
|
168 |
NSEnumerator *enumerator = [touches objectEnumerator];
|
slouken@5131
|
169 |
UITouch *touch = (UITouch*)[enumerator nextObject];
|
kees@6001
|
170 |
|
slouken@6597
|
171 |
while (touch) {
|
icculus@7050
|
172 |
if (touch == leftFingerDown) {
|
slouken@6597
|
173 |
CGPoint locationInView = [self touchLocation:touch shouldNormalize:NO];
|
slouken@4488
|
174 |
|
slouken@6597
|
175 |
/* send moved event */
|
slouken@6950
|
176 |
SDL_SendMouseMotion(NULL, SDL_TOUCH_MOUSEID, 0, locationInView.x, locationInView.y);
|
slouken@6597
|
177 |
}
|
jim@4660
|
178 |
|
slouken@6436
|
179 |
CGPoint locationInView = [self touchLocation:touch shouldNormalize:YES];
|
jim@4662
|
180 |
#ifdef IPHONE_TOUCH_EFFICIENT_DANGEROUS
|
kees@6003
|
181 |
SDL_SendTouchMotion(touchId, (long)touch,
|
slouken@6951
|
182 |
locationInView.x, locationInView.y, 1.0f);
|
jim@4662
|
183 |
#else
|
kees@6003
|
184 |
int i;
|
kees@6003
|
185 |
for (i = 0; i < MAX_SIMULTANEOUS_TOUCHES; i++) {
|
kees@6003
|
186 |
if (finger[i] == touch) {
|
kees@6003
|
187 |
SDL_SendTouchMotion(touchId, i,
|
slouken@6951
|
188 |
locationInView.x, locationInView.y, 1.0f);
|
kees@6003
|
189 |
break;
|
kees@6003
|
190 |
}
|
slouken@5131
|
191 |
}
|
jim@4662
|
192 |
#endif
|
kees@6003
|
193 |
touch = (UITouch*)[enumerator nextObject];
|
slouken@5131
|
194 |
}
|
slouken@2765
|
195 |
}
|
slouken@2765
|
196 |
|
slouken@2765
|
197 |
/*
|
slouken@5131
|
198 |
---- Keyboard related functionality below this line ----
|
slouken@2765
|
199 |
*/
|
slouken@2765
|
200 |
#if SDL_IPHONE_KEYBOARD
|
slouken@2765
|
201 |
|
slouken@7962
|
202 |
@synthesize textInputRect = textInputRect;
|
slouken@7962
|
203 |
@synthesize keyboardHeight = keyboardHeight;
|
slouken@7962
|
204 |
|
slouken@2765
|
205 |
/* Is the iPhone virtual keyboard visible onscreen? */
|
kees@6003
|
206 |
- (BOOL)keyboardVisible
|
kees@6003
|
207 |
{
|
slouken@5131
|
208 |
return keyboardVisible;
|
slouken@2765
|
209 |
}
|
slouken@2765
|
210 |
|
slouken@2765
|
211 |
/* Set ourselves up as a UITextFieldDelegate */
|
kees@6003
|
212 |
- (void)initializeKeyboard
|
kees@6003
|
213 |
{
|
slouken@5131
|
214 |
textField = [[UITextField alloc] initWithFrame: CGRectZero];
|
slouken@5131
|
215 |
textField.delegate = self;
|
slouken@5131
|
216 |
/* placeholder so there is something to delete! */
|
kees@6001
|
217 |
textField.text = @" ";
|
kees@6001
|
218 |
|
slouken@5131
|
219 |
/* set UITextInputTrait properties, mostly to defaults */
|
slouken@5131
|
220 |
textField.autocapitalizationType = UITextAutocapitalizationTypeNone;
|
slouken@5131
|
221 |
textField.autocorrectionType = UITextAutocorrectionTypeNo;
|
slouken@5131
|
222 |
textField.enablesReturnKeyAutomatically = NO;
|
slouken@5131
|
223 |
textField.keyboardAppearance = UIKeyboardAppearanceDefault;
|
slouken@5131
|
224 |
textField.keyboardType = UIKeyboardTypeDefault;
|
slouken@5131
|
225 |
textField.returnKeyType = UIReturnKeyDefault;
|
kees@6001
|
226 |
textField.secureTextEntry = NO;
|
kees@6001
|
227 |
|
slouken@5131
|
228 |
textField.hidden = YES;
|
slouken@5131
|
229 |
keyboardVisible = NO;
|
slouken@5131
|
230 |
/* add the UITextField (hidden) to our view */
|
slouken@5131
|
231 |
[self addSubview: textField];
|
slouken@5131
|
232 |
[textField release];
|
slouken@7962
|
233 |
|
slouken@7962
|
234 |
_uikit_keyboard_init();
|
slouken@2765
|
235 |
}
|
slouken@2765
|
236 |
|
slouken@2765
|
237 |
/* reveal onscreen virtual keyboard */
|
kees@6003
|
238 |
- (void)showKeyboard
|
kees@6003
|
239 |
{
|
slouken@5131
|
240 |
keyboardVisible = YES;
|
slouken@5131
|
241 |
[textField becomeFirstResponder];
|
slouken@2765
|
242 |
}
|
slouken@2765
|
243 |
|
slouken@2765
|
244 |
/* hide onscreen virtual keyboard */
|
kees@6003
|
245 |
- (void)hideKeyboard
|
kees@6003
|
246 |
{
|
slouken@5131
|
247 |
keyboardVisible = NO;
|
slouken@5131
|
248 |
[textField resignFirstResponder];
|
slouken@2765
|
249 |
}
|
slouken@2765
|
250 |
|
slouken@2765
|
251 |
/* UITextFieldDelegate method. Invoked when user types something. */
|
kees@6003
|
252 |
- (BOOL)textField:(UITextField *)_textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
|
kees@6003
|
253 |
{
|
slouken@5131
|
254 |
if ([string length] == 0) {
|
slouken@5131
|
255 |
/* it wants to replace text with nothing, ie a delete */
|
icculus@7774
|
256 |
SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_BACKSPACE);
|
icculus@7774
|
257 |
SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_BACKSPACE);
|
slouken@5131
|
258 |
}
|
slouken@5131
|
259 |
else {
|
slouken@5131
|
260 |
/* go through all the characters in the string we've been sent
|
slouken@5131
|
261 |
and convert them to key presses */
|
slouken@5131
|
262 |
int i;
|
kees@6003
|
263 |
for (i = 0; i < [string length]; i++) {
|
kees@6001
|
264 |
|
slouken@5131
|
265 |
unichar c = [string characterAtIndex: i];
|
kees@6001
|
266 |
|
slouken@5131
|
267 |
Uint16 mod = 0;
|
slouken@5218
|
268 |
SDL_Scancode code;
|
kees@6001
|
269 |
|
slouken@5131
|
270 |
if (c < 127) {
|
slouken@5218
|
271 |
/* figure out the SDL_Scancode and SDL_keymod for this unichar */
|
slouken@5131
|
272 |
code = unicharToUIKeyInfoTable[c].code;
|
slouken@5131
|
273 |
mod = unicharToUIKeyInfoTable[c].mod;
|
slouken@5131
|
274 |
}
|
slouken@5131
|
275 |
else {
|
slouken@5131
|
276 |
/* we only deal with ASCII right now */
|
slouken@5131
|
277 |
code = SDL_SCANCODE_UNKNOWN;
|
slouken@5131
|
278 |
mod = 0;
|
slouken@5131
|
279 |
}
|
kees@6001
|
280 |
|
slouken@5131
|
281 |
if (mod & KMOD_SHIFT) {
|
slouken@5131
|
282 |
/* If character uses shift, press shift down */
|
slouken@5131
|
283 |
SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_LSHIFT);
|
slouken@5131
|
284 |
}
|
slouken@5131
|
285 |
/* send a keydown and keyup even for the character */
|
slouken@5131
|
286 |
SDL_SendKeyboardKey(SDL_PRESSED, code);
|
slouken@5131
|
287 |
SDL_SendKeyboardKey(SDL_RELEASED, code);
|
slouken@5131
|
288 |
if (mod & KMOD_SHIFT) {
|
slouken@5131
|
289 |
/* If character uses shift, press shift back up */
|
slouken@5131
|
290 |
SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_LSHIFT);
|
kees@6001
|
291 |
}
|
slouken@5131
|
292 |
}
|
slouken@5461
|
293 |
SDL_SendKeyboardText([string UTF8String]);
|
slouken@5131
|
294 |
}
|
slouken@5131
|
295 |
return NO; /* don't allow the edit! (keep placeholder text there) */
|
slouken@2765
|
296 |
}
|
slouken@2765
|
297 |
|
slouken@2765
|
298 |
/* Terminates the editing session */
|
kees@6003
|
299 |
- (BOOL)textFieldShouldReturn:(UITextField*)_textField
|
kees@6003
|
300 |
{
|
slouken@5134
|
301 |
SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_RETURN);
|
slouken@6054
|
302 |
SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_RETURN);
|
slouken@6654
|
303 |
SDL_StopTextInput();
|
slouken@5131
|
304 |
return YES;
|
slouken@2765
|
305 |
}
|
slouken@2765
|
306 |
|
slouken@2765
|
307 |
#endif
|
slouken@2765
|
308 |
|
slouken@2765
|
309 |
@end
|
slouken@2765
|
310 |
|
slouken@2765
|
311 |
/* iPhone keyboard addition functions */
|
slouken@2765
|
312 |
#if SDL_IPHONE_KEYBOARD
|
slouken@2765
|
313 |
|
slouken@6044
|
314 |
static SDL_uikitview * getWindowView(SDL_Window * window)
|
kees@6010
|
315 |
{
|
kees@6010
|
316 |
if (window == NULL) {
|
kees@6010
|
317 |
SDL_SetError("Window does not exist");
|
kees@6010
|
318 |
return nil;
|
kees@6010
|
319 |
}
|
kees@6010
|
320 |
|
kees@6010
|
321 |
SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
|
kees@6010
|
322 |
SDL_uikitview *view = data != NULL ? data->view : nil;
|
kees@6010
|
323 |
|
kees@6010
|
324 |
if (view == nil) {
|
kees@6010
|
325 |
SDL_SetError("Window has no view");
|
kees@6010
|
326 |
}
|
kees@6010
|
327 |
|
kees@6010
|
328 |
return view;
|
kees@6010
|
329 |
}
|
kees@6010
|
330 |
|
slouken@6654
|
331 |
SDL_bool UIKit_HasScreenKeyboardSupport(_THIS)
|
slouken@6392
|
332 |
{
|
slouken@6392
|
333 |
return SDL_TRUE;
|
slouken@6392
|
334 |
}
|
slouken@6392
|
335 |
|
slouken@6654
|
336 |
void UIKit_ShowScreenKeyboard(_THIS, SDL_Window *window)
|
kees@6003
|
337 |
{
|
kees@6010
|
338 |
SDL_uikitview *view = getWindowView(window);
|
slouken@6654
|
339 |
if (view != nil) {
|
slouken@6654
|
340 |
[view showKeyboard];
|
slouken@5131
|
341 |
}
|
slouken@2765
|
342 |
}
|
slouken@2765
|
343 |
|
slouken@6654
|
344 |
void UIKit_HideScreenKeyboard(_THIS, SDL_Window *window)
|
kees@6003
|
345 |
{
|
kees@6010
|
346 |
SDL_uikitview *view = getWindowView(window);
|
slouken@6654
|
347 |
if (view != nil) {
|
slouken@6654
|
348 |
[view hideKeyboard];
|
kees@6001
|
349 |
}
|
slouken@2765
|
350 |
}
|
slouken@2765
|
351 |
|
slouken@6392
|
352 |
SDL_bool UIKit_IsScreenKeyboardShown(_THIS, SDL_Window *window)
|
kees@6003
|
353 |
{
|
kees@6010
|
354 |
SDL_uikitview *view = getWindowView(window);
|
kees@6010
|
355 |
if (view == nil) {
|
kees@6010
|
356 |
return 0;
|
kees@6001
|
357 |
}
|
kees@6001
|
358 |
|
kees@6010
|
359 |
return view.keyboardVisible;
|
slouken@2765
|
360 |
}
|
slouken@2765
|
361 |
|
slouken@7962
|
362 |
|
slouken@7962
|
363 |
void _uikit_keyboard_update() {
|
slouken@7962
|
364 |
SDL_Window *window = SDL_GetFocusWindow();
|
slouken@7962
|
365 |
if (!window) { return; }
|
slouken@7962
|
366 |
SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
|
slouken@7962
|
367 |
if (!data) { return; }
|
slouken@7962
|
368 |
SDL_uikitview *view = data->view;
|
slouken@7962
|
369 |
if (!view) { return; }
|
slouken@7962
|
370 |
|
slouken@7962
|
371 |
SDL_Rect r = view.textInputRect;
|
slouken@7962
|
372 |
int height = view.keyboardHeight;
|
slouken@7962
|
373 |
int offsetx = 0;
|
slouken@7962
|
374 |
int offsety = 0;
|
slouken@7962
|
375 |
if (height) {
|
slouken@7962
|
376 |
int sw,sh;
|
slouken@7962
|
377 |
SDL_GetWindowSize(window,&sw,&sh);
|
slouken@7962
|
378 |
int bottom = (r.y + r.h);
|
slouken@7962
|
379 |
int kbottom = sh - height;
|
slouken@7962
|
380 |
if (kbottom < bottom) {
|
slouken@7962
|
381 |
offsety = kbottom-bottom;
|
slouken@7962
|
382 |
}
|
slouken@7962
|
383 |
}
|
slouken@7962
|
384 |
UIInterfaceOrientation ui_orient = [[UIApplication sharedApplication] statusBarOrientation];
|
slouken@7962
|
385 |
if (ui_orient == UIInterfaceOrientationLandscapeLeft) {
|
slouken@7962
|
386 |
int tmp = offsetx; offsetx = offsety; offsety = tmp;
|
slouken@7962
|
387 |
}
|
slouken@7962
|
388 |
if (ui_orient == UIInterfaceOrientationLandscapeRight) {
|
slouken@7962
|
389 |
offsety = -offsety;
|
slouken@7962
|
390 |
int tmp = offsetx; offsetx = offsety; offsety = tmp;
|
slouken@7962
|
391 |
}
|
slouken@7962
|
392 |
if (ui_orient == UIInterfaceOrientationPortraitUpsideDown) {
|
slouken@7962
|
393 |
offsety = -offsety;
|
slouken@7962
|
394 |
}
|
slouken@7962
|
395 |
if ([[UIScreen mainScreen] respondsToSelector:@selector(displayLinkWithTarget:selector:)]) {
|
slouken@7962
|
396 |
float scale = [UIScreen mainScreen].scale;
|
slouken@7962
|
397 |
offsetx /= scale;
|
slouken@7962
|
398 |
offsety /= scale;
|
slouken@7962
|
399 |
}
|
slouken@7962
|
400 |
view.frame = CGRectMake(offsetx,offsety,view.frame.size.width,view.frame.size.height);
|
slouken@7962
|
401 |
}
|
slouken@7962
|
402 |
|
slouken@7962
|
403 |
void _uikit_keyboard_set_height(int height) {
|
slouken@7962
|
404 |
SDL_uikitview *view = getWindowView(SDL_GetFocusWindow());
|
slouken@7962
|
405 |
if (view == nil) {
|
slouken@7962
|
406 |
return ;
|
slouken@7962
|
407 |
}
|
slouken@7962
|
408 |
|
slouken@7962
|
409 |
view.keyboardHeight = height;
|
slouken@7962
|
410 |
_uikit_keyboard_update();
|
slouken@7962
|
411 |
}
|
slouken@7962
|
412 |
|
slouken@7962
|
413 |
void _uikit_keyboard_init() {
|
slouken@7962
|
414 |
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
|
slouken@7962
|
415 |
NSOperationQueue *queue = [NSOperationQueue mainQueue];
|
slouken@7962
|
416 |
[center addObserverForName:UIKeyboardWillShowNotification
|
slouken@7962
|
417 |
object:nil
|
slouken@7962
|
418 |
queue:queue
|
slouken@7962
|
419 |
usingBlock:^(NSNotification *notification) {
|
slouken@7962
|
420 |
int height = 0;
|
slouken@7962
|
421 |
CGSize keyboardSize = [[[notification userInfo] objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
|
slouken@7962
|
422 |
height = keyboardSize.height;
|
slouken@7962
|
423 |
UIInterfaceOrientation ui_orient = [[UIApplication sharedApplication] statusBarOrientation];
|
slouken@7962
|
424 |
if (ui_orient == UIInterfaceOrientationLandscapeRight || ui_orient == UIInterfaceOrientationLandscapeLeft) {
|
slouken@7962
|
425 |
height = keyboardSize.width;
|
slouken@7962
|
426 |
}
|
slouken@7962
|
427 |
if ([[UIScreen mainScreen] respondsToSelector:@selector(displayLinkWithTarget:selector:)]) {
|
slouken@7962
|
428 |
height *= [UIScreen mainScreen].scale;
|
slouken@7962
|
429 |
}
|
slouken@7962
|
430 |
_uikit_keyboard_set_height(height);
|
slouken@7962
|
431 |
}
|
slouken@7962
|
432 |
];
|
slouken@7962
|
433 |
[center addObserverForName:UIKeyboardDidHideNotification
|
slouken@7962
|
434 |
object:nil
|
slouken@7962
|
435 |
queue:queue
|
slouken@7962
|
436 |
usingBlock:^(NSNotification *notification) {
|
slouken@7962
|
437 |
_uikit_keyboard_set_height(0);
|
slouken@7962
|
438 |
}
|
slouken@7962
|
439 |
];
|
slouken@7962
|
440 |
}
|
slouken@7962
|
441 |
|
slouken@7962
|
442 |
void
|
slouken@7962
|
443 |
UIKit_SetTextInputRect(_THIS, SDL_Rect *rect)
|
slouken@7962
|
444 |
{
|
slouken@7962
|
445 |
if (!rect) {
|
slouken@7962
|
446 |
SDL_InvalidParamError("rect");
|
slouken@7962
|
447 |
return;
|
slouken@7962
|
448 |
}
|
slouken@7962
|
449 |
|
slouken@7962
|
450 |
SDL_uikitview *view = getWindowView(SDL_GetFocusWindow());
|
slouken@7962
|
451 |
if (view == nil) {
|
slouken@7962
|
452 |
return ;
|
slouken@7962
|
453 |
}
|
slouken@7962
|
454 |
|
slouken@7962
|
455 |
view.textInputRect = *rect;
|
slouken@7962
|
456 |
}
|
slouken@7962
|
457 |
|
slouken@7962
|
458 |
|
slouken@5132
|
459 |
#endif /* SDL_IPHONE_KEYBOARD */
|
slouken@2765
|
460 |
|
slouken@6044
|
461 |
#endif /* SDL_VIDEO_DRIVER_UIKIT */
|
slouken@6044
|
462 |
|
slouken@5132
|
463 |
/* vi: set ts=4 sw=4 expandtab: */
|