From 349a231c2d9dcb1d22a0a288cd731d8c5aad8246 Mon Sep 17 00:00:00 2001 From: eismpesd Date: Fri, 28 Jun 2024 08:41:34 +0200 Subject: [PATCH 1/3] . --- .../DrawNodeEx/src/DrawNodeEx/DrawNodeEx.cpp | 177 ++++++++---------- .../DrawNodeEx/src/DrawNodeEx/DrawNodeEx.h | 15 +- .../Source/DrawNodeExTest/DrawNodeExTest.cpp | 86 +++++---- .../Source/DrawNodeExTest/DrawNodeExTest.h | 7 +- 4 files changed, 136 insertions(+), 149 deletions(-) diff --git a/extensions/DrawNodeEx/src/DrawNodeEx/DrawNodeEx.cpp b/extensions/DrawNodeEx/src/DrawNodeEx/DrawNodeEx.cpp index 147d94d8327c..76972c72d933 100644 --- a/extensions/DrawNodeEx/src/DrawNodeEx/DrawNodeEx.cpp +++ b/extensions/DrawNodeEx/src/DrawNodeEx/DrawNodeEx.cpp @@ -47,7 +47,6 @@ NS_AX_EXT_BEGIN - /** Is a polygon convex? * @param verts A pointer to point coordinates. * @param count The number of verts measured in points. @@ -149,16 +148,16 @@ DrawNodeEx::~DrawNodeEx() { AX_SAFE_FREE(_bufferTriangle); -#if defined(DRAWNODE_DRAW_LINE_POINT) +//#if defined(AX_ENABLE_DRAWNODE_DRAW_LINE_POINT) AX_SAFE_FREE(_bufferPoint); AX_SAFE_FREE(_bufferLine); -#endif +//#endif freeShaderInternal(_customCommandTriangle); -#if defined(DRAWNODE_DRAW_LINE_POINT) +//#if defined(AX_ENABLE_DRAWNODE_DRAW_LINE_POINT) freeShaderInternal(_customCommandPoint); freeShaderInternal(_customCommandLine); -#endif +//#endif } DrawNodeEx* DrawNodeEx::create(float defaultLineWidth) @@ -191,7 +190,7 @@ void DrawNodeEx::ensureCapacityTriangle(int count) } } -#if defined(DRAWNODE_DRAW_LINE_POINT) +//#if defined(AX_ENABLE_DRAWNODE_DRAW_LINE_POINT) void DrawNodeEx::ensureCapacityPoint(int count) { AXASSERT(count >= 0, "capacity must be >= 0"); @@ -221,7 +220,7 @@ void DrawNodeEx::ensureCapacityLine(int count) _customCommandLine.updateVertexBuffer(_bufferLine, _bufferCapacityLine * sizeof(V2F_C4B_T2F)); } } -#endif +//#endif bool DrawNodeEx::init() { @@ -230,7 +229,7 @@ bool DrawNodeEx::init() ensureCapacityTriangle(512); _dirtyTriangle = true; -#if defined(DRAWNODE_DRAW_LINE_POINT) +#if defined(AX_ENABLE_DRAWNODE_DRAW_LINE_POINT) ensureCapacityPoint(64); ensureCapacityLine(256); _dirtyLine = true; @@ -244,7 +243,7 @@ void DrawNodeEx::updateShader() { updateShaderInternal(_customCommandTriangle, backend::ProgramType::POSITION_COLOR_LENGTH_TEXTURE, CustomCommand::DrawType::ARRAY, CustomCommand::PrimitiveType::TRIANGLE); -#if defined(DRAWNODE_DRAW_LINE_POINT) +#if defined(AX_ENABLE_DRAWNODE_DRAW_LINE_POINT) updateShaderInternal(_customCommandPoint, backend::ProgramType::POSITION_COLOR_TEXTURE_AS_POINTSIZE, CustomCommand::DrawType::ARRAY, CustomCommand::PrimitiveType::POINT); @@ -324,7 +323,7 @@ void DrawNodeEx::draw(Renderer* renderer, const Mat4& transform, uint32_t flags) _customCommandTriangle.init(_globalZOrder); renderer->addCommand(&_customCommandTriangle); } -#if defined(DRAWNODE_DRAW_LINE_POINT) +#if defined(AX_ENABLE_DRAWNODE_DRAW_LINE_POINT) if (_bufferCountPoint) { updateBlendState(_customCommandPoint); @@ -345,16 +344,16 @@ void DrawNodeEx::draw(Renderer* renderer, const Mat4& transform, uint32_t flags) void DrawNodeEx::drawPoint(const Vec2& position, const float pointSize, const Color4B& color) { -#if defined(DRAWNODE_DRAW_LINE_POINT) +#if defined(AX_ENABLE_DRAWNODE_DRAW_LINE_POINT) if (_drawOrder == true) { #endif drawSolidCircle(position, pointSize, 0.f, 12, 1.f, 1.f, color, 0.f, color); -#if defined(DRAWNODE_DRAW_LINE_POINT) +#if defined(AX_ENABLE_DRAWNODE_DRAW_LINE_POINT) return; } #endif -#if defined(DRAWNODE_DRAW_LINE_POINT) +#if defined(AX_ENABLE_DRAWNODE_DRAW_LINE_POINT) ensureCapacityPoint(1); V2F_C4B_T2F* point = _bufferPoint + _bufferCountPoint; @@ -377,7 +376,7 @@ void DrawNodeEx::drawPoints(const Vec2* position, const float pointSize, const Color4B& color) { -#if defined(DRAWNODE_DRAW_LINE_POINT) +#if defined(AX_ENABLE_DRAWNODE_DRAW_LINE_POINT) if (_drawOrder == true) { #endif @@ -385,11 +384,11 @@ void DrawNodeEx::drawPoints(const Vec2* position, { drawSolidCircle(position[i], pointSize, 0.f, 12, 1.f, 1.f, color, 0.f, color); } -#if defined(DRAWNODE_DRAW_LINE_POINT) +#if defined(AX_ENABLE_DRAWNODE_DRAW_LINE_POINT) return; } #endif -#if defined(DRAWNODE_DRAW_LINE_POINT) +#if defined(AX_ENABLE_DRAWNODE_DRAW_LINE_POINT) ensureCapacityPoint(numberOfPoints); V2F_C4B_T2F* point = _bufferPoint + _bufferCountPoint; @@ -415,16 +414,16 @@ void DrawNodeEx::drawLine(const Vec2& origin, const Vec2& destination, const Col } else { -#if defined(DRAWNODE_DRAW_LINE_POINT) +#if defined(AX_ENABLE_DRAWNODE_DRAW_LINE_POINT) if (_drawOrder == true) { #endif drawSegment(origin, destination, thickness / 3, color); -#if defined(DRAWNODE_DRAW_LINE_POINT) +#if defined(AX_ENABLE_DRAWNODE_DRAW_LINE_POINT) return; } #endif -#if defined(DRAWNODE_DRAW_LINE_POINT) +#if defined(AX_ENABLE_DRAWNODE_DRAW_LINE_POINT) Vec2 line[2] = { origin, destination }; Vec2* _vertices = transform(line, 2); @@ -476,16 +475,16 @@ void DrawNodeEx::drawPoly(const Vec2* poli, } else { -#if defined(DRAWNODE_DRAW_LINE_POINT) +#if defined(AX_ENABLE_DRAWNODE_DRAW_LINE_POINT) if (_drawOrder == true) { #endif _drawPolygon(poli, numberOfPoints, Color4B::TRANSPARENT, thickness / 3, color, closePolygon); -#if defined(DRAWNODE_DRAW_LINE_POINT) +#if defined(AX_ENABLE_DRAWNODE_DRAW_LINE_POINT) return; } #endif -#if defined(DRAWNODE_DRAW_LINE_POINT) +#if defined(AX_ENABLE_DRAWNODE_DRAW_LINE_POINT) Vec2* _vertices = transform(poli, numberOfPoints); unsigned int vertex_count; @@ -762,7 +761,7 @@ void DrawNodeEx::drawRect(const Vec2& p1, } } -void DrawNodeEx::drawSegment(const Vec2& from, const Vec2& to, float radius, const Color4B& color, DrawNodeEx::EndType endType) +void DrawNodeEx::drawSegment(const Vec2& from, const Vec2& to, float radius, const Color4B& color, DrawNodeEx::EndType etStart, DrawNodeEx::EndType etEnd) { Vec2 line[2] = { from, to }; Vec2* _vertices = transform(line, 2); @@ -790,9 +789,9 @@ void DrawNodeEx::drawSegment(const Vec2& from, const Vec2& to, float radius, con // Color4B col = color; - switch (endType) + // End + switch (etEnd) { - case DrawNodeEx::EndType::Butt: break; @@ -841,8 +840,8 @@ void DrawNodeEx::drawSegment(const Vec2& from, const Vec2& to, float radius, con {v5, col, Tex2F(n)}, }; - // End - switch (endType) + // Start + switch (etStart) { case DrawNodeEx::EndType::Butt: break; @@ -938,11 +937,19 @@ void DrawNodeEx::drawPie(const Vec2& center, DrawMode drawMode, float thickness) { +#define DEGREES 360 + bool _circle = false; + // not a real line! if (startAngle == endAngle) return; -#define DEGREES 360 + // Its a circle? + if (MAX((startAngle - endAngle), (endAngle-startAngle)) == DEGREES) + { + _circle = true; + } + const float coef = 2.0f * (float)M_PI / DEGREES; Vec2* vertices = _abuf.get(DEGREES + 2); @@ -953,6 +960,7 @@ void DrawNodeEx::drawPie(const Vec2& center, if (startAngle > endAngle) { + // std::swap(endAngle, startAngle); int tmp = endAngle; endAngle = startAngle; startAngle = tmp; @@ -976,13 +984,24 @@ void DrawNodeEx::drawPie(const Vec2& center, { case DrawMode::Fill: vertices[n++] = center; + if (_circle) + { + this->drawSolidCircle(center, radius, 0, 36, scaleX, scaleY, fillColor, thickness, borderColor); + break; + } _drawPolygon(vertices, n, fillColor, thickness, borderColor, true); break; case DrawMode::Outline: vertices[n++] = center; + if (_circle) + { + this->drawCircle(center, radius, 0, 36, false, scaleX, scaleY, fillColor, thickness); + break; + } _drawPolygon(vertices, n, Color4B::TRANSPARENT, thickness, borderColor, true); break; case DrawMode::Line: + vertices[n++] = center; _drawPolygon(vertices, n, Color4B::TRANSPARENT, thickness, borderColor, false); break; case DrawMode::Semi: @@ -1091,7 +1110,7 @@ void DrawNodeEx::clear() { _bufferCountTriangle = 0; _dirtyTriangle = true; -#if defined(DRAWNODE_DRAW_LINE_POINT) +#if defined(AX_ENABLE_DRAWNODE_DRAW_LINE_POINT) _bufferCountLine = 0; _dirtyLine = true; _bufferCountPoint = 0; @@ -1137,16 +1156,13 @@ void DrawNodeEx::_drawPolygon(const Vec2* verts, unsigned int count, const Color4B& fillColor, float borderWidth, - const Color4B& borderColo, + const Color4B& borderColor, bool closedPolygon) { AXASSERT(count >= 0, "invalid count value"); Vec2* _vertices = transform(verts, count); - - bool outline = (borderColo.a > 0.0f && borderWidth > 0.0f); - - Color4B borderColor = borderColo; + bool outline = (borderColor.a > 0.0f && borderWidth > 0.0f); auto triangle_count = outline ? (3 * count - 2) : (count - 2); auto vertex_count = 3 * triangle_count; @@ -1225,39 +1241,7 @@ void DrawNodeEx::_drawPolygon(const Vec2* verts, extrude[i] = { offset, n2 }; } - int i = 0; - int j = (i + 1) % count; - Vec2 v0 = _vertices[i]; - Vec2 v1 = _vertices[j]; - - Vec2 n0 = extrude[i].n; - - Vec2 offset0 = extrude[i].offset; - Vec2 offset1 = extrude[j].offset; - - Vec2 inner0 = v0 - offset0 * borderWidth; - Vec2 inner1 = v1 - offset1 * borderWidth; - Vec2 outer0 = v0 + offset0 * borderWidth; - Vec2 outer1 = v1 + offset1 * borderWidth; - borderColor = borderColo; - //if (i >= (count - 1) && !closedPolygon) // /-2 ?? - //{ - // borderColor = Color4B::TRANSPARENT; - //} - - V2F_C4B_T2F_Triangle tmp1 = { {inner0, borderColor, Tex2F(-n0)}, - {inner1, borderColor, Tex2F(-n0)}, - {outer1, borderColor, Tex2F(n0)} }; - *cursor++ = tmp1; - - V2F_C4B_T2F_Triangle tmp2 = { {inner0, borderColor, Tex2F(-n0)}, - {outer0, borderColor, Tex2F(n0)}, - {outer1, borderColor, Tex2F(n0)} }; - *cursor++ = tmp2; - - - - for (unsigned int i = 1; i < (count - 1); i++) + for (unsigned int i = 0; i < (count - 2); i++) { int j = (i + 1) % count; Vec2 v0 = _vertices[i]; @@ -1272,11 +1256,6 @@ void DrawNodeEx::_drawPolygon(const Vec2* verts, Vec2 inner1 = v1 - offset1 * borderWidth; Vec2 outer0 = v0 + offset0 * borderWidth; Vec2 outer1 = v1 + offset1 * borderWidth; - borderColor = borderColo; - //if (i >= (count - 1) && !closedPolygon) // /-2 ?? - //{ - // borderColor = Color4B::TRANSPARENT; - //} V2F_C4B_T2F_Triangle tmp1 = { {inner0, borderColor, Tex2F(-n0)}, {inner1, borderColor, Tex2F(-n0)}, @@ -1289,35 +1268,35 @@ void DrawNodeEx::_drawPolygon(const Vec2* verts, *cursor++ = tmp2; } - i = count - 1; - j = (i + 1) % count; - v0 = _vertices[i]; - v1 = _vertices[j]; + // drawPie stuff + for (unsigned int i = count - 2; i <= (count - 1); i++) + { + int j = (i + 1) % count; + Vec2 v0 = _vertices[i]; + Vec2 v1 = _vertices[j]; + + Vec2 n0 = extrude[i].n; - n0 = extrude[i].n; + Vec2 offset0 = extrude[i].offset; + Vec2 offset1 = extrude[j].offset; - offset0 = extrude[i].offset; - offset1 = extrude[j].offset; + Vec2 inner0 = v0 - offset0 * borderWidth; + Vec2 inner1 = v1 - offset1 * borderWidth; + Vec2 outer0 = v0 + offset0 * borderWidth; + Vec2 outer1 = v1 + offset1 * borderWidth; - inner0 = v0 - offset0 * borderWidth; - inner1 = v1 - offset1 * borderWidth; - outer0 = v0 + offset0 * borderWidth; - outer1 = v1 + offset1 * borderWidth; - borderColor = borderColo; - //if (i >= (count - 1) && !closedPolygon) // /-2 ?? - //{ - // borderColor = Color4B::TRANSPARENT; - //} + Color4B borderColorTemp = (!closedPolygon) ? Color4B::TRANSPARENT : borderColor; - tmp1 = { {inner0, borderColor, Tex2F(-n0)}, - {inner1, borderColor, Tex2F(-n0)}, - {outer1, borderColor, Tex2F(n0)} }; - *cursor++ = tmp1; + V2F_C4B_T2F_Triangle tmp1 = { {inner0, borderColorTemp, Tex2F(-n0)}, + {inner1, borderColorTemp, Tex2F(-n0)}, + {outer1, borderColorTemp, Tex2F(n0)} }; + *cursor++ = tmp1; - tmp2 = { {inner0, borderColor, Tex2F(-n0)}, - {outer0, borderColor, Tex2F(n0)}, - {outer1, borderColor, Tex2F(n0)} }; - *cursor++ = tmp2; + V2F_C4B_T2F_Triangle tmp2 = { {inner0, borderColorTemp, Tex2F(-n0)}, + {outer0, borderColorTemp, Tex2F(n0)}, + {outer1, borderColorTemp, Tex2F(n0)} }; + *cursor++ = tmp2; + } free(extrude); } @@ -1351,16 +1330,16 @@ void DrawNodeEx::_drawPoly(const Vec2* poli, } else { -#if defined(DRAWNODE_DRAW_LINE_POINT) +#if defined(AX_ENABLE_DRAWNODE_DRAW_LINE_POINT) if (_drawOrder == true) { #endif _drawPolygon(poli, numberOfPoints, Color4B::TRANSPARENT, thickness / 3, color, false); -#if defined(DRAWNODE_DRAW_LINE_POINT) +#if defined(AX_ENABLE_DRAWNODE_DRAW_LINE_POINT) return; } #endif -#if defined(DRAWNODE_DRAW_LINE_POINT) +#if defined(AX_ENABLE_DRAWNODE_DRAW_LINE_POINT) Vec2* _vertices = transform(poli, numberOfPoints); unsigned int vertex_count; diff --git a/extensions/DrawNodeEx/src/DrawNodeEx/DrawNodeEx.h b/extensions/DrawNodeEx/src/DrawNodeEx/DrawNodeEx.h index ad8e416dc2af..6fa512397991 100644 --- a/extensions/DrawNodeEx/src/DrawNodeEx/DrawNodeEx.h +++ b/extensions/DrawNodeEx/src/DrawNodeEx/DrawNodeEx.h @@ -45,7 +45,8 @@ NS_AX_EXT_BEGIN -#define DRAWNODE_DRAW_LINE_POINT +// AX_ENABLE_DRAWNODE_DRAW_LINE_POINT an option for future versions of DrawNode (currently: defined) +#define AX_ENABLE_DRAWNODE_DRAW_LINE_POINT static const int DEFAULT_LINEWIDTH = 2; @@ -106,7 +107,7 @@ class AX_EX_DLL DrawNodeEx : public ax::Node float _dnLineWidthTmp = _dnLineWidth; bool _dnTransform = false; -#if defined(DRAWNODE_DRAW_LINE_POINT) +#if defined(AX_ENABLE_DRAWNODE_DRAW_LINE_POINT) bool _drawOrder = true; #endif @@ -503,9 +504,10 @@ class AX_EX_DLL DrawNodeEx : public ax::Node * @param to The segment destination. * @param radius The segment radius. * @param color The segment color. - * @param endType The segment DrawNodeEx::EndType. + * @param etStart The segment first DrawNodeEx::EndType. + * @param etEnd The segment last DrawNodeEx::EndType. */ - void drawSegment(const ax::Vec2& from, const ax::Vec2& to, float radius, const ax::Color4B& color, DrawNodeEx::EndType endType = DrawNodeEx::EndType::Round); + void drawSegment(const ax::Vec2& from, const ax::Vec2& to, float radius, const ax::Color4B& color, DrawNodeEx::EndType etStart = DrawNodeEx::EndType::Round, DrawNodeEx::EndType etEnd = DrawNodeEx::EndType::Round); /** draw a polygon with a fill color and line color * @code @@ -548,7 +550,6 @@ class AX_EX_DLL DrawNodeEx : public ax::Node * @param color The triangle color. * @js NA */ - void drawTriangle(const ax::Vec2& p1, const ax::Vec2& p2, const ax::Vec2& p3, @@ -601,7 +602,7 @@ class AX_EX_DLL DrawNodeEx : public ax::Node protected: void ensureCapacityTriangle(int count); -#if defined(DRAWNODE_DRAW_LINE_POINT) +#if defined(AX_ENABLE_DRAWNODE_DRAW_LINE_POINT) void ensureCapacityPoint(int count); void ensureCapacityLine(int count); #endif @@ -624,7 +625,7 @@ class AX_EX_DLL DrawNodeEx : public ax::Node ax::CustomCommand _customCommandTriangle; bool _dirtyTriangle = false; -#if defined(DRAWNODE_DRAW_LINE_POINT) +#if defined(AX_ENABLE_DRAWNODE_DRAW_LINE_POINT) int _bufferCapacityPoint = 0; int _bufferCountPoint = 0; ax::V2F_C4B_T2F* _bufferPoint = nullptr; diff --git a/tests/cpp-tests/Source/DrawNodeExTest/DrawNodeExTest.cpp b/tests/cpp-tests/Source/DrawNodeExTest/DrawNodeExTest.cpp index 95ff311353a1..c8b871ec7d52 100644 --- a/tests/cpp-tests/Source/DrawNodeExTest/DrawNodeExTest.cpp +++ b/tests/cpp-tests/Source/DrawNodeExTest/DrawNodeExTest.cpp @@ -33,8 +33,6 @@ USING_NS_AX; USING_NS_AX_EXT; -#define DRAWNODE_DRAW_LINE_POINT - using namespace std; const int drawMethodsCounter = 19; @@ -60,7 +58,6 @@ std::string drawMethods[drawMethodsCounter] = { "drawLine", - Vec2 vertices1[] = { {45.750000f, 144.375000f}, {75.500000f, 136.875000f}, {75.500000f, 159.125000f}, {100.250000f, 161.375000f}, {65.500000f, 181.375000f}, {102.250000f, 179.125000f}, {95.000000f, 215.125000f}, {129.331467f, 189.926208f}, @@ -104,7 +101,7 @@ DrawNodeExTests::DrawNodeExTests() ADD_TEST_CASE(DrawNodeDrawInWrongOrder_Issue1888); ADD_TEST_CASE(DrawNodeCocos2dxTest1); - ADD_TEST_CASE(DrawNodeCocos2dxTest2); + ADD_TEST_CASE(DrawNodeAxmolTest2); ADD_TEST_CASE(DrawNodeCocos2dxBackwardsAPITest); ADD_TEST_CASE(DrawNodeCocos2dxBetterCircleRendering); ADD_TEST_CASE(DrawNodeCocos2dxDrawNodePieTest); @@ -1397,9 +1394,10 @@ void DrawNodeMethodesTest::drawAll() { case 0: { - float nodeRotation = draw->getRotation(); - draw->setRotation(rotation * 3); - draw->setAnchorPoint(Vec2::ANCHOR_MIDDLE); + // drawLine + //float nodeRotation = draw->getRotation(); + //draw->setRotation(rotation * 3); + // draw->setAnchorPoint(Vec2::ANCHOR_MIDDLE); draw->setScale(0.3); // draw->setPosition(0.1); @@ -1408,27 +1406,27 @@ void DrawNodeMethodesTest::drawAll() Vec2 gear3 = { 200.f, 200.f }; Vec2 gear4 = { s.width - 200, s.height - 200 }; - draw->drawLine(gear2, gear4, Color4F::RED, thickness); // line - draw->setDNCenter(gear1); - draw->setDNRotation(rotation + 45); - draw->drawStar(Vec2(gear1), 30, 60, 8, Color4F::BLUE, 4.0); - draw->setDNRotation(-rotation); - draw->setDNCenter(gear2); - draw->drawSolidStar(gear2, 30, 60, 8, Color4F::GREEN, Color4F::YELLOW, 4.0); + draw->drawLine(gear2, gear4, Color4F::BLUE, thickness); // line + //draw->setDNCenter(gear1); + //draw->setDNRotation(rotation + 45); + //draw->drawStar(Vec2(gear1), 30, 60, 8, Color4F::BLUE, 4.0); + //draw->setDNRotation(-rotation); + //draw->setDNCenter(gear2); + //draw->drawSolidStar(gear2, 30, 60, 8, Color4F::GREEN, Color4F::YELLOW, 4.0); - draw->resetDNValues(); + //draw->resetDNValues(); draw->drawLine(gear2, gear1, Color4F::RED, thickness); // line - draw->setDNCenter(gear4); + /* draw->setDNCenter(gear4); draw->setDNRotation(rotation + 45); - draw->drawStar(gear3, 30, 60, 18, Color4F::RED, 1.0); + draw->drawStar(gear3, 30, 60, 18, Color4F::RED, 1.0);*/ draw->drawLine(gear3, gear4, Color4F::YELLOW, thickness); // line - draw->resetDNValues(); - draw->setDNRotation(rotation - 45); - draw->setDNCenter(gear4); - draw->drawStar(gear4, 40, 60, 60, Color4F::GREEN, 1.0); - draw->resetDNValues(); - isDirty = true; - draw->setRotation(nodeRotation); + //draw->resetDNValues(); + //draw->setDNRotation(rotation - 45); + //draw->setDNCenter(gear4); + //draw->drawStar(gear4, 40, 60, 60, Color4F::GREEN, 1.0); + //draw->resetDNValues(); + // isDirty = true; + // draw->setRotation(nodeRotation); break; } case 1: @@ -1611,21 +1609,21 @@ void DrawNodeMethodesTest::drawAll() int yy1 = 0; int yy = 50; draw->drawSegment(Vec2(50.0f, yy), Vec2(400, yy - yy1), count / 20, - Color4F::GREEN); //default DrawNodeEx::Round + Color4F::GREEN, DrawNodeEx::Square, DrawNodeEx::Round); //default DrawNodeEx::Round - label1->setPosition(Vec2(410.0f, yy + 55)); + // label1->setPosition(Vec2(410.0f, yy + 55)); yy += 110; draw->drawSegment(Vec2(50.0f, yy), Vec2(400, yy - yy1), count / 20, - Color4F::BLUE, DrawNodeEx::Square); - label2->setPosition(Vec2(410.0f, yy)); + Color4F::BLUE, DrawNodeEx::Butt, DrawNodeEx::Square); + // label2->setPosition(Vec2(410.0f, yy)); yy += 110; draw->drawSegment(Vec2(50.0f, yy), Vec2(400, yy - yy1), count / 20, - Color4F::RED, DrawNodeEx::Butt); - label3->setPosition(Vec2(410.0f, yy - 55)); + Color4F::RED, DrawNodeEx::Round, DrawNodeEx::Butt); + // label3->setPosition(Vec2(410.0f, yy - 55)); break; } @@ -1886,6 +1884,13 @@ void DrawNodePerformaneTest::update(float dt) draw->clear(); + label1->setVisible(false); + label2->setVisible(false); + label3->setVisible(false); + + + + label->setString("Count: (" + Value(count).asString() + ")"); switch (_currentSeletedItemIndex) { @@ -1938,24 +1943,27 @@ void DrawNodePerformaneTest::update(float dt) case 4: { // Draw segment + label1->setVisible(true); + label2->setVisible(true); + label3->setVisible(true); int yy1 = 0; int yy = 50; draw->drawSegment(Vec2(50.0f, yy), Vec2(400, yy - yy1), count / 20, - Color4F::GREEN); //default DrawNodeEx::Round + Color4F::GREEN, DrawNodeEx::Round, DrawNodeEx::Round); label1->setPosition(Vec2(410.0f, yy + 55)); yy += 110; draw->drawSegment(Vec2(50.0f, yy), Vec2(400, yy - yy1), count / 20, - Color4F::BLUE, DrawNodeEx::Square); + Color4F::BLUE, DrawNodeEx::Round, DrawNodeEx::Square); label2->setPosition(Vec2(410.0f, yy)); yy += 110; draw->drawSegment(Vec2(50.0f, yy), Vec2(400, yy - yy1), count / 20, - Color4F::RED, DrawNodeEx::Butt); + Color4F::RED, DrawNodeEx::Round, DrawNodeEx::Butt); label3->setPosition(Vec2(410.0f, yy - 55)); break; @@ -2146,8 +2154,8 @@ void DrawNodeDrawInWrongOrder_Issue1888::update(float dt) } -// DrawNodeCocos2dxTest2 -DrawNodeCocos2dxTest2::DrawNodeCocos2dxTest2() +// DrawNodeAxmolTest2 +DrawNodeAxmolTest2::DrawNodeAxmolTest2() { auto s = Director::getInstance()->getWinSize(); @@ -2307,14 +2315,14 @@ DrawNodeCocos2dxTest2::DrawNodeCocos2dxTest2() draw1->runAction(RepeatForever::create(Sequence::create(FadeIn::create(1.2f), FadeOut::create(1.2f), NULL))); } -string DrawNodeCocos2dxTest2::title() const +string DrawNodeAxmolTest2::title() const { - return "Test DrawNode"; + return "Axmol DrawNode v2 test"; } -string DrawNodeCocos2dxTest2::subtitle() const +string DrawNodeAxmolTest2::subtitle() const { - return "Testing DrawNode - batched draws. Concave polygons working too!"; + return ""; } // diff --git a/tests/cpp-tests/Source/DrawNodeExTest/DrawNodeExTest.h b/tests/cpp-tests/Source/DrawNodeExTest/DrawNodeExTest.h index 6941f5ec62be..ec7279dbc533 100644 --- a/tests/cpp-tests/Source/DrawNodeExTest/DrawNodeExTest.h +++ b/tests/cpp-tests/Source/DrawNodeExTest/DrawNodeExTest.h @@ -29,7 +29,6 @@ #include "../BaseTest.h" #include "DrawNodeEx/DrawNodeEx.h" - DEFINE_TEST_SUITE(DrawNodeExTests); class DrawNodeExBaseTest : public TestCase @@ -350,12 +349,12 @@ class DrawNodeDrawInWrongOrder_Issue1888 : public DrawNodeExBaseTest -class DrawNodeCocos2dxTest2 : public DrawNodeExBaseTest +class DrawNodeAxmolTest2 : public DrawNodeExBaseTest { public: - CREATE_FUNC(DrawNodeCocos2dxTest2); + CREATE_FUNC(DrawNodeAxmolTest2); - DrawNodeCocos2dxTest2(); + DrawNodeAxmolTest2(); virtual std::string title() const override; virtual std::string subtitle() const override; From f2d6017cdb60ef4bb1e1c4c4ff4a45b25f41ee76 Mon Sep 17 00:00:00 2001 From: eismpesd Date: Fri, 28 Jun 2024 09:04:17 +0200 Subject: [PATCH 2/3] Update DrawNodeEx.cpp --- .../DrawNodeEx/src/DrawNodeEx/DrawNodeEx.cpp | 22 ++++++++----------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/extensions/DrawNodeEx/src/DrawNodeEx/DrawNodeEx.cpp b/extensions/DrawNodeEx/src/DrawNodeEx/DrawNodeEx.cpp index 76972c72d933..741d65ea509e 100644 --- a/extensions/DrawNodeEx/src/DrawNodeEx/DrawNodeEx.cpp +++ b/extensions/DrawNodeEx/src/DrawNodeEx/DrawNodeEx.cpp @@ -148,16 +148,16 @@ DrawNodeEx::~DrawNodeEx() { AX_SAFE_FREE(_bufferTriangle); -//#if defined(AX_ENABLE_DRAWNODE_DRAW_LINE_POINT) +#if defined(AX_ENABLE_DRAWNODE_DRAW_LINE_POINT) AX_SAFE_FREE(_bufferPoint); AX_SAFE_FREE(_bufferLine); -//#endif +#endif freeShaderInternal(_customCommandTriangle); -//#if defined(AX_ENABLE_DRAWNODE_DRAW_LINE_POINT) +#if defined(AX_ENABLE_DRAWNODE_DRAW_LINE_POINT) freeShaderInternal(_customCommandPoint); freeShaderInternal(_customCommandLine); -//#endif +#endif } DrawNodeEx* DrawNodeEx::create(float defaultLineWidth) @@ -190,7 +190,7 @@ void DrawNodeEx::ensureCapacityTriangle(int count) } } -//#if defined(AX_ENABLE_DRAWNODE_DRAW_LINE_POINT) +#if defined(AX_ENABLE_DRAWNODE_DRAW_LINE_POINT) void DrawNodeEx::ensureCapacityPoint(int count) { AXASSERT(count >= 0, "capacity must be >= 0"); @@ -220,7 +220,7 @@ void DrawNodeEx::ensureCapacityLine(int count) _customCommandLine.updateVertexBuffer(_bufferLine, _bufferCapacityLine * sizeof(V2F_C4B_T2F)); } } -//#endif +#endif bool DrawNodeEx::init() { @@ -940,7 +940,7 @@ void DrawNodeEx::drawPie(const Vec2& center, #define DEGREES 360 bool _circle = false; - // not a real line! + // Not a real line! if (startAngle == endAngle) return; @@ -950,7 +950,6 @@ void DrawNodeEx::drawPie(const Vec2& center, _circle = true; } - const float coef = 2.0f * (float)M_PI / DEGREES; Vec2* vertices = _abuf.get(DEGREES + 2); @@ -960,10 +959,7 @@ void DrawNodeEx::drawPie(const Vec2& center, if (startAngle > endAngle) { - // std::swap(endAngle, startAngle); - int tmp = endAngle; - endAngle = startAngle; - startAngle = tmp; + std::swap(endAngle, startAngle); } for (int i = 0; i <= DEGREES; i++) @@ -995,7 +991,7 @@ void DrawNodeEx::drawPie(const Vec2& center, vertices[n++] = center; if (_circle) { - this->drawCircle(center, radius, 0, 36, false, scaleX, scaleY, fillColor, thickness); + this->drawCircle(center, radius, 0, 36, false, scaleX, scaleY, borderColor, thickness); break; } _drawPolygon(vertices, n, Color4B::TRANSPARENT, thickness, borderColor, true); From b4d8017878dd2ac65221f7d147751afaf068c69c Mon Sep 17 00:00:00 2001 From: eismpesd Date: Fri, 28 Jun 2024 09:29:01 +0200 Subject: [PATCH 3/3] Update DrawNodeEx.cpp --- extensions/DrawNodeEx/src/DrawNodeEx/DrawNodeEx.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/DrawNodeEx/src/DrawNodeEx/DrawNodeEx.cpp b/extensions/DrawNodeEx/src/DrawNodeEx/DrawNodeEx.cpp index 741d65ea509e..baa6a9d6a39a 100644 --- a/extensions/DrawNodeEx/src/DrawNodeEx/DrawNodeEx.cpp +++ b/extensions/DrawNodeEx/src/DrawNodeEx/DrawNodeEx.cpp @@ -1001,7 +1001,7 @@ void DrawNodeEx::drawPie(const Vec2& center, _drawPolygon(vertices, n, Color4B::TRANSPARENT, thickness, borderColor, false); break; case DrawMode::Semi: - _drawPolygon(vertices, n, fillColor, thickness, borderColor, true); + _drawPolygon(vertices, n-1, fillColor, thickness, borderColor, true); break; default: