add visible

This commit is contained in:
cw 2014-05-08 13:47:41 +08:00
parent 784761828b
commit b9d5ef5eda
6 changed files with 148 additions and 100 deletions

View File

@ -21,9 +21,9 @@ AppDelegate::~AppDelegate()
bool AppDelegate::applicationDidFinishLaunching()
{
string entryfile ="src/main.lua";
#if (COCOS2D_DEBUG>0)
initRuntime();
initRuntime(entryfile);
#endif
// initialize director
@ -38,7 +38,7 @@ bool AppDelegate::applicationDidFinishLaunching()
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);
extern void createSimulator(const char* viewName, float width, float height,bool isLandscape = true, float frameZoomFactor = 1.0f);
bool isLanscape = ConfigParser::getInstance()->isLanscape();
createSimulator(title.c_str(),viewSize.width,viewSize.height,isLanscape);
#else
@ -53,14 +53,19 @@ bool AppDelegate::applicationDidFinishLaunching()
// set FPS. the default value is 1.0/60 if you don't call this
director->setAnimationInterval(1.0 / 60);
auto engine = LuaEngine::getInstance();
ScriptEngineManager::getInstance()->setScriptEngine(engine);
//register custom function
//LuaStack* stack = engine->getLuaStack();
//register_custom_function(stack->getLuaState());
#if (COCOS2D_DEBUG>0)
if (startRuntime())
return true;
#endif
auto engine = LuaEngine::getInstance();
ScriptEngineManager::getInstance()->setScriptEngine(engine);
engine->executeScriptFile("src/main.lua");
engine->executeScriptFile(entryfile.c_str());
return true;
}

View File

@ -31,6 +31,7 @@ THE SOFTWARE.
#include "json/stringbuffer.h"
#include "json/writer.h"
#include "LuaBasicConversions.h"
#include "VisibleRect.h"
#ifdef _WIN32
#include <direct.h>
@ -46,12 +47,13 @@ using namespace cocos2d;
std::string g_resourcePath;
static rapidjson::Document g_filecfgjson;
static string g_entryfile;
extern string getIPAddress();
const char* getRuntimeVersion()
{
return "1.1";
}
void startScript(string strDebugArg)
{
// register lua engine
@ -61,7 +63,7 @@ void startScript(string strDebugArg)
engine->executeString(strDebugArg.c_str());
}
cocos2d::log("debug args = %s",strDebugArg.c_str());
engine->executeScriptFile("src/main.lua");
engine->executeScriptFile(g_entryfile.c_str());
}
bool reloadScript(const string& modulefile)
@ -69,7 +71,7 @@ bool reloadScript(const string& modulefile)
string strfile = modulefile;
if (strfile.empty())
{
strfile = "src/main.lua";
strfile = g_entryfile;
}
auto director = Director::getInstance();
@ -87,95 +89,6 @@ bool reloadScript(const string& modulefile)
return (LuaEngine::getInstance()->reload(strfile.c_str())==0);
}
class VisibleRect
{
public:
static Rect getVisibleRect();
static Point left();
static Point right();
static Point top();
static Point bottom();
static Point center();
static Point leftTop();
static Point rightTop();
static Point leftBottom();
static Point rightBottom();
private:
static void lazyInit();
static Rect s_visibleRect;
};
Rect VisibleRect::s_visibleRect;
void VisibleRect::lazyInit()
{
// no lazy init
// Useful if we change the resolution in runtime
s_visibleRect = Director::getInstance()->getOpenGLView()->getVisibleRect();
}
Rect VisibleRect::getVisibleRect()
{
lazyInit();
return s_visibleRect;
}
Point VisibleRect::left()
{
lazyInit();
return Point(s_visibleRect.origin.x, s_visibleRect.origin.y+s_visibleRect.size.height/2);
}
Point VisibleRect::right()
{
lazyInit();
return Point(s_visibleRect.origin.x+s_visibleRect.size.width, s_visibleRect.origin.y+s_visibleRect.size.height/2);
}
Point VisibleRect::top()
{
lazyInit();
return Point(s_visibleRect.origin.x+s_visibleRect.size.width/2, s_visibleRect.origin.y+s_visibleRect.size.height);
}
Point VisibleRect::bottom()
{
lazyInit();
return Point(s_visibleRect.origin.x+s_visibleRect.size.width/2, s_visibleRect.origin.y);
}
Point VisibleRect::center()
{
lazyInit();
return Point(s_visibleRect.origin.x+s_visibleRect.size.width/2, s_visibleRect.origin.y+s_visibleRect.size.height/2);
}
Point VisibleRect::leftTop()
{
lazyInit();
return Point(s_visibleRect.origin.x, s_visibleRect.origin.y+s_visibleRect.size.height);
}
Point VisibleRect::rightTop()
{
lazyInit();
return Point(s_visibleRect.origin.x+s_visibleRect.size.width, s_visibleRect.origin.y+s_visibleRect.size.height);
}
Point VisibleRect::leftBottom()
{
lazyInit();
return s_visibleRect.origin;
}
Point VisibleRect::rightBottom()
{
lazyInit();
return Point(s_visibleRect.origin.x+s_visibleRect.size.width, s_visibleRect.origin.y);
}
class ConnectWaitLayer: public Layer
{
public:
@ -811,8 +724,9 @@ static void register_runtime_override_function(lua_State* tolua_S)
lua_pop(tolua_S, 1);
}
bool initRuntime()
bool initRuntime(string& execufile)
{
g_entryfile = execufile;
vector<string> searchPathArray;
searchPathArray=FileUtils::getInstance()->getSearchPaths();
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 || CC_TARGET_PLATFORM == CC_PLATFORM_MAC)

View File

@ -28,7 +28,7 @@ THE SOFTWARE.
#include <string>
using namespace std;
bool initRuntime();
bool initRuntime(string& execufile);
bool startRuntime();
bool reloadScript(const string& modulefile);

View File

@ -0,0 +1,96 @@
/****************************************************************************
Copyright (c) 2013-2014 Chukong Technologies Inc.
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.
****************************************************************************/
#include "VisibleRect.h"
USING_NS_CC;
Rect VisibleRect::s_visibleRect;
void VisibleRect::lazyInit()
{
// no lazy init
// Useful if we change the resolution in runtime
s_visibleRect = Director::getInstance()->getOpenGLView()->getVisibleRect();
}
Rect VisibleRect::getVisibleRect()
{
lazyInit();
return s_visibleRect;
}
Vector2 VisibleRect::left()
{
lazyInit();
return Vector2(s_visibleRect.origin.x, s_visibleRect.origin.y+s_visibleRect.size.height/2);
}
Vector2 VisibleRect::right()
{
lazyInit();
return Vector2(s_visibleRect.origin.x+s_visibleRect.size.width, s_visibleRect.origin.y+s_visibleRect.size.height/2);
}
Vector2 VisibleRect::top()
{
lazyInit();
return Vector2(s_visibleRect.origin.x+s_visibleRect.size.width/2, s_visibleRect.origin.y+s_visibleRect.size.height);
}
Vector2 VisibleRect::bottom()
{
lazyInit();
return Vector2(s_visibleRect.origin.x+s_visibleRect.size.width/2, s_visibleRect.origin.y);
}
Vector2 VisibleRect::center()
{
lazyInit();
return Vector2(s_visibleRect.origin.x+s_visibleRect.size.width/2, s_visibleRect.origin.y+s_visibleRect.size.height/2);
}
Vector2 VisibleRect::leftTop()
{
lazyInit();
return Vector2(s_visibleRect.origin.x, s_visibleRect.origin.y+s_visibleRect.size.height);
}
Vector2 VisibleRect::rightTop()
{
lazyInit();
return Vector2(s_visibleRect.origin.x+s_visibleRect.size.width, s_visibleRect.origin.y+s_visibleRect.size.height);
}
Vector2 VisibleRect::leftBottom()
{
lazyInit();
return s_visibleRect.origin;
}
Vector2 VisibleRect::rightBottom()
{
lazyInit();
return Vector2(s_visibleRect.origin.x+s_visibleRect.size.width, s_visibleRect.origin.y);
}

View File

@ -0,0 +1,25 @@
#ifndef __VISIBLERECT_H__
#define __VISIBLERECT_H__
#include "cocos2d.h"
class VisibleRect
{
public:
static cocos2d::Rect getVisibleRect();
static cocos2d::Vector2 left();
static cocos2d::Vector2 right();
static cocos2d::Vector2 top();
static cocos2d::Vector2 bottom();
static cocos2d::Vector2 center();
static cocos2d::Vector2 leftTop();
static cocos2d::Vector2 rightTop();
static cocos2d::Vector2 leftBottom();
static cocos2d::Vector2 rightBottom();
private:
static void lazyInit();
static cocos2d::Rect s_visibleRect;
};
#endif /* __VISIBLERECT_H__ */

View File

@ -50,6 +50,8 @@
50D7C96C17EBBEDF005D0B91 /* OpenGL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 50D7C96B17EBBEDF005D0B91 /* OpenGL.framework */; };
50D7C96E17EBBEE6005D0B91 /* AppKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 50D7C96D17EBBEE6005D0B91 /* AppKit.framework */; };
50D7C97017EBBEEC005D0B91 /* IOKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 50D7C96F17EBBEEC005D0B91 /* IOKit.framework */; };
C033B51C191B337200D06937 /* VisibleRect.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C033B51A191B337200D06937 /* VisibleRect.cpp */; };
C033B51D191B337200D06937 /* VisibleRect.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C033B51A191B337200D06937 /* VisibleRect.cpp */; };
C03781B918BF655400FE4F13 /* res in Resources */ = {isa = PBXBuildFile; fileRef = C03781B718BF655400FE4F13 /* res */; };
C03781BA18BF655400FE4F13 /* res in Resources */ = {isa = PBXBuildFile; fileRef = C03781B718BF655400FE4F13 /* res */; };
C03781BB18BF655400FE4F13 /* src in Resources */ = {isa = PBXBuildFile; fileRef = C03781B818BF655400FE4F13 /* src */; };
@ -342,6 +344,8 @@
50D7C96B17EBBEDF005D0B91 /* OpenGL.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenGL.framework; path = System/Library/Frameworks/OpenGL.framework; sourceTree = SDKROOT; };
50D7C96D17EBBEE6005D0B91 /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = System/Library/Frameworks/AppKit.framework; sourceTree = SDKROOT; };
50D7C96F17EBBEEC005D0B91 /* IOKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = IOKit.framework; path = System/Library/Frameworks/IOKit.framework; sourceTree = SDKROOT; };
C033B51A191B337200D06937 /* VisibleRect.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = VisibleRect.cpp; path = ../Classes/VisibleRect.cpp; sourceTree = "<group>"; };
C033B51B191B337200D06937 /* VisibleRect.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = VisibleRect.h; path = ../Classes/VisibleRect.h; sourceTree = "<group>"; };
C03781AE18BF654500FE4F13 /* cocos2d_lua_bindings.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = cocos2d_lua_bindings.xcodeproj; path = "../../cocos2d-x/cocos/scripting/lua-bindings/proj.ios_mac/cocos2d_lua_bindings.xcodeproj"; sourceTree = "<group>"; };
C03781B718BF655400FE4F13 /* res */ = {isa = PBXFileReference; lastKnownFileType = folder; name = res; path = ../../../res; sourceTree = "<group>"; };
C03781B818BF655400FE4F13 /* src */ = {isa = PBXFileReference; lastKnownFileType = folder; name = src; path = ../../../src; sourceTree = "<group>"; };
@ -619,6 +623,8 @@
F293BB7C15EB830F00256477 /* Classes */ = {
isa = PBXGroup;
children = (
C033B51A191B337200D06937 /* VisibleRect.cpp */,
C033B51B191B337200D06937 /* VisibleRect.h */,
C06C3794191A1D1E00617BED /* ConfigParser.cpp */,
C06C3795191A1D1E00617BED /* ConfigParser.h */,
C07828FB18B4DC6F00BD2287 /* Runtime.cpp */,
@ -920,6 +926,7 @@
files = (
C07828FA18B4D72E00BD2287 /* SimulatorApp.mm in Sources */,
5023813317EBBCE400990C9B /* AppDelegate.cpp in Sources */,
C033B51D191B337200D06937 /* VisibleRect.cpp in Sources */,
C09BA7EE18BCA49600A85A3E /* NSAppSheetAdditions.m in Sources */,
C07828FE18B4DC7000BD2287 /* Runtime.cpp in Sources */,
C06C3797191A1D1E00617BED /* ConfigParser.cpp in Sources */,
@ -937,6 +944,7 @@
F293BB9C15EB831F00256477 /* AppDelegate.cpp in Sources */,
C06C3796191A1D1E00617BED /* ConfigParser.cpp in Sources */,
5023812417EBBCAC00990C9B /* main.m in Sources */,
C033B51C191B337200D06937 /* VisibleRect.cpp in Sources */,
C0619CD71896894800872C26 /* Runtime_ios-mac.mm in Sources */,
C07828FD18B4DC6F00BD2287 /* Runtime.cpp in Sources */,
5023811817EBBCAC00990C9B /* AppController.mm in Sources */,