author | koda |
Sat, 01 May 2010 12:53:55 +0000 | |
changeset 3385 | 361bd29293f4 |
parent 3364 | e5403e2bf02c |
child 3395 | 095273ad0e08 |
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 |
|
3385 | 32 |
-(void) didRotate:(NSNotification *)notification { |
33 |
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation]; |
|
34 |
CGRect rect = [[UIScreen mainScreen] bounds]; |
|
35 |
||
3340 | 36 |
if (orientation == UIDeviceOrientationLandscapeLeft) { |
3385 | 37 |
[UIView beginAnimations:@"flip1" context:NULL]; |
38 |
[UIView setAnimationDuration:0.8f]; |
|
39 |
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; |
|
40 |
[[SDLUIKitDelegate sharedAppDelegate].uiwindow viewWithTag:SDL_VIEW_TAG].transform = CGAffineTransformMakeRotation(degreesToRadian(0)); |
|
41 |
self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(90)); |
|
42 |
self.view.frame = CGRectMake(0, 0, rect.size.width, rect.size.height); |
|
43 |
[UIView commitAnimations]; |
|
44 |
} else |
|
45 |
if (orientation == UIDeviceOrientationLandscapeRight) { |
|
46 |
[UIView beginAnimations:@"flip2" context:NULL]; |
|
47 |
[UIView setAnimationDuration:0.8f]; |
|
48 |
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; |
|
49 |
[[SDLUIKitDelegate sharedAppDelegate].uiwindow viewWithTag:SDL_VIEW_TAG].transform = CGAffineTransformMakeRotation(degreesToRadian(180)); |
|
50 |
self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(-90)); |
|
51 |
self.view.frame = CGRectMake(0, 0, rect.size.width, rect.size.height); |
|
52 |
[UIView commitAnimations]; |
|
53 |
} |
|
3340 | 54 |
} |
3385 | 55 |
|
3340 | 56 |
|
3117
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
57 |
-(void) viewDidLoad { |
3385 | 58 |
|
3308 | 59 |
isPopoverVisible = NO; |
3117
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
60 |
self.view.alpha = 0; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
61 |
self.view.center = CGPointMake(self.view.frame.size.height/2.0, self.view.frame.size.width/2.0); |
3385 | 62 |
|
3317
198ec44b6d92
minor tweaks, icon for ipad, merged overlayviewcontroller, pop viewcontroller when selected a hat
koda
parents:
3308
diff
changeset
|
63 |
|
3117
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
64 |
dimTimer = [[NSTimer alloc] initWithFireDate:[NSDate dateWithTimeIntervalSinceNow:6] |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
65 |
interval:1000 |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
66 |
target:self |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
67 |
selector:@selector(dimOverlay) |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
68 |
userInfo:nil |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
69 |
repeats:YES]; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
70 |
|
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
71 |
// add timer too runloop, otherwise it doesn't work |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
72 |
[[NSRunLoop currentRunLoop] addTimer:dimTimer forMode:NSDefaultRunLoopMode]; |
3357 | 73 |
|
74 |
// listen for dismissal of the popover (see below) |
|
75 |
[[NSNotificationCenter defaultCenter] addObserver:self |
|
76 |
selector:@selector(dismissPopover) |
|
77 |
name:@"dismissPopover" |
|
78 |
object:nil]; |
|
3117
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
79 |
// present the overlay after 2 seconds |
3357 | 80 |
[NSTimer scheduledTimerWithTimeInterval:2 |
81 |
target:self |
|
82 |
selector:@selector(showMenuAfterwards) |
|
83 |
userInfo:nil |
|
84 |
repeats:NO]; |
|
3117
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
85 |
} |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
86 |
|
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
87 |
-(void) viewDidUnload { |
3308 | 88 |
self.popoverController = nil; |
89 |
self.popupMenu = nil; |
|
3305 | 90 |
[super viewDidUnload]; |
3117
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
91 |
} |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
92 |
|
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
93 |
-(void) dealloc { |
3357 | 94 |
[dimTimer invalidate]; |
3308 | 95 |
[popupMenu release]; |
96 |
[popoverController release]; |
|
3117
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
97 |
// dimTimer is autoreleased |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
98 |
[super dealloc]; |
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 |
// 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
|
102 |
-(void) showMenuAfterwards { |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
103 |
[[SDLUIKitDelegate sharedAppDelegate].uiwindow bringSubviewToFront:self.view]; |
3385 | 104 |
|
105 |
// need to split paths because iphone doesn't rotate (so we don't need to subscribe to any notification |
|
106 |
// nor perform engine actions when rotating |
|
107 |
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { |
|
108 |
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; |
|
109 |
[[NSNotificationCenter defaultCenter] addObserver:self |
|
110 |
selector:@selector(didRotate:) |
|
111 |
name:@"UIDeviceOrientationDidChangeNotification" |
|
112 |
object:nil]; |
|
113 |
||
114 |
[self didRotate:nil]; |
|
115 |
} else |
|
116 |
self.view.transform = CGAffineTransformRotate(self.view.transform, (M_PI/2.0)); |
|
117 |
||
3117
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
118 |
[UIView beginAnimations:@"showing overlay" context:NULL]; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
119 |
[UIView setAnimationDuration:1]; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
120 |
self.view.alpha = 1; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
121 |
[UIView commitAnimations]; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
122 |
} |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
123 |
|
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
124 |
// 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
|
125 |
-(IBAction) buttonReleased:(id) sender { |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
126 |
HW_allKeysUp(); |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
127 |
[dimTimer setFireDate:[NSDate dateWithTimeIntervalSinceNow:2.7]]; |
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 |
|
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
130 |
// nice transition for dimming |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
131 |
-(void) dimOverlay { |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
132 |
[UIView beginAnimations:@"overlay dim" context:NULL]; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
133 |
[UIView setAnimationDuration:0.6]; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
134 |
self.view.alpha = 0.2; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
135 |
[UIView commitAnimations]; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
136 |
} |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
137 |
|
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
138 |
// 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
|
139 |
-(void) activateOverlay { |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
140 |
self.view.alpha = 1; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
141 |
[dimTimer setFireDate:[NSDate dateWithTimeIntervalSinceNow:1000]]; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
142 |
} |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
143 |
|
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
144 |
// 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
|
145 |
-(IBAction) buttonPressed:(id) sender { |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
146 |
[self activateOverlay]; |
3308 | 147 |
if (isPopoverVisible) { |
148 |
[self dismissPopover]; |
|
149 |
} |
|
3117
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
150 |
UIButton *theButton = (UIButton *)sender; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
151 |
|
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
152 |
switch (theButton.tag) { |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
153 |
case 0: |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
154 |
HW_walkLeft(); |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
155 |
break; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
156 |
case 1: |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
157 |
HW_walkRight(); |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
158 |
break; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
159 |
case 2: |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
160 |
HW_aimUp(); |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
161 |
break; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
162 |
case 3: |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
163 |
HW_aimDown(); |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
164 |
break; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
165 |
case 4: |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
166 |
HW_shoot(); |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
167 |
break; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
168 |
case 5: |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
169 |
HW_jump(); |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
170 |
break; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
171 |
case 6: |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
172 |
HW_backjump(); |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
173 |
break; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
174 |
case 7: |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
175 |
HW_tab(); |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
176 |
break; |
3308 | 177 |
case 10: |
178 |
[self showPopover]; |
|
179 |
break; |
|
3117
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
180 |
default: |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
181 |
NSLog(@"Nope"); |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
182 |
break; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
183 |
} |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
184 |
} |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
185 |
|
3305 | 186 |
// present a further check before closing game |
187 |
-(void) actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger) buttonIndex { |
|
188 |
if ([actionSheet cancelButtonIndex] != buttonIndex) |
|
189 |
HW_terminate(NO); |
|
190 |
else |
|
191 |
HW_pause(); |
|
192 |
} |
|
193 |
||
194 |
// show up a popover containing a popupMenuViewController; we hook it with setPopoverContentSize |
|
3308 | 195 |
// on iphone instead just use the tableViewController directly (and implement manually all animations) |
3305 | 196 |
-(IBAction) showPopover{ |
3308 | 197 |
isPopoverVisible = YES; |
198 |
Class popoverControllerClass = NSClassFromString(@"UIPopoverController"); |
|
199 |
if (popoverControllerClass) { |
|
3305 | 200 |
#ifdef __IPHONE_3_2 |
3308 | 201 |
popupMenu = [[PopoverMenuViewController alloc] initWithStyle:UITableViewStylePlain]; |
202 |
popoverController = [[popoverControllerClass alloc] initWithContentViewController:popupMenu]; |
|
203 |
[popoverController setPopoverContentSize:CGSizeMake(220, 170) animated:YES]; |
|
204 |
[popoverController setPassthroughViews:[NSArray arrayWithObject:self.view]]; |
|
3305 | 205 |
|
3308 | 206 |
[popoverController presentPopoverFromRect:CGRectMake(960, 0, 220, 32) |
207 |
inView:self.view |
|
208 |
permittedArrowDirections:UIPopoverArrowDirectionUp |
|
209 |
animated:YES]; |
|
3305 | 210 |
#endif |
211 |
} else { |
|
3308 | 212 |
popupMenu = [[PopoverMenuViewController alloc] initWithStyle:UITableViewStyleGrouped]; |
213 |
popupMenu.view.backgroundColor = [UIColor clearColor]; |
|
214 |
popupMenu.view.frame = CGRectMake(480, 0, 200, 170); |
|
215 |
[self.view addSubview:popupMenu.view]; |
|
216 |
||
217 |
[UIView beginAnimations:@"showing popover" context:NULL]; |
|
218 |
[UIView setAnimationDuration:0.35]; |
|
219 |
popupMenu.view.frame = CGRectMake(280, 0, 200, 170); |
|
220 |
[UIView commitAnimations]; |
|
221 |
} |
|
222 |
popupMenu.tableView.scrollEnabled = NO; |
|
223 |
} |
|
224 |
||
225 |
// on ipad just dismiss it, on iphone transtion on the right |
|
226 |
-(void) dismissPopover { |
|
227 |
if (YES == isPopoverVisible) { |
|
228 |
isPopoverVisible = NO; |
|
229 |
||
230 |
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { |
|
231 |
#ifdef __IPHONE_3_2 |
|
232 |
[popoverController dismissPopoverAnimated:YES]; |
|
233 |
#endif |
|
234 |
} else { |
|
235 |
[UIView beginAnimations:@"hiding popover" context:NULL]; |
|
236 |
[UIView setAnimationDuration:0.35]; |
|
237 |
popupMenu.view.frame = CGRectMake(480, 0, 200, 170); |
|
238 |
[UIView commitAnimations]; |
|
239 |
||
240 |
[popupMenu.view performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:0.35]; |
|
241 |
[popupMenu performSelector:@selector(release) withObject:nil afterDelay:0.35]; |
|
242 |
||
243 |
//[dimTimer setFireDate:[NSDate dateWithTimeIntervalSinceNow:2.7]]; |
|
244 |
} |
|
245 |
[self buttonReleased:nil]; |
|
3305 | 246 |
} |
247 |
} |
|
248 |
||
249 |
||
3117
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
250 |
#pragma mark - |
3305 | 251 |
#pragma mark Custom touch event handling |
252 |
||
3117
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
253 |
#define kMinimumPinchDelta 50 |
3347 | 254 |
|
3117
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
255 |
|
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
256 |
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
257 |
NSArray *twoTouches; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
258 |
UITouch *touch = [touches anyObject]; |
3305 | 259 |
|
3308 | 260 |
if (isPopoverVisible) { |
261 |
[self dismissPopover]; |
|
262 |
} |
|
3347 | 263 |
|
264 |
gestureStartPoint = [touch locationInView:self.view]; |
|
3308 | 265 |
|
3117
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
266 |
switch ([touches count]) { |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
267 |
case 1: |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
268 |
initialDistanceForPinching = 0; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
269 |
switch ([touch tapCount]) { |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
270 |
case 1: |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
271 |
NSLog(@"X:%d Y:%d", (int)gestureStartPoint.x, (int)gestureStartPoint.y ); |
3347 | 272 |
//SDL_WarpMouseInWindow([SDLUIKitDelegate sharedAppDelegate].window, |
273 |
// (int)gestureStartPoint.y, width - (int)gestureStartPoint.x); |
|
274 |
//HW_click(); |
|
3117
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
275 |
break; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
276 |
case 2: |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
277 |
HW_ammoMenu(); |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
278 |
break; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
279 |
default: |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
280 |
break; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
281 |
} |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
282 |
break; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
283 |
case 2: |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
284 |
if (2 == [touch tapCount]) { |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
285 |
HW_zoomReset(); |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
286 |
} |
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 |
// pinching |
3347 | 289 |
gestureStartPoint.x = 0; |
290 |
gestureStartPoint.y = 0; |
|
3117
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
291 |
twoTouches = [touches allObjects]; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
292 |
UITouch *first = [twoTouches objectAtIndex:0]; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
293 |
UITouch *second = [twoTouches objectAtIndex:1]; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
294 |
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
|
295 |
break; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
296 |
default: |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
297 |
break; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
298 |
} |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
299 |
|
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
300 |
} |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
301 |
|
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
302 |
-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
303 |
initialDistanceForPinching = 0; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
304 |
HW_allKeysUp(); |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
305 |
} |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
306 |
|
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
307 |
-(void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event { |
3347 | 308 |
// 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
|
309 |
[self touchesEnded:touches withEvent:event]; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
310 |
} |
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 |
-(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { |
3364 | 313 |
CGFloat minimumGestureLength; |
3347 | 314 |
int logCoeff; |
315 |
||
316 |
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { |
|
3364 | 317 |
minimumGestureLength = 5.0f; |
3347 | 318 |
logCoeff = 19; |
319 |
} else { |
|
3364 | 320 |
minimumGestureLength = 3.0f; |
3347 | 321 |
logCoeff = 3; |
322 |
} |
|
323 |
||
3117
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
324 |
NSArray *twoTouches; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
325 |
CGPoint currentPosition; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
326 |
UITouch *touch = [touches anyObject]; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
327 |
|
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
328 |
switch ([touches count]) { |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
329 |
case 1: |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
330 |
currentPosition = [touch locationInView:self.view]; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
331 |
// panning |
3347 | 332 |
CGFloat deltaX = fabsf(gestureStartPoint.x - currentPosition.x); |
333 |
CGFloat deltaY = fabsf(gestureStartPoint.y - currentPosition.y); |
|
3117
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
334 |
|
3347 | 335 |
if (deltaX >= minimumGestureLength) { |
336 |
NSLog(@"Horizontal swipe detected, deltaX: %f deltaY: %f",deltaX, deltaY); |
|
3364 | 337 |
if (currentPosition.x > gestureStartPoint.x) { |
3356 | 338 |
HW_cursorLeft(logCoeff*log(deltaX)); |
3347 | 339 |
} else { |
3356 | 340 |
HW_cursorRight(logCoeff*log(deltaX)); |
3347 | 341 |
} |
342 |
||
343 |
} |
|
344 |
if (deltaY >= minimumGestureLength) { |
|
345 |
NSLog(@"Horizontal swipe detected, deltaX: %f deltaY: %f",deltaX, deltaY); |
|
3364 | 346 |
if (currentPosition.y < gestureStartPoint.y) { |
3356 | 347 |
HW_cursorDown(logCoeff*log(deltaY)); |
3347 | 348 |
} else { |
3356 | 349 |
HW_cursorUp(logCoeff*log(deltaY)); |
3347 | 350 |
} |
351 |
} |
|
352 |
||
3117
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 |
case 2: |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
355 |
twoTouches = [touches allObjects]; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
356 |
UITouch *first = [twoTouches objectAtIndex:0]; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
357 |
UITouch *second = [twoTouches objectAtIndex:1]; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
358 |
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
|
359 |
|
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
360 |
if (0 == initialDistanceForPinching) |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
361 |
initialDistanceForPinching = currentDistanceOfPinching; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
362 |
|
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
363 |
if (currentDistanceOfPinching < initialDistanceForPinching + kMinimumPinchDelta) |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
364 |
HW_zoomOut(); |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
365 |
else if (currentDistanceOfPinching > initialDistanceForPinching + kMinimumPinchDelta) |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
366 |
HW_zoomIn(); |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
367 |
|
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
368 |
currentDistanceOfPinching = initialDistanceForPinching; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
369 |
break; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
370 |
default: |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
371 |
break; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
372 |
} |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
373 |
} |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
374 |
|
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
375 |
|
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
376 |
@end |