mirror of https://github.com/axmolengine/axmol.git
Merge pull request #3290 from samuele3hu/DrawNode
issue #2426:Add Drawprimitives and DrawNode lua binding and modify releated test sample
This commit is contained in:
commit
301f5218ff
|
@ -1,8 +1,8 @@
|
|||
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()
|
||||
|
@ -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)
|
||||
|
@ -149,9 +158,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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -1 +1 @@
|
|||
ab4c02a68cfeccde64ff6b990aba6925d8e7787d
|
||||
8afb042695f24ec222ea28a558b08174d9119ea9
|
|
@ -1 +1 @@
|
|||
d515328a92ac0cf64fb7b1ee9d1b0b200d36c473
|
||||
2efea3ea5a42e9f65134e21718f66987bfc7d7c7
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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();
|
||||
};
|
|
@ -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);
|
|
@ -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"
|
||||
|
@ -86,3 +85,4 @@ $pfile "CCControlPotentiometer.pkg"
|
|||
$pfile "CCControlStepper.pkg"
|
||||
$pfile "CCEditBox.pkg"
|
||||
$pfile "CCInteger.pkg"
|
||||
$pfile "CCDrawNode.pkg"
|
||||
|
|
|
@ -198,6 +198,7 @@ local CCObjectTypes = {
|
|||
"CCControlSwitch",
|
||||
"CCEditBox",
|
||||
"CCInteger",
|
||||
"CCDrawNode",
|
||||
}
|
||||
|
||||
-- register CCObject types
|
||||
|
|
Loading…
Reference in New Issue