mirror of https://github.com/axmolengine/axmol.git
Fix cc.DrawNode.drawPoly
This commit is contained in:
parent
ade1d0ef8d
commit
a3c2904e7f
|
@ -4185,70 +4185,6 @@ bool js_cocos2dx_CCTMXLayer_getTileFlagsAt(JSContext *cx, uint32_t argc, jsval *
|
|||
return false;
|
||||
}
|
||||
|
||||
//#pragma mark - DrawNode
|
||||
|
||||
// Arguments: Array of points, fill color (Color4F), width(float), border color (Color4F)
|
||||
// Ret value: void
|
||||
bool js_cocos2dx_CCDrawNode_drawPolygon(JSContext *cx, uint32_t argc, jsval *vp)
|
||||
{
|
||||
|
||||
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
|
||||
JS::RootedObject obj(cx, args.thisv().toObjectOrNull());
|
||||
js_proxy_t *proxy = jsb_get_js_proxy(obj);
|
||||
DrawNode* cobj = (DrawNode*)(proxy ? proxy->ptr : NULL);
|
||||
TEST_NATIVE_OBJECT(cx, cobj)
|
||||
|
||||
if ( argc == 4) {
|
||||
bool ok = true;
|
||||
JS::RootedObject argArray(cx);
|
||||
Color4F argFillColor = Color4F(0.0f, 0.0f, 0.0f, 0.0f);
|
||||
double argWidth = 0.0;
|
||||
Color4F argBorderColor = Color4F(0.0f, 0.0f, 0.0f, 0.0f);
|
||||
|
||||
// Points
|
||||
ok &= JS_ValueToObject(cx, args.get(0), &argArray);
|
||||
JSB_PRECONDITION2( (argArray && JS_IsArrayObject(cx, argArray)) , cx, false, "Vertex should be anArray object");
|
||||
|
||||
// Color 4F
|
||||
ok &= jsval_to_cccolor4f(cx, args.get(1), &argFillColor);
|
||||
|
||||
// Width
|
||||
ok &= JS::ToNumber( cx, args.get(2), &argWidth );
|
||||
|
||||
// Color Border (4F)
|
||||
ok &= jsval_to_cccolor4f(cx, args.get(3), &argBorderColor);
|
||||
|
||||
JSB_PRECONDITION2(ok, cx, false, "Error parsing arguments");
|
||||
|
||||
{
|
||||
uint32_t l;
|
||||
if( ! JS_GetArrayLength(cx, argArray, &l) )
|
||||
return false;
|
||||
|
||||
Point* verts = new Point[ l ];
|
||||
Point p;
|
||||
|
||||
for( uint32_t i=0; i<l; i++ ) {
|
||||
JS::RootedValue pointvp(cx);
|
||||
ok &= JS_GetElement(cx, argArray, i, &pointvp);
|
||||
JSB_PRECONDITION2(ok, cx, false, "JS_GetElement fails.");
|
||||
|
||||
ok &= jsval_to_ccpoint(cx, pointvp, &p);
|
||||
JSB_PRECONDITION2(ok, cx, false, "Error processing arguments");
|
||||
verts[i] = p;
|
||||
}
|
||||
|
||||
cobj->drawPolygon(verts, l, argFillColor, argWidth, argBorderColor);
|
||||
CC_SAFE_DELETE_ARRAY(verts);
|
||||
}
|
||||
args.rval().setUndefined();
|
||||
return true;
|
||||
}
|
||||
|
||||
JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 4);
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool jsval_to_string_vector(JSContext* cx, jsval v, std::vector<std::string>& ret) {
|
||||
JS::RootedObject jsobj(cx);
|
||||
bool ok = JS_ValueToObject( cx, JS::RootedValue(cx, v), &jsobj );
|
||||
|
@ -6228,10 +6164,9 @@ void register_cocos2dx_js_core(JSContext* cx, JS::HandleObject global)
|
|||
tmpObj.set(jsb_cocos2d_TMXLayer_prototype);
|
||||
JS_DefineFunction(cx, tmpObj, "getTileFlagsAt", js_cocos2dx_CCTMXLayer_getTileFlagsAt, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT);
|
||||
|
||||
tmpObj.set(jsb_cocos2d_DrawNode_prototype);
|
||||
JS_DefineFunction(cx, tmpObj, "drawPoly", js_cocos2dx_CCDrawNode_drawPolygon, 4, JSPROP_ENUMERATE | JSPROP_PERMANENT);
|
||||
|
||||
tmpObj.set(jsb_cocos2d_Texture2D_prototype);
|
||||
JS_DefineFunction(cx, tmpObj, "retain", js_cocos2dx_retain, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT);
|
||||
JS_DefineFunction(cx, tmpObj, "release", js_cocos2dx_release, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT);
|
||||
JS_DefineFunction(cx, tmpObj, "setTexParameters", js_cocos2dx_CCTexture2D_setTexParameters, 4, JSPROP_ENUMERATE | JSPROP_PERMANENT);
|
||||
|
||||
tmpObj.set(jsb_cocos2d_Menu_prototype);
|
||||
|
|
|
@ -1774,6 +1774,9 @@ cc.cardinalSplineAt = function (p0, p1, p2, p3, tension, t) {
|
|||
};
|
||||
|
||||
cc._DrawNode = cc.DrawNode;
|
||||
cc._DrawNode.prototype.drawPoly = function (verts, fillColor, borderWidth, borderColor) {
|
||||
cc._DrawNode.prototype.drawPolygon.call(this, verts, verts.length, fillColor, borderWidth, borderColor);
|
||||
}
|
||||
cc.DrawNode = cc._DrawNode.extend({
|
||||
_drawColor: cc.color(255, 255, 255, 255),
|
||||
_lineWidth: 1,
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit d51c2fce9065101387db2bd850bee7726bcad425
|
||||
Subproject commit 2318a1593d2d490a3860179acaf81a1bf867a36b
|
|
@ -45,7 +45,7 @@ skip = Node::[^setPosition$ setGLServerState description getUserObject .*UserDat
|
|||
NodeGrid::[setGrid],
|
||||
SpriteBatchNode::[getDescendants],
|
||||
MotionStreak::[draw update],
|
||||
DrawNode::[drawPolygon listenBackToForeground],
|
||||
DrawNode::[drawPoly$ listenBackToForeground],
|
||||
Director::[getAccelerometer getProjection getFrustum getRenderer getConsole getCocos2dThreadId],
|
||||
Layer.*::[didAccelerate keyPressed keyReleased],
|
||||
Menu.*::[.*Target getSubItems create initWithItems alignItemsInRows alignItemsInColumns],
|
||||
|
|
Loading…
Reference in New Issue