From 5bbdb69db1ce00f518b3ac3d5c9dacb36efa7ad0 Mon Sep 17 00:00:00 2001 From: chsieh Date: Tue, 26 Apr 2011 21:05:09 -0700 Subject: [PATCH] Reorganization. --- Littlest/GameConfig.h | 28 ------- Littlest/OS/GameConfig.h | 28 +++++++ Littlest/OS/RootViewController.h | 16 ++++ Littlest/OS/RootViewController.m | 152 ++++++++++++++++++++++++++++++++++++++ Littlest/RootViewController.h | 16 ---- Littlest/RootViewController.m | 152 -------------------------------------- 6 files changed, 196 insertions(+), 196 deletions(-) delete mode 100644 Littlest/GameConfig.h create mode 100644 Littlest/OS/GameConfig.h create mode 100644 Littlest/OS/RootViewController.h create mode 100644 Littlest/OS/RootViewController.m delete mode 100644 Littlest/RootViewController.h delete mode 100644 Littlest/RootViewController.m diff --git a/Littlest/GameConfig.h b/Littlest/GameConfig.h deleted file mode 100644 index bad9b07..0000000 --- a/Littlest/GameConfig.h +++ /dev/null @@ -1,28 +0,0 @@ -// -// GameConfig.h -// Littlest -// -// Created by Doris Chen on 4/17/11. -// Copyright __MyCompanyName__ 2011. All rights reserved. -// - -#ifndef __GAME_CONFIG_H -#define __GAME_CONFIG_H - -// -// Supported Autorotations: -// None, -// UIViewController, -// CCDirector -// -#define kGameAutorotationNone 0 -#define kGameAutorotationCCDirector 1 -#define kGameAutorotationUIViewController 2 - -// -// Define here the type of autorotation that you want for your game -// -#define GAME_AUTOROTATION kGameAutorotationUIViewController - - -#endif // __GAME_CONFIG_H \ No newline at end of file diff --git a/Littlest/OS/GameConfig.h b/Littlest/OS/GameConfig.h new file mode 100644 index 0000000..bad9b07 --- /dev/null +++ b/Littlest/OS/GameConfig.h @@ -0,0 +1,28 @@ +// +// GameConfig.h +// Littlest +// +// Created by Doris Chen on 4/17/11. +// Copyright __MyCompanyName__ 2011. All rights reserved. +// + +#ifndef __GAME_CONFIG_H +#define __GAME_CONFIG_H + +// +// Supported Autorotations: +// None, +// UIViewController, +// CCDirector +// +#define kGameAutorotationNone 0 +#define kGameAutorotationCCDirector 1 +#define kGameAutorotationUIViewController 2 + +// +// Define here the type of autorotation that you want for your game +// +#define GAME_AUTOROTATION kGameAutorotationUIViewController + + +#endif // __GAME_CONFIG_H \ No newline at end of file diff --git a/Littlest/OS/RootViewController.h b/Littlest/OS/RootViewController.h new file mode 100644 index 0000000..ca05da8 --- /dev/null +++ b/Littlest/OS/RootViewController.h @@ -0,0 +1,16 @@ +// +// RootViewController.h +// Littlest +// +// Created by Doris Chen on 4/17/11. +// Copyright __MyCompanyName__ 2011. All rights reserved. +// + +#import + + +@interface RootViewController : UIViewController { + +} + +@end diff --git a/Littlest/OS/RootViewController.m b/Littlest/OS/RootViewController.m new file mode 100644 index 0000000..db5f37e --- /dev/null +++ b/Littlest/OS/RootViewController.m @@ -0,0 +1,152 @@ +// +// RootViewController.m +// Littlest +// +// Created by Doris Chen on 4/17/11. +// Copyright __MyCompanyName__ 2011. All rights reserved. +// + +// +// RootViewController + iAd +// If you want to support iAd, use this class as the controller of your iAd +// + +#import "cocos2d.h" + +#import "RootViewController.h" +#import "GameConfig.h" + +@implementation RootViewController + +/* + // The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad. + - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { + if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) { + // Custom initialization + } + return self; + } + */ + +/* + // Implement loadView to create a view hierarchy programmatically, without using a nib. + - (void)loadView { + } + */ + +/* + // Implement viewDidLoad to do additional setup after loading the view, typically from a nib. + - (void)viewDidLoad { + [super viewDidLoad]; + } + */ + + +// Override to allow orientations other than the default portrait orientation. +- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { + + // + // There are 2 ways to support auto-rotation: + // - The OpenGL / cocos2d way + // - Faster, but doesn't rotate the UIKit objects + // - The ViewController way + // - A bit slower, but the UiKit objects are placed in the right place + // + +#if GAME_AUTOROTATION==kGameAutorotationNone + // + // EAGLView won't be autorotated. + // Since this method should return YES in at least 1 orientation, + // we return YES only in the Portrait orientation + // + return ( interfaceOrientation == UIInterfaceOrientationPortrait ); + +#elif GAME_AUTOROTATION==kGameAutorotationCCDirector + // + // EAGLView will be rotated by cocos2d + // + // Sample: Autorotate only in landscape mode + // + if( interfaceOrientation == UIInterfaceOrientationLandscapeLeft ) { + [[CCDirector sharedDirector] setDeviceOrientation: kCCDeviceOrientationLandscapeRight]; + } else if( interfaceOrientation == UIInterfaceOrientationLandscapeRight) { + [[CCDirector sharedDirector] setDeviceOrientation: kCCDeviceOrientationLandscapeLeft]; + } + + // Since this method should return YES in at least 1 orientation, + // we return YES only in the Portrait orientation + return ( interfaceOrientation == UIInterfaceOrientationPortrait ); + +#elif GAME_AUTOROTATION == kGameAutorotationUIViewController + // + // EAGLView will be rotated by the UIViewController + // + // Sample: Autorotate only in landscpe mode + // + // return YES for the supported orientations + + return ( UIInterfaceOrientationIsLandscape( interfaceOrientation ) ); + +#else +#error Unknown value in GAME_AUTOROTATION + +#endif // GAME_AUTOROTATION + + + // Shold not happen + return NO; +} + +// +// This callback only will be called when GAME_AUTOROTATION == kGameAutorotationUIViewController +// +#if GAME_AUTOROTATION == kGameAutorotationUIViewController +-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration +{ + // + // Assuming that the main window has the size of the screen + // BUG: This won't work if the EAGLView is not fullscreen + /// + CGRect screenRect = [[UIScreen mainScreen] bounds]; + CGRect rect; + + if(toInterfaceOrientation == UIInterfaceOrientationPortrait || toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) + rect = screenRect; + + else if(toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) + rect.size = CGSizeMake( screenRect.size.height, screenRect.size.width ); + + CCDirector *director = [CCDirector sharedDirector]; + EAGLView *glView = [director openGLView]; + float contentScaleFactor = [director contentScaleFactor]; + + if( contentScaleFactor != 1 ) { + rect.size.width *= contentScaleFactor; + rect.size.height *= contentScaleFactor; + } + glView.frame = rect; +} +#endif // GAME_AUTOROTATION == kGameAutorotationUIViewController + + +- (void)didReceiveMemoryWarning { + // Releases the view if it doesn't have a superview. + [super didReceiveMemoryWarning]; + + // Release any cached data, images, etc that aren't in use. +} + +- (void)viewDidUnload { + [super viewDidUnload]; + // Release any retained subviews of the main view. + // e.g. self.myOutlet = nil; +} + + +- (void)dealloc { + [super dealloc]; +} + + +@end + diff --git a/Littlest/RootViewController.h b/Littlest/RootViewController.h deleted file mode 100644 index ca05da8..0000000 --- a/Littlest/RootViewController.h +++ /dev/null @@ -1,16 +0,0 @@ -// -// RootViewController.h -// Littlest -// -// Created by Doris Chen on 4/17/11. -// Copyright __MyCompanyName__ 2011. All rights reserved. -// - -#import - - -@interface RootViewController : UIViewController { - -} - -@end diff --git a/Littlest/RootViewController.m b/Littlest/RootViewController.m deleted file mode 100644 index db5f37e..0000000 --- a/Littlest/RootViewController.m +++ /dev/null @@ -1,152 +0,0 @@ -// -// RootViewController.m -// Littlest -// -// Created by Doris Chen on 4/17/11. -// Copyright __MyCompanyName__ 2011. All rights reserved. -// - -// -// RootViewController + iAd -// If you want to support iAd, use this class as the controller of your iAd -// - -#import "cocos2d.h" - -#import "RootViewController.h" -#import "GameConfig.h" - -@implementation RootViewController - -/* - // The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad. - - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { - if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) { - // Custom initialization - } - return self; - } - */ - -/* - // Implement loadView to create a view hierarchy programmatically, without using a nib. - - (void)loadView { - } - */ - -/* - // Implement viewDidLoad to do additional setup after loading the view, typically from a nib. - - (void)viewDidLoad { - [super viewDidLoad]; - } - */ - - -// Override to allow orientations other than the default portrait orientation. -- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { - - // - // There are 2 ways to support auto-rotation: - // - The OpenGL / cocos2d way - // - Faster, but doesn't rotate the UIKit objects - // - The ViewController way - // - A bit slower, but the UiKit objects are placed in the right place - // - -#if GAME_AUTOROTATION==kGameAutorotationNone - // - // EAGLView won't be autorotated. - // Since this method should return YES in at least 1 orientation, - // we return YES only in the Portrait orientation - // - return ( interfaceOrientation == UIInterfaceOrientationPortrait ); - -#elif GAME_AUTOROTATION==kGameAutorotationCCDirector - // - // EAGLView will be rotated by cocos2d - // - // Sample: Autorotate only in landscape mode - // - if( interfaceOrientation == UIInterfaceOrientationLandscapeLeft ) { - [[CCDirector sharedDirector] setDeviceOrientation: kCCDeviceOrientationLandscapeRight]; - } else if( interfaceOrientation == UIInterfaceOrientationLandscapeRight) { - [[CCDirector sharedDirector] setDeviceOrientation: kCCDeviceOrientationLandscapeLeft]; - } - - // Since this method should return YES in at least 1 orientation, - // we return YES only in the Portrait orientation - return ( interfaceOrientation == UIInterfaceOrientationPortrait ); - -#elif GAME_AUTOROTATION == kGameAutorotationUIViewController - // - // EAGLView will be rotated by the UIViewController - // - // Sample: Autorotate only in landscpe mode - // - // return YES for the supported orientations - - return ( UIInterfaceOrientationIsLandscape( interfaceOrientation ) ); - -#else -#error Unknown value in GAME_AUTOROTATION - -#endif // GAME_AUTOROTATION - - - // Shold not happen - return NO; -} - -// -// This callback only will be called when GAME_AUTOROTATION == kGameAutorotationUIViewController -// -#if GAME_AUTOROTATION == kGameAutorotationUIViewController --(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration -{ - // - // Assuming that the main window has the size of the screen - // BUG: This won't work if the EAGLView is not fullscreen - /// - CGRect screenRect = [[UIScreen mainScreen] bounds]; - CGRect rect; - - if(toInterfaceOrientation == UIInterfaceOrientationPortrait || toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) - rect = screenRect; - - else if(toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) - rect.size = CGSizeMake( screenRect.size.height, screenRect.size.width ); - - CCDirector *director = [CCDirector sharedDirector]; - EAGLView *glView = [director openGLView]; - float contentScaleFactor = [director contentScaleFactor]; - - if( contentScaleFactor != 1 ) { - rect.size.width *= contentScaleFactor; - rect.size.height *= contentScaleFactor; - } - glView.frame = rect; -} -#endif // GAME_AUTOROTATION == kGameAutorotationUIViewController - - -- (void)didReceiveMemoryWarning { - // Releases the view if it doesn't have a superview. - [super didReceiveMemoryWarning]; - - // Release any cached data, images, etc that aren't in use. -} - -- (void)viewDidUnload { - [super viewDidUnload]; - // Release any retained subviews of the main view. - // e.g. self.myOutlet = nil; -} - - -- (void)dealloc { - [super dealloc]; -} - - -@end - -- 1.7.0.4