project_files/HedgewarsMobile/Classes/AmmoMenuViewController.m
changeset 4946 076767e86f2b
parent 4945 541d35d1f2e8
child 4976 088d40d8aba2
equal deleted inserted replaced
4945:541d35d1f2e8 4946:076767e86f2b
   314 -(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
   314 -(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
   315     NSSet *allTouches = [event allTouches];
   315     NSSet *allTouches = [event allTouches];
   316 
   316 
   317     if (IS_IPAD() && [touches count] == 1) {
   317     if (IS_IPAD() && [touches count] == 1) {
   318         self.view.layer.borderWidth = 3.5;
   318         self.view.layer.borderWidth = 3.5;
   319         startingPoint = [[[allTouches allObjects] objectAtIndex:0] locationInView:self.view];
   319         currentPoint = [[[allTouches allObjects] objectAtIndex:0] locationInView:self.view];
   320     }
   320     }
   321 
   321 
   322     if (IS_IPAD() == NO)
   322     if (IS_IPAD() == NO)
   323         [self disappear];
   323         [self disappear];
   324 }
   324 }
   325 
   325 
   326 -(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
   326 -(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
   327     self.view.layer.borderWidth = 1.3;
   327     self.view.layer.borderWidth = 1.3;
   328 }
   328 }
   329 
   329 
       
   330 // better window dragging implementation by
       
   331 // http://iphonedevelopertips.com/graphics/drag-an-image-within-the-bounds-of-superview.html
   330 -(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
   332 -(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
   331     NSSet *allTouches = [event allTouches];
       
   332 
       
   333     if (IS_IPAD() && [touches count] == 1) {
   333     if (IS_IPAD() && [touches count] == 1) {
   334         CGPoint touchedPoint = [[[allTouches allObjects] objectAtIndex:0] locationInView:self.view];
   334         // Get active location upon move
   335         CGFloat deltaX = touchedPoint.x - startingPoint.x;
   335         CGPoint activePoint = [[touches anyObject] locationInView:self.view];
   336         CGFloat deltaY = touchedPoint.y - startingPoint.y;
   336 
   337 
   337         // Determine new point based on where the touch is now located
   338         //startingPoint = touchedPoint;
   338         CGPoint newPoint = CGPointMake(self.view.center.x + (activePoint.x - currentPoint.x),
   339         self.view.frame = CGRectMake(self.view.frame.origin.x + deltaX, self.view.frame.origin.y + deltaY,
   339                                        self.view.center.y + (activePoint.y - currentPoint.y));
   340                                      self.view.frame.size.width, self.view.frame.size.height);
   340 
       
   341         // Make sure we stay within the bounds of the parent view
       
   342         float midPointX = CGRectGetMidX(self.view.bounds);
       
   343         if (newPoint.x > self.view.superview.bounds.size.width  - midPointX)
       
   344             newPoint.x = self.view.superview.bounds.size.width - midPointX;
       
   345         else if (newPoint.x < midPointX)
       
   346             newPoint.x = midPointX;
       
   347 
       
   348         float midPointY = CGRectGetMidY(self.view.bounds);
       
   349         if (newPoint.y > self.view.superview.bounds.size.height  - midPointY)
       
   350             newPoint.y = self.view.superview.bounds.size.height - midPointY;
       
   351         else if (newPoint.y < midPointY)
       
   352             newPoint.y = midPointY;
       
   353 
       
   354         self.view.center = newPoint;
   341     }
   355     }
   342 }
   356 }
   343 
   357 
   344 -(void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
   358 -(void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
   345     [self touchesEnded:touches withEvent:event];
   359     [self touchesEnded:touches withEvent:event];