mirror of https://github.com/axmolengine/axmol.git
add suport ios screen orientation set
This commit is contained in:
parent
c9a7c44537
commit
919a780e2a
|
@ -22,7 +22,7 @@ AppDelegate::~AppDelegate()
|
|||
bool AppDelegate::applicationDidFinishLaunching()
|
||||
{
|
||||
|
||||
#ifdef COCOS2D_DEBUG
|
||||
#if (COCOS2D_DEBUG>0)
|
||||
initRuntime();
|
||||
#endif
|
||||
|
||||
|
@ -30,12 +30,17 @@ bool AppDelegate::applicationDidFinishLaunching()
|
|||
auto director = Director::getInstance();
|
||||
auto glview = director->getOpenGLView();
|
||||
if(!glview) {
|
||||
ConfigParser::getInstance()->readConfig();
|
||||
|
||||
if (!ConfigParser::getInstance()->isInit()) {
|
||||
ConfigParser::getInstance()->readConfig();
|
||||
}
|
||||
|
||||
Size viewSize = ConfigParser::getInstance()->getInitViewSize();
|
||||
string title = ConfigParser::getInstance()->getInitViewName();
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 || CC_TARGET_PLATFORM == CC_PLATFORM_MAC)
|
||||
extern void createSimulator(const char* viewName, float width, float height,float frameZoomFactor = 1.0f);
|
||||
createSimulator(title.c_str(),viewSize.width,viewSize.height);
|
||||
bool isLanscape = ConfigParser::getInstance()->isLanscape();
|
||||
createSimulator(title.c_str(),viewSize.width,viewSize.height,isLanscape);
|
||||
#else
|
||||
glview = GLView::createWithRect(title.c_str(), Rect(0,0,viewSize.width,viewSize.height));
|
||||
director->setOpenGLView(glview);
|
||||
|
@ -48,7 +53,7 @@ bool AppDelegate::applicationDidFinishLaunching()
|
|||
// set FPS. the default value is 1.0/60 if you don't call this
|
||||
director->setAnimationInterval(1.0 / 60);
|
||||
|
||||
#ifdef COCOS2D_DEBUG
|
||||
#if (COCOS2D_DEBUG>0)
|
||||
if (startRuntime())
|
||||
return true;
|
||||
#endif
|
||||
|
|
|
@ -16,36 +16,43 @@ ConfigParser *ConfigParser::getInstance(void)
|
|||
return s_sharedInstance;
|
||||
}
|
||||
|
||||
bool ConfigParser::isInit()
|
||||
{
|
||||
return _isInit;
|
||||
}
|
||||
|
||||
void ConfigParser::readConfig()
|
||||
{
|
||||
_initViewSize.setSize(960,640);
|
||||
_viewName="HelloLua";
|
||||
_isInit = true;
|
||||
string filecfg = "res/config.json";
|
||||
string fullPathFile = FileUtils::getInstance()->fullPathForFilename(filecfg);
|
||||
FILE * pFile = fopen (fullPathFile.c_str() , "r");
|
||||
if(pFile)
|
||||
{
|
||||
rapidjson::FileStream inputStream(pFile);
|
||||
rapidjson::Document runtimecfgjson;
|
||||
runtimecfgjson.ParseStream<0>(inputStream);
|
||||
_docRootjson.ParseStream<0>(inputStream);
|
||||
fclose(pFile);
|
||||
if (runtimecfgjson.HasMember("init_view") && runtimecfgjson["init_view"].IsObject())
|
||||
if (_docRootjson.HasMember("init_view") && _docRootjson["init_view"].IsObject())
|
||||
{
|
||||
const rapidjson::Value& objectInitView = runtimecfgjson["init_view"];
|
||||
const rapidjson::Value& objectInitView = _docRootjson["init_view"];
|
||||
if (objectInitView.HasMember("width") && objectInitView.HasMember("height"))
|
||||
{
|
||||
_initViewSize.width = objectInitView["width"].GetUint();
|
||||
_initViewSize.height = objectInitView["height"].GetUint();
|
||||
}
|
||||
if (objectInitView.HasMember("name"))
|
||||
if (objectInitView.HasMember("name") && objectInitView["name"].IsString())
|
||||
{
|
||||
_viewName = objectInitView["name"].GetString();
|
||||
}
|
||||
|
||||
if (objectInitView.HasMember("isLandscape") && objectInitView["isLandscape"].IsBool()) {
|
||||
_isLandscape = objectInitView["isLandscape"].GetBool();
|
||||
}
|
||||
}
|
||||
if (runtimecfgjson.HasMember("simulator_screen_size"))
|
||||
if (_docRootjson.HasMember("simulator_screen_size"))
|
||||
{
|
||||
const rapidjson::Value& ArrayScreenSize = runtimecfgjson["simulator_screen_size"];
|
||||
const rapidjson::Value& ArrayScreenSize = _docRootjson["simulator_screen_size"];
|
||||
if (ArrayScreenSize.IsArray())
|
||||
{
|
||||
for (int i=0; i<ArrayScreenSize.Size(); i++)
|
||||
|
@ -58,14 +65,20 @@ void ConfigParser::readConfig()
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
ConfigParser::ConfigParser(void)
|
||||
ConfigParser::ConfigParser(void):_isInit(false),_isLandscape(true)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
rapidjson::Document& ConfigParser::getConfigJsonRoot()
|
||||
{
|
||||
return _docRootjson;
|
||||
}
|
||||
string ConfigParser::getInitViewName()
|
||||
{
|
||||
return _viewName;
|
||||
|
@ -76,6 +89,11 @@ Size ConfigParser::getInitViewSize()
|
|||
return _initViewSize;
|
||||
}
|
||||
|
||||
bool ConfigParser::isLanscape()
|
||||
{
|
||||
return _isLandscape;
|
||||
}
|
||||
|
||||
int ConfigParser::getScreenSizeCount(void)
|
||||
{
|
||||
return (int)_screenSizeArray.size();
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include <string>
|
||||
#include <vector>
|
||||
#include "cocos2d.h"
|
||||
#include "json/document.h"
|
||||
using namespace std;
|
||||
USING_NS_CC;
|
||||
|
||||
|
@ -32,14 +33,21 @@ public:
|
|||
int getScreenSizeCount(void);
|
||||
cocos2d::Size getInitViewSize();
|
||||
string getInitViewName();
|
||||
rapidjson::Document& getConfigJsonRoot();
|
||||
const SimulatorScreenSize getScreenSize(int index);
|
||||
|
||||
bool isLanscape();
|
||||
bool isInit();
|
||||
|
||||
private:
|
||||
ConfigParser(void);
|
||||
static ConfigParser *s_sharedInstance;
|
||||
ScreenSizeArray _screenSizeArray;
|
||||
cocos2d::Size _initViewSize;
|
||||
string _viewName;
|
||||
bool _isLandscape;
|
||||
bool _isInit;
|
||||
|
||||
rapidjson::Document _docRootjson;
|
||||
};
|
||||
|
||||
#endif // __CONFIG_PARSER_H__
|
||||
|
|
|
@ -94,6 +94,8 @@
|
|||
C03781F618BF65B100FE4F13 /* libluabindings iOS.a in Frameworks */ = {isa = PBXBuildFile; fileRef = C03781B618BF654500FE4F13 /* libluabindings iOS.a */; };
|
||||
C0619CD71896894800872C26 /* Runtime_ios-mac.mm in Sources */ = {isa = PBXBuildFile; fileRef = C0619CD61896894800872C26 /* Runtime_ios-mac.mm */; };
|
||||
C0619CD81896894800872C26 /* Runtime_ios-mac.mm in Sources */ = {isa = PBXBuildFile; fileRef = C0619CD61896894800872C26 /* Runtime_ios-mac.mm */; };
|
||||
C06C3796191A1D1E00617BED /* ConfigParser.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C06C3794191A1D1E00617BED /* ConfigParser.cpp */; };
|
||||
C06C3797191A1D1E00617BED /* ConfigParser.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C06C3794191A1D1E00617BED /* ConfigParser.cpp */; };
|
||||
C07828F818B4D72E00BD2287 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = C07828F418B4D72E00BD2287 /* main.m */; };
|
||||
C07828F918B4D72E00BD2287 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = C07828F518B4D72E00BD2287 /* MainMenu.xib */; };
|
||||
C07828FA18B4D72E00BD2287 /* SimulatorApp.mm in Sources */ = {isa = PBXBuildFile; fileRef = C07828F718B4D72E00BD2287 /* SimulatorApp.mm */; };
|
||||
|
@ -362,6 +364,8 @@
|
|||
C03781CD18BF656A00FE4F13 /* OpenglConstants.lua */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = OpenglConstants.lua; path = "../../cocos2d-x/cocos/scripting/lua-bindings/script/OpenglConstants.lua"; sourceTree = "<group>"; };
|
||||
C03781CE18BF656A00FE4F13 /* StudioConstants.lua */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = StudioConstants.lua; path = "../../cocos2d-x/cocos/scripting/lua-bindings/script/StudioConstants.lua"; sourceTree = "<group>"; };
|
||||
C0619CD61896894800872C26 /* Runtime_ios-mac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = "Runtime_ios-mac.mm"; sourceTree = "<group>"; };
|
||||
C06C3794191A1D1E00617BED /* ConfigParser.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ConfigParser.cpp; path = ../Classes/ConfigParser.cpp; sourceTree = "<group>"; };
|
||||
C06C3795191A1D1E00617BED /* ConfigParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ConfigParser.h; path = ../Classes/ConfigParser.h; sourceTree = "<group>"; };
|
||||
C07828F418B4D72E00BD2287 /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
|
||||
C07828F518B4D72E00BD2287 /* MainMenu.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = MainMenu.xib; sourceTree = "<group>"; };
|
||||
C07828F618B4D72E00BD2287 /* SimulatorApp.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SimulatorApp.h; sourceTree = "<group>"; };
|
||||
|
@ -615,6 +619,8 @@
|
|||
F293BB7C15EB830F00256477 /* Classes */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
C06C3794191A1D1E00617BED /* ConfigParser.cpp */,
|
||||
C06C3795191A1D1E00617BED /* ConfigParser.h */,
|
||||
C07828FB18B4DC6F00BD2287 /* Runtime.cpp */,
|
||||
C07828FC18B4DC6F00BD2287 /* Runtime.h */,
|
||||
C0619CD61896894800872C26 /* Runtime_ios-mac.mm */,
|
||||
|
@ -916,6 +922,7 @@
|
|||
5023813317EBBCE400990C9B /* AppDelegate.cpp in Sources */,
|
||||
C09BA7EE18BCA49600A85A3E /* NSAppSheetAdditions.m in Sources */,
|
||||
C07828FE18B4DC7000BD2287 /* Runtime.cpp in Sources */,
|
||||
C06C3797191A1D1E00617BED /* ConfigParser.cpp in Sources */,
|
||||
C09BA7E818BC929700A85A3E /* WorkSpaceDialogController.mm in Sources */,
|
||||
C07828F818B4D72E00BD2287 /* main.m in Sources */,
|
||||
C0619CD81896894800872C26 /* Runtime_ios-mac.mm in Sources */,
|
||||
|
@ -928,6 +935,7 @@
|
|||
files = (
|
||||
5023812517EBBCAC00990C9B /* RootViewController.mm in Sources */,
|
||||
F293BB9C15EB831F00256477 /* AppDelegate.cpp in Sources */,
|
||||
C06C3796191A1D1E00617BED /* ConfigParser.cpp in Sources */,
|
||||
5023812417EBBCAC00990C9B /* main.m in Sources */,
|
||||
C0619CD71896894800872C26 /* Runtime_ios-mac.mm in Sources */,
|
||||
C07828FD18B4DC6F00BD2287 /* Runtime.cpp in Sources */,
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#import "AppDelegate.h"
|
||||
#import "RootViewController.h"
|
||||
#import "CCEAGLView.h"
|
||||
#include "ConfigParser.h"
|
||||
|
||||
@implementation AppController
|
||||
|
||||
|
@ -43,7 +44,9 @@ static AppDelegate s_sharedApplication;
|
|||
{
|
||||
|
||||
// Override point for customization after application launch.
|
||||
|
||||
|
||||
ConfigParser::getInstance()->readConfig();
|
||||
|
||||
// Add the view controller's view to the window and display.
|
||||
window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]];
|
||||
CCEAGLView *eaglView = [CCEAGLView viewWithFrame: [window bounds]
|
||||
|
|
|
@ -64,8 +64,9 @@
|
|||
<true/>
|
||||
<key>UISupportedInterfaceOrientations</key>
|
||||
<array>
|
||||
<string>UIInterfaceOrientationLandscapeRight</string>
|
||||
<string>UIInterfaceOrientationPortrait</string>
|
||||
<string>UIInterfaceOrientationLandscapeLeft</string>
|
||||
<string>UIInterfaceOrientationLandscapeRight</string>
|
||||
</array>
|
||||
</dict>
|
||||
</plist>
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#import "RootViewController.h"
|
||||
#import "cocos2d.h"
|
||||
#import "CCEAGLView.h"
|
||||
#include "ConfigParser.h"
|
||||
|
||||
@implementation RootViewController
|
||||
|
||||
|
@ -55,18 +56,32 @@
|
|||
// Override to allow orientations other than the default portrait orientation.
|
||||
// This method is deprecated on ios6
|
||||
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
|
||||
return UIInterfaceOrientationIsLandscape( interfaceOrientation );
|
||||
|
||||
if (ConfigParser::getInstance()->isLanscape()) {
|
||||
return UIInterfaceOrientationIsLandscape( interfaceOrientation );
|
||||
}else{
|
||||
return UIInterfaceOrientationIsPortrait( interfaceOrientation );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// For ios6, use supportedInterfaceOrientations & shouldAutorotate instead
|
||||
- (NSUInteger) supportedInterfaceOrientations{
|
||||
#ifdef __IPHONE_6_0
|
||||
return UIInterfaceOrientationMaskAllButUpsideDown;
|
||||
if (ConfigParser::getInstance()->isLanscape()) {
|
||||
return UIInterfaceOrientationMaskLandscape;
|
||||
}else{
|
||||
return UIInterfaceOrientationMaskPortraitUpsideDown;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
- (BOOL) shouldAutorotate {
|
||||
return YES;
|
||||
if (ConfigParser::getInstance()->isLanscape()) {
|
||||
return YES;
|
||||
}else{
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
|
||||
|
|
|
@ -1,9 +1,4 @@
|
|||
//
|
||||
// main.m
|
||||
// HelloLua
|
||||
//
|
||||
// Copyright __MyCompanyName__ 2011. All rights reserved.
|
||||
//
|
||||
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="4514" systemVersion="13B42" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none">
|
||||
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="5056" systemVersion="13C64" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none">
|
||||
<dependencies>
|
||||
<deployment version="1060" defaultVersion="1090" identifier="macosx"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="4514"/>
|
||||
<deployment version="1060" defaultVersion="1070" identifier="macosx"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="5056"/>
|
||||
</dependencies>
|
||||
<objects>
|
||||
<customObject id="-2" userLabel="File's Owner" customClass="AppController">
|
||||
|
@ -121,10 +121,9 @@
|
|||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<menu key="submenu" title="Control" id="ysx-9J-ekz">
|
||||
<items>
|
||||
<menuItem title="Reload" id="hfu-OP-8X3">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<menuItem title="Relaunch" keyEquivalent="r" id="hfu-OP-8X3">
|
||||
<connections>
|
||||
<action selector="onReloadScript:" target="-1" id="ar6-Pq-fmZ"/>
|
||||
<action selector="onRelaunch:" target="-1" id="XXg-eJ-YSn"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
</items>
|
||||
|
@ -143,4 +142,4 @@
|
|||
</connections>
|
||||
</customObject>
|
||||
</objects>
|
||||
</document>
|
||||
</document>
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
#include <string>
|
||||
#include "AppDelegate.h"
|
||||
|
||||
void createSimulator(const char* viewName, float width, float height,float frameZoomFactor = 1.0f);
|
||||
void createSimulator(const char* viewName, float width, float height,bool isLandscape = true,float frameZoomFactor = 1.0f);
|
||||
|
||||
@interface AppController : NSObject <NSApplicationDelegate, NSWindowDelegate>
|
||||
{
|
||||
|
@ -46,7 +46,7 @@ void createSimulator(const char* viewName, float width, float height,float frame
|
|||
- (IBAction) onScreenPortait:(id)sender;
|
||||
- (IBAction) onScreenLandscape:(id)sender;
|
||||
- (IBAction) onScreenZoomOut:(id)sender;
|
||||
- (IBAction) onReloadScript:(id)sender;
|
||||
- (IBAction) onRelaunch:(id)sender;
|
||||
|
||||
|
||||
@end
|
||||
|
|
|
@ -117,10 +117,17 @@ std::string getCurAppPath(void)
|
|||
[window makeKeyAndOrderFront:self];
|
||||
}
|
||||
|
||||
void createSimulator(const char* viewName, float width, float height,float frameZoomFactor)
|
||||
void createSimulator(const char* viewName, float width, float height,bool isLandscape,float frameZoomFactor)
|
||||
{
|
||||
if(g_nsAppDelegate)
|
||||
{
|
||||
if((isLandscape && height > width) || (!isLandscape && width > height))
|
||||
{
|
||||
float tmpvalue =width;
|
||||
width = height;
|
||||
height = width;
|
||||
}
|
||||
|
||||
[g_nsAppDelegate createSimulator:[NSString stringWithUTF8String:viewName] viewWidth:width viewHeight:height factor:frameZoomFactor];
|
||||
}
|
||||
|
||||
|
@ -281,9 +288,26 @@ void createSimulator(const char* viewName, float width, float height,float frame
|
|||
[self updateView];
|
||||
}
|
||||
|
||||
- (IBAction) onReloadScript:(id)sender
|
||||
- (void) launch:(NSArray*)args
|
||||
{
|
||||
reloadScript("");
|
||||
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]];
|
||||
NSMutableDictionary *configuration = [NSMutableDictionary dictionaryWithObject:args forKey:NSWorkspaceLaunchConfigurationArguments];
|
||||
NSError *error = [[[NSError alloc] init] autorelease];
|
||||
[[NSWorkspace sharedWorkspace] launchApplicationAtURL:url
|
||||
options:NSWorkspaceLaunchNewInstance
|
||||
configuration:configuration error:&error];
|
||||
}
|
||||
|
||||
- (void) relaunch:(NSArray*)args
|
||||
{
|
||||
[self launch:args];
|
||||
[[NSApplication sharedApplication] terminate:self];
|
||||
}
|
||||
|
||||
- (IBAction) onRelaunch:(id)sender
|
||||
{
|
||||
NSArray* args=[[NSArray alloc] initWithObjects:@" ", nil];
|
||||
[self relaunch:args];
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -301,13 +301,20 @@ INT_PTR CALLBACK AboutDialogCallback(HWND hDlg, UINT message, WPARAM wParam, LPA
|
|||
return (INT_PTR)FALSE;
|
||||
}
|
||||
|
||||
void createSimulator(const char* viewName, float width, float height, float frameZoomFactor)
|
||||
void createSimulator(const char* viewName, float width, float height, bool isLandscape, float frameZoomFactor)
|
||||
{
|
||||
if (g_eglView)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if((isLandscape && height > width) || (!isLandscape && width > height))
|
||||
{
|
||||
float tmpvalue =width;
|
||||
width = height;
|
||||
height = width;
|
||||
}
|
||||
|
||||
g_eglView = GLView::createWithRect(viewName,Rect(0,0,width,height),frameZoomFactor);
|
||||
auto director = Director::getInstance();
|
||||
director->setOpenGLView(g_eglView);
|
||||
|
|
|
@ -28,6 +28,6 @@ THE SOFTWARE.
|
|||
/************************
|
||||
@brief create Simulator
|
||||
*********************************/
|
||||
void createSimulator(const char* viewName, float width, float height,float frameZoomFactor = 1.0f);
|
||||
void createSimulator(const char* viewName, float width, float height,bool isLandscape = true,float frameZoomFactor = 1.0f);
|
||||
|
||||
#endif /* __PROJECT_CONFIG_H_ */
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
{
|
||||
"init_view":{
|
||||
"isLandscape": true,
|
||||
"name": "HelloLua",
|
||||
"width": 960,
|
||||
"height": 640
|
||||
|
|
Loading…
Reference in New Issue