2011-03-02 17:05:22 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2010 cocos2d-x.org
|
|
|
|
|
|
|
|
http://www.cocos2d-x.org
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
|
|
|
|
2011-03-09 16:19:20 +08:00
|
|
|
#import "CCApplication_ios.h"
|
2011-03-02 17:05:22 +08:00
|
|
|
|
|
|
|
#import <UIKit/UIKit.h>
|
|
|
|
|
2011-03-09 16:19:20 +08:00
|
|
|
#import "CCGeometry.h"
|
2011-03-02 17:05:22 +08:00
|
|
|
#import "CCDirectorCaller.h"
|
|
|
|
|
|
|
|
NS_CC_BEGIN;
|
|
|
|
|
2011-03-09 16:19:20 +08:00
|
|
|
CCApplication* CCApplication::sm_pSharedApplication = 0;
|
2011-03-02 17:05:22 +08:00
|
|
|
|
2011-03-09 16:19:20 +08:00
|
|
|
CCApplication::CCApplication()
|
2011-03-02 17:05:22 +08:00
|
|
|
{
|
2011-03-09 16:19:20 +08:00
|
|
|
CC_ASSERT(! sm_pSharedApplication);
|
2011-03-02 17:05:22 +08:00
|
|
|
sm_pSharedApplication = this;
|
|
|
|
}
|
|
|
|
|
2011-03-09 16:19:20 +08:00
|
|
|
CCApplication::~CCApplication()
|
2011-03-02 17:05:22 +08:00
|
|
|
{
|
2011-03-09 16:19:20 +08:00
|
|
|
CC_ASSERT(this == sm_pSharedApplication);
|
2011-03-02 17:05:22 +08:00
|
|
|
sm_pSharedApplication = 0;
|
|
|
|
}
|
|
|
|
|
2011-03-09 16:19:20 +08:00
|
|
|
int CCApplication::run()
|
2011-03-02 17:05:22 +08:00
|
|
|
{
|
|
|
|
if (initInstance() && applicationDidFinishLaunching())
|
|
|
|
{
|
|
|
|
[[CCDirectorCaller sharedDirectorCaller] startMainLoop];
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-03-09 16:19:20 +08:00
|
|
|
void CCApplication::setAnimationInterval(double interval)
|
2011-03-02 17:05:22 +08:00
|
|
|
{
|
|
|
|
[[CCDirectorCaller sharedDirectorCaller] setAnimationInterval: interval ];
|
|
|
|
}
|
|
|
|
|
2011-03-09 16:19:20 +08:00
|
|
|
CCApplication::Orientation CCApplication::setOrientation(Orientation eOritation)
|
2011-03-02 17:05:22 +08:00
|
|
|
{
|
|
|
|
UIApplication * app = [UIApplication sharedApplication];
|
|
|
|
UIInterfaceOrientation newOrientation;
|
|
|
|
switch (eOritation)
|
|
|
|
{
|
|
|
|
case kOrientationPortrait:
|
|
|
|
newOrientation = UIInterfaceOrientationPortrait;
|
|
|
|
break;
|
|
|
|
case kOrientationPortraitUpsideDown:
|
|
|
|
newOrientation = UIInterfaceOrientationPortraitUpsideDown;
|
|
|
|
break;
|
|
|
|
case kOrientationLandscapeLeft:
|
|
|
|
newOrientation = UIInterfaceOrientationLandscapeRight;
|
|
|
|
break;
|
|
|
|
case kOrientationLandscapeRight:
|
|
|
|
newOrientation = UIInterfaceOrientationLandscapeLeft;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
newOrientation = UIInterfaceOrientationPortrait;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (newOrientation != [app statusBarOrientation])
|
|
|
|
{
|
|
|
|
[app setStatusBarOrientation: newOrientation];
|
|
|
|
}
|
|
|
|
return eOritation;
|
|
|
|
}
|
|
|
|
|
2011-03-09 16:19:20 +08:00
|
|
|
void CCApplication::statusBarFrame(cocos2d::CCRect * rect)
|
2011-03-02 17:05:22 +08:00
|
|
|
{
|
|
|
|
rect->origin.x = [[UIApplication sharedApplication] statusBarFrame].origin.x;
|
|
|
|
rect->origin.y = [[UIApplication sharedApplication] statusBarFrame].origin.y;
|
|
|
|
rect->size.width = [[UIApplication sharedApplication] statusBarFrame].size.width;
|
|
|
|
rect->size.height = [[UIApplication sharedApplication] statusBarFrame].size.height;
|
|
|
|
}
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// static member function
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2011-03-09 16:19:20 +08:00
|
|
|
CCApplication& CCApplication::sharedApplication()
|
2011-03-02 17:05:22 +08:00
|
|
|
{
|
2011-03-09 16:19:20 +08:00
|
|
|
CC_ASSERT(sm_pSharedApplication);
|
2011-03-02 17:05:22 +08:00
|
|
|
return *sm_pSharedApplication;
|
|
|
|
}
|
|
|
|
|
2011-06-17 10:49:02 +08:00
|
|
|
ccLanguageType CCApplication::getCurrentLanguage()
|
|
|
|
{
|
|
|
|
// get the current language and country config
|
|
|
|
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
|
|
|
NSArray *languages = [defaults objectForKey:@"AppleLanguages"];
|
|
|
|
NSString *currentLanguage = [languages objectAtIndex:0];
|
|
|
|
|
|
|
|
// get the current language code.(such as English is "en", Chinese is "zh" and so on)
|
|
|
|
NSDictionary* temp = [NSLocale componentsFromLocaleIdentifier:currentLanguage];
|
|
|
|
NSString * languageCode = [temp objectForKey:NSLocaleLanguageCode];
|
|
|
|
|
|
|
|
ccLanguageType ret = kLanguageEnglish;
|
|
|
|
if ([languageCode isEqualToString:@"zh"])
|
|
|
|
{
|
|
|
|
ret = kLanguageChinese;
|
|
|
|
}
|
|
|
|
else if ([languageCode isEqualToString:@"en"])
|
|
|
|
{
|
|
|
|
ret = kLanguageEnglish;
|
|
|
|
}
|
2011-08-31 14:20:33 +08:00
|
|
|
else if ([languageCode isEqualToString:@"fr"]){
|
|
|
|
ret = kLanguageFrench;
|
|
|
|
}
|
|
|
|
else if ([languageCode isEqualToString:@"it"]){
|
|
|
|
ret = kLanguageItalian;
|
|
|
|
}
|
|
|
|
else if ([languageCode isEqualToString:@"de"]){
|
|
|
|
ret = kLanguageGerman;
|
|
|
|
}
|
|
|
|
else if ([languageCode isEqualToString:@"es"]){
|
|
|
|
ret = kLanguageSpanish;
|
|
|
|
}
|
2011-06-17 10:49:02 +08:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-03-02 17:05:22 +08:00
|
|
|
NS_CC_END;
|