project_files/HedgewarsMobile/Classes/OverlayViewController.m
author koda
Wed, 23 Jun 2010 22:03:56 +0200
changeset 3547 02875b1145b7
parent 3546 ccf4854df294
child 3551 d4de36b3801a
permissions -rw-r--r--
i <3 mercurial
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
     1
//
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
     2
//  overlayViewController.m
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
     3
//  HedgewarsMobile
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
     4
//
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
     5
//  Created by Vittorio on 16/03/10.
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
     6
//  Copyright 2010 __MyCompanyName__. All rights reserved.
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
     7
//
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
     8
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
     9
#import "OverlayViewController.h"
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    10
#import "SDL_uikitappdelegate.h"
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    11
#import "PascalImports.h"
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    12
#import "CGPointUtils.h"
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    13
#import "SDL_mouse.h"
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    14
#import "SDL_config_iphoneos.h"
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    15
#import "PopoverMenuViewController.h"
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    16
#import "CommodityFunctions.h"
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    17
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    18
#define HIDING_TIME_DEFAULT [NSDate dateWithTimeIntervalSinceNow:2.7]
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    19
#define HIDING_TIME_NEVER   [NSDate dateWithTimeIntervalSinceNow:10000]
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    20
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    21
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    22
@implementation OverlayViewController
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    23
@synthesize popoverController, popupMenu, writeChatTextField, spinningWheel;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    24
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    25
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    26
    return rotationManager(interfaceOrientation);
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    27
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    28
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    29
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    30
-(void) didReceiveMemoryWarning {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    31
    // Releases the view if it doesn't have a superview.
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    32
    [super didReceiveMemoryWarning];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    33
    // Release any cached data, images, etc that aren't in use.
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    34
    if (popupMenu.view.superview == nil) 
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    35
        popupMenu = nil;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    36
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    37
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    38
-(void) didRotate:(NSNotification *)notification {  
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    39
    UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    40
    CGRect rect = [[UIScreen mainScreen] bounds];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    41
    CGRect usefulRect = CGRectMake(0, 0, rect.size.width, rect.size.height);
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    42
    UIView *sdlView = [[[UIApplication sharedApplication] keyWindow] viewWithTag:12345];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    43
    
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    44
    [UIView beginAnimations:@"rotation" context:NULL];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    45
    [UIView setAnimationDuration:0.8f];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    46
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    47
    switch (orientation) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    48
        case UIDeviceOrientationLandscapeLeft:
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    49
            sdlView.transform = CGAffineTransformMakeRotation(degreesToRadian(0));
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    50
            self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(90));
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    51
            [self chatDisappear];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    52
            HW_setLandscape(YES);
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    53
            break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    54
        case UIDeviceOrientationLandscapeRight:
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    55
            sdlView.transform = CGAffineTransformMakeRotation(degreesToRadian(180));
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    56
            self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(-90));
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    57
            [self chatDisappear];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    58
            HW_setLandscape(YES);
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    59
            break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    60
        case UIDeviceOrientationPortrait:
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    61
            if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    62
                sdlView.transform = CGAffineTransformMakeRotation(degreesToRadian(270));
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    63
                self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(0));
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    64
                [self chatAppear];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    65
                HW_setLandscape(NO);
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    66
            }
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    67
            break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    68
        case UIDeviceOrientationPortraitUpsideDown:
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    69
            if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    70
                sdlView.transform = CGAffineTransformMakeRotation(degreesToRadian(90));
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    71
                self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(180));
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    72
                [self chatAppear];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    73
                HW_setLandscape(NO);
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    74
            }
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    75
            break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    76
        default:
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    77
            break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    78
    }
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    79
    self.view.frame = usefulRect;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    80
    //sdlView.frame = usefulRect;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    81
    [UIView commitAnimations];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    82
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    83
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    84
-(void) chatAppear {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    85
    if (writeChatTextField == nil) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    86
        writeChatTextField = [[UITextField alloc] initWithFrame:CGRectMake(0, 100, 768, [UIFont systemFontSize]+8)];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    87
        writeChatTextField.textColor = [UIColor whiteColor];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    88
        writeChatTextField.backgroundColor = [UIColor blueColor];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    89
        writeChatTextField.autocapitalizationType = UITextAutocapitalizationTypeNone;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    90
        writeChatTextField.autocorrectionType = UITextAutocorrectionTypeNo;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    91
        writeChatTextField.enablesReturnKeyAutomatically = NO;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    92
        writeChatTextField.keyboardAppearance = UIKeyboardAppearanceDefault;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    93
        writeChatTextField.keyboardType = UIKeyboardTypeDefault;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    94
        writeChatTextField.returnKeyType = UIReturnKeyDefault;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    95
        writeChatTextField.secureTextEntry = NO;    
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    96
        [self.view addSubview:writeChatTextField];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    97
    }
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    98
    writeChatTextField.alpha = 1;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    99
    [self activateOverlay];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   100
    [dimTimer setFireDate:HIDING_TIME_NEVER];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   101
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   102
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   103
-(void) chatDisappear {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   104
    writeChatTextField.alpha = 0;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   105
    [writeChatTextField resignFirstResponder];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   106
    [dimTimer setFireDate:HIDING_TIME_DEFAULT];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   107
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   108
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   109
#pragma mark -
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   110
#pragma mark View Management
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   111
-(void) viewDidLoad {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   112
    isPopoverVisible = NO;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   113
    singleton = self.spinningWheel;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   114
    canDim = NO;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   115
    self.view.alpha = 0;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   116
    self.view.center = CGPointMake(self.view.frame.size.height/2.0, self.view.frame.size.width/2.0);
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   117
    
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   118
    
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   119
    dimTimer = [[NSTimer alloc] initWithFireDate:[NSDate dateWithTimeIntervalSinceNow:6]
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   120
                                        interval:1000
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   121
                                          target:self
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   122
                                        selector:@selector(dimOverlay)
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   123
                                        userInfo:nil
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   124
                                         repeats:YES];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   125
    
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   126
    // add timer too runloop, otherwise it doesn't work
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   127
    [[NSRunLoop currentRunLoop] addTimer:dimTimer forMode:NSDefaultRunLoopMode];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   128
    
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   129
    // listen for dismissal of the popover (see below)
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   130
    [[NSNotificationCenter defaultCenter] addObserver:self
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   131
                                             selector:@selector(dismissPopover)
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   132
                                                 name:@"dismissPopover"
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   133
                                               object:nil];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   134
    
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   135
    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];   
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   136
    [[NSNotificationCenter defaultCenter] addObserver:self
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   137
                                             selector:@selector(didRotate:)
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   138
                                                 name:@"UIDeviceOrientationDidChangeNotification"
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   139
                                               object:nil];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   140
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   141
    //self.view.transform = CGAffineTransformRotate(self.view.transform, (M_PI/2.0)); 
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   142
    [UIView beginAnimations:@"showing overlay" context:NULL];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   143
    [UIView setAnimationDuration:1];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   144
    self.view.alpha = 1;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   145
    [UIView commitAnimations];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   146
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   147
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   148
-(void) viewDidUnload {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   149
    self.writeChatTextField = nil;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   150
    self.popoverController = nil;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   151
    self.popupMenu = nil;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   152
    self.spinningWheel = nil;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   153
    [super viewDidUnload];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   154
    MSG_DIDUNLOAD();
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   155
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   156
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   157
-(void) dealloc {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   158
    [dimTimer invalidate];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   159
    [writeChatTextField release];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   160
    [popupMenu release];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   161
    [popoverController release];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   162
    // dimTimer is autoreleased
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   163
    [spinningWheel release];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   164
    [super dealloc];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   165
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   166
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   167
#pragma mark -
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   168
#pragma mark Overlay actions and members
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   169
// dim the overlay when there's no more input for a certain amount of time
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   170
-(IBAction) buttonReleased:(id) sender {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   171
    HW_allKeysUp();
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   172
    [dimTimer setFireDate:HIDING_TIME_DEFAULT];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   173
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   174
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   175
// nice transition for dimming, should be called only by the timer himself
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   176
-(void) dimOverlay {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   177
    if (canDim) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   178
        [UIView beginAnimations:@"overlay dim" context:NULL];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   179
        [UIView setAnimationDuration:0.6];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   180
        self.view.alpha = 0.2;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   181
        [UIView commitAnimations];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   182
    }
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   183
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   184
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   185
// set the overlay visible and put off the timer for enough time
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   186
-(void) activateOverlay {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   187
    self.view.alpha = 1;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   188
    [dimTimer setFireDate:HIDING_TIME_NEVER];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   189
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   190
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   191
// issue certain action based on the tag of the button 
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   192
-(IBAction) buttonPressed:(id) sender {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   193
    [self activateOverlay];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   194
    if (isPopoverVisible) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   195
        [self dismissPopover];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   196
    }
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   197
    UIButton *theButton = (UIButton *)sender;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   198
    
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   199
    switch (theButton.tag) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   200
        case 0:
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   201
            HW_walkLeft();
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   202
            break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   203
        case 1:
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   204
            HW_walkRight();
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   205
            break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   206
        case 2:
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   207
            HW_aimUp();
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   208
            break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   209
        case 3:
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   210
            HW_aimDown();
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   211
            break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   212
        case 4:
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   213
            HW_shoot();
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   214
            break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   215
        case 5:
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   216
            HW_jump();
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   217
            break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   218
        case 6:
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   219
            HW_backjump();
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   220
            break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   221
        case 7:
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   222
            HW_tab();
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   223
            break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   224
        case 10:
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   225
            [self showPopover];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   226
            break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   227
        default:
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   228
            NSLog(@"Nope");
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   229
            break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   230
    }
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   231
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   232
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   233
// present a further check before closing game
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   234
-(void) actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger) buttonIndex {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   235
    if ([actionSheet cancelButtonIndex] != buttonIndex)
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   236
        HW_terminate(NO);
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   237
    else
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   238
        HW_pause();     
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   239
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   240
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   241
// show up a popover containing a popupMenuViewController; we hook it with setPopoverContentSize
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   242
// on iphone instead just use the tableViewController directly (and implement manually all animations)
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   243
-(IBAction) showPopover{
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   244
    isPopoverVisible = YES;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   245
    CGRect anchorForPopover;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   246
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   247
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   248
        if (popupMenu == nil) 
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   249
            popupMenu = [[PopoverMenuViewController alloc] initWithStyle:UITableViewStylePlain];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   250
        if (popoverController == nil) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   251
            popoverController = [[UIPopoverController alloc] initWithContentViewController:popupMenu];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   252
            [popoverController setPopoverContentSize:CGSizeMake(220, 170) animated:YES];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   253
            [popoverController setPassthroughViews:[NSArray arrayWithObject:self.view]];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   254
        }
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   255
        
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   256
        if (UIDeviceOrientationIsLandscape([[UIDevice currentDevice] orientation]))
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   257
            anchorForPopover = CGRectMake(960, 0, 220, 32);
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   258
        else
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   259
            anchorForPopover = CGRectMake(736, 0, 220, 32);
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   260
        
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   261
        [popoverController presentPopoverFromRect:anchorForPopover
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   262
                                           inView:self.view
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   263
                         permittedArrowDirections:UIPopoverArrowDirectionUp
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   264
                                         animated:YES];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   265
    } else {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   266
        if (popupMenu == nil) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   267
            popupMenu = [[PopoverMenuViewController alloc] initWithStyle:UITableViewStyleGrouped];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   268
            popupMenu.view.backgroundColor = [UIColor clearColor];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   269
            popupMenu.view.frame = CGRectMake(480, 0, 200, 170);
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   270
        }
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   271
        [self.view addSubview:popupMenu.view];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   272
        
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   273
        [UIView beginAnimations:@"showing popover" context:NULL];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   274
        [UIView setAnimationDuration:0.35];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   275
        popupMenu.view.frame = CGRectMake(280, 0, 200, 170);
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   276
        [UIView commitAnimations];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   277
    }
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   278
    popupMenu.tableView.scrollEnabled = NO;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   279
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   280
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   281
// on ipad just dismiss it, on iphone transtion to the right
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   282
-(void) dismissPopover {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   283
    if (YES == isPopoverVisible) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   284
        isPopoverVisible = NO;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   285
        
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   286
        if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   287
            [popoverController dismissPopoverAnimated:YES];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   288
        } else {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   289
            [UIView beginAnimations:@"hiding popover" context:NULL];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   290
            [UIView setAnimationDuration:0.35];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   291
            popupMenu.view.frame = CGRectMake(480, 0, 200, 170);
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   292
            [UIView commitAnimations];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   293
        
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   294
            [popupMenu.view performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:0.35];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   295
        }
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   296
        [self buttonReleased:nil];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   297
    }
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   298
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   299
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   300
-(void) textFieldDoneEditing:(id) sender{
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   301
    [sender resignFirstResponder];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   302
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   303
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   304
// this function is called by pascal FinishProgress and removes the spinning wheel when loading is done
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   305
void spinningWheelDone (void) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   306
    [UIView beginAnimations:@"hiding spinning wheel" context:NULL];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   307
    [UIView setAnimationDuration:0.7];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   308
    singleton.alpha = 0;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   309
    [UIView commitAnimations];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   310
    [singleton performSelector:@selector(stopAnimating) withObject:nil afterDelay:0.7];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   311
    canDim = YES;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   312
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   313
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   314
#pragma mark -
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   315
#pragma mark Custom touch event handling
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   316
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   317
    NSArray *twoTouches;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   318
    UITouch *touch = [touches anyObject];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   319
    
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   320
    if (isPopoverVisible) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   321
        [self dismissPopover];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   322
    }
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   323
    if (writeChatTextField) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   324
        [self.writeChatTextField resignFirstResponder];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   325
        [dimTimer setFireDate:HIDING_TIME_DEFAULT];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   326
    }
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   327
    
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   328
    gestureStartPoint = [touch locationInView:self.view];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   329
        
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   330
    switch ([touches count]) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   331
        /*case 1:
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   332
            initialDistanceForPinching = 0;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   333
            switch ([touch tapCount]) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   334
                case 1:
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   335
                    NSLog(@"X:%d Y:%d", (int)gestureStartPoint.x, (int)gestureStartPoint.y );
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   336
                    //SDL_WarpMouseInWindow([SDLUIKitDelegate sharedAppDelegate].window, 
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   337
                    //            (int)gestureStartPoint.y, width - (int)gestureStartPoint.x);
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   338
                    //HW_click();
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   339
                    break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   340
                case 2:
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   341
                    HW_ammoMenu();
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   342
                    break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   343
                default:
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   344
                    break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   345
            }
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   346
            break;*/
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   347
        case 2:
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   348
            if (2 == [touch tapCount]) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   349
                HW_zoomReset();
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   350
            }
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   351
            
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   352
            // pinching
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   353
            gestureStartPoint = CGPointMake(0, 0);
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   354
            twoTouches = [touches allObjects];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   355
            UITouch *first = [twoTouches objectAtIndex:0];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   356
            UITouch *second = [twoTouches objectAtIndex:1];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   357
            initialDistanceForPinching = distanceBetweenPoints([first locationInView:self.view], [second locationInView:self.view]);
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   358
            break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   359
        default:
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   360
            break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   361
    }
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   362
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   363
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   364
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   365
-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   366
    gestureStartPoint = CGPointMake(0, 0);
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   367
    initialDistanceForPinching = 0;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   368
    //HW_allKeysUp();
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   369
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   370
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   371
-(void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   372
    // this can happen if the user puts more than 5 touches on the screen at once, or perhaps in other circumstances
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   373
    [self touchesEnded:touches withEvent:event];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   374
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   375
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   376
-(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   377
    CGFloat minimumGestureLength;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   378
    int logCoeff;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   379
    
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   380
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   381
        minimumGestureLength = 5.0f;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   382
        logCoeff = 19;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   383
    } else {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   384
        minimumGestureLength = 3.0f;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   385
        logCoeff = 3;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   386
    }
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   387
    
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   388
    NSArray *twoTouches;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   389
    CGPoint currentPosition;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   390
    UITouch *touch = [touches anyObject];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   391
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   392
    switch ([touches count]) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   393
        /*case 1:
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   394
            currentPosition = [touch locationInView:self.view];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   395
            // panning
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   396
            CGFloat deltaX = fabsf(gestureStartPoint.x - currentPosition.x);
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   397
            CGFloat deltaY = fabsf(gestureStartPoint.y - currentPosition.y);
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   398
            
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   399
            // the two ifs are not mutually exclusive
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   400
            if (deltaX >= minimumGestureLength) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   401
                DLog(@"deltaX: %f deltaY: %f", deltaX, deltaY);
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   402
                if (currentPosition.x > gestureStartPoint.x) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   403
                    HW_cursorLeft(logCoeff*log(deltaX));
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   404
                } else {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   405
                    HW_cursorRight(logCoeff*log(deltaX));
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   406
                }
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   407
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   408
            } 
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   409
            if (deltaY >= minimumGestureLength) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   410
                DLog(@"deltaX: %f deltaY: %f", deltaX, deltaY);
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   411
                if (currentPosition.y < gestureStartPoint.y) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   412
                    HW_cursorDown(logCoeff*log(deltaY));
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   413
                } else {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   414
                    HW_cursorUp(logCoeff*log(deltaY));
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   415
                }            
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   416
            }
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   417
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   418
            break;*/
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   419
        case 2:
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   420
            twoTouches = [touches allObjects];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   421
            UITouch *first = [twoTouches objectAtIndex:0];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   422
            UITouch *second = [twoTouches objectAtIndex:1];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   423
            CGFloat currentDistanceOfPinching = distanceBetweenPoints([first locationInView:self.view], [second locationInView:self.view]);
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   424
            const int pinchDelta = 40;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   425
            
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   426
            if (0 != initialDistanceForPinching) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   427
                if (currentDistanceOfPinching - initialDistanceForPinching > pinchDelta) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   428
                    HW_zoomIn();
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   429
                    initialDistanceForPinching = currentDistanceOfPinching;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   430
                }
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   431
                else if (initialDistanceForPinching - currentDistanceOfPinching > pinchDelta) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   432
                    HW_zoomOut();
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   433
                    initialDistanceForPinching = currentDistanceOfPinching;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   434
                }
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   435
            } else 
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   436
                initialDistanceForPinching = currentDistanceOfPinching;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   437
            
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   438
            break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   439
        default:
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   440
            break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   441
    }
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   442
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   443
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   444
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   445
@end