cocoaTouch/iPad/OverlayViewController.m
author mbait
Sun, 28 Mar 2010 23:21:07 +0000
changeset 3148 3e28a12be5ac
parent 3116 97dc65a47b15
child 3165 3ec07a7d8456
permissions -rw-r--r--
Feather: sprites was moved to another layer
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3116
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
     1
//
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
     2
//  overlayViewController.m
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
     3
//  HedgewarsMobile
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
     4
//
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
     5
//  Created by Vittorio on 16/03/10.
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
     6
//  Copyright 2010 __MyCompanyName__. All rights reserved.
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
     7
//
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
     8
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
     9
#import "OverlayViewController.h"
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    10
#import "SDL_uikitappdelegate.h"
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    11
#import "PascalImports.h"
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    12
#import "CGPointUtils.h"
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    13
#import "SDL_mouse.h"
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    14
#import "PopupMenuViewController.h"
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    15
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    16
@implementation OverlayViewController
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    17
@synthesize dimTimer, menuPopover;
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    18
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    19
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    20
-(void) didReceiveMemoryWarning {
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    21
	// Releases the view if it doesn't have a superview.
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    22
    [super didReceiveMemoryWarning];
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    23
	
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    24
	// Release any cached data, images, etc that aren't in use.
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    25
}
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    26
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    27
-(void) viewDidLoad {
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    28
    self.view.alpha = 0;
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    29
    
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    30
    // needed for rotation to work on os < 3.2
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    31
    self.view.center = CGPointMake(self.view.frame.size.height/2.0, self.view.frame.size.width/2.0);
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    32
    self.view.transform = CGAffineTransformRotate(self.view.transform, (M_PI/2.0));
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    33
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    34
    dimTimer = [[NSTimer alloc] initWithFireDate:[NSDate dateWithTimeIntervalSinceNow:6]
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    35
                                        interval:1000
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    36
                                          target:self
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    37
                                        selector:@selector(dimOverlay)
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    38
                                        userInfo:nil
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    39
                                         repeats:YES];
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    40
    
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    41
    // add timer too runloop, otherwise it doesn't work
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    42
    [[NSRunLoop currentRunLoop] addTimer:dimTimer forMode:NSDefaultRunLoopMode];
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    43
    // listen for dismissal of the popover (see below)x
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    44
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(dismissPopover) name:@"dismissPopover" object:nil];
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    45
    // present the overlay after 2 seconds
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    46
    [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(showMenuAfterwards) userInfo:nil repeats:NO];
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    47
}
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    48
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    49
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation {
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    50
    return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    51
}
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    52
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    53
-(void) viewDidUnload {
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    54
	[dimTimer invalidate];
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    55
}
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    56
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    57
-(void) dealloc {
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    58
    [menuPopover release];
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    59
    // dimTimer is autoreleased
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    60
    [super dealloc];
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    61
}
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    62
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    63
// draws the controller overlay after the sdl window has taken control
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    64
-(void) showMenuAfterwards {
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    65
    [[SDLUIKitDelegate sharedAppDelegate].uiwindow bringSubviewToFront:self.view];
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    66
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    67
	[UIView beginAnimations:@"showing overlay" context:NULL];
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    68
	[UIView setAnimationDuration:1];
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    69
	self.view.alpha = 1;
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    70
	[UIView commitAnimations];
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    71
}
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    72
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    73
// dim the overlay when there's no more input for a certain amount of time
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    74
-(IBAction) buttonReleased:(id) sender {
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    75
	HW_allKeysUp();
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    76
    [dimTimer setFireDate:[NSDate dateWithTimeIntervalSinceNow:2.7]];
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    77
}
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    78
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    79
// nice transition for dimming
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    80
-(void) dimOverlay {
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    81
    [UIView beginAnimations:@"overlay dim" context:NULL];
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    82
   	[UIView setAnimationDuration:0.6];
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    83
    self.view.alpha = 0.2;
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    84
	[UIView commitAnimations];
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    85
}
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    86
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    87
// set the overlay visible and put off the timer for enough time
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    88
-(void) activateOverlay {
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    89
    self.view.alpha = 1;
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    90
    [dimTimer setFireDate:[NSDate dateWithTimeIntervalSinceNow:1000]];
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    91
}
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    92
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    93
// issue certain action based on the tag of the button 
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    94
-(IBAction) buttonPressed:(id) sender {
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    95
    [self activateOverlay];
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    96
    UIActionSheet *actionSheet;
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    97
    UIButton *theButton = (UIButton *)sender;
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    98
    
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    99
    switch (theButton.tag) {
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   100
        case 0:
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   101
            HW_walkLeft();
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   102
            break;
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   103
        case 1:
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   104
            HW_walkRight();
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   105
            break;
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   106
        case 2:
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   107
            HW_aimUp();
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   108
            break;
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   109
        case 3:
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   110
            HW_aimDown();
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   111
            break;
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   112
        case 4:
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   113
            HW_shoot();
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   114
            break;
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   115
        case 5:
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   116
            HW_jump();
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   117
            break;
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   118
        case 6:
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   119
            HW_backjump();
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   120
            break;
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   121
        case 7:
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   122
            HW_pause();
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   123
            break;
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   124
        case 8:
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   125
            HW_chat();
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   126
            break;
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   127
        case 9:
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   128
            actionSheet = [[UIActionSheet alloc] initWithTitle:NSLocalizedString(@"Are you reeeeeally sure?", @"")
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   129
                                                      delegate:self
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   130
                                             cancelButtonTitle:NSLocalizedString(@"Well, maybe not...", @"")
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   131
                                        destructiveButtonTitle:NSLocalizedString(@"As sure as I can be!", @"")
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   132
                                             otherButtonTitles:nil];
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   133
            [actionSheet showInView:self.view];
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   134
            [actionSheet release];
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   135
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   136
            HW_pause();
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   137
	    break;
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   138
        case 10:
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   139
            HW_tab();
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   140
            break;
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   141
        default:
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   142
            NSLog(@"Nope");
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   143
            break;
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   144
    }
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   145
}
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   146
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   147
// present a further check before closing game
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   148
-(void) actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger) buttonIndex {
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   149
	if ([actionSheet cancelButtonIndex] != buttonIndex)
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   150
	    HW_terminate(NO);
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   151
	else
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   152
            HW_pause();		
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   153
}
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   154
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   155
// show up a popover containing a popupMenuViewController; we hook it with setPopoverContentSize
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   156
-(IBAction) showPopover{
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   157
    PopupMenuViewController *popupMenu = [[PopupMenuViewController alloc] initWithNibName:@"PopupMenuViewController" bundle:nil];
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   158
    
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   159
    menuPopover = [[UIPopoverController alloc] initWithContentViewController:popupMenu];
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   160
    [menuPopover setPopoverContentSize:CGSizeMake(220, 170) animated:YES];
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   161
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   162
    /*UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   163
    button.frame= CGRectMake(960, 0, 64, 64);
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   164
    button.titleLabel.text=@"UUUUUUUF";
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   165
    [self.view addSubview:button];*/
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   166
    
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   167
    [menuPopover presentPopoverFromRect:CGRectMake(960, 0, 220, 32) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   168
    //UIBarButtonItem *sender = [[useless items] objectAtIndex:1];
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   169
    //[self.popoverController presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   170
}
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   171
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   172
// because of the actionSheet, the popOver might not get dismissed, so we do it manually (through a NSNotification system, see above)
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   173
-(void) dismissPopover {
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   174
    if (menuPopover.popoverVisible) 
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   175
        [menuPopover dismissPopoverAnimated:YES];
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   176
}
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   177
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   178
#pragma mark -
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   179
#define kMinimumPinchDelta      50
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   180
#define kMinimumGestureLength	10
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   181
#define kMaximumVariance        3
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   182
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   183
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   184
	NSArray *twoTouches;
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   185
	UITouch *touch = [touches anyObject];
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   186
	
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   187
	switch ([touches count]) {
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   188
		case 1:
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   189
			gestureStartPoint = [touch locationInView:self.view];
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   190
			initialDistanceForPinching = 0;
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   191
			switch ([touch tapCount]) {
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   192
				case 1:
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   193
					NSLog(@"X:%d Y:%d", (int)gestureStartPoint.x, (int)gestureStartPoint.y );
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   194
					SDL_WarpMouseInWindow([SDLUIKitDelegate sharedAppDelegate].window, 
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   195
							      (int)gestureStartPoint.y, 320 - (int)gestureStartPoint.x);
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   196
					HW_click();
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   197
					break;
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   198
				case 2:
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   199
					HW_ammoMenu();
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   200
					break;
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   201
				default:
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   202
					break;
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   203
			}
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   204
			break;
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   205
		case 2:
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   206
			if (2 == [touch tapCount]) {
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   207
				HW_zoomReset();
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   208
			}
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   209
			
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   210
			// pinching
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   211
			twoTouches = [touches allObjects];
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   212
			UITouch *first = [twoTouches objectAtIndex:0];
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   213
			UITouch *second = [twoTouches objectAtIndex:1];
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   214
			initialDistanceForPinching = distanceBetweenPoints([first locationInView:self.view], [second locationInView:self.view]);
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   215
			break;
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   216
		default:
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   217
			break;
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   218
	}
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   219
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   220
}
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   221
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   222
-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   223
	initialDistanceForPinching = 0;
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   224
	gestureStartPoint.x = 0;
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   225
	gestureStartPoint.y = 0;
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   226
	HW_allKeysUp();
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   227
}
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   228
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   229
-(void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   230
	// this can happen if the user puts more than 5 touches on the screen at once, or perhaps in other circumstances.
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   231
	[self touchesEnded:touches withEvent:event];
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   232
}
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   233
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   234
-(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   235
	NSArray *twoTouches;
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   236
	CGPoint currentPosition;
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   237
	UITouch *touch = [touches anyObject];
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   238
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   239
	switch ([touches count]) {
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   240
		case 1:
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   241
			currentPosition = [touch locationInView:self.view];
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   242
			// panning
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   243
			SDL_WarpMouseInWindow([SDLUIKitDelegate sharedAppDelegate].window, 
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   244
							(int)gestureStartPoint.y, 320 - (int)gestureStartPoint.x);
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   245
			// remember that we have x and y inverted
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   246
			/* temporarily disabling hog movements for camera panning testing
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   247
			CGFloat vertDiff = gestureStartPoint.x - currentPosition.x;
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   248
			CGFloat horizDiff = gestureStartPoint.y - currentPosition.y;
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   249
			CGFloat deltaX = fabsf(vertDiff);
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   250
			CGFloat deltaY = fabsf(horizDiff);
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   251
			
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   252
			if (deltaY >= kMinimumGestureLength && deltaX <= kMaximumVariance) {
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   253
				NSLog(@"Horizontal swipe detected, begX:%f curX:%f", gestureStartPoint.x, currentPosition.x);
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   254
				if (horizDiff > 0) HW_walkLeft();
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   255
				else HW_walkRight();
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   256
			} else if (deltaX >= kMinimumGestureLength && deltaY <= kMaximumVariance){
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   257
				NSLog(@"Vertical swipe detected, begY:%f curY:%f", gestureStartPoint.y, currentPosition.y);
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   258
				if (vertDiff < 0) HW_aimUp();
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   259
				else HW_aimDown();
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   260
			}
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   261
			*/
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   262
			break;
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   263
		case 2:
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   264
			twoTouches = [touches allObjects];
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   265
			UITouch *first = [twoTouches objectAtIndex:0];
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   266
			UITouch *second = [twoTouches objectAtIndex:1];
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   267
			CGFloat currentDistanceOfPinching = distanceBetweenPoints([first locationInView:self.view], [second locationInView:self.view]);
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   268
			
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   269
			if (0 == initialDistanceForPinching) 
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   270
				initialDistanceForPinching = currentDistanceOfPinching;
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   271
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   272
			if (currentDistanceOfPinching < initialDistanceForPinching + kMinimumPinchDelta)
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   273
				HW_zoomOut();
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   274
			else if (currentDistanceOfPinching > initialDistanceForPinching + kMinimumPinchDelta)
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   275
				HW_zoomIn();
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   276
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   277
			currentDistanceOfPinching = initialDistanceForPinching;
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   278
			break;
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   279
		default:
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   280
			break;
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   281
	}
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   282
}
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   283
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   284
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   285
@end