project_files/HedgewarsMobile/Classes/OverlayViewController.m
changeset 3697 d5b30d6373fc
parent 3680 aaf832c6fbd7
child 3701 8c449776ebe6
equal deleted inserted replaced
3695:c11abf387a7d 3697:d5b30d6373fc
    21 #define doNotDim()          [dimTimer setFireDate:HIDING_TIME_NEVER]
    21 #define doNotDim()          [dimTimer setFireDate:HIDING_TIME_NEVER]
    22 
    22 
    23 #define CONFIRMATION_TAG 5959
    23 #define CONFIRMATION_TAG 5959
    24 #define GRENADE_TAG 9595
    24 #define GRENADE_TAG 9595
    25 #define ANIMATION_DURATION 0.25
    25 #define ANIMATION_DURATION 0.25
    26 #define removeConfirmationInput()   [[self.view viewWithTag:CONFIRMATION_TAG] removeFromSuperview]; 
    26 #define removeConfirmationInput()   [[self.view viewWithTag:CONFIRMATION_TAG] removeFromSuperview];
    27 
    27 
    28 @implementation OverlayViewController
    28 @implementation OverlayViewController
    29 @synthesize popoverController, popupMenu;
    29 @synthesize popoverController, popupMenu;
    30 
    30 
    31 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation {
    31 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation {
    32     return rotationManager(interfaceOrientation);
    32     return rotationManager(interfaceOrientation);
    33 }
    33 }
    34 
    34 
    35 -(void) didRotate:(NSNotification *)notification {  
    35 -(void) didRotate:(NSNotification *)notification {
    36     UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
    36     UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
    37     CGRect rect = [[UIScreen mainScreen] bounds];
    37     CGRect rect = [[UIScreen mainScreen] bounds];
    38     CGRect usefulRect = CGRectMake(0, 0, rect.size.width, rect.size.height);
    38     CGRect usefulRect = CGRectMake(0, 0, rect.size.width, rect.size.height);
    39     UIView *sdlView = [[[UIApplication sharedApplication] keyWindow] viewWithTag:SDL_VIEW_TAG];
    39     UIView *sdlView = [[[UIApplication sharedApplication] keyWindow] viewWithTag:SDL_VIEW_TAG];
    40     
    40 
    41     [UIView beginAnimations:@"rotation" context:NULL];
    41     [UIView beginAnimations:@"rotation" context:NULL];
    42     [UIView setAnimationDuration:0.8f];
    42     [UIView setAnimationDuration:0.8f];
    43     [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    43     [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    44     switch (orientation) {
    44     switch (orientation) {
    45         case UIDeviceOrientationLandscapeLeft:
    45         case UIDeviceOrientationLandscapeLeft:
    82 #pragma mark View Management
    82 #pragma mark View Management
    83 -(void) viewDidLoad {
    83 -(void) viewDidLoad {
    84     isPopoverVisible = NO;
    84     isPopoverVisible = NO;
    85     self.view.alpha = 0;
    85     self.view.alpha = 0;
    86     self.view.center = CGPointMake(self.view.frame.size.height/2.0, self.view.frame.size.width/2.0);
    86     self.view.center = CGPointMake(self.view.frame.size.height/2.0, self.view.frame.size.width/2.0);
    87     
    87 
    88     // set initial orientation
    88     // set initial orientation
    89     UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
    89     UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
    90     UIView *sdlView = [[[UIApplication sharedApplication] keyWindow] viewWithTag:SDL_VIEW_TAG];
    90     UIView *sdlView = [[[UIApplication sharedApplication] keyWindow] viewWithTag:SDL_VIEW_TAG];
    91     switch (orientation) {
    91     switch (orientation) {
    92         case UIDeviceOrientationLandscapeLeft:
    92         case UIDeviceOrientationLandscapeLeft:
   100         default:
   100         default:
   101             break;
   101             break;
   102     }
   102     }
   103     CGRect rect = [[UIScreen mainScreen] bounds];
   103     CGRect rect = [[UIScreen mainScreen] bounds];
   104     self.view.frame = CGRectMake(0, 0, rect.size.width, rect.size.height);
   104     self.view.frame = CGRectMake(0, 0, rect.size.width, rect.size.height);
   105     
   105 
   106     dimTimer = [[NSTimer alloc] initWithFireDate:[NSDate dateWithTimeIntervalSinceNow:6]
   106     dimTimer = [[NSTimer alloc] initWithFireDate:[NSDate dateWithTimeIntervalSinceNow:6]
   107                                         interval:1000
   107                                         interval:1000
   108                                           target:self
   108                                           target:self
   109                                         selector:@selector(dimOverlay)
   109                                         selector:@selector(dimOverlay)
   110                                         userInfo:nil
   110                                         userInfo:nil
   111                                          repeats:YES];
   111                                          repeats:YES];
   112     
   112 
   113     // add timer too runloop, otherwise it doesn't work
   113     // add timer too runloop, otherwise it doesn't work
   114     [[NSRunLoop currentRunLoop] addTimer:dimTimer forMode:NSDefaultRunLoopMode];
   114     [[NSRunLoop currentRunLoop] addTimer:dimTimer forMode:NSDefaultRunLoopMode];
   115     
   115 
   116     [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];   
   116     [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
   117     [[NSNotificationCenter defaultCenter] addObserver:self
   117     [[NSNotificationCenter defaultCenter] addObserver:self
   118                                              selector:@selector(didRotate:)
   118                                              selector:@selector(didRotate:)
   119                                                  name:UIDeviceOrientationDidChangeNotification
   119                                                  name:UIDeviceOrientationDidChangeNotification
   120                                                object:nil];
   120                                                object:nil];
   121 
   121 
   122     [UIView beginAnimations:@"showing overlay" context:NULL];
   122     [UIView beginAnimations:@"showing overlay" context:NULL];
   123     [UIView setAnimationDuration:1];
   123     [UIView setAnimationDuration:1];
   124     self.view.alpha = 1;
   124     self.view.alpha = 1;
   125     [UIView commitAnimations];
   125     [UIView commitAnimations];
   126     
   126 
   127     // find the sdl window we're on
   127     // find the sdl window we're on
   128     SDL_VideoDevice *_this = SDL_GetVideoDevice();
   128     SDL_VideoDevice *_this = SDL_GetVideoDevice();
   129     SDL_VideoDisplay *display = &_this->displays[0];
   129     SDL_VideoDisplay *display = &_this->displays[0];
   130     sdlwindow = display->windows;
   130     sdlwindow = display->windows;
   131 }
   131 }
   139 
   139 
   140 -(void) didReceiveMemoryWarning {
   140 -(void) didReceiveMemoryWarning {
   141     // Releases the view if it doesn't have a superview.
   141     // Releases the view if it doesn't have a superview.
   142     [super didReceiveMemoryWarning];
   142     [super didReceiveMemoryWarning];
   143     // Release any cached data, images, etc that aren't in use.
   143     // Release any cached data, images, etc that aren't in use.
   144     if (popupMenu.view.superview == nil) 
   144     if (popupMenu.view.superview == nil)
   145         popupMenu = nil;
   145         popupMenu = nil;
   146     MSG_MEMCLEAN();
   146     MSG_MEMCLEAN();
   147 }
   147 }
   148 
   148 
   149 
   149 
   174 
   174 
   175 // dim the overlay when there's no more input for a certain amount of time
   175 // dim the overlay when there's no more input for a certain amount of time
   176 -(IBAction) buttonReleased:(id) sender {
   176 -(IBAction) buttonReleased:(id) sender {
   177     if (!isGameRunning)
   177     if (!isGameRunning)
   178         return;
   178         return;
   179     
   179 
   180     UIButton *theButton = (UIButton *)sender;
   180     UIButton *theButton = (UIButton *)sender;
   181     
   181 
   182     switch (theButton.tag) {
   182     switch (theButton.tag) {
   183         case 0:
   183         case 0:
   184         case 1:
   184         case 1:
   185         case 2:
   185         case 2:
   186         case 3:
   186         case 3:
   200     }
   200     }
   201 
   201 
   202     doDim();
   202     doDim();
   203 }
   203 }
   204 
   204 
   205 // issue certain action based on the tag of the button 
   205 // issue certain action based on the tag of the button
   206 -(IBAction) buttonPressed:(id) sender {
   206 -(IBAction) buttonPressed:(id) sender {
   207     [self activateOverlay];
   207     [self activateOverlay];
   208     if (isPopoverVisible) {
   208     if (isPopoverVisible) {
   209         [self dismissPopover];
   209         [self dismissPopover];
   210     }
   210     }
   211     
   211 
   212     if (!isGameRunning)
   212     if (!isGameRunning)
   213         return;
   213         return;
   214     
   214 
   215     UIButton *theButton = (UIButton *)sender;
   215     UIButton *theButton = (UIButton *)sender;
   216     
   216 
   217     switch (theButton.tag) {
   217     switch (theButton.tag) {
   218         case 0:
   218         case 0:
   219             HW_walkLeft();
   219             HW_walkLeft();
   220             break;
   220             break;
   221         case 1:
   221         case 1:
   265 // present a further check before closing game
   265 // present a further check before closing game
   266 -(void) actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger) buttonIndex {
   266 -(void) actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger) buttonIndex {
   267     if ([actionSheet cancelButtonIndex] != buttonIndex)
   267     if ([actionSheet cancelButtonIndex] != buttonIndex)
   268         HW_terminate(NO);
   268         HW_terminate(NO);
   269     else
   269     else
   270         HW_pause();     
   270         HW_pause();
   271 }
   271 }
   272 
   272 
   273 // show up a popover containing a popupMenuViewController; we hook it with setPopoverContentSize
   273 // show up a popover containing a popupMenuViewController; we hook it with setPopoverContentSize
   274 // on iphone instead just use the tableViewController directly (and implement manually all animations)
   274 // on iphone instead just use the tableViewController directly (and implement manually all animations)
   275 -(IBAction) showPopover{
   275 -(IBAction) showPopover{
   276     CGRect screen = [[UIScreen mainScreen] bounds];
   276     CGRect screen = [[UIScreen mainScreen] bounds];
   277     isPopoverVisible = YES;
   277     isPopoverVisible = YES;
   278 
   278 
   279     if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
   279     if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
   280         if (popupMenu == nil) 
   280         if (popupMenu == nil)
   281             popupMenu = [[InGameMenuViewController alloc] initWithStyle:UITableViewStylePlain];
   281             popupMenu = [[InGameMenuViewController alloc] initWithStyle:UITableViewStylePlain];
   282         if (popoverController == nil) {
   282         if (popoverController == nil) {
   283             popoverController = [[UIPopoverController alloc] initWithContentViewController:popupMenu];
   283             popoverController = [[UIPopoverController alloc] initWithContentViewController:popupMenu];
   284             [popoverController setPopoverContentSize:CGSizeMake(220, 170) animated:YES];
   284             [popoverController setPopoverContentSize:CGSizeMake(220, 170) animated:YES];
   285             [popoverController setPassthroughViews:[NSArray arrayWithObject:self.view]];
   285             [popoverController setPassthroughViews:[NSArray arrayWithObject:self.view]];
   290                          permittedArrowDirections:UIPopoverArrowDirectionAny
   290                          permittedArrowDirections:UIPopoverArrowDirectionAny
   291                                          animated:YES];
   291                                          animated:YES];
   292     } else {
   292     } else {
   293         if (popupMenu == nil)
   293         if (popupMenu == nil)
   294             popupMenu = [[InGameMenuViewController alloc] initWithStyle:UITableViewStyleGrouped];
   294             popupMenu = [[InGameMenuViewController alloc] initWithStyle:UITableViewStyleGrouped];
   295         
   295 
   296         [self.view addSubview:popupMenu.view];
   296         [self.view addSubview:popupMenu.view];
   297         [popupMenu present];
   297         [popupMenu present];
   298     }
   298     }
   299     popupMenu.tableView.scrollEnabled = NO;
   299     popupMenu.tableView.scrollEnabled = NO;
   300 }
   300 }
   303 -(void) dismissPopover {
   303 -(void) dismissPopover {
   304     if (YES == isPopoverVisible) {
   304     if (YES == isPopoverVisible) {
   305         isPopoverVisible = NO;
   305         isPopoverVisible = NO;
   306         if (HW_isPaused())
   306         if (HW_isPaused())
   307             HW_pause();
   307             HW_pause();
   308         
   308 
   309         if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
   309         if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
   310             [(InGameMenuViewController *)popoverController.contentViewController removeChat];
   310             [(InGameMenuViewController *)popoverController.contentViewController removeChat];
   311             [popoverController dismissPopoverAnimated:YES];
   311             [popoverController dismissPopoverAnimated:YES];
   312         } else {
   312         } else {
   313             [popupMenu dismiss];
   313             [popupMenu dismiss];
   319 #pragma mark -
   319 #pragma mark -
   320 #pragma mark Custom touch event handling
   320 #pragma mark Custom touch event handling
   321 -(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
   321 -(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
   322     NSSet *allTouches = [event allTouches];
   322     NSSet *allTouches = [event allTouches];
   323     UITouch *first, *second;
   323     UITouch *first, *second;
   324     
   324 
   325     // hide in-game menu
   325     // hide in-game menu
   326     if (isPopoverVisible)
   326     if (isPopoverVisible)
   327         [self dismissPopover];
   327         [self dismissPopover];
   328     
   328 
   329     // reset default dimming
   329     // reset default dimming
   330     doDim();
   330     doDim();
   331     
   331 
   332     HW_setPianoSound([allTouches count]);
   332     HW_setPianoSound([allTouches count]);
   333     
   333 
   334     switch ([allTouches count]) {
   334     switch ([allTouches count]) {
   335         case 1:       
   335         case 1:
   336             removeConfirmationInput();
   336             removeConfirmationInput();
   337             startingPoint = [[[allTouches allObjects] objectAtIndex:0] locationInView:self.view];
   337             startingPoint = [[[allTouches allObjects] objectAtIndex:0] locationInView:self.view];
   338             if (2 == [[[allTouches allObjects] objectAtIndex:0] tapCount])
   338             if (2 == [[[allTouches allObjects] objectAtIndex:0] tapCount])
   339                 HW_zoomReset();
   339                 HW_zoomReset();
   340             break;
   340             break;
   341         case 2:                
   341         case 2:
   342             // pinching
   342             // pinching
   343             first = [[allTouches allObjects] objectAtIndex:0];
   343             first = [[allTouches allObjects] objectAtIndex:0];
   344             second = [[allTouches allObjects] objectAtIndex:1];
   344             second = [[allTouches allObjects] objectAtIndex:1];
   345             initialDistanceForPinching = distanceBetweenPoints([first locationInView:self.view], [second locationInView:self.view]);
   345             initialDistanceForPinching = distanceBetweenPoints([first locationInView:self.view], [second locationInView:self.view]);
   346             break;
   346             break;
   353 
   353 
   354 -(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
   354 -(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
   355     CGRect screen = [[UIScreen mainScreen] bounds];
   355     CGRect screen = [[UIScreen mainScreen] bounds];
   356     NSSet *allTouches = [event allTouches];
   356     NSSet *allTouches = [event allTouches];
   357     CGPoint currentPosition = [[[allTouches allObjects] objectAtIndex:0] locationInView:self.view];
   357     CGPoint currentPosition = [[[allTouches allObjects] objectAtIndex:0] locationInView:self.view];
   358     
   358 
   359     switch ([allTouches count]) {
   359     switch ([allTouches count]) {
   360         case 1:
   360         case 1:
   361             // if we're in the menu we just click in the point
   361             // if we're in the menu we just click in the point
   362             if (HW_isAmmoOpen()) {
   362             if (HW_isAmmoOpen()) {
   363                 HW_setCursor(HWXZ(currentPosition.x), HWYZ(currentPosition.y));
   363                 HW_setCursor(HWXZ(currentPosition.x), HWYZ(currentPosition.y));
   364                 // this click doesn't need any wrapping because the ammoMenu already limits the cursor
   364                 // this click doesn't need any wrapping because the ammoMenu already limits the cursor
   365                 HW_click();
   365                 HW_click();
   366             } else 
   366             } else
   367                 // if weapon requires a further click, ask for tapping again
   367                 // if weapon requires a further click, ask for tapping again
   368                 if (HW_isWeaponRequiringClick()) {
   368                 if (HW_isWeaponRequiringClick()) {
   369                     // here don't have to wrap thanks to isCursorVisible magic
   369                     // here don't have to wrap thanks to isCursorVisible magic
   370                     HW_setCursor(HWX(currentPosition.x), HWY(currentPosition.y));
   370                     HW_setCursor(HWX(currentPosition.x), HWY(currentPosition.y));
   371                     
   371 
   372                     // draw the button at the last touched point (which is the current position)
   372                     // draw the button at the last touched point (which is the current position)
   373                     UIButton *tapAgain = [UIButton buttonWithType:UIButtonTypeRoundedRect];
   373                     UIButton *tapAgain = [UIButton buttonWithType:UIButtonTypeRoundedRect];
   374                     tapAgain.frame = CGRectMake(currentPosition.x - 75, currentPosition.y + 25, 150, 40);
   374                     tapAgain.frame = CGRectMake(currentPosition.x - 75, currentPosition.y + 25, 150, 40);
   375                     tapAgain.tag = CONFIRMATION_TAG;
   375                     tapAgain.tag = CONFIRMATION_TAG;
   376                     tapAgain.alpha = 0;
   376                     tapAgain.alpha = 0;
   377                     [tapAgain addTarget:self action:@selector(sendHWClick) forControlEvents:UIControlEventTouchUpInside];
   377                     [tapAgain addTarget:self action:@selector(sendHWClick) forControlEvents:UIControlEventTouchUpInside];
   378                     [tapAgain setTitle:NSLocalizedString(@"Tap to set!",@"from the overlay") forState:UIControlStateNormal];
   378                     [tapAgain setTitle:NSLocalizedString(@"Tap to set!",@"from the overlay") forState:UIControlStateNormal];
   379                     [self.view addSubview:tapAgain];
   379                     [self.view addSubview:tapAgain];
   380                     
   380 
   381                     // animation ftw!
   381                     // animation ftw!
   382                     [UIView beginAnimations:@"inserting button" context:NULL]; 
   382                     [UIView beginAnimations:@"inserting button" context:NULL];
   383                     [UIView setAnimationDuration:ANIMATION_DURATION];
   383                     [UIView setAnimationDuration:ANIMATION_DURATION];
   384                     [self.view viewWithTag:CONFIRMATION_TAG].alpha = 1;
   384                     [self.view viewWithTag:CONFIRMATION_TAG].alpha = 1;
   385                     [UIView commitAnimations];
   385                     [UIView commitAnimations];
   386                     
   386 
   387                     // keep the overlay active, or the button will fade
   387                     // keep the overlay active, or the button will fade
   388                     [self activateOverlay];
   388                     [self activateOverlay];
   389                     doNotDim();
   389                     doNotDim();
   390                 } else
   390                 } else
   391                     if (HW_isWeaponTimerable()) {
   391                     if (HW_isWeaponTimerable()) {
   392                         if (isSegmentVisible) {
   392                         if (isSegmentVisible) {
   393                             UISegmentedControl *grenadeTime = (UISegmentedControl *)[self.view viewWithTag:GRENADE_TAG];
   393                             UISegmentedControl *grenadeTime = (UISegmentedControl *)[self.view viewWithTag:GRENADE_TAG];
   394                             
   394 
   395                             [UIView beginAnimations:@"removing segmented control" context:NULL];
   395                             [UIView beginAnimations:@"removing segmented control" context:NULL];
   396                             [UIView setAnimationDuration:ANIMATION_DURATION];
   396                             [UIView setAnimationDuration:ANIMATION_DURATION];
   397                             [UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
   397                             [UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
   398                             grenadeTime.frame = CGRectMake(screen.size.height / 2 - 125, screen.size.width, 250, 50);
   398                             grenadeTime.frame = CGRectMake(screen.size.height / 2 - 125, screen.size.width, 250, 50);
   399                             [UIView commitAnimations];
   399                             [UIView commitAnimations];
   400                             
   400 
   401                             [grenadeTime performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:ANIMATION_DURATION];
   401                             [grenadeTime performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:ANIMATION_DURATION];
   402                         } else {
   402                         } else {
   403                             NSArray *items = [[NSArray alloc] initWithObjects:@"1",@"2",@"3",@"4",@"5",nil];
   403                             NSArray *items = [[NSArray alloc] initWithObjects:@"1",@"2",@"3",@"4",@"5",nil];
   404                             UISegmentedControl *grenadeTime = [[UISegmentedControl alloc] initWithItems:items];
   404                             UISegmentedControl *grenadeTime = [[UISegmentedControl alloc] initWithItems:items];
   405                             [items release];
   405                             [items release];
   406                             
   406 
   407                             [grenadeTime addTarget:self action:@selector(setGrenadeTime:) forControlEvents:UIControlEventValueChanged];
   407                             [grenadeTime addTarget:self action:@selector(setGrenadeTime:) forControlEvents:UIControlEventValueChanged];
   408                             grenadeTime.frame = CGRectMake(screen.size.height / 2 - 125, screen.size.width, 250, 50);
   408                             grenadeTime.frame = CGRectMake(screen.size.height / 2 - 125, screen.size.width, 250, 50);
   409                             grenadeTime.selectedSegmentIndex = 2;
   409                             grenadeTime.selectedSegmentIndex = 2;
   410                             grenadeTime.tag = GRENADE_TAG;
   410                             grenadeTime.tag = GRENADE_TAG;
   411                             [self.view addSubview:grenadeTime];
   411                             [self.view addSubview:grenadeTime];
   412                             [grenadeTime release];
   412                             [grenadeTime release];
   413                             
   413 
   414                             [UIView beginAnimations:@"inserting segmented control" context:NULL];
   414                             [UIView beginAnimations:@"inserting segmented control" context:NULL];
   415                             [UIView setAnimationDuration:ANIMATION_DURATION];
   415                             [UIView setAnimationDuration:ANIMATION_DURATION];
   416                             [UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
   416                             [UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
   417                             grenadeTime.frame = CGRectMake(screen.size.height / 2 - 125, screen.size.width - 100, 250, 50);
   417                             grenadeTime.frame = CGRectMake(screen.size.height / 2 - 125, screen.size.width - 100, 250, 50);
   418                             [UIView commitAnimations];
   418                             [UIView commitAnimations];
   419                             
   419 
   420                             [self activateOverlay];
   420                             [self activateOverlay];
   421                             doNotDim();
   421                             doNotDim();
   422                         } 
   422                         }
   423                         isSegmentVisible = !isSegmentVisible;
   423                         isSegmentVisible = !isSegmentVisible;
   424                     } else
   424                     } else
   425                         if (HW_isWeaponSwitch())
   425                         if (HW_isWeaponSwitch())
   426                             HW_tab();
   426                             HW_tab();
   427             break;
   427             break;
   429             HW_allKeysUp();
   429             HW_allKeysUp();
   430             break;
   430             break;
   431         default:
   431         default:
   432             break;
   432             break;
   433     }
   433     }
   434     
   434 
   435     initialDistanceForPinching = 0;
   435     initialDistanceForPinching = 0;
   436 }
   436 }
   437 
   437 
   438 -(void) sendHWClick {
   438 -(void) sendHWClick {
   439     HW_click();
   439     HW_click();
   452 
   452 
   453 -(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
   453 -(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
   454     CGRect screen = [[UIScreen mainScreen] bounds];
   454     CGRect screen = [[UIScreen mainScreen] bounds];
   455     NSSet *allTouches = [event allTouches];
   455     NSSet *allTouches = [event allTouches];
   456     int x, y, dx, dy;
   456     int x, y, dx, dy;
   457     
   457 
   458     UITouch *touch, *first, *second;
   458     UITouch *touch, *first, *second;
   459 
   459 
   460     switch ([allTouches count]) {
   460     switch ([allTouches count]) {
   461         case 1:
   461         case 1:
   462             touch = [[allTouches allObjects] objectAtIndex:0];
   462             touch = [[allTouches allObjects] objectAtIndex:0];
   486         case 2:
   486         case 2:
   487             first = [[allTouches allObjects] objectAtIndex:0];
   487             first = [[allTouches allObjects] objectAtIndex:0];
   488             second = [[allTouches allObjects] objectAtIndex:1];
   488             second = [[allTouches allObjects] objectAtIndex:1];
   489             CGFloat currentDistanceOfPinching = distanceBetweenPoints([first locationInView:self.view], [second locationInView:self.view]);
   489             CGFloat currentDistanceOfPinching = distanceBetweenPoints([first locationInView:self.view], [second locationInView:self.view]);
   490             const int pinchDelta = 40;
   490             const int pinchDelta = 40;
   491             
   491 
   492             if (0 != initialDistanceForPinching) {
   492             if (0 != initialDistanceForPinching) {
   493                 if (currentDistanceOfPinching - initialDistanceForPinching > pinchDelta) {
   493                 if (currentDistanceOfPinching - initialDistanceForPinching > pinchDelta) {
   494                     HW_zoomIn();
   494                     HW_zoomIn();
   495                     initialDistanceForPinching = currentDistanceOfPinching;
   495                     initialDistanceForPinching = currentDistanceOfPinching;
   496                 }
   496                 }
   497                 else if (initialDistanceForPinching - currentDistanceOfPinching > pinchDelta) {
   497                 else if (initialDistanceForPinching - currentDistanceOfPinching > pinchDelta) {
   498                     HW_zoomOut();
   498                     HW_zoomOut();
   499                     initialDistanceForPinching = currentDistanceOfPinching;
   499                     initialDistanceForPinching = currentDistanceOfPinching;
   500                 }
   500                 }
   501             } else 
   501             } else
   502                 initialDistanceForPinching = currentDistanceOfPinching;
   502                 initialDistanceForPinching = currentDistanceOfPinching;
   503             
   503 
   504             break;
   504             break;
   505         default:
   505         default:
   506             break;
   506             break;
   507     }
   507     }
   508 }
   508 }
   530 
   530 
   531 void clearView() {
   531 void clearView() {
   532     UIWindow *theWindow = [[UIApplication sharedApplication] keyWindow];
   532     UIWindow *theWindow = [[UIApplication sharedApplication] keyWindow];
   533     UIButton *theButton = (UIButton *)[theWindow viewWithTag:CONFIRMATION_TAG];
   533     UIButton *theButton = (UIButton *)[theWindow viewWithTag:CONFIRMATION_TAG];
   534     UISegmentedControl *theSegment = (UISegmentedControl *)[theWindow viewWithTag:GRENADE_TAG];
   534     UISegmentedControl *theSegment = (UISegmentedControl *)[theWindow viewWithTag:GRENADE_TAG];
   535     
   535 
   536     [UIView beginAnimations:@"remove button" context:NULL];
   536     [UIView beginAnimations:@"remove button" context:NULL];
   537     [UIView setAnimationDuration:ANIMATION_DURATION];
   537     [UIView setAnimationDuration:ANIMATION_DURATION];
   538     theButton.alpha = 0;
   538     theButton.alpha = 0;
   539     theSegment.alpha = 0;
   539     theSegment.alpha = 0;
   540     [UIView commitAnimations];
   540     [UIView commitAnimations];
   541     
   541 
   542     [theWindow performSelector:@selector(removeFromSuperview) withObject:theButton afterDelay:0.3];
   542     [theWindow performSelector:@selector(removeFromSuperview) withObject:theButton afterDelay:0.3];
   543     [theWindow performSelector:@selector(removeFromSuperview) withObject:theSegment afterDelay:0.3];    
   543     [theWindow performSelector:@selector(removeFromSuperview) withObject:theSegment afterDelay:0.3];
   544 }
   544 }
   545 
   545 
   546 @end
   546 @end