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