issue #2426:Add Drawprimitives.lua and Drawprimitives lua test sample

This commit is contained in:
samuele3hu 2013-07-27 00:28:06 +08:00
parent 6b9c7d4ade
commit 016593bd0e
9 changed files with 92 additions and 3 deletions

View File

@ -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

View File

@ -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

View File

@ -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;

View File

@ -1 +1 @@
d2e1fc14f4c663f31bc92cb89e099efdbfc986a2
785c7bd17e5ccba8b2d5330e4f310e52b287a6b6

View File

@ -1 +1 @@
d515328a92ac0cf64fb7b1ee9d1b0b200d36c473
1bb73c663636a6565f819f3851fe763b97b30786

View File

@ -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);

View File

@ -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();
};

View File

@ -86,3 +86,4 @@ $pfile "CCControlPotentiometer.pkg"
$pfile "CCControlStepper.pkg"
$pfile "CCEditBox.pkg"
$pfile "CCInteger.pkg"
$pfile "CCDrawNode.pkg"

View File

@ -198,6 +198,7 @@ local CCObjectTypes = {
"CCControlSwitch",
"CCEditBox",
"CCInteger",
"CCDrawNode",
}
-- register CCObject types