cocoaTouch/OverlayViewController.m
author sheepluva
Tue, 04 May 2010 00:44:32 +0000
changeset 3414 b2f3bb44777e
parent 3405 8fdb08497bf1
child 3463 23c50be687a9
permissions -rw-r--r--
some portal changes, warning: no loop prevention yet, note: entry angle not preserved yet
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
     1
//
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
     2
//  overlayViewController.m
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
     3
//  HedgewarsMobile
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
     4
//
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
     5
//  Created by Vittorio on 16/03/10.
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
     6
//  Copyright 2010 __MyCompanyName__. All rights reserved.
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
     7
//
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
     8
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
     9
#import "OverlayViewController.h"
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    10
#import "SDL_uikitappdelegate.h"
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    11
#import "PascalImports.h"
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    12
#import "CGPointUtils.h"
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    13
#import "SDL_mouse.h"
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
    14
#import "PopoverMenuViewController.h"
3335
2520ee7a5484 new manager for handling (future) rotations
koda
parents: 3317
diff changeset
    15
#import "CommodityFunctions.h"
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    16
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    17
@implementation OverlayViewController
3364
e5403e2bf02c no more hardcoded teams, team selection is real \o/
koda
parents: 3357
diff changeset
    18
@synthesize popoverController, popupMenu;
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    19
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    20
3335
2520ee7a5484 new manager for handling (future) rotations
koda
parents: 3317
diff changeset
    21
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation {
2520ee7a5484 new manager for handling (future) rotations
koda
parents: 3317
diff changeset
    22
	return rotationManager(interfaceOrientation);
2520ee7a5484 new manager for handling (future) rotations
koda
parents: 3317
diff changeset
    23
}
2520ee7a5484 new manager for handling (future) rotations
koda
parents: 3317
diff changeset
    24
2520ee7a5484 new manager for handling (future) rotations
koda
parents: 3317
diff changeset
    25
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    26
-(void) didReceiveMemoryWarning {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    27
	// Releases the view if it doesn't have a superview.
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    28
    [super didReceiveMemoryWarning];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    29
	// Release any cached data, images, etc that aren't in use.
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    30
}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    31
3385
361bd29293f4 add automatic rotation in ipad (landscape only)
koda
parents: 3364
diff changeset
    32
-(void) didRotate:(NSNotification *)notification {	
361bd29293f4 add automatic rotation in ipad (landscape only)
koda
parents: 3364
diff changeset
    33
    UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
361bd29293f4 add automatic rotation in ipad (landscape only)
koda
parents: 3364
diff changeset
    34
    CGRect rect = [[UIScreen mainScreen] bounds];
3395
095273ad0e08 adding a somewhat working autoration for ipad (uStore.pas and uWorld.pas got mixed in the last two commits)
koda
parents: 3385
diff changeset
    35
    CGRect usefulRect = CGRectMake(0, 0, rect.size.width, rect.size.height);
095273ad0e08 adding a somewhat working autoration for ipad (uStore.pas and uWorld.pas got mixed in the last two commits)
koda
parents: 3385
diff changeset
    36
    UIView *sdlView = [[SDLUIKitDelegate sharedAppDelegate].uiwindow viewWithTag:SDL_VIEW_TAG];
3385
361bd29293f4 add automatic rotation in ipad (landscape only)
koda
parents: 3364
diff changeset
    37
    
3395
095273ad0e08 adding a somewhat working autoration for ipad (uStore.pas and uWorld.pas got mixed in the last two commits)
koda
parents: 3385
diff changeset
    38
    [UIView beginAnimations:@"rotation" context:NULL];
095273ad0e08 adding a somewhat working autoration for ipad (uStore.pas and uWorld.pas got mixed in the last two commits)
koda
parents: 3385
diff changeset
    39
    [UIView setAnimationDuration:0.8f];
095273ad0e08 adding a somewhat working autoration for ipad (uStore.pas and uWorld.pas got mixed in the last two commits)
koda
parents: 3385
diff changeset
    40
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
095273ad0e08 adding a somewhat working autoration for ipad (uStore.pas and uWorld.pas got mixed in the last two commits)
koda
parents: 3385
diff changeset
    41
	switch (orientation) {
095273ad0e08 adding a somewhat working autoration for ipad (uStore.pas and uWorld.pas got mixed in the last two commits)
koda
parents: 3385
diff changeset
    42
        case UIDeviceOrientationLandscapeLeft:
095273ad0e08 adding a somewhat working autoration for ipad (uStore.pas and uWorld.pas got mixed in the last two commits)
koda
parents: 3385
diff changeset
    43
            sdlView.transform = CGAffineTransformMakeRotation(degreesToRadian(0));
095273ad0e08 adding a somewhat working autoration for ipad (uStore.pas and uWorld.pas got mixed in the last two commits)
koda
parents: 3385
diff changeset
    44
            self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(90));
095273ad0e08 adding a somewhat working autoration for ipad (uStore.pas and uWorld.pas got mixed in the last two commits)
koda
parents: 3385
diff changeset
    45
            HW_setLandscape(YES);
095273ad0e08 adding a somewhat working autoration for ipad (uStore.pas and uWorld.pas got mixed in the last two commits)
koda
parents: 3385
diff changeset
    46
            break;
095273ad0e08 adding a somewhat working autoration for ipad (uStore.pas and uWorld.pas got mixed in the last two commits)
koda
parents: 3385
diff changeset
    47
        case UIDeviceOrientationLandscapeRight:
095273ad0e08 adding a somewhat working autoration for ipad (uStore.pas and uWorld.pas got mixed in the last two commits)
koda
parents: 3385
diff changeset
    48
            sdlView.transform = CGAffineTransformMakeRotation(degreesToRadian(180));
3385
361bd29293f4 add automatic rotation in ipad (landscape only)
koda
parents: 3364
diff changeset
    49
            self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(-90));
3395
095273ad0e08 adding a somewhat working autoration for ipad (uStore.pas and uWorld.pas got mixed in the last two commits)
koda
parents: 3385
diff changeset
    50
            HW_setLandscape(YES);
095273ad0e08 adding a somewhat working autoration for ipad (uStore.pas and uWorld.pas got mixed in the last two commits)
koda
parents: 3385
diff changeset
    51
            break;
095273ad0e08 adding a somewhat working autoration for ipad (uStore.pas and uWorld.pas got mixed in the last two commits)
koda
parents: 3385
diff changeset
    52
        case UIDeviceOrientationPortrait:
095273ad0e08 adding a somewhat working autoration for ipad (uStore.pas and uWorld.pas got mixed in the last two commits)
koda
parents: 3385
diff changeset
    53
            sdlView.transform = CGAffineTransformMakeRotation(degreesToRadian(270));
095273ad0e08 adding a somewhat working autoration for ipad (uStore.pas and uWorld.pas got mixed in the last two commits)
koda
parents: 3385
diff changeset
    54
            self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(0));
095273ad0e08 adding a somewhat working autoration for ipad (uStore.pas and uWorld.pas got mixed in the last two commits)
koda
parents: 3385
diff changeset
    55
            HW_setLandscape(NO);
095273ad0e08 adding a somewhat working autoration for ipad (uStore.pas and uWorld.pas got mixed in the last two commits)
koda
parents: 3385
diff changeset
    56
            break;
095273ad0e08 adding a somewhat working autoration for ipad (uStore.pas and uWorld.pas got mixed in the last two commits)
koda
parents: 3385
diff changeset
    57
        case UIDeviceOrientationPortraitUpsideDown:
095273ad0e08 adding a somewhat working autoration for ipad (uStore.pas and uWorld.pas got mixed in the last two commits)
koda
parents: 3385
diff changeset
    58
            sdlView.transform = CGAffineTransformMakeRotation(degreesToRadian(90));
095273ad0e08 adding a somewhat working autoration for ipad (uStore.pas and uWorld.pas got mixed in the last two commits)
koda
parents: 3385
diff changeset
    59
            self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(180));
095273ad0e08 adding a somewhat working autoration for ipad (uStore.pas and uWorld.pas got mixed in the last two commits)
koda
parents: 3385
diff changeset
    60
            HW_setLandscape(NO);
095273ad0e08 adding a somewhat working autoration for ipad (uStore.pas and uWorld.pas got mixed in the last two commits)
koda
parents: 3385
diff changeset
    61
            break;
095273ad0e08 adding a somewhat working autoration for ipad (uStore.pas and uWorld.pas got mixed in the last two commits)
koda
parents: 3385
diff changeset
    62
        default:
095273ad0e08 adding a somewhat working autoration for ipad (uStore.pas and uWorld.pas got mixed in the last two commits)
koda
parents: 3385
diff changeset
    63
            NSLog(@"warning - Unknown rotation status");
095273ad0e08 adding a somewhat working autoration for ipad (uStore.pas and uWorld.pas got mixed in the last two commits)
koda
parents: 3385
diff changeset
    64
            break;
095273ad0e08 adding a somewhat working autoration for ipad (uStore.pas and uWorld.pas got mixed in the last two commits)
koda
parents: 3385
diff changeset
    65
    }
095273ad0e08 adding a somewhat working autoration for ipad (uStore.pas and uWorld.pas got mixed in the last two commits)
koda
parents: 3385
diff changeset
    66
    self.view.frame = usefulRect;
095273ad0e08 adding a somewhat working autoration for ipad (uStore.pas and uWorld.pas got mixed in the last two commits)
koda
parents: 3385
diff changeset
    67
    sdlView.frame = usefulRect;
095273ad0e08 adding a somewhat working autoration for ipad (uStore.pas and uWorld.pas got mixed in the last two commits)
koda
parents: 3385
diff changeset
    68
    [UIView commitAnimations];
3340
96dd168b080b fix all of what was committed before
koda
parents: 3335
diff changeset
    69
}
3385
361bd29293f4 add automatic rotation in ipad (landscape only)
koda
parents: 3364
diff changeset
    70
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    71
-(void) viewDidLoad {
3308
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
    72
    isPopoverVisible = NO;
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    73
    self.view.alpha = 0;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    74
    self.view.center = CGPointMake(self.view.frame.size.height/2.0, self.view.frame.size.width/2.0);
3385
361bd29293f4 add automatic rotation in ipad (landscape only)
koda
parents: 3364
diff changeset
    75
    
3317
198ec44b6d92 minor tweaks, icon for ipad, merged overlayviewcontroller, pop viewcontroller when selected a hat
koda
parents: 3308
diff changeset
    76
    
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    77
    dimTimer = [[NSTimer alloc] initWithFireDate:[NSDate dateWithTimeIntervalSinceNow:6]
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    78
                                        interval:1000
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    79
                                          target:self
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    80
                                        selector:@selector(dimOverlay)
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    81
                                        userInfo:nil
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    82
                                         repeats:YES];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    83
    
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    84
    // add timer too runloop, otherwise it doesn't work
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    85
    [[NSRunLoop currentRunLoop] addTimer:dimTimer forMode:NSDefaultRunLoopMode];
3357
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3356
diff changeset
    86
    
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3356
diff changeset
    87
    // listen for dismissal of the popover (see below)
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3356
diff changeset
    88
    [[NSNotificationCenter defaultCenter] addObserver:self
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3356
diff changeset
    89
                                             selector:@selector(dismissPopover)
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3356
diff changeset
    90
                                                 name:@"dismissPopover"
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3356
diff changeset
    91
                                               object:nil];
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    92
    // present the overlay after 2 seconds
3357
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3356
diff changeset
    93
    [NSTimer scheduledTimerWithTimeInterval:2
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3356
diff changeset
    94
                                     target:self
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3356
diff changeset
    95
                                   selector:@selector(showMenuAfterwards)
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3356
diff changeset
    96
                                   userInfo:nil
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3356
diff changeset
    97
                                    repeats:NO];
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    98
}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    99
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   100
-(void) viewDidUnload {
3308
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   101
    self.popoverController = nil;
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   102
    self.popupMenu = nil;
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   103
    [super viewDidUnload];
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   104
}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   105
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   106
-(void) dealloc {
3357
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3356
diff changeset
   107
	[dimTimer invalidate];
3308
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   108
    [popupMenu release];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   109
    [popoverController release];
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   110
    // dimTimer is autoreleased
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   111
    [super dealloc];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   112
}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   113
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   114
// draws the controller overlay after the sdl window has taken control
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   115
-(void) showMenuAfterwards {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   116
    [[SDLUIKitDelegate sharedAppDelegate].uiwindow bringSubviewToFront:self.view];
3385
361bd29293f4 add automatic rotation in ipad (landscape only)
koda
parents: 3364
diff changeset
   117
    
361bd29293f4 add automatic rotation in ipad (landscape only)
koda
parents: 3364
diff changeset
   118
    // need to split paths because iphone doesn't rotate (so we don't need to subscribe to any notification
361bd29293f4 add automatic rotation in ipad (landscape only)
koda
parents: 3364
diff changeset
   119
    // nor perform engine actions when rotating
361bd29293f4 add automatic rotation in ipad (landscape only)
koda
parents: 3364
diff changeset
   120
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
361bd29293f4 add automatic rotation in ipad (landscape only)
koda
parents: 3364
diff changeset
   121
        [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];	
361bd29293f4 add automatic rotation in ipad (landscape only)
koda
parents: 3364
diff changeset
   122
        [[NSNotificationCenter defaultCenter] addObserver:self
361bd29293f4 add automatic rotation in ipad (landscape only)
koda
parents: 3364
diff changeset
   123
                                                 selector:@selector(didRotate:)
361bd29293f4 add automatic rotation in ipad (landscape only)
koda
parents: 3364
diff changeset
   124
                                                     name:@"UIDeviceOrientationDidChangeNotification"
361bd29293f4 add automatic rotation in ipad (landscape only)
koda
parents: 3364
diff changeset
   125
                                                   object:nil];
361bd29293f4 add automatic rotation in ipad (landscape only)
koda
parents: 3364
diff changeset
   126
        
361bd29293f4 add automatic rotation in ipad (landscape only)
koda
parents: 3364
diff changeset
   127
        [self didRotate:nil];
361bd29293f4 add automatic rotation in ipad (landscape only)
koda
parents: 3364
diff changeset
   128
    } else 
361bd29293f4 add automatic rotation in ipad (landscape only)
koda
parents: 3364
diff changeset
   129
        self.view.transform = CGAffineTransformRotate(self.view.transform, (M_PI/2.0));
361bd29293f4 add automatic rotation in ipad (landscape only)
koda
parents: 3364
diff changeset
   130
    
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   131
	[UIView beginAnimations:@"showing overlay" context:NULL];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   132
	[UIView setAnimationDuration:1];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   133
	self.view.alpha = 1;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   134
	[UIView commitAnimations];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   135
}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   136
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   137
// dim the overlay when there's no more input for a certain amount of time
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   138
-(IBAction) buttonReleased:(id) sender {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   139
	HW_allKeysUp();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   140
    [dimTimer setFireDate:[NSDate dateWithTimeIntervalSinceNow:2.7]];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   141
}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   142
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   143
// nice transition for dimming
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   144
-(void) dimOverlay {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   145
    [UIView beginAnimations:@"overlay dim" context:NULL];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   146
   	[UIView setAnimationDuration:0.6];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   147
    self.view.alpha = 0.2;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   148
	[UIView commitAnimations];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   149
}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   150
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   151
// set the overlay visible and put off the timer for enough time
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   152
-(void) activateOverlay {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   153
    self.view.alpha = 1;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   154
    [dimTimer setFireDate:[NSDate dateWithTimeIntervalSinceNow:1000]];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   155
}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   156
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   157
// issue certain action based on the tag of the button 
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   158
-(IBAction) buttonPressed:(id) sender {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   159
    [self activateOverlay];
3308
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   160
    if (isPopoverVisible) {
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   161
        [self dismissPopover];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   162
    }
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   163
    UIButton *theButton = (UIButton *)sender;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   164
    
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   165
    switch (theButton.tag) {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   166
        case 0:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   167
            HW_walkLeft();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   168
            break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   169
        case 1:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   170
            HW_walkRight();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   171
            break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   172
        case 2:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   173
            HW_aimUp();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   174
            break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   175
        case 3:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   176
            HW_aimDown();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   177
            break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   178
        case 4:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   179
            HW_shoot();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   180
            break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   181
        case 5:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   182
            HW_jump();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   183
            break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   184
        case 6:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   185
            HW_backjump();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   186
            break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   187
        case 7:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   188
            HW_tab();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   189
            break;
3308
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   190
        case 10:
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   191
            [self showPopover];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   192
            break;
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   193
        default:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   194
            NSLog(@"Nope");
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   195
            break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   196
    }
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   197
}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   198
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   199
// present a further check before closing game
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   200
-(void) actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger) buttonIndex {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   201
	if ([actionSheet cancelButtonIndex] != buttonIndex)
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   202
	    HW_terminate(NO);
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   203
	else
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   204
        HW_pause();		
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   205
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   206
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   207
// show up a popover containing a popupMenuViewController; we hook it with setPopoverContentSize
3308
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   208
// on iphone instead just use the tableViewController directly (and implement manually all animations)
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   209
-(IBAction) showPopover{
3308
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   210
    isPopoverVisible = YES;
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   211
    Class popoverControllerClass = NSClassFromString(@"UIPopoverController");
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   212
    if (popoverControllerClass) {
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   213
#ifdef __IPHONE_3_2
3308
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   214
        popupMenu = [[PopoverMenuViewController alloc] initWithStyle:UITableViewStylePlain];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   215
        popoverController = [[popoverControllerClass alloc] initWithContentViewController:popupMenu];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   216
        [popoverController setPopoverContentSize:CGSizeMake(220, 170) animated:YES];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   217
        [popoverController setPassthroughViews:[NSArray arrayWithObject:self.view]];
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   218
        
3308
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   219
        [popoverController presentPopoverFromRect:CGRectMake(960, 0, 220, 32)
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   220
                                           inView:self.view
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   221
                         permittedArrowDirections:UIPopoverArrowDirectionUp 
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   222
                                         animated:YES];
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   223
#endif
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   224
    } else {
3308
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   225
        popupMenu = [[PopoverMenuViewController alloc] initWithStyle:UITableViewStyleGrouped];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   226
        popupMenu.view.backgroundColor = [UIColor clearColor];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   227
        popupMenu.view.frame = CGRectMake(480, 0, 200, 170);
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   228
        [self.view addSubview:popupMenu.view];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   229
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   230
        [UIView beginAnimations:@"showing popover" context:NULL];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   231
        [UIView setAnimationDuration:0.35];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   232
        popupMenu.view.frame = CGRectMake(280, 0, 200, 170);
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   233
        [UIView commitAnimations];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   234
    }
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   235
    popupMenu.tableView.scrollEnabled = NO;
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   236
}
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   237
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   238
// on ipad just dismiss it, on iphone transtion on the right
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   239
-(void) dismissPopover {
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   240
    if (YES == isPopoverVisible) {
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   241
        isPopoverVisible = NO;
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   242
        
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   243
        if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   244
#ifdef __IPHONE_3_2
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   245
            [popoverController dismissPopoverAnimated:YES];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   246
#endif
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   247
        } else {
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   248
            [UIView beginAnimations:@"hiding popover" context:NULL];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   249
            [UIView setAnimationDuration:0.35];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   250
            popupMenu.view.frame = CGRectMake(480, 0, 200, 170);
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   251
            [UIView commitAnimations];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   252
        
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   253
            [popupMenu.view performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:0.35];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   254
            [popupMenu performSelector:@selector(release) withObject:nil afterDelay:0.35];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   255
            
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   256
            //[dimTimer setFireDate:[NSDate dateWithTimeIntervalSinceNow:2.7]];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   257
        }
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   258
        [self buttonReleased:nil];
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   259
    }
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   260
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   261
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   262
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   263
#pragma mark -
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   264
#pragma mark Custom touch event handling
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   265
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   266
#define kMinimumPinchDelta      50
3347
5d0ac8197eb7 camera panning ftw
koda
parents: 3340
diff changeset
   267
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   268
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   269
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   270
	NSArray *twoTouches;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   271
	UITouch *touch = [touches anyObject];
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   272
    
3308
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   273
    if (isPopoverVisible) {
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   274
        [self dismissPopover];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   275
    }
3347
5d0ac8197eb7 camera panning ftw
koda
parents: 3340
diff changeset
   276
    
5d0ac8197eb7 camera panning ftw
koda
parents: 3340
diff changeset
   277
    gestureStartPoint = [touch locationInView:self.view];
3308
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   278
        
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   279
	switch ([touches count]) {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   280
		case 1:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   281
			initialDistanceForPinching = 0;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   282
			switch ([touch tapCount]) {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   283
				case 1:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   284
					NSLog(@"X:%d Y:%d", (int)gestureStartPoint.x, (int)gestureStartPoint.y );
3347
5d0ac8197eb7 camera panning ftw
koda
parents: 3340
diff changeset
   285
					//SDL_WarpMouseInWindow([SDLUIKitDelegate sharedAppDelegate].window, 
5d0ac8197eb7 camera panning ftw
koda
parents: 3340
diff changeset
   286
					//		      (int)gestureStartPoint.y, width - (int)gestureStartPoint.x);
5d0ac8197eb7 camera panning ftw
koda
parents: 3340
diff changeset
   287
					//HW_click();
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   288
					break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   289
				case 2:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   290
					HW_ammoMenu();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   291
					break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   292
				default:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   293
					break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   294
			}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   295
			break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   296
		case 2:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   297
			if (2 == [touch tapCount]) {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   298
				HW_zoomReset();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   299
			}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   300
			
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   301
			// pinching
3347
5d0ac8197eb7 camera panning ftw
koda
parents: 3340
diff changeset
   302
            gestureStartPoint.x = 0;
5d0ac8197eb7 camera panning ftw
koda
parents: 3340
diff changeset
   303
            gestureStartPoint.y = 0;
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   304
			twoTouches = [touches allObjects];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   305
			UITouch *first = [twoTouches objectAtIndex:0];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   306
			UITouch *second = [twoTouches objectAtIndex:1];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   307
			initialDistanceForPinching = distanceBetweenPoints([first locationInView:self.view], [second locationInView:self.view]);
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   308
			break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   309
		default:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   310
			break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   311
	}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   312
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   313
}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   314
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   315
-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   316
	initialDistanceForPinching = 0;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   317
	HW_allKeysUp();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   318
}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   319
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   320
-(void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
3347
5d0ac8197eb7 camera panning ftw
koda
parents: 3340
diff changeset
   321
	// this can happen if the user puts more than 5 touches on the screen at once, or perhaps in other circumstances
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   322
	[self touchesEnded:touches withEvent:event];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   323
}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   324
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   325
-(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
3364
e5403e2bf02c no more hardcoded teams, team selection is real \o/
koda
parents: 3357
diff changeset
   326
    CGFloat minimumGestureLength;
3347
5d0ac8197eb7 camera panning ftw
koda
parents: 3340
diff changeset
   327
    int logCoeff;
5d0ac8197eb7 camera panning ftw
koda
parents: 3340
diff changeset
   328
    
5d0ac8197eb7 camera panning ftw
koda
parents: 3340
diff changeset
   329
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
3364
e5403e2bf02c no more hardcoded teams, team selection is real \o/
koda
parents: 3357
diff changeset
   330
        minimumGestureLength = 5.0f;
3347
5d0ac8197eb7 camera panning ftw
koda
parents: 3340
diff changeset
   331
        logCoeff = 19;
5d0ac8197eb7 camera panning ftw
koda
parents: 3340
diff changeset
   332
    } else {
3364
e5403e2bf02c no more hardcoded teams, team selection is real \o/
koda
parents: 3357
diff changeset
   333
        minimumGestureLength = 3.0f;
3347
5d0ac8197eb7 camera panning ftw
koda
parents: 3340
diff changeset
   334
        logCoeff = 3;
5d0ac8197eb7 camera panning ftw
koda
parents: 3340
diff changeset
   335
    }
5d0ac8197eb7 camera panning ftw
koda
parents: 3340
diff changeset
   336
    
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   337
	NSArray *twoTouches;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   338
	CGPoint currentPosition;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   339
	UITouch *touch = [touches anyObject];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   340
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   341
	switch ([touches count]) {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   342
		case 1:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   343
			currentPosition = [touch locationInView:self.view];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   344
			// panning
3347
5d0ac8197eb7 camera panning ftw
koda
parents: 3340
diff changeset
   345
			CGFloat deltaX = fabsf(gestureStartPoint.x - currentPosition.x);
5d0ac8197eb7 camera panning ftw
koda
parents: 3340
diff changeset
   346
			CGFloat deltaY = fabsf(gestureStartPoint.y - currentPosition.y);
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   347
			
3347
5d0ac8197eb7 camera panning ftw
koda
parents: 3340
diff changeset
   348
            if (deltaX >= minimumGestureLength) {
5d0ac8197eb7 camera panning ftw
koda
parents: 3340
diff changeset
   349
                NSLog(@"Horizontal swipe detected, deltaX: %f deltaY: %f",deltaX, deltaY);
3364
e5403e2bf02c no more hardcoded teams, team selection is real \o/
koda
parents: 3357
diff changeset
   350
                if (currentPosition.x > gestureStartPoint.x) {
3356
3ae3fccb439e add missing controller stubs
koda
parents: 3347
diff changeset
   351
                    HW_cursorLeft(logCoeff*log(deltaX));
3347
5d0ac8197eb7 camera panning ftw
koda
parents: 3340
diff changeset
   352
                } else {
3356
3ae3fccb439e add missing controller stubs
koda
parents: 3347
diff changeset
   353
                    HW_cursorRight(logCoeff*log(deltaX));
3347
5d0ac8197eb7 camera panning ftw
koda
parents: 3340
diff changeset
   354
                }
5d0ac8197eb7 camera panning ftw
koda
parents: 3340
diff changeset
   355
5d0ac8197eb7 camera panning ftw
koda
parents: 3340
diff changeset
   356
            } 
5d0ac8197eb7 camera panning ftw
koda
parents: 3340
diff changeset
   357
            if (deltaY >= minimumGestureLength) {
5d0ac8197eb7 camera panning ftw
koda
parents: 3340
diff changeset
   358
                NSLog(@"Horizontal swipe detected, deltaX: %f deltaY: %f",deltaX, deltaY);
3364
e5403e2bf02c no more hardcoded teams, team selection is real \o/
koda
parents: 3357
diff changeset
   359
                if (currentPosition.y < gestureStartPoint.y) {
3356
3ae3fccb439e add missing controller stubs
koda
parents: 3347
diff changeset
   360
                    HW_cursorDown(logCoeff*log(deltaY));
3347
5d0ac8197eb7 camera panning ftw
koda
parents: 3340
diff changeset
   361
                } else {
3356
3ae3fccb439e add missing controller stubs
koda
parents: 3347
diff changeset
   362
                    HW_cursorUp(logCoeff*log(deltaY));
3347
5d0ac8197eb7 camera panning ftw
koda
parents: 3340
diff changeset
   363
                }            
5d0ac8197eb7 camera panning ftw
koda
parents: 3340
diff changeset
   364
            }
5d0ac8197eb7 camera panning ftw
koda
parents: 3340
diff changeset
   365
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   366
			break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   367
		case 2:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   368
			twoTouches = [touches allObjects];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   369
			UITouch *first = [twoTouches objectAtIndex:0];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   370
			UITouch *second = [twoTouches objectAtIndex:1];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   371
			CGFloat currentDistanceOfPinching = distanceBetweenPoints([first locationInView:self.view], [second locationInView:self.view]);
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   372
			
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   373
			if (0 == initialDistanceForPinching) 
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   374
				initialDistanceForPinching = currentDistanceOfPinching;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   375
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   376
			if (currentDistanceOfPinching < initialDistanceForPinching + kMinimumPinchDelta)
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   377
				HW_zoomOut();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   378
			else if (currentDistanceOfPinching > initialDistanceForPinching + kMinimumPinchDelta)
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   379
				HW_zoomIn();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   380
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   381
			currentDistanceOfPinching = initialDistanceForPinching;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   382
			break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   383
		default:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   384
			break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   385
	}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   386
}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   387
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   388
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   389
@end