cocoaTouch/OverlayViewController.m
author koda
Sun, 18 Apr 2010 23:19:15 +0000
changeset 3356 3ae3fccb439e
parent 3347 5d0ac8197eb7
child 3357 3836a31879e7
permissions -rw-r--r--
add missing controller stubs initial work for the game configuration in the ifrontend stuff for working with official apple certificates use lazy loading whenever possible
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
     1
//
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
     2
//  overlayViewController.m
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
     3
//  HedgewarsMobile
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
     4
//
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
     5
//  Created by Vittorio on 16/03/10.
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
     6
//  Copyright 2010 __MyCompanyName__. All rights reserved.
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
     7
//
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
     8
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
     9
#import "OverlayViewController.h"
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    10
#import "SDL_uikitappdelegate.h"
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    11
#import "PascalImports.h"
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    12
#import "CGPointUtils.h"
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    13
#import "SDL_mouse.h"
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
    14
#import "PopoverMenuViewController.h"
3335
2520ee7a5484 new manager for handling (future) rotations
koda
parents: 3317
diff changeset
    15
#import "CommodityFunctions.h"
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    16
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    17
@implementation OverlayViewController
3308
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
    18
@synthesize dimTimer, popoverController, popupMenu;
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    19
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    20
3335
2520ee7a5484 new manager for handling (future) rotations
koda
parents: 3317
diff changeset
    21
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation {
2520ee7a5484 new manager for handling (future) rotations
koda
parents: 3317
diff changeset
    22
	return rotationManager(interfaceOrientation);
2520ee7a5484 new manager for handling (future) rotations
koda
parents: 3317
diff changeset
    23
}
2520ee7a5484 new manager for handling (future) rotations
koda
parents: 3317
diff changeset
    24
2520ee7a5484 new manager for handling (future) rotations
koda
parents: 3317
diff changeset
    25
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    26
-(void) didReceiveMemoryWarning {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    27
	// Releases the view if it doesn't have a superview.
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    28
    [super didReceiveMemoryWarning];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    29
	// Release any cached data, images, etc that aren't in use.
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    30
}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    31
3340
96dd168b080b fix all of what was committed before
koda
parents: 3335
diff changeset
    32
/*
96dd168b080b fix all of what was committed before
koda
parents: 3335
diff changeset
    33
- (void)didRotate:(NSNotification *)notification {	
96dd168b080b fix all of what was committed before
koda
parents: 3335
diff changeset
    34
	if (orientation == UIDeviceOrientationLandscapeLeft) {
96dd168b080b fix all of what was committed before
koda
parents: 3335
diff changeset
    35
	}
96dd168b080b fix all of what was committed before
koda
parents: 3335
diff changeset
    36
    if (orientation == UIDeviceOrientationLandscapeRight) {
96dd168b080b fix all of what was committed before
koda
parents: 3335
diff changeset
    37
    }
96dd168b080b fix all of what was committed before
koda
parents: 3335
diff changeset
    38
	if (orientation == UIDeviceOrientationPortrait) {
96dd168b080b fix all of what was committed before
koda
parents: 3335
diff changeset
    39
	}
96dd168b080b fix all of what was committed before
koda
parents: 3335
diff changeset
    40
    if (orientation == UIDeviceOrientationPortrait) {
96dd168b080b fix all of what was committed before
koda
parents: 3335
diff changeset
    41
	}
96dd168b080b fix all of what was committed before
koda
parents: 3335
diff changeset
    42
}
96dd168b080b fix all of what was committed before
koda
parents: 3335
diff changeset
    43
*/
96dd168b080b fix all of what was committed before
koda
parents: 3335
diff changeset
    44
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    45
-(void) viewDidLoad {
3340
96dd168b080b fix all of what was committed before
koda
parents: 3335
diff changeset
    46
    /*
96dd168b080b fix all of what was committed before
koda
parents: 3335
diff changeset
    47
    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];	
96dd168b080b fix all of what was committed before
koda
parents: 3335
diff changeset
    48
    [[NSNotificationCenter defaultCenter] addObserver:self
96dd168b080b fix all of what was committed before
koda
parents: 3335
diff changeset
    49
							selector:@selector(didRotate:)
96dd168b080b fix all of what was committed before
koda
parents: 3335
diff changeset
    50
							name:UIDeviceOrientationDidChangeNotification
96dd168b080b fix all of what was committed before
koda
parents: 3335
diff changeset
    51
							object:nil];
96dd168b080b fix all of what was committed before
koda
parents: 3335
diff changeset
    52
    */
3308
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
    53
    isPopoverVisible = NO;
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    54
    self.view.alpha = 0;
3308
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
    55
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    56
    // needed for rotation to work on os < 3.2
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    57
    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
    58
    self.view.transform = CGAffineTransformRotate(self.view.transform, (M_PI/2.0));
3317
198ec44b6d92 minor tweaks, icon for ipad, merged overlayviewcontroller, pop viewcontroller when selected a hat
koda
parents: 3308
diff changeset
    59
    self.view.frame = [[UIScreen mainScreen] applicationFrame];
198ec44b6d92 minor tweaks, icon for ipad, merged overlayviewcontroller, pop viewcontroller when selected a hat
koda
parents: 3308
diff changeset
    60
    
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    61
    dimTimer = [[NSTimer alloc] initWithFireDate:[NSDate dateWithTimeIntervalSinceNow:6]
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    62
                                        interval:1000
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    63
                                          target:self
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    64
                                        selector:@selector(dimOverlay)
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    65
                                        userInfo:nil
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    66
                                         repeats:YES];
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
    // add timer too runloop, otherwise it doesn't work
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    69
    [[NSRunLoop currentRunLoop] addTimer:dimTimer forMode:NSDefaultRunLoopMode];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    70
    // listen for dismissal of the popover (see below)x
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    71
    [[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
    72
    // present the overlay after 2 seconds
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    73
    [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
    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
-(void) viewDidUnload {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    77
	[dimTimer invalidate];
3308
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
    78
	self.dimTimer = nil;
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
    79
    self.popoverController = nil;
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
    80
    self.popupMenu = nil;
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
    81
    [super viewDidUnload];
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    82
}
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
-(void) dealloc {
3308
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
    85
    [popupMenu release];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
    86
    [popoverController release];
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    87
    // dimTimer is autoreleased
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    88
    [super dealloc];
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
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    91
// 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
    92
-(void) showMenuAfterwards {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    93
    [[SDLUIKitDelegate sharedAppDelegate].uiwindow bringSubviewToFront:self.view];
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
	[UIView beginAnimations:@"showing overlay" context:NULL];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    96
	[UIView setAnimationDuration:1];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    97
	self.view.alpha = 1;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    98
	[UIView commitAnimations];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    99
}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   100
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   101
// 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
   102
-(IBAction) buttonReleased:(id) sender {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   103
	HW_allKeysUp();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   104
    [dimTimer setFireDate:[NSDate dateWithTimeIntervalSinceNow:2.7]];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   105
}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   106
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   107
// nice transition for dimming
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   108
-(void) dimOverlay {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   109
    [UIView beginAnimations:@"overlay dim" context:NULL];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   110
   	[UIView setAnimationDuration:0.6];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   111
    self.view.alpha = 0.2;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   112
	[UIView commitAnimations];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   113
}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   114
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   115
// 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
   116
-(void) activateOverlay {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   117
    self.view.alpha = 1;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   118
    [dimTimer setFireDate:[NSDate dateWithTimeIntervalSinceNow:1000]];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   119
}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   120
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   121
// 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
   122
-(IBAction) buttonPressed:(id) sender {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   123
    [self activateOverlay];
3308
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   124
    if (isPopoverVisible) {
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   125
        [self dismissPopover];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   126
    }
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   127
    UIButton *theButton = (UIButton *)sender;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   128
    
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   129
    switch (theButton.tag) {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   130
        case 0:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   131
            HW_walkLeft();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   132
            break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   133
        case 1:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   134
            HW_walkRight();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   135
            break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   136
        case 2:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   137
            HW_aimUp();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   138
            break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   139
        case 3:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   140
            HW_aimDown();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   141
            break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   142
        case 4:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   143
            HW_shoot();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   144
            break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   145
        case 5:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   146
            HW_jump();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   147
            break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   148
        case 6:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   149
            HW_backjump();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   150
            break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   151
        case 7:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   152
            HW_tab();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   153
            break;
3308
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   154
        case 10:
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   155
            [self showPopover];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   156
            break;
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   157
        default:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   158
            NSLog(@"Nope");
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   159
            break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   160
    }
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   161
}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   162
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   163
// present a further check before closing game
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   164
-(void) actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger) buttonIndex {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   165
	if ([actionSheet cancelButtonIndex] != buttonIndex)
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   166
	    HW_terminate(NO);
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   167
	else
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   168
        HW_pause();		
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   169
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   170
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   171
// 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
   172
// 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
   173
-(IBAction) showPopover{
3308
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   174
    isPopoverVisible = YES;
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   175
    Class popoverControllerClass = NSClassFromString(@"UIPopoverController");
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   176
    if (popoverControllerClass) {
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   177
#ifdef __IPHONE_3_2
3308
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   178
        popupMenu = [[PopoverMenuViewController alloc] initWithStyle:UITableViewStylePlain];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   179
        popoverController = [[popoverControllerClass alloc] initWithContentViewController:popupMenu];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   180
        [popoverController setPopoverContentSize:CGSizeMake(220, 170) animated:YES];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   181
        [popoverController setPassthroughViews:[NSArray arrayWithObject:self.view]];
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   182
        
3308
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   183
        [popoverController presentPopoverFromRect:CGRectMake(960, 0, 220, 32)
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   184
                                           inView:self.view
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   185
                         permittedArrowDirections:UIPopoverArrowDirectionUp 
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   186
                                         animated:YES];
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   187
#endif
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   188
    } else {
3308
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   189
        popupMenu = [[PopoverMenuViewController alloc] initWithStyle:UITableViewStyleGrouped];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   190
        popupMenu.view.backgroundColor = [UIColor clearColor];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   191
        popupMenu.view.frame = CGRectMake(480, 0, 200, 170);
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   192
        [self.view addSubview:popupMenu.view];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   193
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   194
        [UIView beginAnimations:@"showing popover" context:NULL];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   195
        [UIView setAnimationDuration:0.35];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   196
        popupMenu.view.frame = CGRectMake(280, 0, 200, 170);
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   197
        [UIView commitAnimations];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   198
    }
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   199
    popupMenu.tableView.scrollEnabled = NO;
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   200
}
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   201
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   202
// on ipad just dismiss it, on iphone transtion on the right
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   203
-(void) dismissPopover {
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   204
    if (YES == isPopoverVisible) {
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   205
        isPopoverVisible = NO;
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   206
        
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   207
        if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   208
#ifdef __IPHONE_3_2
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   209
            [popoverController dismissPopoverAnimated:YES];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   210
#endif
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   211
        } else {
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   212
            [UIView beginAnimations:@"hiding popover" context:NULL];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   213
            [UIView setAnimationDuration:0.35];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   214
            popupMenu.view.frame = CGRectMake(480, 0, 200, 170);
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   215
            [UIView commitAnimations];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   216
        
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   217
            [popupMenu.view performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:0.35];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   218
            [popupMenu performSelector:@selector(release) withObject:nil afterDelay:0.35];
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
            //[dimTimer setFireDate:[NSDate dateWithTimeIntervalSinceNow:2.7]];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   221
        }
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   222
        [self buttonReleased:nil];
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   223
    }
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   224
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   225
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   226
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   227
#pragma mark -
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   228
#pragma mark Custom touch event handling
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   229
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   230
#define kMinimumPinchDelta      50
3347
5d0ac8197eb7 camera panning ftw
koda
parents: 3340
diff changeset
   231
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   232
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   233
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   234
	NSArray *twoTouches;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   235
	UITouch *touch = [touches anyObject];
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   236
    
3308
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   237
    if (isPopoverVisible) {
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   238
        [self dismissPopover];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   239
    }
3347
5d0ac8197eb7 camera panning ftw
koda
parents: 3340
diff changeset
   240
    
5d0ac8197eb7 camera panning ftw
koda
parents: 3340
diff changeset
   241
    gestureStartPoint = [touch locationInView:self.view];
3308
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   242
        
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   243
	switch ([touches count]) {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   244
		case 1:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   245
			initialDistanceForPinching = 0;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   246
			switch ([touch tapCount]) {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   247
				case 1:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   248
					NSLog(@"X:%d Y:%d", (int)gestureStartPoint.x, (int)gestureStartPoint.y );
3347
5d0ac8197eb7 camera panning ftw
koda
parents: 3340
diff changeset
   249
					//SDL_WarpMouseInWindow([SDLUIKitDelegate sharedAppDelegate].window, 
5d0ac8197eb7 camera panning ftw
koda
parents: 3340
diff changeset
   250
					//		      (int)gestureStartPoint.y, width - (int)gestureStartPoint.x);
5d0ac8197eb7 camera panning ftw
koda
parents: 3340
diff changeset
   251
					//HW_click();
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   252
					break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   253
				case 2:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   254
					HW_ammoMenu();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   255
					break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   256
				default:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   257
					break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   258
			}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   259
			break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   260
		case 2:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   261
			if (2 == [touch tapCount]) {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   262
				HW_zoomReset();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   263
			}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   264
			
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   265
			// pinching
3347
5d0ac8197eb7 camera panning ftw
koda
parents: 3340
diff changeset
   266
            gestureStartPoint.x = 0;
5d0ac8197eb7 camera panning ftw
koda
parents: 3340
diff changeset
   267
            gestureStartPoint.y = 0;
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   268
			twoTouches = [touches allObjects];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   269
			UITouch *first = [twoTouches objectAtIndex:0];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   270
			UITouch *second = [twoTouches objectAtIndex:1];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   271
			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
   272
			break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   273
		default:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   274
			break;
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
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   277
}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   278
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   279
-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   280
	initialDistanceForPinching = 0;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   281
	HW_allKeysUp();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   282
}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   283
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   284
-(void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
3347
5d0ac8197eb7 camera panning ftw
koda
parents: 3340
diff changeset
   285
	// this can happen if the user puts more than 5 touches on the screen at once, or perhaps in other circumstances
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   286
	[self touchesEnded:touches withEvent:event];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   287
}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   288
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   289
-(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
3347
5d0ac8197eb7 camera panning ftw
koda
parents: 3340
diff changeset
   290
    int minimumGestureLength;
5d0ac8197eb7 camera panning ftw
koda
parents: 3340
diff changeset
   291
    int logCoeff;
5d0ac8197eb7 camera panning ftw
koda
parents: 3340
diff changeset
   292
    
5d0ac8197eb7 camera panning ftw
koda
parents: 3340
diff changeset
   293
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
5d0ac8197eb7 camera panning ftw
koda
parents: 3340
diff changeset
   294
        minimumGestureLength =	5;
5d0ac8197eb7 camera panning ftw
koda
parents: 3340
diff changeset
   295
        logCoeff = 19;
5d0ac8197eb7 camera panning ftw
koda
parents: 3340
diff changeset
   296
    } else {
5d0ac8197eb7 camera panning ftw
koda
parents: 3340
diff changeset
   297
        minimumGestureLength =	3;
5d0ac8197eb7 camera panning ftw
koda
parents: 3340
diff changeset
   298
        logCoeff = 3;
5d0ac8197eb7 camera panning ftw
koda
parents: 3340
diff changeset
   299
    }
5d0ac8197eb7 camera panning ftw
koda
parents: 3340
diff changeset
   300
    
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   301
	NSArray *twoTouches;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   302
	CGPoint currentPosition;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   303
	UITouch *touch = [touches anyObject];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   304
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   305
	switch ([touches count]) {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   306
		case 1:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   307
			currentPosition = [touch locationInView:self.view];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   308
			// panning
3347
5d0ac8197eb7 camera panning ftw
koda
parents: 3340
diff changeset
   309
			CGFloat deltaX = fabsf(gestureStartPoint.x - currentPosition.x);
5d0ac8197eb7 camera panning ftw
koda
parents: 3340
diff changeset
   310
			CGFloat deltaY = fabsf(gestureStartPoint.y - currentPosition.y);
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   311
			
3347
5d0ac8197eb7 camera panning ftw
koda
parents: 3340
diff changeset
   312
            if (deltaX >= minimumGestureLength) {
5d0ac8197eb7 camera panning ftw
koda
parents: 3340
diff changeset
   313
                NSLog(@"Horizontal swipe detected, deltaX: %f deltaY: %f",deltaX, deltaY);
5d0ac8197eb7 camera panning ftw
koda
parents: 3340
diff changeset
   314
                if (currentPosition.x > gestureStartPoint.x ) {
3356
3ae3fccb439e add missing controller stubs
koda
parents: 3347
diff changeset
   315
                    HW_cursorLeft(logCoeff*log(deltaX));
3347
5d0ac8197eb7 camera panning ftw
koda
parents: 3340
diff changeset
   316
                } else {
3356
3ae3fccb439e add missing controller stubs
koda
parents: 3347
diff changeset
   317
                    HW_cursorRight(logCoeff*log(deltaX));
3347
5d0ac8197eb7 camera panning ftw
koda
parents: 3340
diff changeset
   318
                }
5d0ac8197eb7 camera panning ftw
koda
parents: 3340
diff changeset
   319
5d0ac8197eb7 camera panning ftw
koda
parents: 3340
diff changeset
   320
            } 
5d0ac8197eb7 camera panning ftw
koda
parents: 3340
diff changeset
   321
            if (deltaY >= minimumGestureLength) {
5d0ac8197eb7 camera panning ftw
koda
parents: 3340
diff changeset
   322
                NSLog(@"Horizontal swipe detected, deltaX: %f deltaY: %f",deltaX, deltaY);
5d0ac8197eb7 camera panning ftw
koda
parents: 3340
diff changeset
   323
                if (currentPosition.y < gestureStartPoint.y ) {
3356
3ae3fccb439e add missing controller stubs
koda
parents: 3347
diff changeset
   324
                    HW_cursorDown(logCoeff*log(deltaY));
3347
5d0ac8197eb7 camera panning ftw
koda
parents: 3340
diff changeset
   325
                } else {
3356
3ae3fccb439e add missing controller stubs
koda
parents: 3347
diff changeset
   326
                    HW_cursorUp(logCoeff*log(deltaY));
3347
5d0ac8197eb7 camera panning ftw
koda
parents: 3340
diff changeset
   327
                }            
5d0ac8197eb7 camera panning ftw
koda
parents: 3340
diff changeset
   328
            }
5d0ac8197eb7 camera panning ftw
koda
parents: 3340
diff changeset
   329
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   330
			break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   331
		case 2:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   332
			twoTouches = [touches allObjects];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   333
			UITouch *first = [twoTouches objectAtIndex:0];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   334
			UITouch *second = [twoTouches objectAtIndex:1];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   335
			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
   336
			
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   337
			if (0 == initialDistanceForPinching) 
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   338
				initialDistanceForPinching = currentDistanceOfPinching;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   339
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   340
			if (currentDistanceOfPinching < initialDistanceForPinching + kMinimumPinchDelta)
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   341
				HW_zoomOut();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   342
			else if (currentDistanceOfPinching > initialDistanceForPinching + kMinimumPinchDelta)
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   343
				HW_zoomIn();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   344
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   345
			currentDistanceOfPinching = initialDistanceForPinching;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   346
			break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   347
		default:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   348
			break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   349
	}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   350
}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   351
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   352
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   353
@end