author | smxx |
Sat, 03 Apr 2010 08:46:01 +0000 | |
changeset 3282 | 9ca28cef559a |
parent 3250 | d5cd1a617123 |
permissions | -rw-r--r-- |
3116
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
1 |
// |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
2 |
// overlayViewController.m |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
3 |
// HedgewarsMobile |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
4 |
// |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
5 |
// Created by Vittorio on 16/03/10. |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
6 |
// Copyright 2010 __MyCompanyName__. All rights reserved. |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
7 |
// |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
8 |
|
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
9 |
#import "OverlayViewController.h" |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
10 |
#import "SDL_uikitappdelegate.h" |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
11 |
#import "PascalImports.h" |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
12 |
#import "CGPointUtils.h" |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
13 |
#import "SDL_mouse.h" |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
14 |
#import "PopupMenuViewController.h" |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
15 |
|
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
16 |
@implementation OverlayViewController |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
17 |
@synthesize dimTimer, menuPopover; |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
18 |
|
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
19 |
|
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
20 |
-(void) didReceiveMemoryWarning { |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
21 |
// Releases the view if it doesn't have a superview. |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
22 |
[super didReceiveMemoryWarning]; |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
23 |
|
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
24 |
// Release any cached data, images, etc that aren't in use. |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
25 |
} |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
26 |
|
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
27 |
-(void) viewDidLoad { |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
28 |
self.view.alpha = 0; |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
29 |
|
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
30 |
// needed for rotation to work on os < 3.2 |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
31 |
self.view.center = CGPointMake(self.view.frame.size.height/2.0, self.view.frame.size.width/2.0); |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
32 |
self.view.transform = CGAffineTransformRotate(self.view.transform, (M_PI/2.0)); |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
33 |
|
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
34 |
dimTimer = [[NSTimer alloc] initWithFireDate:[NSDate dateWithTimeIntervalSinceNow:6] |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
35 |
interval:1000 |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
36 |
target:self |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
37 |
selector:@selector(dimOverlay) |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
38 |
userInfo:nil |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
39 |
repeats:YES]; |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
40 |
|
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
41 |
// add timer too runloop, otherwise it doesn't work |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
42 |
[[NSRunLoop currentRunLoop] addTimer:dimTimer forMode:NSDefaultRunLoopMode]; |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
43 |
// listen for dismissal of the popover (see below)x |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
44 |
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(dismissPopover) name:@"dismissPopover" object:nil]; |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
45 |
// present the overlay after 2 seconds |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
46 |
[NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(showMenuAfterwards) userInfo:nil repeats:NO]; |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
47 |
} |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
48 |
|
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
49 |
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation { |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
50 |
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight); |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
51 |
} |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
52 |
|
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
53 |
-(void) viewDidUnload { |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
54 |
[dimTimer invalidate]; |
3250
d5cd1a617123
intial support for team configuration on the ifrontend
koda
parents:
3165
diff
changeset
|
55 |
self.dimTimer = nil; |
d5cd1a617123
intial support for team configuration on the ifrontend
koda
parents:
3165
diff
changeset
|
56 |
menuPopover = nil; |
d5cd1a617123
intial support for team configuration on the ifrontend
koda
parents:
3165
diff
changeset
|
57 |
[super viewDidUnload]; |
3116
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
58 |
} |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
59 |
|
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
60 |
-(void) dealloc { |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
61 |
[menuPopover release]; |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
62 |
// dimTimer is autoreleased |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
63 |
[super dealloc]; |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
64 |
} |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
65 |
|
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
66 |
// draws the controller overlay after the sdl window has taken control |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
67 |
-(void) showMenuAfterwards { |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
68 |
[[SDLUIKitDelegate sharedAppDelegate].uiwindow bringSubviewToFront:self.view]; |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
69 |
|
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
70 |
[UIView beginAnimations:@"showing overlay" context:NULL]; |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
71 |
[UIView setAnimationDuration:1]; |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
72 |
self.view.alpha = 1; |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
73 |
[UIView commitAnimations]; |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
74 |
} |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
75 |
|
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
76 |
// dim the overlay when there's no more input for a certain amount of time |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
77 |
-(IBAction) buttonReleased:(id) sender { |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
78 |
HW_allKeysUp(); |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
79 |
[dimTimer setFireDate:[NSDate dateWithTimeIntervalSinceNow:2.7]]; |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
80 |
} |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
81 |
|
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
82 |
// nice transition for dimming |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
83 |
-(void) dimOverlay { |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
84 |
[UIView beginAnimations:@"overlay dim" context:NULL]; |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
85 |
[UIView setAnimationDuration:0.6]; |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
86 |
self.view.alpha = 0.2; |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
87 |
[UIView commitAnimations]; |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
88 |
} |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
89 |
|
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
90 |
// set the overlay visible and put off the timer for enough time |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
91 |
-(void) activateOverlay { |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
92 |
self.view.alpha = 1; |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
93 |
[dimTimer setFireDate:[NSDate dateWithTimeIntervalSinceNow:1000]]; |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
94 |
} |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
95 |
|
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
96 |
// issue certain action based on the tag of the button |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
97 |
-(IBAction) buttonPressed:(id) sender { |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
98 |
[self activateOverlay]; |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
99 |
UIButton *theButton = (UIButton *)sender; |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
100 |
|
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
101 |
switch (theButton.tag) { |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
102 |
case 0: |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
103 |
HW_walkLeft(); |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
104 |
break; |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
105 |
case 1: |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
106 |
HW_walkRight(); |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
107 |
break; |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
108 |
case 2: |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
109 |
HW_aimUp(); |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
110 |
break; |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
111 |
case 3: |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
112 |
HW_aimDown(); |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
113 |
break; |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
114 |
case 4: |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
115 |
HW_shoot(); |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
116 |
break; |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
117 |
case 5: |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
118 |
HW_jump(); |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
119 |
break; |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
120 |
case 6: |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
121 |
HW_backjump(); |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
122 |
break; |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
123 |
case 7: |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
124 |
HW_tab(); |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
125 |
break; |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
126 |
default: |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
127 |
NSLog(@"Nope"); |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
128 |
break; |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
129 |
} |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
130 |
} |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
131 |
|
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
132 |
// present a further check before closing game |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
133 |
-(void) actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger) buttonIndex { |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
134 |
if ([actionSheet cancelButtonIndex] != buttonIndex) |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
135 |
HW_terminate(NO); |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
136 |
else |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
137 |
HW_pause(); |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
138 |
} |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
139 |
|
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
140 |
// show up a popover containing a popupMenuViewController; we hook it with setPopoverContentSize |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
141 |
-(IBAction) showPopover{ |
3250
d5cd1a617123
intial support for team configuration on the ifrontend
koda
parents:
3165
diff
changeset
|
142 |
PopupMenuViewController *popupMenu = [[PopupMenuViewController alloc] init]; |
3116
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
143 |
|
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
144 |
menuPopover = [[UIPopoverController alloc] initWithContentViewController:popupMenu]; |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
145 |
[menuPopover setPopoverContentSize:CGSizeMake(220, 170) animated:YES]; |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
146 |
|
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
147 |
[menuPopover presentPopoverFromRect:CGRectMake(960, 0, 220, 32) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES]; |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
148 |
} |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
149 |
|
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
150 |
// because of the actionSheet, the popOver might not get dismissed, so we do it manually (through a NSNotification system, see above) |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
151 |
-(void) dismissPopover { |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
152 |
if (menuPopover.popoverVisible) |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
153 |
[menuPopover dismissPopoverAnimated:YES]; |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
154 |
} |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
155 |
|
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
156 |
#pragma mark - |
3250
d5cd1a617123
intial support for team configuration on the ifrontend
koda
parents:
3165
diff
changeset
|
157 |
#pragma mark Custom touch event handling |
d5cd1a617123
intial support for team configuration on the ifrontend
koda
parents:
3165
diff
changeset
|
158 |
|
3116
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
159 |
#define kMinimumPinchDelta 50 |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
160 |
#define kMinimumGestureLength 10 |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
161 |
#define kMaximumVariance 3 |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
162 |
|
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
163 |
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
164 |
NSArray *twoTouches; |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
165 |
UITouch *touch = [touches anyObject]; |
3165
3ec07a7d8456
just some very sane stuff for the iphone port (plus some macro on pascal files)
koda
parents:
3116
diff
changeset
|
166 |
int width = [[UIScreen mainScreen] bounds].size.width; |
3ec07a7d8456
just some very sane stuff for the iphone port (plus some macro on pascal files)
koda
parents:
3116
diff
changeset
|
167 |
|
3116
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
168 |
switch ([touches count]) { |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
169 |
case 1: |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
170 |
gestureStartPoint = [touch locationInView:self.view]; |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
171 |
initialDistanceForPinching = 0; |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
172 |
switch ([touch tapCount]) { |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
173 |
case 1: |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
174 |
NSLog(@"X:%d Y:%d", (int)gestureStartPoint.x, (int)gestureStartPoint.y ); |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
175 |
SDL_WarpMouseInWindow([SDLUIKitDelegate sharedAppDelegate].window, |
3165
3ec07a7d8456
just some very sane stuff for the iphone port (plus some macro on pascal files)
koda
parents:
3116
diff
changeset
|
176 |
(int)gestureStartPoint.y, width - (int)gestureStartPoint.x); |
3116
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
177 |
HW_click(); |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
178 |
break; |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
179 |
case 2: |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
180 |
HW_ammoMenu(); |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
181 |
break; |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
182 |
default: |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
183 |
break; |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
184 |
} |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
185 |
break; |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
186 |
case 2: |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
187 |
if (2 == [touch tapCount]) { |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
188 |
HW_zoomReset(); |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
189 |
} |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
190 |
|
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
191 |
// pinching |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
192 |
twoTouches = [touches allObjects]; |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
193 |
UITouch *first = [twoTouches objectAtIndex:0]; |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
194 |
UITouch *second = [twoTouches objectAtIndex:1]; |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
195 |
initialDistanceForPinching = distanceBetweenPoints([first locationInView:self.view], [second locationInView:self.view]); |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
196 |
break; |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
197 |
default: |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
198 |
break; |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
199 |
} |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
200 |
|
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
201 |
} |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
202 |
|
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
203 |
-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
204 |
initialDistanceForPinching = 0; |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
205 |
gestureStartPoint.x = 0; |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
206 |
gestureStartPoint.y = 0; |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
207 |
HW_allKeysUp(); |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
208 |
} |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
209 |
|
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
210 |
-(void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event { |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
211 |
// this can happen if the user puts more than 5 touches on the screen at once, or perhaps in other circumstances. |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
212 |
[self touchesEnded:touches withEvent:event]; |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
213 |
} |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
214 |
|
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
215 |
-(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
216 |
NSArray *twoTouches; |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
217 |
CGPoint currentPosition; |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
218 |
UITouch *touch = [touches anyObject]; |
3165
3ec07a7d8456
just some very sane stuff for the iphone port (plus some macro on pascal files)
koda
parents:
3116
diff
changeset
|
219 |
int width = [[UIScreen mainScreen] bounds].size.width; |
3116
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
220 |
|
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
221 |
switch ([touches count]) { |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
222 |
case 1: |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
223 |
currentPosition = [touch locationInView:self.view]; |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
224 |
// panning |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
225 |
SDL_WarpMouseInWindow([SDLUIKitDelegate sharedAppDelegate].window, |
3165
3ec07a7d8456
just some very sane stuff for the iphone port (plus some macro on pascal files)
koda
parents:
3116
diff
changeset
|
226 |
(int)gestureStartPoint.y, width - (int)gestureStartPoint.x); |
3116
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
227 |
// remember that we have x and y inverted |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
228 |
/* temporarily disabling hog movements for camera panning testing |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
229 |
CGFloat vertDiff = gestureStartPoint.x - currentPosition.x; |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
230 |
CGFloat horizDiff = gestureStartPoint.y - currentPosition.y; |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
231 |
CGFloat deltaX = fabsf(vertDiff); |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
232 |
CGFloat deltaY = fabsf(horizDiff); |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
233 |
|
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
234 |
if (deltaY >= kMinimumGestureLength && deltaX <= kMaximumVariance) { |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
235 |
NSLog(@"Horizontal swipe detected, begX:%f curX:%f", gestureStartPoint.x, currentPosition.x); |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
236 |
if (horizDiff > 0) HW_walkLeft(); |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
237 |
else HW_walkRight(); |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
238 |
} else if (deltaX >= kMinimumGestureLength && deltaY <= kMaximumVariance){ |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
239 |
NSLog(@"Vertical swipe detected, begY:%f curY:%f", gestureStartPoint.y, currentPosition.y); |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
240 |
if (vertDiff < 0) HW_aimUp(); |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
241 |
else HW_aimDown(); |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
242 |
} |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
243 |
*/ |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
244 |
break; |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
245 |
case 2: |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
246 |
twoTouches = [touches allObjects]; |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
247 |
UITouch *first = [twoTouches objectAtIndex:0]; |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
248 |
UITouch *second = [twoTouches objectAtIndex:1]; |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
249 |
CGFloat currentDistanceOfPinching = distanceBetweenPoints([first locationInView:self.view], [second locationInView:self.view]); |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
250 |
|
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
251 |
if (0 == initialDistanceForPinching) |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
252 |
initialDistanceForPinching = currentDistanceOfPinching; |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
253 |
|
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
254 |
if (currentDistanceOfPinching < initialDistanceForPinching + kMinimumPinchDelta) |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
255 |
HW_zoomOut(); |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
256 |
else if (currentDistanceOfPinching > initialDistanceForPinching + kMinimumPinchDelta) |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
257 |
HW_zoomIn(); |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
258 |
|
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
259 |
currentDistanceOfPinching = initialDistanceForPinching; |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
260 |
break; |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
261 |
default: |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
262 |
break; |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
263 |
} |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
264 |
} |
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
265 |
|
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
266 |
|
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff
changeset
|
267 |
@end |