author | koda |
Thu, 29 Apr 2010 17:20:42 +0000 | |
changeset 3375 | 88bb88294e06 |
parent 3364 | e5403e2bf02c |
child 3385 | 361bd29293f4 |
permissions | -rw-r--r-- |
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 | 14 |
#import "PopoverMenuViewController.h" |
3335 | 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 |
3364 | 18 |
@synthesize 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 | 21 |
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation { |
22 |
return rotationManager(interfaceOrientation); |
|
23 |
} |
|
24 |
||
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 | 32 |
/* |
33 |
- (void)didRotate:(NSNotification *)notification { |
|
34 |
if (orientation == UIDeviceOrientationLandscapeLeft) { |
|
35 |
} |
|
36 |
if (orientation == UIDeviceOrientationLandscapeRight) { |
|
37 |
} |
|
38 |
if (orientation == UIDeviceOrientationPortrait) { |
|
39 |
} |
|
40 |
if (orientation == UIDeviceOrientationPortrait) { |
|
41 |
} |
|
42 |
} |
|
43 |
*/ |
|
44 |
||
3117
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
45 |
-(void) viewDidLoad { |
3340 | 46 |
/* |
47 |
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; |
|
48 |
[[NSNotificationCenter defaultCenter] addObserver:self |
|
49 |
selector:@selector(didRotate:) |
|
50 |
name:UIDeviceOrientationDidChangeNotification |
|
51 |
object:nil]; |
|
52 |
*/ |
|
3308 | 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 | 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]; |
3357 | 70 |
|
71 |
// listen for dismissal of the popover (see below) |
|
72 |
[[NSNotificationCenter defaultCenter] addObserver:self |
|
73 |
selector:@selector(dismissPopover) |
|
74 |
name:@"dismissPopover" |
|
75 |
object:nil]; |
|
3117
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
76 |
// present the overlay after 2 seconds |
3357 | 77 |
[NSTimer scheduledTimerWithTimeInterval:2 |
78 |
target:self |
|
79 |
selector:@selector(showMenuAfterwards) |
|
80 |
userInfo:nil |
|
81 |
repeats:NO]; |
|
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) viewDidUnload { |
3308 | 85 |
self.popoverController = nil; |
86 |
self.popupMenu = nil; |
|
3305 | 87 |
[super viewDidUnload]; |
3117
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
88 |
} |
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 |
-(void) dealloc { |
3357 | 91 |
[dimTimer invalidate]; |
3308 | 92 |
[popupMenu release]; |
93 |
[popoverController release]; |
|
3117
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
94 |
// dimTimer is autoreleased |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
95 |
[super dealloc]; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
96 |
} |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
97 |
|
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
98 |
// 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
|
99 |
-(void) showMenuAfterwards { |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
100 |
[[SDLUIKitDelegate sharedAppDelegate].uiwindow bringSubviewToFront:self.view]; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
101 |
|
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
102 |
[UIView beginAnimations:@"showing overlay" context:NULL]; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
103 |
[UIView setAnimationDuration:1]; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
104 |
self.view.alpha = 1; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
105 |
[UIView commitAnimations]; |
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 |
|
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
108 |
// 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
|
109 |
-(IBAction) buttonReleased:(id) sender { |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
110 |
HW_allKeysUp(); |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
111 |
[dimTimer setFireDate:[NSDate dateWithTimeIntervalSinceNow:2.7]]; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
112 |
} |
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 |
// nice transition for dimming |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
115 |
-(void) dimOverlay { |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
116 |
[UIView beginAnimations:@"overlay dim" context:NULL]; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
117 |
[UIView setAnimationDuration:0.6]; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
118 |
self.view.alpha = 0.2; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
119 |
[UIView commitAnimations]; |
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 |
|
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
122 |
// 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
|
123 |
-(void) activateOverlay { |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
124 |
self.view.alpha = 1; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
125 |
[dimTimer setFireDate:[NSDate dateWithTimeIntervalSinceNow:1000]]; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
126 |
} |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
127 |
|
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
128 |
// 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
|
129 |
-(IBAction) buttonPressed:(id) sender { |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
130 |
[self activateOverlay]; |
3308 | 131 |
if (isPopoverVisible) { |
132 |
[self dismissPopover]; |
|
133 |
} |
|
3117
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
134 |
UIButton *theButton = (UIButton *)sender; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
135 |
|
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
136 |
switch (theButton.tag) { |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
137 |
case 0: |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
138 |
HW_walkLeft(); |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
139 |
break; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
140 |
case 1: |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
141 |
HW_walkRight(); |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
142 |
break; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
143 |
case 2: |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
144 |
HW_aimUp(); |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
145 |
break; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
146 |
case 3: |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
147 |
HW_aimDown(); |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
148 |
break; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
149 |
case 4: |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
150 |
HW_shoot(); |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
151 |
break; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
152 |
case 5: |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
153 |
HW_jump(); |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
154 |
break; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
155 |
case 6: |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
156 |
HW_backjump(); |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
157 |
break; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
158 |
case 7: |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
159 |
HW_tab(); |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
160 |
break; |
3308 | 161 |
case 10: |
162 |
[self showPopover]; |
|
163 |
break; |
|
3117
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
164 |
default: |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
165 |
NSLog(@"Nope"); |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
166 |
break; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
167 |
} |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
168 |
} |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
169 |
|
3305 | 170 |
// present a further check before closing game |
171 |
-(void) actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger) buttonIndex { |
|
172 |
if ([actionSheet cancelButtonIndex] != buttonIndex) |
|
173 |
HW_terminate(NO); |
|
174 |
else |
|
175 |
HW_pause(); |
|
176 |
} |
|
177 |
||
178 |
// show up a popover containing a popupMenuViewController; we hook it with setPopoverContentSize |
|
3308 | 179 |
// on iphone instead just use the tableViewController directly (and implement manually all animations) |
3305 | 180 |
-(IBAction) showPopover{ |
3308 | 181 |
isPopoverVisible = YES; |
182 |
Class popoverControllerClass = NSClassFromString(@"UIPopoverController"); |
|
183 |
if (popoverControllerClass) { |
|
3305 | 184 |
#ifdef __IPHONE_3_2 |
3308 | 185 |
popupMenu = [[PopoverMenuViewController alloc] initWithStyle:UITableViewStylePlain]; |
186 |
popoverController = [[popoverControllerClass alloc] initWithContentViewController:popupMenu]; |
|
187 |
[popoverController setPopoverContentSize:CGSizeMake(220, 170) animated:YES]; |
|
188 |
[popoverController setPassthroughViews:[NSArray arrayWithObject:self.view]]; |
|
3305 | 189 |
|
3308 | 190 |
[popoverController presentPopoverFromRect:CGRectMake(960, 0, 220, 32) |
191 |
inView:self.view |
|
192 |
permittedArrowDirections:UIPopoverArrowDirectionUp |
|
193 |
animated:YES]; |
|
3305 | 194 |
#endif |
195 |
} else { |
|
3308 | 196 |
popupMenu = [[PopoverMenuViewController alloc] initWithStyle:UITableViewStyleGrouped]; |
197 |
popupMenu.view.backgroundColor = [UIColor clearColor]; |
|
198 |
popupMenu.view.frame = CGRectMake(480, 0, 200, 170); |
|
199 |
[self.view addSubview:popupMenu.view]; |
|
200 |
||
201 |
[UIView beginAnimations:@"showing popover" context:NULL]; |
|
202 |
[UIView setAnimationDuration:0.35]; |
|
203 |
popupMenu.view.frame = CGRectMake(280, 0, 200, 170); |
|
204 |
[UIView commitAnimations]; |
|
205 |
} |
|
206 |
popupMenu.tableView.scrollEnabled = NO; |
|
207 |
} |
|
208 |
||
209 |
// on ipad just dismiss it, on iphone transtion on the right |
|
210 |
-(void) dismissPopover { |
|
211 |
if (YES == isPopoverVisible) { |
|
212 |
isPopoverVisible = NO; |
|
213 |
||
214 |
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { |
|
215 |
#ifdef __IPHONE_3_2 |
|
216 |
[popoverController dismissPopoverAnimated:YES]; |
|
217 |
#endif |
|
218 |
} else { |
|
219 |
[UIView beginAnimations:@"hiding popover" context:NULL]; |
|
220 |
[UIView setAnimationDuration:0.35]; |
|
221 |
popupMenu.view.frame = CGRectMake(480, 0, 200, 170); |
|
222 |
[UIView commitAnimations]; |
|
223 |
||
224 |
[popupMenu.view performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:0.35]; |
|
225 |
[popupMenu performSelector:@selector(release) withObject:nil afterDelay:0.35]; |
|
226 |
||
227 |
//[dimTimer setFireDate:[NSDate dateWithTimeIntervalSinceNow:2.7]]; |
|
228 |
} |
|
229 |
[self buttonReleased:nil]; |
|
3305 | 230 |
} |
231 |
} |
|
232 |
||
233 |
||
3117
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
234 |
#pragma mark - |
3305 | 235 |
#pragma mark Custom touch event handling |
236 |
||
3117
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
237 |
#define kMinimumPinchDelta 50 |
3347 | 238 |
|
3117
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
239 |
|
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
240 |
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
241 |
NSArray *twoTouches; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
242 |
UITouch *touch = [touches anyObject]; |
3305 | 243 |
|
3308 | 244 |
if (isPopoverVisible) { |
245 |
[self dismissPopover]; |
|
246 |
} |
|
3347 | 247 |
|
248 |
gestureStartPoint = [touch locationInView:self.view]; |
|
3308 | 249 |
|
3117
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
250 |
switch ([touches count]) { |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
251 |
case 1: |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
252 |
initialDistanceForPinching = 0; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
253 |
switch ([touch tapCount]) { |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
254 |
case 1: |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
255 |
NSLog(@"X:%d Y:%d", (int)gestureStartPoint.x, (int)gestureStartPoint.y ); |
3347 | 256 |
//SDL_WarpMouseInWindow([SDLUIKitDelegate sharedAppDelegate].window, |
257 |
// (int)gestureStartPoint.y, width - (int)gestureStartPoint.x); |
|
258 |
//HW_click(); |
|
3117
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 |
HW_ammoMenu(); |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
262 |
break; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
263 |
default: |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
264 |
break; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
265 |
} |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
266 |
break; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
267 |
case 2: |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
268 |
if (2 == [touch tapCount]) { |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
269 |
HW_zoomReset(); |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
270 |
} |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
271 |
|
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
272 |
// pinching |
3347 | 273 |
gestureStartPoint.x = 0; |
274 |
gestureStartPoint.y = 0; |
|
3117
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
275 |
twoTouches = [touches allObjects]; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
276 |
UITouch *first = [twoTouches objectAtIndex:0]; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
277 |
UITouch *second = [twoTouches objectAtIndex:1]; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
278 |
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
|
279 |
break; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
280 |
default: |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
281 |
break; |
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 |
} |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
285 |
|
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
286 |
-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
287 |
initialDistanceForPinching = 0; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
288 |
HW_allKeysUp(); |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
289 |
} |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
290 |
|
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
291 |
-(void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event { |
3347 | 292 |
// 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
|
293 |
[self touchesEnded:touches withEvent:event]; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
294 |
} |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
295 |
|
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
296 |
-(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { |
3364 | 297 |
CGFloat minimumGestureLength; |
3347 | 298 |
int logCoeff; |
299 |
||
300 |
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { |
|
3364 | 301 |
minimumGestureLength = 5.0f; |
3347 | 302 |
logCoeff = 19; |
303 |
} else { |
|
3364 | 304 |
minimumGestureLength = 3.0f; |
3347 | 305 |
logCoeff = 3; |
306 |
} |
|
307 |
||
3117
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
308 |
NSArray *twoTouches; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
309 |
CGPoint currentPosition; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
310 |
UITouch *touch = [touches anyObject]; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
311 |
|
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
312 |
switch ([touches count]) { |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
313 |
case 1: |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
314 |
currentPosition = [touch locationInView:self.view]; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
315 |
// panning |
3347 | 316 |
CGFloat deltaX = fabsf(gestureStartPoint.x - currentPosition.x); |
317 |
CGFloat deltaY = fabsf(gestureStartPoint.y - currentPosition.y); |
|
3117
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
318 |
|
3347 | 319 |
if (deltaX >= minimumGestureLength) { |
320 |
NSLog(@"Horizontal swipe detected, deltaX: %f deltaY: %f",deltaX, deltaY); |
|
3364 | 321 |
if (currentPosition.x > gestureStartPoint.x) { |
3356 | 322 |
HW_cursorLeft(logCoeff*log(deltaX)); |
3347 | 323 |
} else { |
3356 | 324 |
HW_cursorRight(logCoeff*log(deltaX)); |
3347 | 325 |
} |
326 |
||
327 |
} |
|
328 |
if (deltaY >= minimumGestureLength) { |
|
329 |
NSLog(@"Horizontal swipe detected, deltaX: %f deltaY: %f",deltaX, deltaY); |
|
3364 | 330 |
if (currentPosition.y < gestureStartPoint.y) { |
3356 | 331 |
HW_cursorDown(logCoeff*log(deltaY)); |
3347 | 332 |
} else { |
3356 | 333 |
HW_cursorUp(logCoeff*log(deltaY)); |
3347 | 334 |
} |
335 |
} |
|
336 |
||
3117
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
337 |
break; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
338 |
case 2: |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
339 |
twoTouches = [touches allObjects]; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
340 |
UITouch *first = [twoTouches objectAtIndex:0]; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
341 |
UITouch *second = [twoTouches objectAtIndex:1]; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
342 |
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
|
343 |
|
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
344 |
if (0 == initialDistanceForPinching) |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
345 |
initialDistanceForPinching = currentDistanceOfPinching; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
346 |
|
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
347 |
if (currentDistanceOfPinching < initialDistanceForPinching + kMinimumPinchDelta) |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
348 |
HW_zoomOut(); |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
349 |
else if (currentDistanceOfPinching > initialDistanceForPinching + kMinimumPinchDelta) |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
350 |
HW_zoomIn(); |
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 |
currentDistanceOfPinching = initialDistanceForPinching; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
353 |
break; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
354 |
default: |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
355 |
break; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
356 |
} |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
357 |
} |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
358 |
|
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
359 |
|
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
360 |
@end |