cocoaTouch/iPad/OverlayViewController.m
changeset 3250 d5cd1a617123
parent 3165 3ec07a7d8456
equal deleted inserted replaced
3249:74a506c9d71b 3250:d5cd1a617123
    50     return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
    50     return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
    51 }
    51 }
    52 
    52 
    53 -(void) viewDidUnload {
    53 -(void) viewDidUnload {
    54 	[dimTimer invalidate];
    54 	[dimTimer invalidate];
       
    55     self.dimTimer = nil;
       
    56     menuPopover = nil;
       
    57     [super viewDidUnload];
    55 }
    58 }
    56 
    59 
    57 -(void) dealloc {
    60 -(void) dealloc {
    58     [menuPopover release];
    61     [menuPopover release];
    59     // dimTimer is autoreleased
    62     // dimTimer is autoreleased
    91 }
    94 }
    92 
    95 
    93 // issue certain action based on the tag of the button 
    96 // issue certain action based on the tag of the button 
    94 -(IBAction) buttonPressed:(id) sender {
    97 -(IBAction) buttonPressed:(id) sender {
    95     [self activateOverlay];
    98     [self activateOverlay];
    96     UIActionSheet *actionSheet;
       
    97     UIButton *theButton = (UIButton *)sender;
    99     UIButton *theButton = (UIButton *)sender;
    98     
   100     
    99     switch (theButton.tag) {
   101     switch (theButton.tag) {
   100         case 0:
   102         case 0:
   101             HW_walkLeft();
   103             HW_walkLeft();
   117             break;
   119             break;
   118         case 6:
   120         case 6:
   119             HW_backjump();
   121             HW_backjump();
   120             break;
   122             break;
   121         case 7:
   123         case 7:
   122             HW_pause();
       
   123             break;
       
   124         case 8:
       
   125             HW_chat();
       
   126             break;
       
   127         case 9:
       
   128             actionSheet = [[UIActionSheet alloc] initWithTitle:NSLocalizedString(@"Are you reeeeeally sure?", @"")
       
   129                                                       delegate:self
       
   130                                              cancelButtonTitle:NSLocalizedString(@"Well, maybe not...", @"")
       
   131                                         destructiveButtonTitle:NSLocalizedString(@"As sure as I can be!", @"")
       
   132                                              otherButtonTitles:nil];
       
   133             [actionSheet showInView:self.view];
       
   134             [actionSheet release];
       
   135 
       
   136             HW_pause();
       
   137 	    break;
       
   138         case 10:
       
   139             HW_tab();
   124             HW_tab();
   140             break;
   125             break;
   141         default:
   126         default:
   142             NSLog(@"Nope");
   127             NSLog(@"Nope");
   143             break;
   128             break;
   152             HW_pause();		
   137             HW_pause();		
   153 }
   138 }
   154 
   139 
   155 // show up a popover containing a popupMenuViewController; we hook it with setPopoverContentSize
   140 // show up a popover containing a popupMenuViewController; we hook it with setPopoverContentSize
   156 -(IBAction) showPopover{
   141 -(IBAction) showPopover{
   157     PopupMenuViewController *popupMenu = [[PopupMenuViewController alloc] initWithNibName:@"PopupMenuViewController" bundle:nil];
   142     PopupMenuViewController *popupMenu = [[PopupMenuViewController alloc] init];
   158     
   143     
   159     menuPopover = [[UIPopoverController alloc] initWithContentViewController:popupMenu];
   144     menuPopover = [[UIPopoverController alloc] initWithContentViewController:popupMenu];
   160     [menuPopover setPopoverContentSize:CGSizeMake(220, 170) animated:YES];
   145     [menuPopover setPopoverContentSize:CGSizeMake(220, 170) animated:YES];
   161 
   146 
   162     /*UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
       
   163     button.frame= CGRectMake(960, 0, 64, 64);
       
   164     button.titleLabel.text=@"UUUUUUUF";
       
   165     [self.view addSubview:button];*/
       
   166     
       
   167     [menuPopover presentPopoverFromRect:CGRectMake(960, 0, 220, 32) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
   147     [menuPopover presentPopoverFromRect:CGRectMake(960, 0, 220, 32) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
   168     //UIBarButtonItem *sender = [[useless items] objectAtIndex:1];
       
   169     //[self.popoverController presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
       
   170 }
   148 }
   171 
   149 
   172 // because of the actionSheet, the popOver might not get dismissed, so we do it manually (through a NSNotification system, see above)
   150 // because of the actionSheet, the popOver might not get dismissed, so we do it manually (through a NSNotification system, see above)
   173 -(void) dismissPopover {
   151 -(void) dismissPopover {
   174     if (menuPopover.popoverVisible) 
   152     if (menuPopover.popoverVisible) 
   175         [menuPopover dismissPopoverAnimated:YES];
   153         [menuPopover dismissPopoverAnimated:YES];
   176 }
   154 }
   177 
   155 
   178 #pragma mark -
   156 #pragma mark -
       
   157 #pragma mark Custom touch event handling
       
   158 
   179 #define kMinimumPinchDelta      50
   159 #define kMinimumPinchDelta      50
   180 #define kMinimumGestureLength	10
   160 #define kMinimumGestureLength	10
   181 #define kMaximumVariance        3
   161 #define kMaximumVariance        3
   182 
   162 
   183 -(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
   163 -(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {