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