From 016593bd0e2ca4b13aa9f2e7935d8c1359ba9fb0 Mon Sep 17 00:00:00 2001 From: samuele3hu Date: Sat, 27 Jul 2013 00:28:06 +0800 Subject: [PATCH 1/3] issue #2426:Add Drawprimitives.lua and Drawprimitives lua test sample --- .../DrawPrimitivesTest/DrawPrimitivesTest.lua | 47 ++++++++++++++++++- .../lua/cocos2dx_support/CCLuaEngine.cpp | 18 +++++++ scripting/lua/cocos2dx_support/CCLuaEngine.h | 1 + .../LuaCocos2d.cpp.REMOVED.git-id | 2 +- .../LuaOpengl.cpp.REMOVED.git-id | 2 +- scripting/lua/cocos2dx_support/LuaOpengl.h | 1 + tools/tolua++/CCDrawNode.pkg | 22 +++++++++ tools/tolua++/Cocos2d.pkg | 1 + tools/tolua++/basic.lua | 1 + 9 files changed, 92 insertions(+), 3 deletions(-) create mode 100644 tools/tolua++/CCDrawNode.pkg 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 From faa0b46f57e5d4ca42dee7c567dad17c1777810c Mon Sep 17 00:00:00 2001 From: samuele3hu Date: Sat, 27 Jul 2013 10:42:22 +0800 Subject: [PATCH 2/3] issue #2426:Add Drawprimitives and DrawNode lua binding and modify releated test sample --- .../DrawPrimitivesTest/DrawPrimitivesTest.lua | 69 +++++++++++-------- .../LuaCocos2d.cpp.REMOVED.git-id | 2 +- .../LuaOpengl.cpp.REMOVED.git-id | 2 +- tools/tolua++/CCDrawingPrimitives.pkg | 19 ----- tools/tolua++/Cocos2d.pkg | 1 - 5 files changed, 41 insertions(+), 52 deletions(-) delete mode 100644 tools/tolua++/CCDrawingPrimitives.pkg diff --git a/samples/Lua/TestLua/Resources/luaScript/DrawPrimitivesTest/DrawPrimitivesTest.lua b/samples/Lua/TestLua/Resources/luaScript/DrawPrimitivesTest/DrawPrimitivesTest.lua index d3dcacab81..dbd1d6a235 100644 --- a/samples/Lua/TestLua/Resources/luaScript/DrawPrimitivesTest/DrawPrimitivesTest.lua +++ b/samples/Lua/TestLua/Resources/luaScript/DrawPrimitivesTest/DrawPrimitivesTest.lua @@ -1,4 +1,4 @@ -require "DrawPrimitives" + local function drawPrimitivesMainLayer() local kItemTagBasic = 1000 @@ -86,60 +86,69 @@ local function drawPrimitivesMainLayer() glNode:setAnchorPoint(CCPoint(0.5, 0.5)) local function primitivesDraw() - ccDrawLine(VisibleRect:leftBottom(), VisibleRect:rightTop() ) + CCDrawPrimitives.ccDrawLine(VisibleRect:leftBottom(), VisibleRect:rightTop() ) gl.lineWidth( 5.0 ) - ccDrawColor4B(255,0,0,255) - ccDrawLine( VisibleRect:leftTop(), VisibleRect:rightBottom() ) + CCDrawPrimitives.ccDrawColor4B(255,0,0,255) + CCDrawPrimitives.ccDrawLine( VisibleRect:leftTop(), VisibleRect:rightBottom() ) - ccPointSize(64) - ccDrawColor4B(0, 0, 255, 128) - ccDrawPoint(VisibleRect:center()) + + + CCDrawPrimitives.ccPointSize(64) + CCDrawPrimitives.ccDrawColor4B(0, 0, 255, 128) + CCDrawPrimitives.ccDrawPoint(VisibleRect:center()) local points = {CCPoint(60,60), CCPoint(70,70), CCPoint(60,70), CCPoint(70,60) } - ccPointSize(4) - ccDrawColor4B(0,255,255,255) - ccDrawPoints(points,4) + CCDrawPrimitives.ccPointSize(4) + CCDrawPrimitives.ccDrawColor4B(0,255,255,255) + CCDrawPrimitives.ccDrawPoints(points,4) gl.lineWidth(16) - ccDrawColor4B(0, 255, 0, 255) - ccDrawCircle( VisibleRect:center(), 100, 0, 10, false) + CCDrawPrimitives.ccDrawColor4B(0, 255, 0, 255) + CCDrawPrimitives.ccDrawCircle( VisibleRect:center(), 100, 0, 10, false) gl.lineWidth(2) - ccDrawColor4B(0, 255, 255, 255) - ccDrawCircle( VisibleRect:center(), 50, math.pi / 2, 50, true) - + CCDrawPrimitives.ccDrawColor4B(0, 255, 255, 255) + CCDrawPrimitives.ccDrawCircle( VisibleRect:center(), 50, math.pi / 2, 50, true) + gl.lineWidth(2) - ccDrawColor4B(255, 0, 255, 255) - ccDrawSolidCircle( VisibleRect:center() + CCPoint(140,0), 40, math.rad(90), 50, 1.0, 1.0) + CCDrawPrimitives.ccDrawColor4B(255, 0, 255, 255) + CCDrawPrimitives.ccDrawSolidCircle( VisibleRect:center() + CCPoint(140,0), 40, math.rad(90), 50, 1.0, 1.0) - - ccDrawColor4B(255, 255, 0, 255) gl.lineWidth(10) + CCDrawPrimitives.ccDrawColor4B(255, 255, 0, 255) local yellowPoints = { CCPoint(0,0), CCPoint(50,50), CCPoint(100,50), CCPoint(100,100), CCPoint(50,100)} - ccDrawPoly( yellowPoints, 5, false) + CCDrawPrimitives.ccDrawPoly( yellowPoints, 5, false) gl.lineWidth(1) local filledVertices = { CCPoint(0,120), CCPoint(50,120), CCPoint(50,170), CCPoint(25,200), CCPoint(0,170) } - local colorFilled = { 0.5, 0.5, 1, 1 } - ccDrawSolidPoly(filledVertices, 5, colorFilled) + CCDrawPrimitives.ccDrawSolidPoly(filledVertices, 5, Color4F(0.5, 0.5, 1, 1)) - ccDrawColor4B(255, 0, 255, 255) gl.lineWidth(2) + CCDrawPrimitives.ccDrawColor4B(255, 0, 255, 255) local closePoints= { CCPoint(30,130), CCPoint(30,230), CCPoint(50,200) } - ccDrawPoly( closePoints, 3, true) + CCDrawPrimitives.ccDrawPoly( closePoints, 3, true) - ccDrawQuadBezier(VisibleRect:leftTop(), VisibleRect:center(), VisibleRect:rightTop(), 50) + CCDrawPrimitives.ccDrawQuadBezier(VisibleRect:leftTop(), VisibleRect:center(), VisibleRect:rightTop(), 50) - ccDrawCubicBezier(VisibleRect:center(), CCPoint(VisibleRect:center().x + 30, VisibleRect:center().y + 50), CCPoint(VisibleRect:center().x + 60,VisibleRect:center().y - 50), VisibleRect:right(), 100) + CCDrawPrimitives.ccDrawCubicBezier(VisibleRect:center(), CCPoint(VisibleRect:center().x + 30, VisibleRect:center().y + 50), CCPoint(VisibleRect:center().x + 60,VisibleRect:center().y - 50), VisibleRect:right(), 100) local solidvertices = {CCPoint(60,160), CCPoint(70,190), CCPoint(100,190), CCPoint(90,160)} - local colorsolid= { 1, 1, 0, 1 } - ccDrawSolidPoly( solidvertices, 4, colorsolid ) + CCDrawPrimitives.ccDrawSolidPoly( solidvertices, 4, Color4F(1, 1, 0, 1) ) + + local array = CCPointArray:create(20) + array:addControlPoint(CCPoint(0, 0)) + array:addControlPoint(CCPoint(size.width / 2 - 30, 0)) + array:addControlPoint(CCPoint(size.width / 2 - 30, size.height - 80)) + array:addControlPoint(CCPoint(0, size.height - 80)) + array:addControlPoint(CCPoint(0, 0)) + CCDrawPrimitives.ccDrawCatmullRom( array, 5) + + CCDrawPrimitives.ccDrawCardinalSpline( array, 0,100) gl.lineWidth(1) - ccDrawColor4B(255,255,255,255) - ccPointSize(1) + CCDrawPrimitives.ccDrawColor4B(255,255,255,255) + CCDrawPrimitives.ccPointSize(1) end glNode:registerScriptDrawHandler(primitivesDraw) diff --git a/scripting/lua/cocos2dx_support/LuaCocos2d.cpp.REMOVED.git-id b/scripting/lua/cocos2dx_support/LuaCocos2d.cpp.REMOVED.git-id index cc3d273456..b621bedada 100644 --- a/scripting/lua/cocos2dx_support/LuaCocos2d.cpp.REMOVED.git-id +++ b/scripting/lua/cocos2dx_support/LuaCocos2d.cpp.REMOVED.git-id @@ -1 +1 @@ -eef4dc73121c2d01fef0f2da0914ddfeb9bb3ceb \ No newline at end of file +8afb042695f24ec222ea28a558b08174d9119ea9 \ 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 2d70fa473e..39eebdd084 100644 --- a/scripting/lua/cocos2dx_support/LuaOpengl.cpp.REMOVED.git-id +++ b/scripting/lua/cocos2dx_support/LuaOpengl.cpp.REMOVED.git-id @@ -1 +1 @@ -1bb73c663636a6565f819f3851fe763b97b30786 \ No newline at end of file +d61cb1b15a1fb49e65ea3294507317376bf182aa \ No newline at end of file diff --git a/tools/tolua++/CCDrawingPrimitives.pkg b/tools/tolua++/CCDrawingPrimitives.pkg deleted file mode 100644 index 2a46584e55..0000000000 --- a/tools/tolua++/CCDrawingPrimitives.pkg +++ /dev/null @@ -1,19 +0,0 @@ - -void ccDrawPoint(CCPoint point); -void ccDrawPoints(const CCPoint *points, unsigned int numberOfPoints); -void ccDrawLine(CCPoint origin, CCPoint destination); -void ccDrawRect(CCPoint origin, CCPoint destination); -void ccDrawSolidRect(CCPoint origin, CCPoint destination, Color4F color); -void ccDrawPoly(const CCPoint *vertices, unsigned int numOfVertices, bool closePolygon); -void ccDrawSolidPoly(const CCPoint* poli, unsigned int numberOfPoints, Color4F color); -void ccDrawCircle(const CCPoint& center, float radius, float angle, unsigned int segments, bool drawLineToCenter, float xScale = 1.0f, float yScale = 1.0f); -void ccDrawQuadBezier(CCPoint origin, CCPoint control, CCPoint destination, unsigned int segments); -void ccDrawCubicBezier(CCPoint origin, CCPoint control1, CCPoint control2, CCPoint destination, unsigned int segments); -void ccDrawCatmullRom(CCPointArray* arrayOfControlPoints, unsigned int segments); -void ccDrawCardinalSpline(CCPointArray* config, float tension, unsigned int segments); -void ccDrawColor4B(GLubyte r, GLubyte g, GLubyte b, GLubyte a); -void ccDrawColor4F(GLubyte r, GLubyte g, GLubyte b, GLubyte a); -void ccPointSize(GLfloat pointSize); - -// glew.h API: -// void glLineWidth(GLfloat width); diff --git a/tools/tolua++/Cocos2d.pkg b/tools/tolua++/Cocos2d.pkg index c357532572..d0ff69ca65 100644 --- a/tools/tolua++/Cocos2d.pkg +++ b/tools/tolua++/Cocos2d.pkg @@ -13,7 +13,6 @@ $pfile "CCEGLViewProtocol.pkg" $pfile "CCProtocols.pkg" $pfile "CCFileUtils.pkg" -$pfile "CCDrawingPrimitives.pkg" $pfile "CCAffineTransform.pkg" $pfile "CCApplication.pkg" $pfile "CCTouchDispatcher.pkg" From ab4aec0dd3d55e1822f2f7a7a5ab9c857b74317d Mon Sep 17 00:00:00 2001 From: samuele3hu Date: Sat, 27 Jul 2013 11:12:12 +0800 Subject: [PATCH 3/3] issue #2426:Replace table with spaces --- scripting/lua/cocos2dx_support/CCLuaEngine.cpp | 2 +- scripting/lua/cocos2dx_support/CCLuaEngine.h | 2 +- scripting/lua/cocos2dx_support/LuaOpengl.cpp.REMOVED.git-id | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/scripting/lua/cocos2dx_support/CCLuaEngine.cpp b/scripting/lua/cocos2dx_support/CCLuaEngine.cpp index 3d926f45a8..a5b18cb394 100644 --- a/scripting/lua/cocos2dx_support/CCLuaEngine.cpp +++ b/scripting/lua/cocos2dx_support/CCLuaEngine.cpp @@ -614,7 +614,7 @@ void LuaEngine::extendLuaObject() extendWebsocket(lua_S); extendGLNode(lua_S); extendScrollView(lua_S); - extendDrawNode(lua_S); + extendDrawNode(lua_S); _stack->clean(); } diff --git a/scripting/lua/cocos2dx_support/CCLuaEngine.h b/scripting/lua/cocos2dx_support/CCLuaEngine.h index 73abef69d6..b051508eaf 100644 --- a/scripting/lua/cocos2dx_support/CCLuaEngine.h +++ b/scripting/lua/cocos2dx_support/CCLuaEngine.h @@ -145,7 +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); + void extendDrawNode(lua_State* lua_S); private: static LuaEngine* _defaultEngine; LuaStack *_stack; diff --git a/scripting/lua/cocos2dx_support/LuaOpengl.cpp.REMOVED.git-id b/scripting/lua/cocos2dx_support/LuaOpengl.cpp.REMOVED.git-id index 39eebdd084..4d47ef34fe 100644 --- a/scripting/lua/cocos2dx_support/LuaOpengl.cpp.REMOVED.git-id +++ b/scripting/lua/cocos2dx_support/LuaOpengl.cpp.REMOVED.git-id @@ -1 +1 @@ -d61cb1b15a1fb49e65ea3294507317376bf182aa \ No newline at end of file +2efea3ea5a42e9f65134e21718f66987bfc7d7c7 \ No newline at end of file