src/video/uikit/SDL_uikitview.m
changeset 6003 fddf81967e2d
parent 6001 3ae3d1e58d59
child 6010 508aa078acc0
     1.1 --- a/src/video/uikit/SDL_uikitview.m	Tue Sep 27 21:07:09 2011 +0200
     1.2 +++ b/src/video/uikit/SDL_uikitview.m	Tue Sep 27 22:51:26 2011 +0200
     1.3 @@ -33,12 +33,13 @@
     1.4  
     1.5  @implementation SDL_uikitview
     1.6  
     1.7 -- (void)dealloc {
     1.8 +- (void)dealloc
     1.9 +{
    1.10      [super dealloc];
    1.11  }
    1.12  
    1.13 -- (id)initWithFrame:(CGRect)frame {
    1.14 -
    1.15 +- (id)initWithFrame:(CGRect)frame
    1.16 +{
    1.17      self = [super initWithFrame: frame];
    1.18  
    1.19  #if SDL_IPHONE_KEYBOARD
    1.20 @@ -72,8 +73,8 @@
    1.21  
    1.22  }
    1.23  
    1.24 -- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    1.25 -
    1.26 +- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
    1.27 +{
    1.28      NSEnumerator *enumerator = [touches objectEnumerator];
    1.29      UITouch *touch = (UITouch*)[enumerator nextObject];
    1.30  
    1.31 @@ -89,36 +90,35 @@
    1.32  
    1.33  #ifdef FIXED_MULTITOUCH
    1.34      while(touch) {
    1.35 -      CGPoint locationInView = [touch locationInView: self];
    1.36 -
    1.37 +        CGPoint locationInView = [touch locationInView: self];
    1.38  
    1.39  #ifdef IPHONE_TOUCH_EFFICIENT_DANGEROUS
    1.40 -      //FIXME: TODO: Using touch as the fingerId is potentially dangerous
    1.41 -      //It is also much more efficient than storing the UITouch pointer
    1.42 -      //and comparing it to the incoming event.
    1.43 -      SDL_SendFingerDown(touchId,(long)touch,
    1.44 -                 SDL_TRUE,locationInView.x,locationInView.y,
    1.45 -                 1);
    1.46 +        //FIXME: TODO: Using touch as the fingerId is potentially dangerous
    1.47 +        //It is also much more efficient than storing the UITouch pointer
    1.48 +        //and comparing it to the incoming event.
    1.49 +        SDL_SendFingerDown(touchId, (long)touch,
    1.50 +                           SDL_TRUE, locationInView.x, locationInView.y,
    1.51 +                           1);
    1.52  #else
    1.53 -      int i;
    1.54 -      for(i = 0;i < MAX_SIMULTANEOUS_TOUCHES;i++) {
    1.55 -        if(finger[i] == NULL) {
    1.56 -          finger[i] = touch;
    1.57 -          SDL_SendFingerDown(touchId,i,
    1.58 -                 SDL_TRUE,locationInView.x,locationInView.y,
    1.59 -                 1);
    1.60 -          break;
    1.61 +        int i;
    1.62 +        for(i = 0; i < MAX_SIMULTANEOUS_TOUCHES; i++) {
    1.63 +            if (finger[i] == NULL) {
    1.64 +                finger[i] = touch;
    1.65 +                SDL_SendFingerDown(touchId, i,
    1.66 +                                   SDL_TRUE, locationInView.x, locationInView.y,
    1.67 +                                   1);
    1.68 +                break;
    1.69 +            }
    1.70          }
    1.71 -      }
    1.72  #endif
    1.73  
    1.74 -      touch = (UITouch*)[enumerator nextObject];
    1.75 +        touch = (UITouch*)[enumerator nextObject];
    1.76      }
    1.77  #endif
    1.78  }
    1.79  
    1.80 -- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    1.81 -
    1.82 +- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
    1.83 +{
    1.84      NSEnumerator *enumerator = [touches objectEnumerator];
    1.85      UITouch *touch = (UITouch*)[enumerator nextObject];
    1.86  
    1.87 @@ -129,32 +129,32 @@
    1.88  
    1.89  #ifdef FIXED_MULTITOUCH
    1.90      while(touch) {
    1.91 -      CGPoint locationInView = [touch locationInView: self];
    1.92 -
    1.93 +        CGPoint locationInView = [touch locationInView: self];
    1.94  
    1.95  #ifdef IPHONE_TOUCH_EFFICIENT_DANGEROUS
    1.96 -      SDL_SendFingerDown(touchId,(long)touch,
    1.97 -                 SDL_FALSE,locationInView.x,locationInView.y,
    1.98 -                 1);
    1.99 +        SDL_SendFingerDown(touchId, (long)touch,
   1.100 +                           SDL_FALSE, locationInView.x, locationInView.y,
   1.101 +                           1);
   1.102  #else
   1.103 -      int i;
   1.104 -      for(i = 0;i < MAX_SIMULTANEOUS_TOUCHES;i++) {
   1.105 -        if(finger[i] == touch) {
   1.106 -          SDL_SendFingerDown(touchId,i,
   1.107 -                 SDL_FALSE,locationInView.x,locationInView.y,
   1.108 -                 1);
   1.109 -          finger[i] = NULL;
   1.110 -          break;
   1.111 +        int i;
   1.112 +        for (i = 0; i < MAX_SIMULTANEOUS_TOUCHES; i++) {
   1.113 +            if (finger[i] == touch) {
   1.114 +                SDL_SendFingerDown(touchId, i,
   1.115 +                                   SDL_FALSE, locationInView.x, locationInView.y,
   1.116 +                                   1);
   1.117 +                finger[i] = NULL;
   1.118 +                break;
   1.119 +            }
   1.120          }
   1.121 -      }
   1.122  #endif
   1.123  
   1.124 -      touch = (UITouch*)[enumerator nextObject];
   1.125 +        touch = (UITouch*)[enumerator nextObject];
   1.126      }
   1.127  #endif
   1.128  }
   1.129  
   1.130 -- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
   1.131 +- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
   1.132 +{
   1.133      /*
   1.134          this can happen if the user puts more than 5 touches on the screen
   1.135          at once, or perhaps in other circumstances.  Usually (it seems)
   1.136 @@ -163,8 +163,8 @@
   1.137      [self touchesEnded: touches withEvent: event];
   1.138  }
   1.139  
   1.140 -- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
   1.141 -
   1.142 +- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
   1.143 +{
   1.144      NSEnumerator *enumerator = [touches objectEnumerator];
   1.145      UITouch *touch = (UITouch*)[enumerator nextObject];
   1.146  
   1.147 @@ -177,26 +177,25 @@
   1.148  
   1.149  #ifdef FIXED_MULTITOUCH
   1.150      while(touch) {
   1.151 -      CGPoint locationInView = [touch locationInView: self];
   1.152 -
   1.153 +        CGPoint locationInView = [touch locationInView: self];
   1.154  
   1.155  #ifdef IPHONE_TOUCH_EFFICIENT_DANGEROUS
   1.156 -      SDL_SendTouchMotion(touchId,(long)touch,
   1.157 -                  SDL_FALSE,locationInView.x,locationInView.y,
   1.158 -                  1);
   1.159 +        SDL_SendTouchMotion(touchId, (long)touch,
   1.160 +                            SDL_FALSE, locationInView.x, locationInView.y,
   1.161 +                            1);
   1.162  #else
   1.163 -      int i;
   1.164 -      for(i = 0;i < MAX_SIMULTANEOUS_TOUCHES;i++) {
   1.165 -        if(finger[i] == touch) {
   1.166 -          SDL_SendTouchMotion(touchId,i,
   1.167 -                  SDL_FALSE,locationInView.x,locationInView.y,
   1.168 -                  1);
   1.169 -          break;
   1.170 +        int i;
   1.171 +        for (i = 0; i < MAX_SIMULTANEOUS_TOUCHES; i++) {
   1.172 +            if (finger[i] == touch) {
   1.173 +                SDL_SendTouchMotion(touchId, i,
   1.174 +                                    SDL_FALSE, locationInView.x, locationInView.y,
   1.175 +                                    1);
   1.176 +                break;
   1.177 +            }
   1.178          }
   1.179 -      }
   1.180  #endif
   1.181  
   1.182 -      touch = (UITouch*)[enumerator nextObject];
   1.183 +        touch = (UITouch*)[enumerator nextObject];
   1.184      }
   1.185  #endif
   1.186  }
   1.187 @@ -207,13 +206,14 @@
   1.188  #if SDL_IPHONE_KEYBOARD
   1.189  
   1.190  /* Is the iPhone virtual keyboard visible onscreen? */
   1.191 -- (BOOL)keyboardVisible {
   1.192 +- (BOOL)keyboardVisible
   1.193 +{
   1.194      return keyboardVisible;
   1.195  }
   1.196  
   1.197  /* Set ourselves up as a UITextFieldDelegate */
   1.198 -- (void)initializeKeyboard {
   1.199 -
   1.200 +- (void)initializeKeyboard
   1.201 +{
   1.202      textField = [[UITextField alloc] initWithFrame: CGRectZero];
   1.203      textField.delegate = self;
   1.204      /* placeholder so there is something to delete! */
   1.205 @@ -236,20 +236,22 @@
   1.206  }
   1.207  
   1.208  /* reveal onscreen virtual keyboard */
   1.209 -- (void)showKeyboard {
   1.210 +- (void)showKeyboard
   1.211 +{
   1.212      keyboardVisible = YES;
   1.213      [textField becomeFirstResponder];
   1.214  }
   1.215  
   1.216  /* hide onscreen virtual keyboard */
   1.217 -- (void)hideKeyboard {
   1.218 +- (void)hideKeyboard
   1.219 +{
   1.220      keyboardVisible = NO;
   1.221      [textField resignFirstResponder];
   1.222  }
   1.223  
   1.224  /* UITextFieldDelegate method.  Invoked when user types something. */
   1.225 -- (BOOL)textField:(UITextField *)_textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
   1.226 -
   1.227 +- (BOOL)textField:(UITextField *)_textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
   1.228 +{
   1.229      if ([string length] == 0) {
   1.230          /* it wants to replace text with nothing, ie a delete */
   1.231          SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_DELETE);
   1.232 @@ -259,7 +261,7 @@
   1.233          /* go through all the characters in the string we've been sent
   1.234             and convert them to key presses */
   1.235          int i;
   1.236 -        for (i=0; i<[string length]; i++) {
   1.237 +        for (i = 0; i < [string length]; i++) {
   1.238  
   1.239              unichar c = [string characterAtIndex: i];
   1.240  
   1.241 @@ -295,7 +297,8 @@
   1.242  }
   1.243  
   1.244  /* Terminates the editing session */
   1.245 -- (BOOL)textFieldShouldReturn:(UITextField*)_textField {
   1.246 +- (BOOL)textFieldShouldReturn:(UITextField*)_textField
   1.247 +{
   1.248      SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_RETURN);
   1.249      [self hideKeyboard];
   1.250      return YES;
   1.251 @@ -308,8 +311,8 @@
   1.252  /* iPhone keyboard addition functions */
   1.253  #if SDL_IPHONE_KEYBOARD
   1.254  
   1.255 -int SDL_iPhoneKeyboardShow(SDL_Window * window) {
   1.256 -
   1.257 +int SDL_iPhoneKeyboardShow(SDL_Window * window)
   1.258 +{
   1.259      SDL_WindowData *data;
   1.260      SDL_uikitview *view;
   1.261  
   1.262 @@ -331,8 +334,8 @@
   1.263      }
   1.264  }
   1.265  
   1.266 -int SDL_iPhoneKeyboardHide(SDL_Window * window) {
   1.267 -
   1.268 +int SDL_iPhoneKeyboardHide(SDL_Window * window)
   1.269 +{
   1.270      SDL_WindowData *data;
   1.271      SDL_uikitview *view;
   1.272  
   1.273 @@ -354,8 +357,8 @@
   1.274      }
   1.275  }
   1.276  
   1.277 -SDL_bool SDL_iPhoneKeyboardIsShown(SDL_Window * window) {
   1.278 -
   1.279 +SDL_bool SDL_iPhoneKeyboardIsShown(SDL_Window * window)
   1.280 +{
   1.281      SDL_WindowData *data;
   1.282      SDL_uikitview *view;
   1.283  
   1.284 @@ -376,8 +379,8 @@
   1.285      }
   1.286  }
   1.287  
   1.288 -int SDL_iPhoneKeyboardToggle(SDL_Window * window) {
   1.289 -
   1.290 +int SDL_iPhoneKeyboardToggle(SDL_Window * window)
   1.291 +{
   1.292      SDL_WindowData *data;
   1.293      SDL_uikitview *view;
   1.294  
   1.295 @@ -408,21 +411,25 @@
   1.296  
   1.297  /* stubs, used if compiled without keyboard support */
   1.298  
   1.299 -int SDL_iPhoneKeyboardShow(SDL_Window * window) {
   1.300 +int SDL_iPhoneKeyboardShow(SDL_Window * window)
   1.301 +{
   1.302      SDL_SetError("Not compiled with keyboard support");
   1.303      return -1;
   1.304  }
   1.305  
   1.306 -int SDL_iPhoneKeyboardHide(SDL_Window * window) {
   1.307 +int SDL_iPhoneKeyboardHide(SDL_Window * window)
   1.308 +{
   1.309      SDL_SetError("Not compiled with keyboard support");
   1.310      return -1;
   1.311  }
   1.312  
   1.313 -SDL_bool SDL_iPhoneKeyboardIsShown(SDL_Window * window) {
   1.314 +SDL_bool SDL_iPhoneKeyboardIsShown(SDL_Window * window)
   1.315 +{
   1.316      return 0;
   1.317  }
   1.318  
   1.319 -int SDL_iPhoneKeyboardToggle(SDL_Window * window) {
   1.320 +int SDL_iPhoneKeyboardToggle(SDL_Window * window)
   1.321 +{
   1.322      SDL_SetError("Not compiled with keyboard support");
   1.323      return -1;
   1.324  }