diff --git a/samples/Lua/TestLua/Resources/luaScript/DrawPrimitivesTest/DrawPrimitivesTest.lua b/samples/Lua/TestLua/Resources/luaScript/DrawPrimitivesTest/DrawPrimitivesTest.lua index b984fb4e37..d3dcacab81 100644 --- a/samples/Lua/TestLua/Resources/luaScript/DrawPrimitivesTest/DrawPrimitivesTest.lua +++ b/samples/Lua/TestLua/Resources/luaScript/DrawPrimitivesTest/DrawPrimitivesTest.lua @@ -2,7 +2,7 @@ require "DrawPrimitives" local function drawPrimitivesMainLayer() local kItemTagBasic = 1000 - local testCount = 1 + local testCount = 2 local maxCases = testCount local curCase = 0 local size = CCDirector:getInstance():getWinSize() @@ -149,9 +149,54 @@ local function drawPrimitivesMainLayer() return layer end + local function createDrawNodeTest() + local layer = CCLayer:create() + + InitTitle(layer) + + local draw = CCDrawNode:create() + layer:addChild(draw, 10) + + --Draw 10 circles + for i=1, 10 do + draw:drawDot(CCPoint(size.width/2, size.height/2), 10*(10-i), Color4F(math.random(0,1), math.random(0,1), math.random(0,1), 1)) + end + + --Draw polygons + points = { CCPoint(size.height/4, 0), CCPoint(size.width, size.height / 5), CCPoint(size.width / 3 * 2, size.height) } + draw:drawPolygon(points, table.getn(points), Color4F(1,0,0,0.5), 4, Color4F(0,0,1,1)) + + local o = 80 + local w = 20 + local h = 50 + local star1 = { CCPoint( o + w, o - h), CCPoint(o + w * 2, o), CCPoint(o + w * 2 + h, o + w), CCPoint(o + w * 2, o + w * 2) } + + draw:drawPolygon(star1, table.getn(star1), Color4F(1,0,0,0.5), 1, Color4F(0,0,1,1)) + + o = 180 + w = 20 + h = 50 + local star2 = { + CCPoint(o, o), CCPoint(o + w, o - h), CCPoint(o + w * 2, o), --lower spike + CCPoint(o + w * 2 + h, o + w ), CCPoint(o + w * 2, o + w * 2), --right spike + CCPoint(o + w, o + w * 2 + h), CCPoint(o, o + w * 2), --top spike + CCPoint(o - h, o + w), --left spike + }; + + draw:drawPolygon(star2, table.getn(star2), Color4F(1,0,0,0.5), 1, Color4F(0,0,1,1)) + + draw:drawSegment(CCPoint(20,size.height), CCPoint(20,size.height/2), 10, Color4F(0, 1, 0, 1)) + + draw:drawSegment(CCPoint(10,size.height/2), CCPoint(size.width/2, size.height/2), 40, Color4F(1, 0, 1, 0.5)) + + return layer + end + local function createLayerByCurCase(curCase) if 0 == curCase then return createDrawPrimitivesEffect() + elseif 1 == curCase then + return createDrawNodeTest() end end diff --git a/scripting/lua/cocos2dx_support/CCLuaEngine.cpp b/scripting/lua/cocos2dx_support/CCLuaEngine.cpp index 898baeb787..3d926f45a8 100644 --- a/scripting/lua/cocos2dx_support/CCLuaEngine.cpp +++ b/scripting/lua/cocos2dx_support/CCLuaEngine.cpp @@ -28,6 +28,7 @@ #include "CCScheduler.h" #include "LuaScriptHandlerMgr.h" #include "GUI/CCControlExtension/CCControl.h" +#include "LuaOpengl.h" NS_CC_BEGIN @@ -613,6 +614,7 @@ void LuaEngine::extendLuaObject() extendWebsocket(lua_S); extendGLNode(lua_S); extendScrollView(lua_S); + extendDrawNode(lua_S); _stack->clean(); } @@ -756,4 +758,20 @@ void LuaEngine::extendScrollView(lua_State* lua_S) lua_rawset(lua_S,-3); } } + +void LuaEngine::extendDrawNode(lua_State* lua_S) +{ + if (NULL == lua_S) + return; + + lua_pushstring(lua_S,"CCDrawNode"); + lua_rawget(lua_S,LUA_REGISTRYINDEX); + if (lua_istable(lua_S,-1)) + { + lua_pushstring(lua_S,"drawPolygon"); + lua_pushcfunction(lua_S,tolua_Cocos2d_CCDrawNode_drawPolygon00); + lua_rawset(lua_S,-3); + } + +} NS_CC_END diff --git a/scripting/lua/cocos2dx_support/CCLuaEngine.h b/scripting/lua/cocos2dx_support/CCLuaEngine.h index f4c493283e..73abef69d6 100644 --- a/scripting/lua/cocos2dx_support/CCLuaEngine.h +++ b/scripting/lua/cocos2dx_support/CCLuaEngine.h @@ -145,6 +145,7 @@ private: void extendWebsocket(lua_State* lua_S); void extendGLNode(lua_State* lua_S); void extendScrollView(lua_State* lua_S); + void extendDrawNode(lua_State* lua_S); private: static LuaEngine* _defaultEngine; LuaStack *_stack; diff --git a/scripting/lua/cocos2dx_support/LuaCocos2d.cpp.REMOVED.git-id b/scripting/lua/cocos2dx_support/LuaCocos2d.cpp.REMOVED.git-id index e35e224c8f..b260b3411c 100644 --- a/scripting/lua/cocos2dx_support/LuaCocos2d.cpp.REMOVED.git-id +++ b/scripting/lua/cocos2dx_support/LuaCocos2d.cpp.REMOVED.git-id @@ -1 +1 @@ -d2e1fc14f4c663f31bc92cb89e099efdbfc986a2 \ No newline at end of file +785c7bd17e5ccba8b2d5330e4f310e52b287a6b6 \ No newline at end of file diff --git a/scripting/lua/cocos2dx_support/LuaOpengl.cpp.REMOVED.git-id b/scripting/lua/cocos2dx_support/LuaOpengl.cpp.REMOVED.git-id index b46045d3c2..2d70fa473e 100644 --- a/scripting/lua/cocos2dx_support/LuaOpengl.cpp.REMOVED.git-id +++ b/scripting/lua/cocos2dx_support/LuaOpengl.cpp.REMOVED.git-id @@ -1 +1 @@ -d515328a92ac0cf64fb7b1ee9d1b0b200d36c473 \ No newline at end of file +1bb73c663636a6565f819f3851fe763b97b30786 \ No newline at end of file diff --git a/scripting/lua/cocos2dx_support/LuaOpengl.h b/scripting/lua/cocos2dx_support/LuaOpengl.h index 605d66c320..c72e000e83 100644 --- a/scripting/lua/cocos2dx_support/LuaOpengl.h +++ b/scripting/lua/cocos2dx_support/LuaOpengl.h @@ -15,6 +15,7 @@ class GLNode:public cocos2d::Node virtual void draw(); }; +TOLUA_API int tolua_Cocos2d_CCDrawNode_drawPolygon00(lua_State* tolua_S); TOLUA_API int tolua_opengl_open(lua_State* tolua_S); diff --git a/tools/tolua++/CCDrawNode.pkg b/tools/tolua++/CCDrawNode.pkg new file mode 100644 index 0000000000..f8a28cef5e --- /dev/null +++ b/tools/tolua++/CCDrawNode.pkg @@ -0,0 +1,22 @@ +class CCDrawNode : public CCNode +{ + static CCDrawNode* create(); + + CCDrawNode(); + + virtual ~CCDrawNode(); + + virtual bool init(); + + void drawDot(const CCPoint &pos, float radius, const Color4F &color); + + void drawSegment(const CCPoint &from, const CCPoint &to, float radius, const Color4F &color); + + void clear(); + + const BlendFunc& getBlendFunc() const; + + void setBlendFunc(const BlendFunc &blendFunc); + + virtual void draw(); +}; diff --git a/tools/tolua++/Cocos2d.pkg b/tools/tolua++/Cocos2d.pkg index 685a0d274d..c357532572 100644 --- a/tools/tolua++/Cocos2d.pkg +++ b/tools/tolua++/Cocos2d.pkg @@ -86,3 +86,4 @@ $pfile "CCControlPotentiometer.pkg" $pfile "CCControlStepper.pkg" $pfile "CCEditBox.pkg" $pfile "CCInteger.pkg" +$pfile "CCDrawNode.pkg" diff --git a/tools/tolua++/basic.lua b/tools/tolua++/basic.lua index d18e2f4bdb..b003f9dce1 100644 --- a/tools/tolua++/basic.lua +++ b/tools/tolua++/basic.lua @@ -198,6 +198,7 @@ local CCObjectTypes = { "CCControlSwitch", "CCEditBox", "CCInteger", + "CCDrawNode", } -- register CCObject types