23 #if SDL_VIDEO_DRIVER_UIKIT
27 #include "../../events/SDL_keyboard_c.h"
28 #include "../../events/SDL_mouse_c.h"
29 #include "../../events/SDL_touch_c.h"
31 #if SDL_IPHONE_KEYBOARD
45 - (
id)initWithFrame:(CGRect)frame
47 self = [
super initWithFrame: frame];
49 #if SDL_IPHONE_KEYBOARD
50 [
self initializeKeyboard];
53 self.multipleTouchEnabled = YES;
62 - (CGPoint)touchLocation:(UITouch *)touch shouldNormalize:(
BOOL)normalize
64 CGPoint point = [touch locationInView: self];
67 SDL_Window *window =
self->viewcontroller.window;
72 CGRect bounds = [
self bounds];
73 point.x /= bounds.size.width;
74 point.y /= bounds.size.height;
76 point.x *= displaymodedata->
scale;
77 point.y *= displaymodedata->
scale;
82 - (
void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
84 NSEnumerator *enumerator = [touches objectEnumerator];
85 UITouch *touch = (UITouch*)[enumerator nextObject];
89 CGPoint locationInView = [
self touchLocation:touch shouldNormalize:NO];
100 CGPoint locationInView = [
self touchLocation:touch shouldNormalize:YES];
101 #ifdef IPHONE_TOUCH_EFFICIENT_DANGEROUS
107 SDL_TRUE, locationInView.x, locationInView.y, 1.0f);
110 for(i = 0; i < MAX_SIMULTANEOUS_TOUCHES; i++) {
111 if (finger[i] ==
NULL) {
114 SDL_TRUE, locationInView.x, locationInView.y, 1.0f);
119 touch = (UITouch*)[enumerator nextObject];
123 - (
void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
125 NSEnumerator *enumerator = [touches objectEnumerator];
126 UITouch *touch = (UITouch*)[enumerator nextObject];
135 CGPoint locationInView = [
self touchLocation:touch shouldNormalize:YES];
136 #ifdef IPHONE_TOUCH_EFFICIENT_DANGEROUS
138 SDL_FALSE, locationInView.x, locationInView.y, 1.0f);
141 for (i = 0; i < MAX_SIMULTANEOUS_TOUCHES; i++) {
142 if (finger[i] == touch) {
144 SDL_FALSE, locationInView.x, locationInView.y, 1.0f);
150 touch = (UITouch*)[enumerator nextObject];
154 - (
void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
161 [
self touchesEnded: touches withEvent: event];
164 - (
void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
166 NSEnumerator *enumerator = [touches objectEnumerator];
167 UITouch *touch = (UITouch*)[enumerator nextObject];
171 CGPoint locationInView = [
self touchLocation:touch shouldNormalize:NO];
177 CGPoint locationInView = [
self touchLocation:touch shouldNormalize:YES];
178 #ifdef IPHONE_TOUCH_EFFICIENT_DANGEROUS
180 locationInView.x, locationInView.y, 1.0f);
183 for (i = 0; i < MAX_SIMULTANEOUS_TOUCHES; i++) {
184 if (finger[i] == touch) {
186 locationInView.x, locationInView.y, 1.0f);
191 touch = (UITouch*)[enumerator nextObject];
198 #if SDL_IPHONE_KEYBOARD
201 - (
BOOL)keyboardVisible
203 return keyboardVisible;
207 - (
void)initializeKeyboard
209 textField = [[UITextField alloc] initWithFrame: CGRectZero];
210 textField.delegate =
self;
212 textField.text =
@" ";
215 textField.autocapitalizationType = UITextAutocapitalizationTypeNone;
216 textField.autocorrectionType = UITextAutocorrectionTypeNo;
217 textField.enablesReturnKeyAutomatically = NO;
218 textField.keyboardAppearance = UIKeyboardAppearanceDefault;
219 textField.keyboardType = UIKeyboardTypeDefault;
220 textField.returnKeyType = UIReturnKeyDefault;
221 textField.secureTextEntry = NO;
223 textField.hidden = YES;
224 keyboardVisible = NO;
226 [
self addSubview: textField];
233 keyboardVisible = YES;
234 [textField becomeFirstResponder];
240 keyboardVisible = NO;
241 [textField resignFirstResponder];
245 - (
BOOL)textField:(UITextField *)_textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
247 if ([
string length] == 0) {
256 for (i = 0; i < [string length]; i++) {
258 unichar
c = [string characterAtIndex: i];
281 if (mod & KMOD_SHIFT) {
292 - (
BOOL)textFieldShouldReturn:(UITextField*)_textField
305 #if SDL_IPHONE_KEYBOARD
309 if (window ==
NULL) {
352 return view.keyboardVisible;
GLvoid **typedef void(GLAPIENTRY *PFNGLGETVERTEXATTRIBDVPROC)(GLuint
int SDL_SendTouch(SDL_TouchID id, SDL_FingerID fingerid, SDL_bool down, float x, float y, float pressure)
#define SDL_TOUCH_MOUSEID
int SDL_SendKeyboardKey(Uint8 state, SDL_Scancode scancode)
int SDL_SendTouchMotion(SDL_TouchID id, SDL_FingerID fingerid, float x, float y, float pressure)
DECLSPEC void SDLCALL SDL_StopTextInput(void)
Stop receiving any text input events. This function will hide the on-screen keyboard if supported...
int SDL_SendMouseMotion(SDL_Window *window, SDL_MouseID mouseID, int relative, int x, int y)
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
static UIKitKeyInfo unicharToUIKeyInfoTable[]
int SDL_SendKeyboardText(const char *text)
SDL_DisplayMode current_mode
DECLSPEC int SDLCALL SDL_SetError(const char *fmt,...)
int SDL_AddTouch(SDL_TouchID touchID, const char *name)
SDL_VideoDisplay * SDL_GetDisplayForWindow(SDL_Window *window)
uint16_t Uint16
An unsigned 16-bit integer type.
int SDL_SendMouseButton(SDL_Window *window, SDL_MouseID mouseID, Uint8 state, Uint8 button)
SDL_Scancode
The SDL keyboard scancode representation.
SDL_uikitopenglview * view
typedef BOOL(WINAPI *PFNWGLSETSTEREOEMITTERSTATE3DLPROC)(HDC hDC