src/video/uikit/SDL_uikitview.m
branchiOS-improvements
changeset 9501 574db299498f
parent 9499 6fe9b44b2d84
child 9503 bff6f1fecc5d
equal deleted inserted replaced
9500:cbf5c5ecf5ac 9501:574db299498f
    35 #include "SDL_uikitmodes.h"
    35 #include "SDL_uikitmodes.h"
    36 #include "SDL_uikitwindow.h"
    36 #include "SDL_uikitwindow.h"
    37 
    37 
    38 void _uikit_keyboard_init();
    38 void _uikit_keyboard_init();
    39 
    39 
    40 @implementation SDL_uikitview
    40 @implementation SDL_uikitview {
       
    41 
       
    42     SDL_TouchID touchId;
       
    43     UITouch *leftFingerDown;
       
    44 #ifndef IPHONE_TOUCH_EFFICIENT_DANGEROUS
       
    45     UITouch *finger[MAX_SIMULTANEOUS_TOUCHES];
       
    46 #endif
       
    47 
       
    48 #if SDL_IPHONE_KEYBOARD
       
    49     UITextField *textField;
       
    50 #endif
       
    51 
       
    52 }
    41 
    53 
    42 - (void)dealloc
    54 - (void)dealloc
    43 {
    55 {
    44     [super dealloc];
    56     [super dealloc];
    45 }
    57 }
    64 - (CGPoint)touchLocation:(UITouch *)touch shouldNormalize:(BOOL)normalize
    76 - (CGPoint)touchLocation:(UITouch *)touch shouldNormalize:(BOOL)normalize
    65 {
    77 {
    66     CGPoint point = [touch locationInView: self];
    78     CGPoint point = [touch locationInView: self];
    67 
    79 
    68     if (normalize) {
    80     if (normalize) {
    69         CGRect bounds = [self bounds];
    81         CGRect bounds = self.bounds;
    70         point.x /= bounds.size.width;
    82         point.x /= bounds.size.width;
    71         point.y /= bounds.size.height;
    83         point.y /= bounds.size.height;
    72     }
    84     }
    73 
    85 
    74     return point;
    86     return point;
   120             leftFingerDown = nil;
   132             leftFingerDown = nil;
   121         }
   133         }
   122 
   134 
   123         CGPoint locationInView = [self touchLocation:touch shouldNormalize:YES];
   135         CGPoint locationInView = [self touchLocation:touch shouldNormalize:YES];
   124 #ifdef IPHONE_TOUCH_EFFICIENT_DANGEROUS
   136 #ifdef IPHONE_TOUCH_EFFICIENT_DANGEROUS
   125         SDL_SendTouch(touchId, (long)touch,
   137         SDL_SendTouch(touchId, (SDL_FingerID)((size_t)touch),
   126                       SDL_FALSE, locationInView.x, locationInView.y, 1.0f);
   138                       SDL_FALSE, locationInView.x, locationInView.y, 1.0f);
   127 #else
   139 #else
   128         int i;
   140         int i;
   129         for (i = 0; i < MAX_SIMULTANEOUS_TOUCHES; i++) {
   141         for (i = 0; i < MAX_SIMULTANEOUS_TOUCHES; i++) {
   130             if (finger[i] == touch) {
   142             if (finger[i] == touch) {
   158             SDL_SendMouseMotion(viewcontroller.window, SDL_TOUCH_MOUSEID, 0, locationInView.x, locationInView.y);
   170             SDL_SendMouseMotion(viewcontroller.window, SDL_TOUCH_MOUSEID, 0, locationInView.x, locationInView.y);
   159         }
   171         }
   160 
   172 
   161         CGPoint locationInView = [self touchLocation:touch shouldNormalize:YES];
   173         CGPoint locationInView = [self touchLocation:touch shouldNormalize:YES];
   162 #ifdef IPHONE_TOUCH_EFFICIENT_DANGEROUS
   174 #ifdef IPHONE_TOUCH_EFFICIENT_DANGEROUS
   163         SDL_SendTouchMotion(touchId, (long)touch,
   175         SDL_SendTouchMotion(touchId, (SDL_FingerID)((size_t)touch),
   164                             locationInView.x, locationInView.y, 1.0f);
   176                             locationInView.x, locationInView.y, 1.0f);
   165 #else
   177 #else
   166         int i;
   178         int i;
   167         for (i = 0; i < MAX_SIMULTANEOUS_TOUCHES; i++) {
   179         for (i = 0; i < MAX_SIMULTANEOUS_TOUCHES; i++) {
   168             if (finger[i] == touch) {
   180             if (finger[i] == touch) {
   178 /*
   190 /*
   179     ---- Keyboard related functionality below this line ----
   191     ---- Keyboard related functionality below this line ----
   180 */
   192 */
   181 #if SDL_IPHONE_KEYBOARD
   193 #if SDL_IPHONE_KEYBOARD
   182 
   194 
   183 @synthesize textInputRect = textInputRect;
   195 @synthesize textInputRect;
   184 @synthesize keyboardHeight = keyboardHeight;
   196 @synthesize keyboardHeight;
   185 
   197 @synthesize keyboardVisible;
   186 /* Is the iPhone virtual keyboard visible onscreen? */
       
   187 - (BOOL)keyboardVisible
       
   188 {
       
   189     return keyboardVisible;
       
   190 }
       
   191 
   198 
   192 /* Set ourselves up as a UITextFieldDelegate */
   199 /* Set ourselves up as a UITextFieldDelegate */
   193 - (void)initializeKeyboard
   200 - (void)initializeKeyboard
   194 {
   201 {
   195     textField = [[UITextField alloc] initWithFrame: CGRectZero];
   202     textField = [[UITextField alloc] initWithFrame: CGRectZero];
   335     SDL_uikitview *view = getWindowView(window);
   342     SDL_uikitview *view = getWindowView(window);
   336     if (view == nil) {
   343     if (view == nil) {
   337         return 0;
   344         return 0;
   338     }
   345     }
   339 
   346 
   340     return view.keyboardVisible;
   347     return view.isKeyboardVisible;
   341 }
   348 }
   342 
   349 
   343 
   350 
   344 void _uikit_keyboard_update() {
   351 void _uikit_keyboard_update() {
   345     SDL_Window *window = SDL_GetFocusWindow();
   352     SDL_Window *window = SDL_GetFocusWindow();