cocoaTouch/OverlayViewController.m
author nemo
Thu, 01 Apr 2010 16:28:03 +0000
changeset 3237 668c323ce27a
parent 3117 f3e363a9b7db
child 3305 91074496d5c9
permissions -rw-r--r--
Further updates by jose1711 - who knows, maybe he'll get it finished before release at this point
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"
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    14
#import "PopupMenuViewController.h"
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    15
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    16
@implementation OverlayViewController
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    17
@synthesize dimTimer;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    18
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
-(void) didReceiveMemoryWarning {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    21
	// 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
    22
    [super didReceiveMemoryWarning];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    23
	
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    24
	// 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
    25
}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    26
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    27
-(void) viewDidLoad {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    28
    self.view.alpha = 0;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    29
    
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    30
    // needed for rotation to work on os < 3.2
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    31
    self.view.center = CGPointMake(self.view.frame.size.height/2.0, self.view.frame.size.width/2.0);
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    32
    self.view.transform = CGAffineTransformRotate(self.view.transform, (M_PI/2.0));
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    33
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    34
    dimTimer = [[NSTimer alloc] initWithFireDate:[NSDate dateWithTimeIntervalSinceNow:6]
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    35
                                        interval:1000
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    36
                                          target:self
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    37
                                        selector:@selector(dimOverlay)
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    38
                                        userInfo:nil
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    39
                                         repeats:YES];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    40
    
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    41
    // add timer too runloop, otherwise it doesn't work
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    42
    [[NSRunLoop currentRunLoop] addTimer:dimTimer forMode:NSDefaultRunLoopMode];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    43
    // listen for dismissal of the popover (see below)x
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    44
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(dismissPopover) name:@"dismissPopover" object:nil];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    45
    // present the overlay after 2 seconds
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    46
    [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(showMenuAfterwards) userInfo:nil repeats:NO];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    47
}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    48
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    49
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    50
    return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    51
}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    52
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    53
-(void) viewDidUnload {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    54
	[dimTimer invalidate];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    55
}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    56
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    57
-(void) dealloc {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    58
    // dimTimer is autoreleased
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    59
    [super dealloc];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    60
}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    61
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    62
// 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
    63
-(void) showMenuAfterwards {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    64
    [[SDLUIKitDelegate sharedAppDelegate].uiwindow bringSubviewToFront:self.view];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    65
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    66
	[UIView beginAnimations:@"showing overlay" context:NULL];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    67
	[UIView setAnimationDuration:1];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    68
	self.view.alpha = 1;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    69
	[UIView commitAnimations];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    70
}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    71
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    72
// 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
    73
-(IBAction) buttonReleased:(id) sender {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    74
	HW_allKeysUp();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    75
    [dimTimer setFireDate:[NSDate dateWithTimeIntervalSinceNow:2.7]];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    76
}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    77
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    78
// nice transition for dimming
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    79
-(void) dimOverlay {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    80
    [UIView beginAnimations:@"overlay dim" context:NULL];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    81
   	[UIView setAnimationDuration:0.6];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    82
    self.view.alpha = 0.2;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    83
	[UIView commitAnimations];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    84
}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    85
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    86
// 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
    87
-(void) activateOverlay {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    88
    self.view.alpha = 1;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    89
    [dimTimer setFireDate:[NSDate dateWithTimeIntervalSinceNow:1000]];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    90
}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    91
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    92
// 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
    93
-(IBAction) buttonPressed:(id) sender {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    94
    [self activateOverlay];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    95
    UIActionSheet *actionSheet;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    96
    UIButton *theButton = (UIButton *)sender;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    97
    
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    98
    switch (theButton.tag) {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    99
        case 0:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   100
            HW_walkLeft();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   101
            break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   102
        case 1:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   103
            HW_walkRight();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   104
            break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   105
        case 2:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   106
            HW_aimUp();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   107
            break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   108
        case 3:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   109
            HW_aimDown();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   110
            break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   111
        case 4:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   112
            HW_shoot();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   113
            break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   114
        case 5:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   115
            HW_jump();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   116
            break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   117
        case 6:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   118
            HW_backjump();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   119
            break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   120
        case 7:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   121
            HW_pause();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   122
            break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   123
        case 8:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   124
            HW_chat();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   125
            break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   126
        case 9:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   127
            actionSheet = [[UIActionSheet alloc] initWithTitle:NSLocalizedString(@"Are you reeeeeally sure?", @"")
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   128
                                                      delegate:self
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   129
                                             cancelButtonTitle:NSLocalizedString(@"Well, maybe not...", @"")
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   130
                                        destructiveButtonTitle:NSLocalizedString(@"As sure as I can be!", @"")
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   131
                                             otherButtonTitles:nil];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   132
            [actionSheet showInView:self.view];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   133
            [actionSheet release];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   134
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   135
            HW_pause();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   136
	    break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   137
        case 10:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   138
            HW_tab();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   139
            break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   140
        default:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   141
            NSLog(@"Nope");
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   142
            break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   143
    }
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   144
}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   145
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   146
#pragma mark -
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   147
#define kMinimumPinchDelta      50
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   148
#define kMinimumGestureLength	10
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   149
#define kMaximumVariance        3
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
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   152
	NSArray *twoTouches;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   153
	UITouch *touch = [touches anyObject];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   154
	
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   155
	switch ([touches count]) {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   156
		case 1:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   157
			gestureStartPoint = [touch locationInView:self.view];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   158
			initialDistanceForPinching = 0;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   159
			switch ([touch tapCount]) {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   160
				case 1:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   161
					NSLog(@"X:%d Y:%d", (int)gestureStartPoint.x, (int)gestureStartPoint.y );
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   162
					SDL_WarpMouseInWindow([SDLUIKitDelegate sharedAppDelegate].window, 
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   163
							      (int)gestureStartPoint.y, 320 - (int)gestureStartPoint.x);
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   164
					HW_click();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   165
					break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   166
				case 2:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   167
					HW_ammoMenu();
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
				default:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   170
					break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   171
			}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   172
			break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   173
		case 2:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   174
			if (2 == [touch tapCount]) {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   175
				HW_zoomReset();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   176
			}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   177
			
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   178
			// pinching
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   179
			twoTouches = [touches allObjects];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   180
			UITouch *first = [twoTouches objectAtIndex:0];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   181
			UITouch *second = [twoTouches objectAtIndex:1];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   182
			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
   183
			break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   184
		default:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   185
			break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   186
	}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   187
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   188
}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   189
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   190
-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   191
	initialDistanceForPinching = 0;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   192
	gestureStartPoint.x = 0;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   193
	gestureStartPoint.y = 0;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   194
	HW_allKeysUp();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   195
}
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
-(void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   198
	// this can happen if the user puts more than 5 touches on the screen at once, or perhaps in other circumstances.
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   199
	[self touchesEnded:touches withEvent:event];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   200
}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   201
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   202
-(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   203
	NSArray *twoTouches;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   204
	CGPoint currentPosition;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   205
	UITouch *touch = [touches anyObject];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   206
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   207
	switch ([touches count]) {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   208
		case 1:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   209
			currentPosition = [touch locationInView:self.view];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   210
			// panning
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   211
			SDL_WarpMouseInWindow([SDLUIKitDelegate sharedAppDelegate].window, 
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   212
							(int)gestureStartPoint.y, 320 - (int)gestureStartPoint.x);
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   213
			// remember that we have x and y inverted
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   214
			/* temporarily disabling hog movements for camera panning testing
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   215
			CGFloat vertDiff = gestureStartPoint.x - currentPosition.x;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   216
			CGFloat horizDiff = gestureStartPoint.y - currentPosition.y;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   217
			CGFloat deltaX = fabsf(vertDiff);
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   218
			CGFloat deltaY = fabsf(horizDiff);
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   219
			
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   220
			if (deltaY >= kMinimumGestureLength && deltaX <= kMaximumVariance) {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   221
				NSLog(@"Horizontal swipe detected, begX:%f curX:%f", gestureStartPoint.x, currentPosition.x);
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   222
				if (horizDiff > 0) HW_walkLeft();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   223
				else HW_walkRight();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   224
			} else if (deltaX >= kMinimumGestureLength && deltaY <= kMaximumVariance){
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   225
				NSLog(@"Vertical swipe detected, begY:%f curY:%f", gestureStartPoint.y, currentPosition.y);
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   226
				if (vertDiff < 0) HW_aimUp();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   227
				else HW_aimDown();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   228
			}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   229
			*/
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   230
			break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   231
		case 2:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   232
			twoTouches = [touches allObjects];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   233
			UITouch *first = [twoTouches objectAtIndex:0];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   234
			UITouch *second = [twoTouches objectAtIndex:1];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   235
			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
   236
			
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   237
			if (0 == initialDistanceForPinching) 
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   238
				initialDistanceForPinching = currentDistanceOfPinching;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   239
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   240
			if (currentDistanceOfPinching < initialDistanceForPinching + kMinimumPinchDelta)
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   241
				HW_zoomOut();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   242
			else if (currentDistanceOfPinching > initialDistanceForPinching + kMinimumPinchDelta)
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   243
				HW_zoomIn();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   244
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   245
			currentDistanceOfPinching = initialDistanceForPinching;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   246
			break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   247
		default:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   248
			break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   249
	}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   250
}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   251
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   252
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   253
@end