src/video/uikit/SDL_uikitview.m
changeset 8337 4a67a3cca43d
parent 8314 24f2de48557b
parent 6597 d359909f8121
child 8340 e470405f3ae9
equal deleted inserted replaced
8336:0b9aa42be7ae 8337:4a67a3cca43d
    48 
    48 
    49 #if SDL_IPHONE_KEYBOARD
    49 #if SDL_IPHONE_KEYBOARD
    50     [self initializeKeyboard];
    50     [self initializeKeyboard];
    51 #endif
    51 #endif
    52 
    52 
    53 #ifdef FIXED_MULTITOUCH
       
    54     self.multipleTouchEnabled = YES;
    53     self.multipleTouchEnabled = YES;
    55 
    54 
    56     SDL_Touch touch;
    55     SDL_Touch touch;
    57     touch.id = 0; //TODO: Should be -1?
    56     touch.id = 0; //TODO: Should be -1?
    58 
    57 
    67     touch.native_yres = touch.y_max - touch.y_min;
    66     touch.native_yres = touch.y_max - touch.y_min;
    68     touch.pressure_min = 0;
    67     touch.pressure_min = 0;
    69     touch.pressure_max = 1;
    68     touch.pressure_max = 1;
    70     touch.native_pressureres = touch.pressure_max - touch.pressure_min;
    69     touch.native_pressureres = touch.pressure_max - touch.pressure_min;
    71 
    70 
    72 
       
    73     touchId = SDL_AddTouch(&touch, "IPHONE SCREEN");
    71     touchId = SDL_AddTouch(&touch, "IPHONE SCREEN");
    74 #endif
       
    75 
    72 
    76     return self;
    73     return self;
    77 
    74 
    78 }
    75 }
    79 
    76 
   100 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
    97 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
   101 {
    98 {
   102     NSEnumerator *enumerator = [touches objectEnumerator];
    99     NSEnumerator *enumerator = [touches objectEnumerator];
   103     UITouch *touch = (UITouch*)[enumerator nextObject];
   100     UITouch *touch = (UITouch*)[enumerator nextObject];
   104 
   101 
   105     if (touch) {
   102     while (touch) {
   106         CGPoint locationInView = [self touchLocation:touch shouldNormalize:NO];
   103         if (!leftFingerDown) {
   107 
   104             CGPoint locationInView = [self touchLocation:touch shouldNormalize:NO];
   108         /* send moved event */
   105 
   109         SDL_SendMouseMotion(NULL, 0, locationInView.x, locationInView.y);
   106             /* send moved event */
   110 
   107             SDL_SendMouseMotion(NULL, 0, locationInView.x, locationInView.y);
   111         /* send mouse down event */
   108 
   112         SDL_SendMouseButton(NULL, SDL_PRESSED, SDL_BUTTON_LEFT);
   109             /* send mouse down event */
   113     }
   110             SDL_SendMouseButton(NULL, SDL_PRESSED, SDL_BUTTON_LEFT);
   114 
   111 
   115 #ifdef FIXED_MULTITOUCH
   112             leftFingerDown = (SDL_FingerID)touch;
   116     while(touch) {
   113         }
       
   114 
   117         CGPoint locationInView = [self touchLocation:touch shouldNormalize:YES];
   115         CGPoint locationInView = [self touchLocation:touch shouldNormalize:YES];
   118 
       
   119 #ifdef IPHONE_TOUCH_EFFICIENT_DANGEROUS
   116 #ifdef IPHONE_TOUCH_EFFICIENT_DANGEROUS
   120         //FIXME: TODO: Using touch as the fingerId is potentially dangerous
   117         // FIXME: TODO: Using touch as the fingerId is potentially dangerous
   121         //It is also much more efficient than storing the UITouch pointer
   118         // It is also much more efficient than storing the UITouch pointer
   122         //and comparing it to the incoming event.
   119         // and comparing it to the incoming event.
   123         SDL_SendFingerDown(touchId, (long)touch,
   120         SDL_SendFingerDown(touchId, (SDL_FingerID)touch,
   124                            SDL_TRUE, locationInView.x, locationInView.y,
   121                            SDL_TRUE, locationInView.x, locationInView.y,
   125                            1);
   122                            1);
   126 #else
   123 #else
   127         int i;
   124         int i;
   128         for(i = 0; i < MAX_SIMULTANEOUS_TOUCHES; i++) {
   125         for(i = 0; i < MAX_SIMULTANEOUS_TOUCHES; i++) {
   133                                    1);
   130                                    1);
   134                 break;
   131                 break;
   135             }
   132             }
   136         }
   133         }
   137 #endif
   134 #endif
   138 
       
   139         touch = (UITouch*)[enumerator nextObject];
   135         touch = (UITouch*)[enumerator nextObject];
   140     }
   136     }
   141 #endif
       
   142 }
   137 }
   143 
   138 
   144 - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
   139 - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
   145 {
   140 {
   146     NSEnumerator *enumerator = [touches objectEnumerator];
   141     NSEnumerator *enumerator = [touches objectEnumerator];
   147     UITouch *touch = (UITouch*)[enumerator nextObject];
   142     UITouch *touch = (UITouch*)[enumerator nextObject];
   148 
   143 
   149     if (touch) {
       
   150         /* send mouse up */
       
   151         SDL_SendMouseButton(NULL, SDL_RELEASED, SDL_BUTTON_LEFT);
       
   152     }
       
   153 
       
   154 #ifdef FIXED_MULTITOUCH
       
   155     while(touch) {
   144     while(touch) {
       
   145         if ((SDL_FingerID)touch == leftFingerDown) {
       
   146             /* send mouse up */
       
   147             SDL_SendMouseButton(NULL, SDL_RELEASED, SDL_BUTTON_LEFT);
       
   148             leftFingerDown = 0;
       
   149         }
       
   150 
   156         CGPoint locationInView = [self touchLocation:touch shouldNormalize:YES];
   151         CGPoint locationInView = [self touchLocation:touch shouldNormalize:YES];
   157 
       
   158 #ifdef IPHONE_TOUCH_EFFICIENT_DANGEROUS
   152 #ifdef IPHONE_TOUCH_EFFICIENT_DANGEROUS
   159         SDL_SendFingerDown(touchId, (long)touch,
   153         SDL_SendFingerDown(touchId, (long)touch,
   160                            SDL_FALSE, locationInView.x, locationInView.y,
   154                            SDL_FALSE, locationInView.x, locationInView.y,
   161                            1);
   155                            1);
   162 #else
   156 #else
   169                 finger[i] = NULL;
   163                 finger[i] = NULL;
   170                 break;
   164                 break;
   171             }
   165             }
   172         }
   166         }
   173 #endif
   167 #endif
   174 
       
   175         touch = (UITouch*)[enumerator nextObject];
   168         touch = (UITouch*)[enumerator nextObject];
   176     }
   169     }
   177 #endif
       
   178 }
   170 }
   179 
   171 
   180 - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
   172 - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
   181 {
   173 {
   182     /*
   174     /*
   190 - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
   182 - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
   191 {
   183 {
   192     NSEnumerator *enumerator = [touches objectEnumerator];
   184     NSEnumerator *enumerator = [touches objectEnumerator];
   193     UITouch *touch = (UITouch*)[enumerator nextObject];
   185     UITouch *touch = (UITouch*)[enumerator nextObject];
   194 
   186 
   195     if (touch) {
   187     while (touch) {
   196         CGPoint locationInView = [self touchLocation:touch shouldNormalize:NO];
   188         if ((SDL_FingerID)touch == leftFingerDown) {
   197 
   189             CGPoint locationInView = [self touchLocation:touch shouldNormalize:NO];
   198         /* send moved event */
   190 
   199         SDL_SendMouseMotion(NULL, 0, locationInView.x, locationInView.y);
   191             /* send moved event */
   200     }
   192             SDL_SendMouseMotion(NULL, 0, locationInView.x, locationInView.y);
   201 
   193         }
   202 #ifdef FIXED_MULTITOUCH
   194 
   203     while(touch) {
       
   204         CGPoint locationInView = [self touchLocation:touch shouldNormalize:YES];
   195         CGPoint locationInView = [self touchLocation:touch shouldNormalize:YES];
   205 
       
   206 #ifdef IPHONE_TOUCH_EFFICIENT_DANGEROUS
   196 #ifdef IPHONE_TOUCH_EFFICIENT_DANGEROUS
   207         SDL_SendTouchMotion(touchId, (long)touch,
   197         SDL_SendTouchMotion(touchId, (long)touch,
   208                             SDL_FALSE, locationInView.x, locationInView.y,
   198                             SDL_FALSE, locationInView.x, locationInView.y,
   209                             1);
   199                             1);
   210 #else
   200 #else
   216                                     1);
   206                                     1);
   217                 break;
   207                 break;
   218             }
   208             }
   219         }
   209         }
   220 #endif
   210 #endif
   221 
       
   222         touch = (UITouch*)[enumerator nextObject];
   211         touch = (UITouch*)[enumerator nextObject];
   223     }
   212     }
   224 #endif
       
   225 }
   213 }
   226 
   214 
   227 /*
   215 /*
   228     ---- Keyboard related functionality below this line ----
   216     ---- Keyboard related functionality below this line ----
   229 */
   217 */