cocoaTouch/OverlayViewController.m
author koda
Sun, 04 Apr 2010 19:51:53 +0000
changeset 3305 91074496d5c9
parent 3117 f3e363a9b7db
child 3308 b6dcae4b6d2c
permissions -rw-r--r--
merged code from ipad and iphone frontends (aka HedgewarsMobile is a universal application)
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"
3117
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
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
    17
@synthesize dimTimer, menuPopover;
3117
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];
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
    55
    self.dimTimer = nil;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
    56
    menuPopover = nil;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
    57
    [super viewDidUnload];
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    58
}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    59
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    60
-(void) dealloc {
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
    61
    [menuPopover release];
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    62
    // dimTimer is autoreleased
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    63
    [super dealloc];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    64
}
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
// 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
    67
-(void) showMenuAfterwards {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    68
    [[SDLUIKitDelegate sharedAppDelegate].uiwindow bringSubviewToFront:self.view];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    69
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    70
	[UIView beginAnimations:@"showing overlay" context:NULL];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    71
	[UIView setAnimationDuration:1];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    72
	self.view.alpha = 1;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    73
	[UIView commitAnimations];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    74
}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    75
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    76
// 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
    77
-(IBAction) buttonReleased:(id) sender {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    78
	HW_allKeysUp();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    79
    [dimTimer setFireDate:[NSDate dateWithTimeIntervalSinceNow:2.7]];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    80
}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    81
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    82
// nice transition for dimming
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    83
-(void) dimOverlay {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    84
    [UIView beginAnimations:@"overlay dim" context:NULL];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    85
   	[UIView setAnimationDuration:0.6];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    86
    self.view.alpha = 0.2;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    87
	[UIView commitAnimations];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    88
}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    89
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    90
// 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
    91
-(void) activateOverlay {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    92
    self.view.alpha = 1;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    93
    [dimTimer setFireDate:[NSDate dateWithTimeIntervalSinceNow:1000]];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    94
}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    95
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    96
// 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
    97
-(IBAction) buttonPressed:(id) sender {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    98
    [self activateOverlay];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    99
    UIButton *theButton = (UIButton *)sender;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   100
    
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   101
    switch (theButton.tag) {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   102
        case 0:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   103
            HW_walkLeft();
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 1:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   106
            HW_walkRight();
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 2:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   109
            HW_aimUp();
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 3:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   112
            HW_aimDown();
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 4:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   115
            HW_shoot();
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 5:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   118
            HW_jump();
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 6:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   121
            HW_backjump();
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 7:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   124
            HW_tab();
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
        default:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   127
            NSLog(@"Nope");
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   128
            break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   129
    }
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   130
}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   131
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   132
// present a further check before closing game
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   133
-(void) actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger) buttonIndex {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   134
	if ([actionSheet cancelButtonIndex] != buttonIndex)
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   135
	    HW_terminate(NO);
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   136
	else
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   137
        HW_pause();		
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   138
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   139
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   140
// show up a popover containing a popupMenuViewController; we hook it with setPopoverContentSize
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   141
-(IBAction) showPopover{
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   142
    PopoverMenuViewController *popupMenu = [[PopoverMenuViewController alloc] init];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   143
    popoverVisible = YES;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   144
    Class popoverController = NSClassFromString(@"UIPopoverController");
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   145
    if (popoverController) {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   146
#ifdef __IPHONE_3_2
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   147
        menuPopover = [[popoverController alloc] initWithContentViewController:popupMenu];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   148
        [menuPopover setPopoverContentSize:CGSizeMake(220, 170) animated:YES];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   149
        
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   150
        [menuPopover presentPopoverFromRect:CGRectMake(960, 0, 220, 32) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   151
#endif
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   152
    } else {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   153
        //iphone stuff
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   154
    }
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   155
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   156
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   157
// because of the actionSheet, the popover might not get dismissed, so we do it manually (through a NSNotification system, see above)
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   158
// are we sure about this?
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   159
-(void) dismissPopover {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   160
    /*if (popoverVisible) 
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   161
        [menuPopover dismissPopoverAnimated:YES];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   162
    popoverVisible = NO;*/
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   163
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   164
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   165
#pragma mark -
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   166
#pragma mark Custom touch event handling
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   167
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   168
#define kMinimumPinchDelta      50
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   169
#define kMinimumGestureLength	10
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   170
#define kMaximumVariance        3
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
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   173
	NSArray *twoTouches;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   174
	UITouch *touch = [touches anyObject];
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   175
	int width = [[UIScreen mainScreen] bounds].size.width;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   176
    
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   177
	switch ([touches count]) {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   178
		case 1:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   179
			gestureStartPoint = [touch locationInView:self.view];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   180
			initialDistanceForPinching = 0;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   181
			switch ([touch tapCount]) {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   182
				case 1:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   183
					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
   184
					SDL_WarpMouseInWindow([SDLUIKitDelegate sharedAppDelegate].window, 
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   185
							      (int)gestureStartPoint.y, width - (int)gestureStartPoint.x);
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   186
					HW_click();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   187
					break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   188
				case 2:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   189
					HW_ammoMenu();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   190
					break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   191
				default:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   192
					break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   193
			}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   194
			break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   195
		case 2:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   196
			if (2 == [touch tapCount]) {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   197
				HW_zoomReset();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   198
			}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   199
			
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   200
			// pinching
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   201
			twoTouches = [touches allObjects];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   202
			UITouch *first = [twoTouches objectAtIndex:0];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   203
			UITouch *second = [twoTouches objectAtIndex:1];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   204
			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
   205
			break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   206
		default:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   207
			break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   208
	}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   209
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   210
}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   211
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   212
-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   213
	initialDistanceForPinching = 0;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   214
	gestureStartPoint.x = 0;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   215
	gestureStartPoint.y = 0;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   216
	HW_allKeysUp();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   217
}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   218
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   219
-(void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   220
	// 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
   221
	[self touchesEnded:touches withEvent:event];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   222
}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   223
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   224
-(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   225
	NSArray *twoTouches;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   226
	CGPoint currentPosition;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   227
	UITouch *touch = [touches anyObject];
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   228
	int width = [[UIScreen mainScreen] bounds].size.width;
3117
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
	switch ([touches count]) {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   231
		case 1:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   232
			currentPosition = [touch locationInView:self.view];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   233
			// panning
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   234
			SDL_WarpMouseInWindow([SDLUIKitDelegate sharedAppDelegate].window, 
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   235
							(int)gestureStartPoint.y, width - (int)gestureStartPoint.x);
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   236
			// remember that we have x and y inverted
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   237
			/* temporarily disabling hog movements for camera panning testing
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   238
			CGFloat vertDiff = gestureStartPoint.x - currentPosition.x;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   239
			CGFloat horizDiff = gestureStartPoint.y - currentPosition.y;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   240
			CGFloat deltaX = fabsf(vertDiff);
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   241
			CGFloat deltaY = fabsf(horizDiff);
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   242
			
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   243
			if (deltaY >= kMinimumGestureLength && deltaX <= kMaximumVariance) {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   244
				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
   245
				if (horizDiff > 0) HW_walkLeft();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   246
				else HW_walkRight();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   247
			} else if (deltaX >= kMinimumGestureLength && deltaY <= kMaximumVariance){
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   248
				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
   249
				if (vertDiff < 0) HW_aimUp();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   250
				else HW_aimDown();
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
			break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   254
		case 2:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   255
			twoTouches = [touches allObjects];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   256
			UITouch *first = [twoTouches objectAtIndex:0];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   257
			UITouch *second = [twoTouches objectAtIndex:1];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   258
			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
   259
			
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   260
			if (0 == initialDistanceForPinching) 
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   261
				initialDistanceForPinching = currentDistanceOfPinching;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   262
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   263
			if (currentDistanceOfPinching < initialDistanceForPinching + kMinimumPinchDelta)
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   264
				HW_zoomOut();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   265
			else if (currentDistanceOfPinching > initialDistanceForPinching + kMinimumPinchDelta)
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   266
				HW_zoomIn();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   267
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   268
			currentDistanceOfPinching = initialDistanceForPinching;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   269
			break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   270
		default:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   271
			break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   272
	}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   273
}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   274
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   275
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   276
@end