project_files/HedgewarsMobile/Classes/OverlayViewController.m
changeset 3535 9e78c1f3d8d8
parent 3525 1d7b056ff866
child 3546 ccf4854df294
equal deleted inserted replaced
3534:51521238724f 3535:9e78c1f3d8d8
   241 // show up a popover containing a popupMenuViewController; we hook it with setPopoverContentSize
   241 // show up a popover containing a popupMenuViewController; we hook it with setPopoverContentSize
   242 // on iphone instead just use the tableViewController directly (and implement manually all animations)
   242 // on iphone instead just use the tableViewController directly (and implement manually all animations)
   243 -(IBAction) showPopover{
   243 -(IBAction) showPopover{
   244     isPopoverVisible = YES;
   244     isPopoverVisible = YES;
   245     CGRect anchorForPopover;
   245     CGRect anchorForPopover;
   246     Class popoverControllerClass = NSClassFromString(@"UIPopoverController");
   246 
   247     if (popoverControllerClass) {
   247     if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
   248 #if __IPHONE_3_2
       
   249         if (popupMenu == nil) 
   248         if (popupMenu == nil) 
   250             popupMenu = [[PopoverMenuViewController alloc] initWithStyle:UITableViewStylePlain];
   249             popupMenu = [[PopoverMenuViewController alloc] initWithStyle:UITableViewStylePlain];
   251         popoverController = [[popoverControllerClass alloc] initWithContentViewController:popupMenu];
   250         if (popoverController == nil) {
   252         [popoverController setPopoverContentSize:CGSizeMake(220, 170) animated:YES];
   251             popoverController = [[UIPopoverController alloc] initWithContentViewController:popupMenu];
   253         [popoverController setPassthroughViews:[NSArray arrayWithObject:self.view]];
   252             [popoverController setPopoverContentSize:CGSizeMake(220, 170) animated:YES];
   254 
   253             [popoverController setPassthroughViews:[NSArray arrayWithObject:self.view]];
       
   254         }
       
   255         
   255         if (UIDeviceOrientationIsLandscape([[UIDevice currentDevice] orientation]))
   256         if (UIDeviceOrientationIsLandscape([[UIDevice currentDevice] orientation]))
   256             anchorForPopover = CGRectMake(960, 0, 220, 32);
   257             anchorForPopover = CGRectMake(960, 0, 220, 32);
   257         else
   258         else
   258             anchorForPopover = CGRectMake(736, 0, 220, 32);
   259             anchorForPopover = CGRectMake(736, 0, 220, 32);
   259         
   260         
   260         [popoverController presentPopoverFromRect:anchorForPopover
   261         [popoverController presentPopoverFromRect:anchorForPopover
   261                                            inView:self.view
   262                                            inView:self.view
   262                          permittedArrowDirections:UIPopoverArrowDirectionUp
   263                          permittedArrowDirections:UIPopoverArrowDirectionUp
   263                                          animated:YES];
   264                                          animated:YES];
   264 #endif
       
   265     } else {
   265     } else {
   266         if (popupMenu == nil) 
   266         if (popupMenu == nil) {
   267             popupMenu = [[PopoverMenuViewController alloc] initWithStyle:UITableViewStyleGrouped];
   267             popupMenu = [[PopoverMenuViewController alloc] initWithStyle:UITableViewStyleGrouped];
   268         popupMenu.view.backgroundColor = [UIColor clearColor];
   268             popupMenu.view.backgroundColor = [UIColor clearColor];
   269         popupMenu.view.frame = CGRectMake(480, 0, 200, 170);
   269             popupMenu.view.frame = CGRectMake(480, 0, 200, 170);
       
   270         }
   270         [self.view addSubview:popupMenu.view];
   271         [self.view addSubview:popupMenu.view];
   271 
   272         
   272         [UIView beginAnimations:@"showing popover" context:NULL];
   273         [UIView beginAnimations:@"showing popover" context:NULL];
   273         [UIView setAnimationDuration:0.35];
   274         [UIView setAnimationDuration:0.35];
   274         popupMenu.view.frame = CGRectMake(280, 0, 200, 170);
   275         popupMenu.view.frame = CGRectMake(280, 0, 200, 170);
   275         [UIView commitAnimations];
   276         [UIView commitAnimations];
   276     }
   277     }
   281 -(void) dismissPopover {
   282 -(void) dismissPopover {
   282     if (YES == isPopoverVisible) {
   283     if (YES == isPopoverVisible) {
   283         isPopoverVisible = NO;
   284         isPopoverVisible = NO;
   284         
   285         
   285         if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
   286         if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
   286 #if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_3_2
       
   287             [popoverController dismissPopoverAnimated:YES];
   287             [popoverController dismissPopoverAnimated:YES];
   288 #endif
       
   289         } else {
   288         } else {
   290             [UIView beginAnimations:@"hiding popover" context:NULL];
   289             [UIView beginAnimations:@"hiding popover" context:NULL];
   291             [UIView setAnimationDuration:0.35];
   290             [UIView setAnimationDuration:0.35];
   292             popupMenu.view.frame = CGRectMake(480, 0, 200, 170);
   291             popupMenu.view.frame = CGRectMake(480, 0, 200, 170);
   293             [UIView commitAnimations];
   292             [UIView commitAnimations];
   294         
   293         
   295             [popupMenu.view performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:0.35];
   294             [popupMenu.view performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:0.35];
   296             [popupMenu performSelector:@selector(release) withObject:nil afterDelay:0.35];
       
   297         }
   295         }
   298         [self buttonReleased:nil];
   296         [self buttonReleased:nil];
   299     }
   297     }
   300 }
   298 }
   301 
   299 
   398 			CGFloat deltaX = fabsf(gestureStartPoint.x - currentPosition.x);
   396 			CGFloat deltaX = fabsf(gestureStartPoint.x - currentPosition.x);
   399 			CGFloat deltaY = fabsf(gestureStartPoint.y - currentPosition.y);
   397 			CGFloat deltaY = fabsf(gestureStartPoint.y - currentPosition.y);
   400 			
   398 			
   401             // the two ifs are not mutually exclusive
   399             // the two ifs are not mutually exclusive
   402             if (deltaX >= minimumGestureLength) {
   400             if (deltaX >= minimumGestureLength) {
   403                 Dlog(@"deltaX: %f deltaY: %f", deltaX, deltaY);
   401                 DLog(@"deltaX: %f deltaY: %f", deltaX, deltaY);
   404                 if (currentPosition.x > gestureStartPoint.x) {
   402                 if (currentPosition.x > gestureStartPoint.x) {
   405                     HW_cursorLeft(logCoeff*log(deltaX));
   403                     HW_cursorLeft(logCoeff*log(deltaX));
   406                 } else {
   404                 } else {
   407                     HW_cursorRight(logCoeff*log(deltaX));
   405                     HW_cursorRight(logCoeff*log(deltaX));
   408                 }
   406                 }