mirror of https://github.com/axmolengine/axmol.git
* Fix issue #1546 of UILayout(#1549) and small performance boost * add test * Committing genbindings changes --------- Co-authored-by: aismann <aismann@users.noreply.github.com>
This commit is contained in:
parent
9414177ce5
commit
c389118571
|
@ -78,7 +78,7 @@ inline bool isConvex(const Vec2* verts, int count)
|
|||
|
||||
// implementation of DrawNode
|
||||
|
||||
DrawNode::DrawNode(float lineWidth) : _lineWidth(lineWidth), _defaultLineWidth(lineWidth)
|
||||
DrawNode::DrawNode(float lineWidth) : _lineWidth(lineWidth), _defaultLineWidth(lineWidth), _isConvex(false)
|
||||
{
|
||||
_blendFunc = BlendFunc::ALPHA_PREMULTIPLIED;
|
||||
#if AX_ENABLE_CACHE_TEXTURE_DATA
|
||||
|
@ -400,7 +400,9 @@ void DrawNode::drawCircle(const Vec2& center,
|
|||
}
|
||||
if (_lineWidth > threshold)
|
||||
{
|
||||
_isConvex = true;
|
||||
drawPolygon(vertices, segments, Color4B(1.0f, 0.0f, 0.0f, 1.0f), _lineWidth/4, color);
|
||||
_isConvex = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -635,7 +637,7 @@ void DrawNode::drawPolygon(const Vec2* verts,
|
|||
V2F_C4B_T2F_Triangle* triangles = (V2F_C4B_T2F_Triangle*)(_bufferTriangle + _bufferCountTriangle);
|
||||
V2F_C4B_T2F_Triangle* cursor = triangles;
|
||||
|
||||
if (count >= 3 && !isConvex(verts, count))
|
||||
if (!_isConvex && count >= 3 && !isConvex(verts, count))
|
||||
{
|
||||
std::vector<p2t::Point> p2pointsStorage;
|
||||
p2pointsStorage.reserve(count);
|
||||
|
@ -751,7 +753,9 @@ void DrawNode::drawSolidRect(const Vec2& origin, const Vec2& destination, const
|
|||
|
||||
void DrawNode::drawSolidPoly(const Vec2* poli, unsigned int numberOfPoints, const Color4B& color)
|
||||
{
|
||||
_isConvex = true; // Fix issue #1546 of UILayout(#1549)
|
||||
drawPolygon(poli, numberOfPoints, color, 0.0, Color4B());
|
||||
_isConvex = false;
|
||||
}
|
||||
|
||||
void DrawNode::drawPie(const Vec2& center,
|
||||
|
@ -843,8 +847,9 @@ void DrawNode::drawSolidCircle(const Vec2& center,
|
|||
vertices[i].x = j;
|
||||
vertices[i].y = k;
|
||||
}
|
||||
|
||||
_isConvex = true;
|
||||
drawPolygon(vertices, segments, fillColor, borderWidth, borderColor);
|
||||
_isConvex = false;
|
||||
}
|
||||
|
||||
void DrawNode::drawSolidCircle(const Vec2& center,
|
||||
|
|
|
@ -397,6 +397,8 @@ public:
|
|||
// Get CocosStudio guide lines width.
|
||||
float getLineWidth();
|
||||
|
||||
void setIsConvex(bool isConvex) { _isConvex = isConvex; }; // Set backwards compatible with cocos2dx/axmol 2.0
|
||||
|
||||
/**
|
||||
* When isolated is set, the position of the node is no longer affected by parent nodes.
|
||||
* Which means it will be drawn just like a root node.
|
||||
|
@ -455,6 +457,8 @@ protected:
|
|||
|
||||
ax::any_buffer _abuf;
|
||||
|
||||
bool _isConvex = true;
|
||||
|
||||
private:
|
||||
AX_DISALLOW_COPY_AND_ASSIGN(DrawNode);
|
||||
};
|
||||
|
|
|
@ -53302,6 +53302,56 @@ int lua_ax_base_DrawNode_getLineWidth(lua_State* tolua_S)
|
|||
|
||||
return 0;
|
||||
}
|
||||
int lua_ax_base_DrawNode_setIsConvex(lua_State* tolua_S)
|
||||
{
|
||||
int argc = 0;
|
||||
ax::DrawNode* cobj = nullptr;
|
||||
bool ok = true;
|
||||
|
||||
#if _AX_DEBUG >= 1
|
||||
tolua_Error tolua_err;
|
||||
#endif
|
||||
|
||||
|
||||
#if _AX_DEBUG >= 1
|
||||
if (!tolua_isusertype(tolua_S,1,"ax.DrawNode",0,&tolua_err)) goto tolua_lerror;
|
||||
#endif
|
||||
|
||||
cobj = (ax::DrawNode*)tolua_tousertype(tolua_S,1,0);
|
||||
|
||||
#if _AX_DEBUG >= 1
|
||||
if (!cobj)
|
||||
{
|
||||
tolua_error(tolua_S,"invalid 'cobj' in function 'lua_ax_base_DrawNode_setIsConvex'", nullptr);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
argc = lua_gettop(tolua_S)-1;
|
||||
if (argc == 1)
|
||||
{
|
||||
bool arg0;
|
||||
|
||||
ok &= luaval_to_boolean(tolua_S, 2,&arg0, "ax.DrawNode:setIsConvex");
|
||||
if(!ok)
|
||||
{
|
||||
tolua_error(tolua_S,"invalid arguments in function 'lua_ax_base_DrawNode_setIsConvex'", nullptr);
|
||||
return 0;
|
||||
}
|
||||
cobj->setIsConvex(arg0);
|
||||
lua_settop(tolua_S, 1);
|
||||
return 1;
|
||||
}
|
||||
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "ax.DrawNode:setIsConvex",argc, 1);
|
||||
return 0;
|
||||
|
||||
#if _AX_DEBUG >= 1
|
||||
tolua_lerror:
|
||||
tolua_error(tolua_S,"#ferror in function 'lua_ax_base_DrawNode_setIsConvex'.",&tolua_err);
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
int lua_ax_base_DrawNode_setIsolated(lua_State* tolua_S)
|
||||
{
|
||||
int argc = 0;
|
||||
|
@ -53530,6 +53580,7 @@ int lua_register_ax_base_DrawNode(lua_State* tolua_S)
|
|||
tolua_function(tolua_S,"setBlendFunc",lua_ax_base_DrawNode_setBlendFunc);
|
||||
tolua_function(tolua_S,"setLineWidth",lua_ax_base_DrawNode_setLineWidth);
|
||||
tolua_function(tolua_S,"getLineWidth",lua_ax_base_DrawNode_getLineWidth);
|
||||
tolua_function(tolua_S,"setIsConvex",lua_ax_base_DrawNode_setIsConvex);
|
||||
tolua_function(tolua_S,"setIsolated",lua_ax_base_DrawNode_setIsolated);
|
||||
tolua_function(tolua_S,"isIsolated",lua_ax_base_DrawNode_isIsolated);
|
||||
tolua_function(tolua_S,"create", lua_ax_base_DrawNode_create);
|
||||
|
|
|
@ -2431,6 +2431,7 @@ int register_all_ax_base(lua_State* tolua_S);
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif // __ax_base_h__
|
||||
|
|
|
@ -33,7 +33,7 @@ using namespace std;
|
|||
DrawPrimitivesTests::DrawPrimitivesTests()
|
||||
{
|
||||
ADD_TEST_CASE(DrawNodeTest);
|
||||
ADD_TEST_CASE(Issue11942Test);
|
||||
ADD_TEST_CASE(DrawNodeBackwardsAPITest);
|
||||
ADD_TEST_CASE(BetterCircleRendering);
|
||||
ADD_TEST_CASE(DrawNodeTestNewFeature1);
|
||||
ADD_TEST_CASE(Issue829Test);
|
||||
|
@ -219,42 +219,56 @@ string DrawNodeTest::subtitle() const
|
|||
//
|
||||
// Issue11942Test
|
||||
//
|
||||
Issue11942Test::Issue11942Test()
|
||||
DrawNodeBackwardsAPITest::DrawNodeBackwardsAPITest()
|
||||
{
|
||||
// DrawNode 0 ------------------------------------------
|
||||
auto draw0 = DrawNode::create();
|
||||
addChild(draw0, 10);
|
||||
float o = 80;
|
||||
float w = 20;
|
||||
float h = 50;
|
||||
|
||||
// draw a circle thickness 10
|
||||
draw0->setLineWidth(10);
|
||||
draw0->drawCircle(VisibleRect::center() - Vec2(140.0f, 40.0f), 50, AX_DEGREES_TO_RADIANS(90), 30, false,
|
||||
Color4F(AXRANDOM_0_1(), AXRANDOM_0_1(), AXRANDOM_0_1(), 1.0f));
|
||||
draw0->setLineWidth(1); // thickness 10 will replaced with thickness 1 (also for all 'same' draw commands before!)
|
||||
draw0->drawCircle(VisibleRect::center() - Vec2(140.0f, -40.0f), 50, AX_DEGREES_TO_RADIANS(90), 30, false,
|
||||
Color4F(AXRANDOM_0_1(), AXRANDOM_0_1(), AXRANDOM_0_1(), 1.0f));
|
||||
auto drawNode1 = DrawNode::create();
|
||||
addChild(drawNode1);
|
||||
drawNode1->setPosition(-40, 20);
|
||||
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
Vec2 vertices[4];
|
||||
drawNode1->setScale(0.5);
|
||||
Color4F color;
|
||||
for (int iy = 0; iy < 5; iy++)
|
||||
{
|
||||
x = 0;
|
||||
for (int ix = 0; ix < 13; ix++)
|
||||
{
|
||||
vertices[0] = Vec2(x + o + w, y + o - h);
|
||||
vertices[1] = Vec2(x + o + w * 2, y + o);
|
||||
vertices[2] = Vec2(x + o + w * 2 + h, y + o + w);
|
||||
vertices[3] = Vec2(x + o + w * 2, y + o + w * 2);
|
||||
|
||||
// DrawNode 1 ------------------------------------------
|
||||
auto draw1 = DrawNode::create();
|
||||
addChild(draw1, 10);
|
||||
|
||||
// draw a second circle thickness 1
|
||||
draw1->setLineWidth(1);
|
||||
draw1->drawCircle(VisibleRect::center() + Vec2(140.0f, 40.0f), 50, AX_DEGREES_TO_RADIANS(90), 30, false,
|
||||
Color4F(AXRANDOM_0_1(), AXRANDOM_0_1(), AXRANDOM_0_1(), 1.0f));
|
||||
draw1->setLineWidth(20); // thickness 1 will replaced with thickness 10 (also for all 'same' draw commands before!)
|
||||
draw1->drawCircle(VisibleRect::center() + Vec2(140.0f, -40.0f), 50, AX_DEGREES_TO_RADIANS(90), 30, false,
|
||||
Color4F(AXRANDOM_0_1(), AXRANDOM_0_1(), AXRANDOM_0_1(), 1.0f));
|
||||
if (AXRANDOM_0_1() > 0.5f)
|
||||
{
|
||||
drawNode1->setIsConvex(true);
|
||||
color = Color4F::YELLOW;
|
||||
}
|
||||
else
|
||||
{
|
||||
drawNode1->setIsConvex(false); // default value!
|
||||
color = Color4F::ORANGE;
|
||||
}
|
||||
drawNode1->drawPolygon(vertices, 4, Color4F(0.7f, 0.7f, 0.7f, 0.5f), 1, color);
|
||||
x += 70;
|
||||
}
|
||||
y += 80;
|
||||
}
|
||||
}
|
||||
|
||||
string Issue11942Test::title() const
|
||||
string DrawNodeBackwardsAPITest::title() const
|
||||
{
|
||||
return "GitHub Issue #11942 (axmol #137)";
|
||||
return "API backwards compatible test";
|
||||
}
|
||||
|
||||
string Issue11942Test::subtitle() const
|
||||
string DrawNodeBackwardsAPITest::subtitle() const
|
||||
{
|
||||
return "setLineWidth() change the WHOLE DrawNode object 'line with'";
|
||||
return "YELLOW=cocos2dx/axmol <=2.0 ORANGE=axmol >2.0";
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -262,7 +276,7 @@ string Issue11942Test::subtitle() const
|
|||
//
|
||||
BetterCircleRendering::BetterCircleRendering()
|
||||
{
|
||||
//Add lines to see the correct "scale of the 'rings'" changing the window size
|
||||
// Add lines to see the correct "scale of the 'rings'" changing the window size
|
||||
|
||||
auto draw = DrawNode::create();
|
||||
draw->setLineWidth(1);
|
||||
|
@ -298,7 +312,8 @@ void BetterCircleRendering::changeThreshold(ax::Ref* pSender, ax::ui::Slider::Ev
|
|||
{
|
||||
ax::ui::Slider* sliderThreshold = dynamic_cast<ax::ui::Slider*>(pSender);
|
||||
threshold = static_cast<float>(sliderThreshold->getPercent());
|
||||
_thresholdLabel->setString("drawCircle(pos, radius, ..., segments, ..., color, " + Value(threshold).asString() + ")");
|
||||
_thresholdLabel->setString("drawCircle(pos, radius, ..., segments, ..., color, " + Value(threshold).asString() +
|
||||
")");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -315,7 +330,7 @@ void BetterCircleRendering::initSliders()
|
|||
slider->addEventListener(AX_CALLBACK_2(BetterCircleRendering::changeThreshold, this));
|
||||
|
||||
auto ttfConfig = TTFConfig("fonts/arial.ttf", 8);
|
||||
_thresholdLabel = Label::createWithTTF(ttfConfig, "drawCircle(pos, radius, ..., segments, ..., color, 0)");
|
||||
_thresholdLabel = Label::createWithTTF(ttfConfig, "drawCircle(pos, radius, ..., segments, ..., color, 0)");
|
||||
addChild(_thresholdLabel, 20);
|
||||
_thresholdLabel->setPosition(Vec2(vsize.width / 2, vsize.height / 6 + 15));
|
||||
|
||||
|
@ -336,8 +351,8 @@ void BetterCircleRendering::initSliders()
|
|||
addChild(sliderLineWidth, 20);
|
||||
}
|
||||
|
||||
void BetterCircleRendering::update(float dt)
|
||||
{
|
||||
void BetterCircleRendering::update(float dt)
|
||||
{
|
||||
drawNode->clear();
|
||||
drawNode->setLineWidth(lineWidth); // value from the slider
|
||||
|
||||
|
@ -353,10 +368,10 @@ void BetterCircleRendering::initSliders()
|
|||
}
|
||||
drawNode->drawCircle(VisibleRect::center() - Vec2(120.0f, 0.0f), 60, AX_DEGREES_TO_RADIANS(90), 36, false, color,
|
||||
threshold);
|
||||
}
|
||||
}
|
||||
|
||||
string BetterCircleRendering::title() const
|
||||
{
|
||||
{
|
||||
return "Rendering drawCircle";
|
||||
}
|
||||
|
||||
|
@ -365,7 +380,6 @@ string BetterCircleRendering::subtitle() const
|
|||
return "Green: smoother rendering; Red: faster but badly rendering";
|
||||
}
|
||||
|
||||
|
||||
DrawNodeTestNewFeature1::DrawNodeTestNewFeature1()
|
||||
{
|
||||
drawNode = DrawNode::create();
|
||||
|
@ -3937,8 +3951,7 @@ Issue1319Test::Issue1319Test()
|
|||
{148.671875f, 216.566895f}, {148.681152f, 216.764160f}, {148.693359f, 216.961670f}, {148.701660f, 217.097168f},
|
||||
{148.709473f, 217.235107f}, {148.720703f, 217.371826f}, {148.739746f, 217.504150f}, {148.770996f, 217.628906f},
|
||||
{148.817383f, 217.741943f}, {148.883301f, 217.840576f}, {148.973145f, 217.920898f}, {149.090332f, 217.979736f},
|
||||
{149.239258f, 218.013916f}
|
||||
};
|
||||
{149.239258f, 218.013916f}};
|
||||
|
||||
Vec2 vertices23[] = {
|
||||
{289.365723f, 227.168457f}, {289.388672f, 227.053467f}, {289.411621f, 226.938965f}, {289.435059f, 226.824219f},
|
||||
|
@ -4143,8 +4156,7 @@ Issue1319Test::Issue1319Test()
|
|||
{286.836914f, 230.352539f}, {287.020996f, 230.461182f}, {287.266113f, 230.535645f}, {287.574219f, 230.580078f},
|
||||
{287.949219f, 230.598145f}, {288.163574f, 230.299805f}, {288.369141f, 229.996338f}, {288.563477f, 229.685059f},
|
||||
{288.743164f, 229.365234f}, {288.905762f, 229.034912f}, {289.048828f, 228.692383f}, {289.169922f, 228.336670f},
|
||||
{289.265137f, 227.965332f}, {289.332520f, 227.577148f}, {289.369629f, 227.170410f}
|
||||
};
|
||||
{289.265137f, 227.965332f}, {289.332520f, 227.577148f}, {289.369629f, 227.170410f}};
|
||||
|
||||
Vec2 vertices24[] = {
|
||||
{45.750000f, 144.375000f}, {75.500000f, 136.875000f}, {75.500000f, 159.125000f}, {100.250000f, 161.375000f},
|
||||
|
@ -4877,7 +4889,8 @@ Issue1319Test::Issue1319Test()
|
|||
2.0f, Color4F::WHITE);
|
||||
|
||||
drawNode[0]->setPosition(Vec2(-30, -20));
|
||||
drawNode[0]->drawPolygon(vertices24, sizeof(vertices24) / sizeof(vertices24[0]), Color4F::RED, 0.3f, Color4F::GREEN);
|
||||
drawNode[0]->drawPolygon(vertices24, sizeof(vertices24) / sizeof(vertices24[0]), Color4F::RED, 0.3f,
|
||||
Color4F::GREEN);
|
||||
|
||||
drawNode[1]->drawPolygon(vertices1, sizeof(vertices1) / sizeof(vertices1[0]), Color4F::YELLOW, 0.3f, Color4F::RED);
|
||||
drawNode[1]->drawPolygon(vertices2, sizeof(vertices2) / sizeof(vertices2[0]), Color4F::YELLOW, 0.3f, Color4F::RED);
|
||||
|
@ -4892,7 +4905,8 @@ Issue1319Test::Issue1319Test()
|
|||
Color4F::RED);
|
||||
drawNode[1]->drawPolygon(vertices11, sizeof(vertices11) / sizeof(vertices11[0]), Color4F::YELLOW, 0.3f,
|
||||
Color4F::RED);
|
||||
drawNode[1]->drawPolygon(vertices12, sizeof(vertices12) / sizeof(vertices12[0]), Color4F::WHITE, 0.3f, Color4F::RED);
|
||||
drawNode[1]->drawPolygon(vertices12, sizeof(vertices12) / sizeof(vertices12[0]), Color4F::WHITE, 0.3f,
|
||||
Color4F::RED);
|
||||
drawNode[1]->drawPolygon(vertices13, sizeof(vertices13) / sizeof(vertices13[0]), Color4F::YELLOW, 0.3f,
|
||||
Color4F::RED);
|
||||
drawNode[1]->drawPolygon(vertices14, sizeof(vertices14) / sizeof(vertices14[0]), Color4F::YELLOW, 0.3f,
|
||||
|
|
|
@ -48,12 +48,12 @@ public:
|
|||
virtual std::string subtitle() const override;
|
||||
};
|
||||
|
||||
class Issue11942Test : public DrawPrimitivesBaseTest
|
||||
class DrawNodeBackwardsAPITest : public DrawPrimitivesBaseTest
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(Issue11942Test);
|
||||
CREATE_FUNC(DrawNodeBackwardsAPITest);
|
||||
|
||||
Issue11942Test();
|
||||
DrawNodeBackwardsAPITest();
|
||||
|
||||
virtual std::string title() const override;
|
||||
virtual std::string subtitle() const override;
|
||||
|
|
Loading…
Reference in New Issue