| 1 |
#import "ViewController.h" |
| 2 |
#import "EAGLView.h" |
| 3 |
#import <allegro5/allegro_iphone_objc.h> |
| 4 |
|
| 5 |
#include "allegroAppDelegate.h" |
| 6 |
|
| 7 |
ALLEGRO_DEBUG_CHANNEL("iphone"); |
| 8 |
|
| 9 |
@implementation ViewController |
| 10 |
|
| 11 |
- (void)didReceiveMemoryWarning |
| 12 |
{ |
| 13 |
[super didReceiveMemoryWarning]; |
| 14 |
} |
| 15 |
|
| 16 |
- (void)loadView |
| 17 |
{ |
| 18 |
} |
| 19 |
|
| 20 |
- (void)viewDidLoad |
| 21 |
{ |
| 22 |
ALLEGRO_DEBUG("Loading view controller.\n"); |
| 23 |
display = NULL; |
| 24 |
} |
| 25 |
|
| 26 |
- (void)viewDidUnload |
| 27 |
{ |
| 28 |
[super viewDidUnload]; |
| 29 |
} |
| 30 |
|
| 31 |
- (BOOL)shouldAutorotate |
| 32 |
{ |
| 33 |
ALLEGRO_DISPLAY_IPHONE *d = (ALLEGRO_DISPLAY_IPHONE *)display; |
| 34 |
if (display == NULL) |
| 35 |
return YES; |
| 36 |
if (d->extra->adapter != 0) { |
| 37 |
return NO; |
| 38 |
} |
| 39 |
return YES; |
| 40 |
} |
| 41 |
|
| 42 |
/* Taken from Apple docs |
| 43 |
*/ |
| 44 |
/* |
| 45 |
typedef enum { |
| 46 |
UIInterfaceOrientationMaskPortrait = (1 << UIInterfaceOrientationPortrait), |
| 47 |
UIInterfaceOrientationMaskLandscapeLeft = (1 << UIInterfaceOrientationLandscapeLeft), |
| 48 |
UIInterfaceOrientationMaskLandscapeRight = (1 << UIInterfaceOrientationLandscapeRight), |
| 49 |
UIInterfaceOrientationMaskPortraitUpsideDown = (1 << UIInterfaceOrientationPortraitUpsideDown), |
| 50 |
UIInterfaceOrientationMaskLandscape = |
| 51 |
(UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight), |
| 52 |
UIInterfaceOrientationMaskAll = |
| 53 |
(UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft | |
| 54 |
UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskPortraitUpsideDown), |
| 55 |
UIInterfaceOrientationMaskAllButUpsideDown = |
| 56 |
(UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft | |
| 57 |
UIInterfaceOrientationMaskLandscapeRight), |
| 58 |
} UIInterfaceOrientationMask; |
| 59 |
*/ |
| 60 |
|
| 61 |
- (NSUInteger)supportedInterfaceOrientations |
| 62 |
{ |
| 63 |
if (!display) return UIInterfaceOrientationMaskAll; |
| 64 |
ALLEGRO_DISPLAY_IPHONE *d = (ALLEGRO_DISPLAY_IPHONE *)display; |
| 65 |
if (d->extra->adapter != 0) return UIInterfaceOrientationMaskAll; |
| 66 |
ALLEGRO_EXTRA_DISPLAY_SETTINGS *options = &display->extra_settings; |
| 67 |
int supported = options->settings[ALLEGRO_SUPPORTED_ORIENTATIONS]; |
| 68 |
int mask = 0; |
| 69 |
|
| 70 |
switch (supported) { |
| 71 |
default: |
| 72 |
case ALLEGRO_DISPLAY_ORIENTATION_ALL: |
| 73 |
mask = UIInterfaceOrientationMaskAll; |
| 74 |
break; |
| 75 |
case ALLEGRO_DISPLAY_ORIENTATION_PORTRAIT: |
| 76 |
mask = UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown; |
| 77 |
break; |
| 78 |
case ALLEGRO_DISPLAY_ORIENTATION_LANDSCAPE: |
| 79 |
mask = UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight; |
| 80 |
break; |
| 81 |
case ALLEGRO_DISPLAY_ORIENTATION_0_DEGREES: |
| 82 |
mask = UIInterfaceOrientationMaskPortrait; |
| 83 |
break; |
| 84 |
case ALLEGRO_DISPLAY_ORIENTATION_90_DEGREES: |
| 85 |
mask = UIInterfaceOrientationMaskLandscapeRight; |
| 86 |
break; |
| 87 |
case ALLEGRO_DISPLAY_ORIENTATION_180_DEGREES: |
| 88 |
mask = UIInterfaceOrientationMaskPortraitUpsideDown; |
| 89 |
break; |
| 90 |
case ALLEGRO_DISPLAY_ORIENTATION_270_DEGREES: |
| 91 |
mask = UIInterfaceOrientationMaskLandscapeLeft; |
| 92 |
break; |
| 93 |
} |
| 94 |
|
| 95 |
return mask; |
| 96 |
} |
| 97 |
|
| 98 |
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation |
| 99 |
{ |
| 100 |
ALLEGRO_DISPLAY_IPHONE *d = (ALLEGRO_DISPLAY_IPHONE *)display; |
| 101 |
if (display == NULL) |
| 102 |
return YES; |
| 103 |
if (d->extra->adapter != 0) { |
| 104 |
return NO; |
| 105 |
} |
| 106 |
EAGLView *view = (EAGLView *)al_iphone_get_view(display); |
| 107 |
if (view) { |
| 108 |
return [view orientation_supported:interfaceOrientation]; |
| 109 |
} |
| 110 |
return NO; |
| 111 |
} |
| 112 |
|
| 113 |
- (void) create_view |
| 114 |
{ |
| 115 |
UIScreen *screen; |
| 116 |
|
| 117 |
if (adapter == 0) |
| 118 |
screen = [UIScreen mainScreen]; |
| 119 |
else |
| 120 |
screen = [[UIScreen screens] objectAtIndex:adapter]; |
| 121 |
self.view = [[EAGLView alloc] initWithFrame:[screen bounds]]; |
| 122 |
[self.view release]; |
| 123 |
} |
| 124 |
|
| 125 |
@end |