12 #import "CGPointUtils.h" |
12 #import "CGPointUtils.h" |
13 #import "SDL_mouse.h" |
13 #import "SDL_mouse.h" |
14 #import "PopoverMenuViewController.h" |
14 #import "PopoverMenuViewController.h" |
15 |
15 |
16 @implementation OverlayViewController |
16 @implementation OverlayViewController |
17 @synthesize dimTimer, menuPopover; |
17 @synthesize dimTimer, popoverController, popupMenu; |
18 |
18 |
19 |
19 |
20 -(void) didReceiveMemoryWarning { |
20 -(void) didReceiveMemoryWarning { |
21 // Releases the view if it doesn't have a superview. |
21 // Releases the view if it doesn't have a superview. |
22 [super didReceiveMemoryWarning]; |
22 [super didReceiveMemoryWarning]; |
23 |
23 |
24 // Release any cached data, images, etc that aren't in use. |
24 // Release any cached data, images, etc that aren't in use. |
25 } |
25 } |
26 |
26 |
27 -(void) viewDidLoad { |
27 -(void) viewDidLoad { |
|
28 isPopoverVisible = NO; |
28 self.view.alpha = 0; |
29 self.view.alpha = 0; |
29 |
30 |
30 // needed for rotation to work on os < 3.2 |
31 // needed for rotation to work on os < 3.2 |
31 self.view.center = CGPointMake(self.view.frame.size.height/2.0, self.view.frame.size.width/2.0); |
32 self.view.center = CGPointMake(self.view.frame.size.height/2.0, self.view.frame.size.width/2.0); |
32 self.view.transform = CGAffineTransformRotate(self.view.transform, (M_PI/2.0)); |
33 self.view.transform = CGAffineTransformRotate(self.view.transform, (M_PI/2.0)); |
33 |
34 |
34 dimTimer = [[NSTimer alloc] initWithFireDate:[NSDate dateWithTimeIntervalSinceNow:6] |
35 dimTimer = [[NSTimer alloc] initWithFireDate:[NSDate dateWithTimeIntervalSinceNow:6] |
50 return (interfaceOrientation == UIInterfaceOrientationLandscapeRight); |
51 return (interfaceOrientation == UIInterfaceOrientationLandscapeRight); |
51 } |
52 } |
52 |
53 |
53 -(void) viewDidUnload { |
54 -(void) viewDidUnload { |
54 [dimTimer invalidate]; |
55 [dimTimer invalidate]; |
55 self.dimTimer = nil; |
56 self.dimTimer = nil; |
56 menuPopover = nil; |
57 self.popoverController = nil; |
|
58 self.popupMenu = nil; |
57 [super viewDidUnload]; |
59 [super viewDidUnload]; |
58 } |
60 } |
59 |
61 |
60 -(void) dealloc { |
62 -(void) dealloc { |
61 [menuPopover release]; |
63 [popupMenu release]; |
|
64 [popoverController release]; |
62 // dimTimer is autoreleased |
65 // dimTimer is autoreleased |
63 [super dealloc]; |
66 [super dealloc]; |
64 } |
67 } |
65 |
68 |
66 // draws the controller overlay after the sdl window has taken control |
69 // draws the controller overlay after the sdl window has taken control |
136 else |
145 else |
137 HW_pause(); |
146 HW_pause(); |
138 } |
147 } |
139 |
148 |
140 // show up a popover containing a popupMenuViewController; we hook it with setPopoverContentSize |
149 // show up a popover containing a popupMenuViewController; we hook it with setPopoverContentSize |
|
150 // on iphone instead just use the tableViewController directly (and implement manually all animations) |
141 -(IBAction) showPopover{ |
151 -(IBAction) showPopover{ |
142 PopoverMenuViewController *popupMenu = [[PopoverMenuViewController alloc] init]; |
152 isPopoverVisible = YES; |
143 popoverVisible = YES; |
153 Class popoverControllerClass = NSClassFromString(@"UIPopoverController"); |
144 Class popoverController = NSClassFromString(@"UIPopoverController"); |
154 if (popoverControllerClass) { |
145 if (popoverController) { |
|
146 #ifdef __IPHONE_3_2 |
155 #ifdef __IPHONE_3_2 |
147 menuPopover = [[popoverController alloc] initWithContentViewController:popupMenu]; |
156 popupMenu = [[PopoverMenuViewController alloc] initWithStyle:UITableViewStylePlain]; |
148 [menuPopover setPopoverContentSize:CGSizeMake(220, 170) animated:YES]; |
157 popoverController = [[popoverControllerClass alloc] initWithContentViewController:popupMenu]; |
|
158 [popoverController setPopoverContentSize:CGSizeMake(220, 170) animated:YES]; |
|
159 [popoverController setPassthroughViews:[NSArray arrayWithObject:self.view]]; |
149 |
160 |
150 [menuPopover presentPopoverFromRect:CGRectMake(960, 0, 220, 32) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES]; |
161 [popoverController presentPopoverFromRect:CGRectMake(960, 0, 220, 32) |
|
162 inView:self.view |
|
163 permittedArrowDirections:UIPopoverArrowDirectionUp |
|
164 animated:YES]; |
151 #endif |
165 #endif |
152 } else { |
166 } else { |
153 //iphone stuff |
167 popupMenu = [[PopoverMenuViewController alloc] initWithStyle:UITableViewStyleGrouped]; |
154 } |
168 popupMenu.view.backgroundColor = [UIColor clearColor]; |
155 } |
169 popupMenu.view.frame = CGRectMake(480, 0, 200, 170); |
156 |
170 [self.view addSubview:popupMenu.view]; |
157 // because of the actionSheet, the popover might not get dismissed, so we do it manually (through a NSNotification system, see above) |
171 |
158 // are we sure about this? |
172 [UIView beginAnimations:@"showing popover" context:NULL]; |
|
173 [UIView setAnimationDuration:0.35]; |
|
174 popupMenu.view.frame = CGRectMake(280, 0, 200, 170); |
|
175 [UIView commitAnimations]; |
|
176 } |
|
177 popupMenu.tableView.scrollEnabled = NO; |
|
178 } |
|
179 |
|
180 // on ipad just dismiss it, on iphone transtion on the right |
159 -(void) dismissPopover { |
181 -(void) dismissPopover { |
160 /*if (popoverVisible) |
182 if (YES == isPopoverVisible) { |
161 [menuPopover dismissPopoverAnimated:YES]; |
183 isPopoverVisible = NO; |
162 popoverVisible = NO;*/ |
184 |
163 } |
185 if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { |
|
186 #ifdef __IPHONE_3_2 |
|
187 [popoverController dismissPopoverAnimated:YES]; |
|
188 #endif |
|
189 } else { |
|
190 [UIView beginAnimations:@"hiding popover" context:NULL]; |
|
191 [UIView setAnimationDuration:0.35]; |
|
192 popupMenu.view.frame = CGRectMake(480, 0, 200, 170); |
|
193 [UIView commitAnimations]; |
|
194 |
|
195 [popupMenu.view performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:0.35]; |
|
196 [popupMenu performSelector:@selector(release) withObject:nil afterDelay:0.35]; |
|
197 |
|
198 //[dimTimer setFireDate:[NSDate dateWithTimeIntervalSinceNow:2.7]]; |
|
199 } |
|
200 [self buttonReleased:nil]; |
|
201 } |
|
202 } |
|
203 |
164 |
204 |
165 #pragma mark - |
205 #pragma mark - |
166 #pragma mark Custom touch event handling |
206 #pragma mark Custom touch event handling |
167 |
207 |
168 #define kMinimumPinchDelta 50 |
208 #define kMinimumPinchDelta 50 |
172 -(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { |
212 -(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { |
173 NSArray *twoTouches; |
213 NSArray *twoTouches; |
174 UITouch *touch = [touches anyObject]; |
214 UITouch *touch = [touches anyObject]; |
175 int width = [[UIScreen mainScreen] bounds].size.width; |
215 int width = [[UIScreen mainScreen] bounds].size.width; |
176 |
216 |
|
217 if (isPopoverVisible) { |
|
218 [self dismissPopover]; |
|
219 } |
|
220 |
177 switch ([touches count]) { |
221 switch ([touches count]) { |
178 case 1: |
222 case 1: |
179 gestureStartPoint = [touch locationInView:self.view]; |
223 gestureStartPoint = [touch locationInView:self.view]; |
180 initialDistanceForPinching = 0; |
224 initialDistanceForPinching = 0; |
181 switch ([touch tapCount]) { |
225 switch ([touch tapCount]) { |