cocoaTouch/OverlayViewController.m
author koda
Tue, 06 Apr 2010 02:39:06 +0000
changeset 3308 b6dcae4b6d2c
parent 3305 91074496d5c9
child 3317 198ec44b6d92
permissions -rw-r--r--
make the tables work also on iphone make the popover menu work also on iphone
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
3308
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
    17
@synthesize dimTimer, popoverController, popupMenu;
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];
3308
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
    23
3117
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 {
3308
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
    28
    isPopoverVisible = NO;
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    29
    self.view.alpha = 0;
3308
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
    30
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    31
    // needed for rotation to work on os < 3.2
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    32
    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
    33
    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
    34
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    35
    dimTimer = [[NSTimer alloc] initWithFireDate:[NSDate dateWithTimeIntervalSinceNow:6]
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    36
                                        interval:1000
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    37
                                          target:self
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    38
                                        selector:@selector(dimOverlay)
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    39
                                        userInfo:nil
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    40
                                         repeats:YES];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    41
    
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    42
    // add timer too runloop, otherwise it doesn't work
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    43
    [[NSRunLoop currentRunLoop] addTimer:dimTimer forMode:NSDefaultRunLoopMode];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    44
    // listen for dismissal of the popover (see below)x
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    45
    [[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
    46
    // present the overlay after 2 seconds
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    47
    [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
    48
}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    49
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    50
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    51
    return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
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
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    54
-(void) viewDidUnload {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    55
	[dimTimer invalidate];
3308
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
    56
	self.dimTimer = nil;
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
    57
    self.popoverController = nil;
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
    58
    self.popupMenu = nil;
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
    59
    [super viewDidUnload];
3117
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
-(void) dealloc {
3308
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
    63
    [popupMenu release];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
    64
    [popoverController release];
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    65
    // dimTimer is autoreleased
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    66
    [super dealloc];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    67
}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    68
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    69
// 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
    70
-(void) showMenuAfterwards {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    71
    [[SDLUIKitDelegate sharedAppDelegate].uiwindow bringSubviewToFront:self.view];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    72
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    73
	[UIView beginAnimations:@"showing overlay" context:NULL];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    74
	[UIView setAnimationDuration:1];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    75
	self.view.alpha = 1;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    76
	[UIView commitAnimations];
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
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    79
// 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
    80
-(IBAction) buttonReleased:(id) sender {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    81
	HW_allKeysUp();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    82
    [dimTimer setFireDate:[NSDate dateWithTimeIntervalSinceNow:2.7]];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    83
}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    84
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    85
// nice transition for dimming
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    86
-(void) dimOverlay {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    87
    [UIView beginAnimations:@"overlay dim" context:NULL];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    88
   	[UIView setAnimationDuration:0.6];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    89
    self.view.alpha = 0.2;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    90
	[UIView commitAnimations];
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
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    93
// 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
    94
-(void) activateOverlay {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    95
    self.view.alpha = 1;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    96
    [dimTimer setFireDate:[NSDate dateWithTimeIntervalSinceNow:1000]];
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
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    99
// 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
   100
-(IBAction) buttonPressed:(id) sender {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   101
    [self activateOverlay];
3308
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   102
    if (isPopoverVisible) {
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   103
        [self dismissPopover];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   104
    }
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   105
    UIButton *theButton = (UIButton *)sender;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   106
    
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   107
    switch (theButton.tag) {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   108
        case 0:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   109
            HW_walkLeft();
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 1:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   112
            HW_walkRight();
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 2:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   115
            HW_aimUp();
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 3:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   118
            HW_aimDown();
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 4:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   121
            HW_shoot();
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 5:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   124
            HW_jump();
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 6:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   127
            HW_backjump();
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
        case 7:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   130
            HW_tab();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   131
            break;
3308
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   132
        case 10:
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   133
            [self showPopover];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   134
            break;
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   135
        default:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   136
            NSLog(@"Nope");
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   137
            break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   138
    }
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   139
}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   140
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   141
// present a further check before closing game
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   142
-(void) actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger) buttonIndex {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   143
	if ([actionSheet cancelButtonIndex] != buttonIndex)
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   144
	    HW_terminate(NO);
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   145
	else
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   146
        HW_pause();		
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   147
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   148
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   149
// show up a popover containing a popupMenuViewController; we hook it with setPopoverContentSize
3308
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   150
// on iphone instead just use the tableViewController directly (and implement manually all animations)
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   151
-(IBAction) showPopover{
3308
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   152
    isPopoverVisible = YES;
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   153
    Class popoverControllerClass = NSClassFromString(@"UIPopoverController");
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   154
    if (popoverControllerClass) {
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   155
#ifdef __IPHONE_3_2
3308
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   156
        popupMenu = [[PopoverMenuViewController alloc] initWithStyle:UITableViewStylePlain];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   157
        popoverController = [[popoverControllerClass alloc] initWithContentViewController:popupMenu];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   158
        [popoverController setPopoverContentSize:CGSizeMake(220, 170) animated:YES];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   159
        [popoverController setPassthroughViews:[NSArray arrayWithObject:self.view]];
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   160
        
3308
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   161
        [popoverController presentPopoverFromRect:CGRectMake(960, 0, 220, 32)
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   162
                                           inView:self.view
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   163
                         permittedArrowDirections:UIPopoverArrowDirectionUp 
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   164
                                         animated:YES];
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   165
#endif
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   166
    } else {
3308
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   167
        popupMenu = [[PopoverMenuViewController alloc] initWithStyle:UITableViewStyleGrouped];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   168
        popupMenu.view.backgroundColor = [UIColor clearColor];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   169
        popupMenu.view.frame = CGRectMake(480, 0, 200, 170);
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   170
        [self.view addSubview:popupMenu.view];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   171
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   172
        [UIView beginAnimations:@"showing popover" context:NULL];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   173
        [UIView setAnimationDuration:0.35];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   174
        popupMenu.view.frame = CGRectMake(280, 0, 200, 170);
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   175
        [UIView commitAnimations];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   176
    }
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   177
    popupMenu.tableView.scrollEnabled = NO;
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   178
}
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   179
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   180
// on ipad just dismiss it, on iphone transtion on the right
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   181
-(void) dismissPopover {
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   182
    if (YES == isPopoverVisible) {
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   183
        isPopoverVisible = NO;
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   184
        
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   185
        if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   186
#ifdef __IPHONE_3_2
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   187
            [popoverController dismissPopoverAnimated:YES];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   188
#endif
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   189
        } else {
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   190
            [UIView beginAnimations:@"hiding popover" context:NULL];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   191
            [UIView setAnimationDuration:0.35];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   192
            popupMenu.view.frame = CGRectMake(480, 0, 200, 170);
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   193
            [UIView commitAnimations];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   194
        
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   195
            [popupMenu.view performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:0.35];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   196
            [popupMenu performSelector:@selector(release) withObject:nil afterDelay:0.35];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   197
            
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   198
            //[dimTimer setFireDate:[NSDate dateWithTimeIntervalSinceNow:2.7]];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   199
        }
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   200
        [self buttonReleased:nil];
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   201
    }
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   202
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   203
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   204
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   205
#pragma mark -
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   206
#pragma mark Custom touch event handling
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   207
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   208
#define kMinimumPinchDelta      50
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   209
#define kMinimumGestureLength	10
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   210
#define kMaximumVariance        3
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) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   213
	NSArray *twoTouches;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   214
	UITouch *touch = [touches anyObject];
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   215
	int width = [[UIScreen mainScreen] bounds].size.width;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   216
    
3308
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   217
    if (isPopoverVisible) {
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   218
        [self dismissPopover];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   219
    }
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   220
        
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   221
	switch ([touches count]) {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   222
		case 1:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   223
			gestureStartPoint = [touch locationInView:self.view];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   224
			initialDistanceForPinching = 0;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   225
			switch ([touch tapCount]) {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   226
				case 1:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   227
					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
   228
					SDL_WarpMouseInWindow([SDLUIKitDelegate sharedAppDelegate].window, 
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   229
							      (int)gestureStartPoint.y, width - (int)gestureStartPoint.x);
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   230
					HW_click();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   231
					break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   232
				case 2:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   233
					HW_ammoMenu();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   234
					break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   235
				default:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   236
					break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   237
			}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   238
			break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   239
		case 2:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   240
			if (2 == [touch tapCount]) {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   241
				HW_zoomReset();
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
			
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   244
			// pinching
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   245
			twoTouches = [touches allObjects];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   246
			UITouch *first = [twoTouches objectAtIndex:0];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   247
			UITouch *second = [twoTouches objectAtIndex:1];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   248
			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
   249
			break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   250
		default:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   251
			break;
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
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   254
}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   255
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   256
-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   257
	initialDistanceForPinching = 0;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   258
	gestureStartPoint.x = 0;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   259
	gestureStartPoint.y = 0;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   260
	HW_allKeysUp();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   261
}
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
-(void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   264
	// 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
   265
	[self touchesEnded:touches withEvent:event];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   266
}
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
-(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   269
	NSArray *twoTouches;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   270
	CGPoint currentPosition;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   271
	UITouch *touch = [touches anyObject];
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   272
	int width = [[UIScreen mainScreen] bounds].size.width;
3117
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
	switch ([touches count]) {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   275
		case 1:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   276
			currentPosition = [touch locationInView:self.view];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   277
			// panning
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   278
			SDL_WarpMouseInWindow([SDLUIKitDelegate sharedAppDelegate].window, 
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   279
							(int)gestureStartPoint.y, width - (int)gestureStartPoint.x);
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   280
			// remember that we have x and y inverted
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   281
			/* temporarily disabling hog movements for camera panning testing
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   282
			CGFloat vertDiff = gestureStartPoint.x - currentPosition.x;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   283
			CGFloat horizDiff = gestureStartPoint.y - currentPosition.y;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   284
			CGFloat deltaX = fabsf(vertDiff);
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   285
			CGFloat deltaY = fabsf(horizDiff);
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   286
			
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   287
			if (deltaY >= kMinimumGestureLength && deltaX <= kMaximumVariance) {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   288
				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
   289
				if (horizDiff > 0) HW_walkLeft();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   290
				else HW_walkRight();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   291
			} else if (deltaX >= kMinimumGestureLength && deltaY <= kMaximumVariance){
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   292
				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
   293
				if (vertDiff < 0) HW_aimUp();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   294
				else HW_aimDown();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   295
			}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   296
			*/
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   297
			break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   298
		case 2:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   299
			twoTouches = [touches allObjects];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   300
			UITouch *first = [twoTouches objectAtIndex:0];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   301
			UITouch *second = [twoTouches objectAtIndex:1];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   302
			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
   303
			
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   304
			if (0 == initialDistanceForPinching) 
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   305
				initialDistanceForPinching = currentDistanceOfPinching;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   306
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   307
			if (currentDistanceOfPinching < initialDistanceForPinching + kMinimumPinchDelta)
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   308
				HW_zoomOut();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   309
			else if (currentDistanceOfPinching > initialDistanceForPinching + kMinimumPinchDelta)
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   310
				HW_zoomIn();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   311
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   312
			currentDistanceOfPinching = initialDistanceForPinching;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   313
			break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   314
		default:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   315
			break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   316
	}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   317
}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   318
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   319
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   320
@end