add suport ios screen orientation set

This commit is contained in:
cw 2014-05-07 20:50:29 +08:00
parent c9a7c44537
commit 919a780e2a
14 changed files with 123 additions and 39 deletions

View File

@ -22,7 +22,7 @@ AppDelegate::~AppDelegate()
bool AppDelegate::applicationDidFinishLaunching() bool AppDelegate::applicationDidFinishLaunching()
{ {
#ifdef COCOS2D_DEBUG #if (COCOS2D_DEBUG>0)
initRuntime(); initRuntime();
#endif #endif
@ -30,12 +30,17 @@ bool AppDelegate::applicationDidFinishLaunching()
auto director = Director::getInstance(); auto director = Director::getInstance();
auto glview = director->getOpenGLView(); auto glview = director->getOpenGLView();
if(!glview) { if(!glview) {
ConfigParser::getInstance()->readConfig();
if (!ConfigParser::getInstance()->isInit()) {
ConfigParser::getInstance()->readConfig();
}
Size viewSize = ConfigParser::getInstance()->getInitViewSize(); Size viewSize = ConfigParser::getInstance()->getInitViewSize();
string title = ConfigParser::getInstance()->getInitViewName(); string title = ConfigParser::getInstance()->getInitViewName();
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 || CC_TARGET_PLATFORM == CC_PLATFORM_MAC) #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); 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 #else
glview = GLView::createWithRect(title.c_str(), Rect(0,0,viewSize.width,viewSize.height)); glview = GLView::createWithRect(title.c_str(), Rect(0,0,viewSize.width,viewSize.height));
director->setOpenGLView(glview); 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 // set FPS. the default value is 1.0/60 if you don't call this
director->setAnimationInterval(1.0 / 60); director->setAnimationInterval(1.0 / 60);
#ifdef COCOS2D_DEBUG #if (COCOS2D_DEBUG>0)
if (startRuntime()) if (startRuntime())
return true; return true;
#endif #endif

View File

@ -16,36 +16,43 @@ ConfigParser *ConfigParser::getInstance(void)
return s_sharedInstance; return s_sharedInstance;
} }
bool ConfigParser::isInit()
{
return _isInit;
}
void ConfigParser::readConfig() void ConfigParser::readConfig()
{ {
_initViewSize.setSize(960,640); _initViewSize.setSize(960,640);
_viewName="HelloLua"; _viewName="HelloLua";
_isInit = true;
string filecfg = "res/config.json"; string filecfg = "res/config.json";
string fullPathFile = FileUtils::getInstance()->fullPathForFilename(filecfg); string fullPathFile = FileUtils::getInstance()->fullPathForFilename(filecfg);
FILE * pFile = fopen (fullPathFile.c_str() , "r"); FILE * pFile = fopen (fullPathFile.c_str() , "r");
if(pFile) if(pFile)
{ {
rapidjson::FileStream inputStream(pFile); rapidjson::FileStream inputStream(pFile);
rapidjson::Document runtimecfgjson; _docRootjson.ParseStream<0>(inputStream);
runtimecfgjson.ParseStream<0>(inputStream);
fclose(pFile); 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")) if (objectInitView.HasMember("width") && objectInitView.HasMember("height"))
{ {
_initViewSize.width = objectInitView["width"].GetUint(); _initViewSize.width = objectInitView["width"].GetUint();
_initViewSize.height = objectInitView["height"].GetUint(); _initViewSize.height = objectInitView["height"].GetUint();
} }
if (objectInitView.HasMember("name")) if (objectInitView.HasMember("name") && objectInitView["name"].IsString())
{ {
_viewName = objectInitView["name"].GetString(); _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()) if (ArrayScreenSize.IsArray())
{ {
for (int i=0; i<ArrayScreenSize.Size(); i++) 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() string ConfigParser::getInitViewName()
{ {
return _viewName; return _viewName;
@ -76,6 +89,11 @@ Size ConfigParser::getInitViewSize()
return _initViewSize; return _initViewSize;
} }
bool ConfigParser::isLanscape()
{
return _isLandscape;
}
int ConfigParser::getScreenSizeCount(void) int ConfigParser::getScreenSizeCount(void)
{ {
return (int)_screenSizeArray.size(); return (int)_screenSizeArray.size();

View File

@ -4,6 +4,7 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "cocos2d.h" #include "cocos2d.h"
#include "json/document.h"
using namespace std; using namespace std;
USING_NS_CC; USING_NS_CC;
@ -32,14 +33,21 @@ public:
int getScreenSizeCount(void); int getScreenSizeCount(void);
cocos2d::Size getInitViewSize(); cocos2d::Size getInitViewSize();
string getInitViewName(); string getInitViewName();
rapidjson::Document& getConfigJsonRoot();
const SimulatorScreenSize getScreenSize(int index); const SimulatorScreenSize getScreenSize(int index);
bool isLanscape();
bool isInit();
private: private:
ConfigParser(void); ConfigParser(void);
static ConfigParser *s_sharedInstance; static ConfigParser *s_sharedInstance;
ScreenSizeArray _screenSizeArray; ScreenSizeArray _screenSizeArray;
cocos2d::Size _initViewSize; cocos2d::Size _initViewSize;
string _viewName; string _viewName;
bool _isLandscape;
bool _isInit;
rapidjson::Document _docRootjson;
}; };
#endif // __CONFIG_PARSER_H__ #endif // __CONFIG_PARSER_H__

View File

@ -94,6 +94,8 @@
C03781F618BF65B100FE4F13 /* libluabindings iOS.a in Frameworks */ = {isa = PBXBuildFile; fileRef = C03781B618BF654500FE4F13 /* libluabindings iOS.a */; }; 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 */; }; 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 */; }; 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 */; }; C07828F818B4D72E00BD2287 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = C07828F418B4D72E00BD2287 /* main.m */; };
C07828F918B4D72E00BD2287 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = C07828F518B4D72E00BD2287 /* MainMenu.xib */; }; C07828F918B4D72E00BD2287 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = C07828F518B4D72E00BD2287 /* MainMenu.xib */; };
C07828FA18B4D72E00BD2287 /* SimulatorApp.mm in Sources */ = {isa = PBXBuildFile; fileRef = C07828F718B4D72E00BD2287 /* SimulatorApp.mm */; }; 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>"; }; 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>"; }; 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>"; }; 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>"; }; 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>"; }; 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>"; }; C07828F618B4D72E00BD2287 /* SimulatorApp.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SimulatorApp.h; sourceTree = "<group>"; };
@ -615,6 +619,8 @@
F293BB7C15EB830F00256477 /* Classes */ = { F293BB7C15EB830F00256477 /* Classes */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
C06C3794191A1D1E00617BED /* ConfigParser.cpp */,
C06C3795191A1D1E00617BED /* ConfigParser.h */,
C07828FB18B4DC6F00BD2287 /* Runtime.cpp */, C07828FB18B4DC6F00BD2287 /* Runtime.cpp */,
C07828FC18B4DC6F00BD2287 /* Runtime.h */, C07828FC18B4DC6F00BD2287 /* Runtime.h */,
C0619CD61896894800872C26 /* Runtime_ios-mac.mm */, C0619CD61896894800872C26 /* Runtime_ios-mac.mm */,
@ -916,6 +922,7 @@
5023813317EBBCE400990C9B /* AppDelegate.cpp in Sources */, 5023813317EBBCE400990C9B /* AppDelegate.cpp in Sources */,
C09BA7EE18BCA49600A85A3E /* NSAppSheetAdditions.m in Sources */, C09BA7EE18BCA49600A85A3E /* NSAppSheetAdditions.m in Sources */,
C07828FE18B4DC7000BD2287 /* Runtime.cpp in Sources */, C07828FE18B4DC7000BD2287 /* Runtime.cpp in Sources */,
C06C3797191A1D1E00617BED /* ConfigParser.cpp in Sources */,
C09BA7E818BC929700A85A3E /* WorkSpaceDialogController.mm in Sources */, C09BA7E818BC929700A85A3E /* WorkSpaceDialogController.mm in Sources */,
C07828F818B4D72E00BD2287 /* main.m in Sources */, C07828F818B4D72E00BD2287 /* main.m in Sources */,
C0619CD81896894800872C26 /* Runtime_ios-mac.mm in Sources */, C0619CD81896894800872C26 /* Runtime_ios-mac.mm in Sources */,
@ -928,6 +935,7 @@
files = ( files = (
5023812517EBBCAC00990C9B /* RootViewController.mm in Sources */, 5023812517EBBCAC00990C9B /* RootViewController.mm in Sources */,
F293BB9C15EB831F00256477 /* AppDelegate.cpp in Sources */, F293BB9C15EB831F00256477 /* AppDelegate.cpp in Sources */,
C06C3796191A1D1E00617BED /* ConfigParser.cpp in Sources */,
5023812417EBBCAC00990C9B /* main.m in Sources */, 5023812417EBBCAC00990C9B /* main.m in Sources */,
C0619CD71896894800872C26 /* Runtime_ios-mac.mm in Sources */, C0619CD71896894800872C26 /* Runtime_ios-mac.mm in Sources */,
C07828FD18B4DC6F00BD2287 /* Runtime.cpp in Sources */, C07828FD18B4DC6F00BD2287 /* Runtime.cpp in Sources */,

View File

@ -30,6 +30,7 @@
#import "AppDelegate.h" #import "AppDelegate.h"
#import "RootViewController.h" #import "RootViewController.h"
#import "CCEAGLView.h" #import "CCEAGLView.h"
#include "ConfigParser.h"
@implementation AppController @implementation AppController
@ -43,7 +44,9 @@ static AppDelegate s_sharedApplication;
{ {
// Override point for customization after application launch. // Override point for customization after application launch.
ConfigParser::getInstance()->readConfig();
// Add the view controller's view to the window and display. // Add the view controller's view to the window and display.
window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]]; window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]];
CCEAGLView *eaglView = [CCEAGLView viewWithFrame: [window bounds] CCEAGLView *eaglView = [CCEAGLView viewWithFrame: [window bounds]

View File

@ -64,8 +64,9 @@
<true/> <true/>
<key>UISupportedInterfaceOrientations</key> <key>UISupportedInterfaceOrientations</key>
<array> <array>
<string>UIInterfaceOrientationLandscapeRight</string> <string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string> <string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array> </array>
</dict> </dict>
</plist> </plist>

View File

@ -26,6 +26,7 @@
#import "RootViewController.h" #import "RootViewController.h"
#import "cocos2d.h" #import "cocos2d.h"
#import "CCEAGLView.h" #import "CCEAGLView.h"
#include "ConfigParser.h"
@implementation RootViewController @implementation RootViewController
@ -55,18 +56,32 @@
// Override to allow orientations other than the default portrait orientation. // Override to allow orientations other than the default portrait orientation.
// This method is deprecated on ios6 // This method is deprecated on ios6
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return UIInterfaceOrientationIsLandscape( interfaceOrientation );
if (ConfigParser::getInstance()->isLanscape()) {
return UIInterfaceOrientationIsLandscape( interfaceOrientation );
}else{
return UIInterfaceOrientationIsPortrait( interfaceOrientation );
}
} }
// For ios6, use supportedInterfaceOrientations & shouldAutorotate instead // For ios6, use supportedInterfaceOrientations & shouldAutorotate instead
- (NSUInteger) supportedInterfaceOrientations{ - (NSUInteger) supportedInterfaceOrientations{
#ifdef __IPHONE_6_0 #ifdef __IPHONE_6_0
return UIInterfaceOrientationMaskAllButUpsideDown; if (ConfigParser::getInstance()->isLanscape()) {
return UIInterfaceOrientationMaskLandscape;
}else{
return UIInterfaceOrientationMaskPortraitUpsideDown;
}
#endif #endif
} }
- (BOOL) shouldAutorotate { - (BOOL) shouldAutorotate {
return YES; if (ConfigParser::getInstance()->isLanscape()) {
return YES;
}else{
return NO;
}
} }
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation { - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {

View File

@ -1,9 +1,4 @@
//
// main.m
// HelloLua
//
// Copyright __MyCompanyName__ 2011. All rights reserved.
//
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>

View File

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <?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> <dependencies>
<deployment version="1060" defaultVersion="1090" identifier="macosx"/> <deployment version="1060" defaultVersion="1070" identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="4514"/> <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="5056"/>
</dependencies> </dependencies>
<objects> <objects>
<customObject id="-2" userLabel="File's Owner" customClass="AppController"> <customObject id="-2" userLabel="File's Owner" customClass="AppController">
@ -121,10 +121,9 @@
<modifierMask key="keyEquivalentModifierMask"/> <modifierMask key="keyEquivalentModifierMask"/>
<menu key="submenu" title="Control" id="ysx-9J-ekz"> <menu key="submenu" title="Control" id="ysx-9J-ekz">
<items> <items>
<menuItem title="Reload" id="hfu-OP-8X3"> <menuItem title="Relaunch" keyEquivalent="r" id="hfu-OP-8X3">
<modifierMask key="keyEquivalentModifierMask"/>
<connections> <connections>
<action selector="onReloadScript:" target="-1" id="ar6-Pq-fmZ"/> <action selector="onRelaunch:" target="-1" id="XXg-eJ-YSn"/>
</connections> </connections>
</menuItem> </menuItem>
</items> </items>
@ -143,4 +142,4 @@
</connections> </connections>
</customObject> </customObject>
</objects> </objects>
</document> </document>

View File

@ -26,7 +26,7 @@
#include <string> #include <string>
#include "AppDelegate.h" #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> @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) onScreenPortait:(id)sender;
- (IBAction) onScreenLandscape:(id)sender; - (IBAction) onScreenLandscape:(id)sender;
- (IBAction) onScreenZoomOut:(id)sender; - (IBAction) onScreenZoomOut:(id)sender;
- (IBAction) onReloadScript:(id)sender; - (IBAction) onRelaunch:(id)sender;
@end @end

View File

@ -117,10 +117,17 @@ std::string getCurAppPath(void)
[window makeKeyAndOrderFront:self]; [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(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]; [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]; [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];
} }

View File

@ -301,13 +301,20 @@ INT_PTR CALLBACK AboutDialogCallback(HWND hDlg, UINT message, WPARAM wParam, LPA
return (INT_PTR)FALSE; 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) if (g_eglView)
{ {
return; 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); g_eglView = GLView::createWithRect(viewName,Rect(0,0,width,height),frameZoomFactor);
auto director = Director::getInstance(); auto director = Director::getInstance();
director->setOpenGLView(g_eglView); director->setOpenGLView(g_eglView);

View File

@ -28,6 +28,6 @@ THE SOFTWARE.
/************************ /************************
@brief create Simulator @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_ */ #endif /* __PROJECT_CONFIG_H_ */

View File

@ -1,5 +1,6 @@
{ {
"init_view":{ "init_view":{
"isLandscape": true,
"name": "HelloLua", "name": "HelloLua",
"width": 960, "width": 960,
"height": 640 "height": 640