diff --git a/axmol/2d/DrawNode.cpp b/axmol/2d/DrawNode.cpp index d6699d1fc274..dee3f091875e 100644 --- a/axmol/2d/DrawNode.cpp +++ b/axmol/2d/DrawNode.cpp @@ -41,11 +41,6 @@ namespace ax { -#if defined(_WIN32) -# pragma push_macro("TRANSPARENT") -# undef TRANSPARENT -#endif - /** Is a polygon convex? * @param verts A pointer to point coordinates. * @param count The number of verts measured in points. @@ -83,7 +78,7 @@ DrawNode::DrawNode() { _blendFunc = BlendFunc::ALPHA_PREMULTIPLIED; - properties.setDefaultValues(); + resetAdvancedSettings(); #if AX_ENABLE_CONTEXT_LOSS_RECOVERY // TODO new-renderer: interface setupBuffer removal @@ -300,12 +295,6 @@ void DrawNode::drawLine(const Vec2& origin, DrawNode::EndType etStart, DrawNode::EndType etEnd) { - if (thickness <= 0.0f) - { - AXLOGW("{}: thickness <= 0", __FUNCTION__); - return; - } - _drawSegment(origin, destination, color, thickness, etStart, etEnd); } @@ -315,11 +304,6 @@ void DrawNode::drawPoly(const Vec2* poli, const Color& color, float thickness) { - if (thickness <= 0.0f) - { - AXLOGW("{}: thickness <= 0", __FUNCTION__); - return; - } _drawPoly(poli, numberOfPoints, closedPolygon, color, thickness); } @@ -333,17 +317,6 @@ void DrawNode::drawCircle(const Vec2& center, const Color& color, float thickness) { - if (thickness <= 0.0f) - { - AXLOGW("{}: thickness <= 0", __FUNCTION__); - return; - } - if (radius == 0.0f) - { - AXLOGW("{}: radius == 0", __FUNCTION__); - return; - } - _drawCircle(center, radius, angle, segments, drawLineToCenter, scaleX, scaleY, color, Color(), false, thickness); } @@ -355,17 +328,6 @@ void DrawNode::drawCircle(const Vec2& center, const Color& color, float thickness) { - if (thickness <= 0.0f) - { - AXLOGW("{}: thickness <= 0", __FUNCTION__); - return; - } - if (radius == 0.0f) - { - AXLOGW("{}: radius == 0", __FUNCTION__); - return; - } - _drawCircle(center, radius, angle, segments, drawLineToCenter, 1.0f, 1.0f, color, color, false, thickness); } @@ -376,11 +338,6 @@ void DrawNode::drawStar(const Vec2& center, const Color& color, float thickness) { - if (thickness <= 0.0f) - { - AXLOGW("{}: thickness <= 0", __FUNCTION__); - return; - } _drawAStar(center, radiusI, radiusO, segments, color, color, thickness, false); } @@ -392,11 +349,6 @@ void DrawNode::drawSolidStar(const Vec2& center, const Color& filledColor, float thickness) { - if (thickness < 0.0f) - { - AXLOGW("{}: thickness < 0, changed to 0", __FUNCTION__); - thickness = 0.0f; - } _drawAStar(center, radiusI, radiusO, segments, color, filledColor, thickness, true); } @@ -407,14 +359,7 @@ void DrawNode::drawQuadBezier(const Vec2& origin, const Color& color, float thickness) { - if (thickness <= 0.0f) - { - AXLOGW("{}: thickness <= 0", __FUNCTION__); - return; - } - - tlx::pod_vector _vertices{ - static_cast(segments + 1)}; // Vec2* _vertices = _abuf.get(segments + 1); + tlx::pod_vector _vertices{static_cast(segments + 1)}; float t = 0.0f; for (unsigned int i = 0; i < segments; i++) @@ -437,12 +382,6 @@ void DrawNode::drawCubicBezier(const Vec2& origin, const Color& color, float thickness) { - if (thickness <= 0.0f) - { - AXLOGW("{}: thickness <= 0", __FUNCTION__); - return; - } - tlx::pod_vector _vertices{static_cast(segments + 1)}; float t = 0.0f; @@ -467,12 +406,6 @@ void DrawNode::drawCardinalSpline(const PointArray* configIn, float thickness, bool closed) { - if (thickness <= 0.0f) - { - AXLOGW("{}: thickness <= 0", __FUNCTION__); - return; - } - // Don't change the original PointArray PointArray* config = configIn->clone(); @@ -531,21 +464,11 @@ void DrawNode::drawCatmullRom(const PointArray* pointsIn, float thickness, bool closed) { - if (thickness <= 0.0f) - { - AXLOGW("{}: thickness <= 0", __FUNCTION__); - return; - } drawCardinalSpline(pointsIn, 0.5f, segments, color, thickness, closed); } void DrawNode::drawDot(const Vec2& pos, float radius, const Color& color) { - if (radius <= 0.0f) - { - AXLOGW("{}: radius <= 0", __FUNCTION__); - return; - } _drawDot(pos, radius, color); } @@ -556,24 +479,12 @@ void DrawNode::drawRect(const Vec2& p1, const Color& color, float thickness) { - if (thickness <= 0.0f) - { - AXLOGW("{}: thickness <= 0", __FUNCTION__); - return; - } - Vec2 line[5] = {p1, p2, p3, p4, p1}; _drawPoly(line, 5, false, color, thickness, true); } void DrawNode::drawRect(const Vec2& origin, const Vec2& destination, const Color& color, float thickness) { - if (thickness <= 0.0f) - { - AXLOGW("{}: thickness <= 0", __FUNCTION__); - return; - } - Vec2 line[5] = {origin, Vec2(destination.x, origin.y), destination, Vec2(origin.x, destination.y), origin}; _drawPoly(line, 5, false, color, thickness, true); } @@ -585,11 +496,6 @@ void DrawNode::drawSegment(const Vec2& from, DrawNode::EndType etStart, DrawNode::EndType etEnd) { - if (thickness <= 0.0f) - { - AXLOGW("{}: thickness <= 0", __FUNCTION__); - return; - } _drawSegment(from, to, color, thickness, etStart, etEnd); } @@ -600,22 +506,12 @@ void DrawNode::drawPolygon(const Vec2* verts, const Color& borderColor, bool isconvex) { - if (thickness < 0.0f) - { - AXLOGW("{}: thickness < 0, changed to 0", __FUNCTION__); - thickness = 0.0f; - } _drawPolygon(verts, count, fillColor, borderColor, true, thickness, isconvex); } void DrawNode::drawPolygon(const Vec2* verts, int count, float thickness, const Color& borderColor, bool isconvex) { - if (thickness < 0.0f) - { - AXLOGW("{}: thickness < 0, changed to 0", __FUNCTION__); - thickness = 0.0f; - } - _drawPolygon(verts, count, Color::TRANSPARENT, borderColor, true, thickness, isconvex); + _drawPolygon(verts, count, Color(), borderColor, true, thickness, isconvex); } void DrawNode::drawSolidPolygon(const Vec2* verts, @@ -625,11 +521,6 @@ void DrawNode::drawSolidPolygon(const Vec2* verts, const Color& borderColor, bool isconvex) { - if (thickness < 0.0f) - { - AXLOGW("{}: thickness < 0, changed to 0", __FUNCTION__); - thickness = 0.0f; - } _drawPolygon(verts, count, fillColor, borderColor, true, thickness, isconvex); } @@ -639,13 +530,8 @@ void DrawNode::drawSolidRect(const Vec2& origin, float thickness, const Color& borderColor) { - if (thickness < 0.0f) - { - AXLOGW("{}: thickness < 0, changed to 0", __FUNCTION__); - thickness = 0.0f; - } - Vec2 _vertices[] = {origin, Vec2(destination.x, origin.y), destination, Vec2(origin.x, destination.y), origin}; - _drawPolygon(_vertices, 5, fillColor, borderColor, true, thickness, true); + Vec2 _vertices5[] = {origin, Vec2(destination.x, origin.y), destination, Vec2(origin.x, destination.y), origin}; + _drawPolygon(_vertices5, 5, fillColor, borderColor, false, thickness, true); } void DrawNode::drawSolidPoly(const Vec2* poli, @@ -655,11 +541,6 @@ void DrawNode::drawSolidPoly(const Vec2* poli, const Color& borderColor, bool isconvex) { - if (thickness < 0.0f) - { - AXLOGW("{}: thickness < 0, changed to 0", __FUNCTION__); - thickness = 0.0f; - } _drawPolygon(poli, numberOfPoints, color, borderColor, true, thickness, isconvex); } @@ -675,11 +556,6 @@ void DrawNode::drawPie(const Vec2& center, DrawMode drawMode, float thickness) { - if (thickness < 0.0f) - { - AXLOGW("{}: thickness < 0, changed to 0", __FUNCTION__); - thickness = 0.0f; - } _drawPie(center, radius, rotation, startAngle, endAngle, scaleX, scaleY, fillColor, borderColor, drawMode, thickness); } @@ -694,7 +570,7 @@ void DrawNode::drawPie(const Vec2& center, const Color& color, DrawMode drawMode) { - _drawPie(center, radius, angle, startAngle, endAngle, scaleX, scaleY, Color::TRANSPARENT, color, drawMode, 1.0f); + _drawPie(center, radius, angle, startAngle, endAngle, scaleX, scaleY, Color(), color, drawMode, 1.0f); } void DrawNode::drawSolidCircle(const Vec2& center, @@ -708,11 +584,6 @@ void DrawNode::drawSolidCircle(const Vec2& center, const Color& borderColor, bool drawLineToCenter) { - if (thickness < 0.0f) - { - AXLOGW("{}: thickness < 0, changed to 0", __FUNCTION__); - thickness = 0.0f; - } _drawCircle(center, radius, angle, segments, drawLineToCenter, scaleX, scaleY, borderColor, fillColor, true, thickness); } @@ -725,40 +596,28 @@ void DrawNode::drawSolidCircle(const Vec2& center, float scaleY, const Color& color) { - if (radius < 0.0f) - { - AXLOGW("{}: radius < 0, changed to 0", __FUNCTION__); - radius = 0.0f; - } _drawCircle(center, radius, angle, segments, false, scaleX, scaleY, Color(), color, true); } void DrawNode::drawSolidCircle(const Vec2& center, float radius, float angle, unsigned int segments, const Color& color) { - if (radius < 0.0f) - { - AXLOGW("{}: radius < 0, changed to 0", __FUNCTION__); - radius = 0.0f; - } _drawCircle(center, radius, angle, segments, false, 1.0f, 1.0f, Color(), color, true); } void DrawNode::drawColoredTriangle(const Vec2* vertices3, const Color* color3) { - Vec2 vertices[3] = {vertices3[0], vertices3[1], vertices3[2]}; - _drawColoredTriangle(vertices, color3); + _drawColoredTriangle(vertices3, color3); } -void DrawNode::drawTriangle(const Vec2* vertices3, const Color& color) +void DrawNode::drawTriangle(const Vec2* vertices3, const Color& color, float thickness) { - Vec2 vertices[3] = {vertices3[0], vertices3[1], vertices3[2]}; - _drawTriangle(vertices, Color::TRANSPARENT, color, false, 0.0f); + _drawPoly(vertices3, 3, true, color, thickness, true); } -void DrawNode::drawTriangle(const Vec2& p1, const Vec2& p2, const Vec2& p3, const Color& color) +void DrawNode::drawTriangle(const Vec2& p1, const Vec2& p2, const Vec2& p3, const Color& color, float thickness) { - Vec2 vertices[3] = {p1, p2, p3}; - _drawTriangle(vertices, Color::TRANSPARENT, color, false, 0.0f); + Vec2 vertices3[3] = {p1, p2, p3}; + _drawPoly(vertices3, 3, true, color, thickness, true); } void DrawNode::drawSolidTriangle(const Vec2* vertices3, @@ -766,13 +625,7 @@ void DrawNode::drawSolidTriangle(const Vec2* vertices3, const Color& borderColor, float thickness) { - if (thickness < 0.0f) - { - AXLOGW("{}: thickness < 0, changed to 0", __FUNCTION__); - thickness = 0.0f; - } - Vec2 vertices[3] = {vertices3[0], vertices3[1], vertices3[2]}; - _drawTriangle(vertices, fillColor, borderColor, true, thickness); + _drawPolygon(vertices3, 3, fillColor, borderColor, true, thickness, true); } void DrawNode::drawSolidTriangle(const Vec2& p1, @@ -782,13 +635,8 @@ void DrawNode::drawSolidTriangle(const Vec2& p1, const Color& borderColor, float thickness) { - if (thickness < 0.0f) - { - AXLOGW("{}: thickness < 0, changed to 0", __FUNCTION__); - thickness = 0.0f; - } - Vec2 vertices[3] = {p1, p2, p3}; - _drawTriangle(vertices, fillColor, borderColor, false, thickness); + Vec2 vertices3[3] = {p1, p2, p3}; + _drawPolygon(vertices3, 3, fillColor, borderColor, true, thickness, true); } void DrawNode::clear() @@ -882,7 +730,7 @@ void DrawNode::_drawPolygon(const Vec2* verts, if (outline) { - if (thickness != 1.0f || properties.drawOrder) + if (thickness != 1.0f || _preserveDrawOrder) { vertex_count += 6 * (count - 1); } @@ -893,7 +741,6 @@ void DrawNode::_drawPolygon(const Vec2* verts, } vertex_count *= 3; - auto triangles = reinterpret_cast(expandBufferAndGetPointer(_triangles, vertex_count)); _trianglesDirty = true; @@ -919,8 +766,8 @@ void DrawNode::_drawPolygon(const Vec2* verts, } if (outline) { - float width = thickness / properties.factor; - if (thickness != 1.0f || properties.drawOrder) + float width = thickness * _thicknessScale * 0.25f; + if (thickness != 1.0f || _preserveDrawOrder) { for (unsigned int i = 1; i < (count); i++) { @@ -1030,7 +877,7 @@ void DrawNode::_drawPoly(const Vec2* verts, float thickness, bool isconvex) { - if (thickness == 1.0f && !properties.drawOrder) + if (thickness == 1.0f && !_preserveDrawOrder) { auto _vertices = _transform(verts, count, closedPolygon); @@ -1053,7 +900,7 @@ void DrawNode::_drawPoly(const Vec2* verts, } else { - _drawPolygon(verts, count, Color::TRANSPARENT, color, closedPolygon, thickness, isconvex); + _drawPolygon(verts, count, Color(), color, closedPolygon, thickness, isconvex); } } @@ -1064,19 +911,15 @@ void DrawNode::_drawSegment(const Vec2& from, DrawNode::EndType etStart, DrawNode::EndType etEnd) { - if (thickness < 1.0f) - thickness = 1.0f; - - if (thickness == 1.0f && !properties.drawOrder) + if (thickness == 1.0f && !_preserveDrawOrder) { _drawLine(from, to, color); // fastest way to draw a line } else { Vec2 vertices[2] = {from, to}; - applyTransform(vertices, vertices, 2); - - float width = thickness / (2 * properties.factor); + applyLocalTransform(vertices, vertices, 2); + float width = thickness * _thicknessScale * 0.25f; Vec2 a = vertices[0]; Vec2 b = vertices[1]; @@ -1187,11 +1030,11 @@ void DrawNode::_drawSegment(const Vec2& from, } } } -// Internal function _drawLine => thickness is always 1 (fastes way to draw a line) +// Internal function _drawLine => thickness is ALWAYS 1 (fastes way to draw a line) void DrawNode::_drawLine(const Vec2& from, const Vec2& to, const Color& color) { Vec2 vertices[2] = {from, to}; - applyTransform(vertices, vertices, 2); + applyLocalTransform(vertices, vertices, 2); auto line = expandBufferAndGetPointer(_lines, 2); _linesDirty = true; @@ -1253,43 +1096,18 @@ void DrawNode::_drawCircle(const Vec2& center, AX_SAFE_DELETE_ARRAY(_vertices); } -void DrawNode::_drawColoredTriangle(Vec2* vertices3, const Color* color3) +void DrawNode::_drawColoredTriangle(const Vec2* vertices3, const Color* color3) { unsigned int vertex_count = 3; - - applyTransform(vertices3, vertices3, vertex_count); + Vec2* _vertices3 = new Vec2[vertex_count]; + applyLocalTransform(vertices3, _vertices3, vertex_count); auto triangles = reinterpret_cast(expandBufferAndGetPointer(_triangles, vertex_count)); _trianglesDirty = true; - triangles[0] = {{vertices3[0], Vec2::ZERO, color3[0]}, - {vertices3[1], Vec2::ZERO, color3[1]}, - {vertices3[2], Vec2::ZERO, color3[2]}}; -} - -void DrawNode::_drawTriangle(Vec2* vertices3, - const Color& borderColor, - const Color& fillColor, - bool solid, - float thickness) -{ - unsigned int vertex_count = 3; - - if (thickness != 0.0f) - { - _drawPolygon(vertices3, vertex_count, fillColor, borderColor, true, thickness, true); - } - else - { - applyTransform(vertices3, vertices3, vertex_count); - - auto triangles = reinterpret_cast(expandBufferAndGetPointer(_triangles, vertex_count)); - _trianglesDirty = true; - - triangles[0] = {{vertices3[0], Vec2::ZERO, fillColor}, - {vertices3[1], Vec2::ZERO, fillColor}, - {vertices3[2], Vec2::ZERO, fillColor}}; - } + triangles[0] = {{_vertices3[0], Vec2::ZERO, color3[0]}, + {_vertices3[1], Vec2::ZERO, color3[1]}, + {_vertices3[2], Vec2::ZERO, color3[2]}}; } void DrawNode::_drawAStar(const Vec2& center, @@ -1331,7 +1149,7 @@ void DrawNode::_drawPoints(const Vec2* position, const Color& color, const DrawNode::PointType pointType) { - if (properties.drawOrder == true) + if (_preserveDrawOrder) { float pointSize4 = pointSize * 0.25f; Vec2 vec2Size4 = Vec2(pointSize4, pointSize4); @@ -1350,7 +1168,7 @@ void DrawNode::_drawPoints(const Vec2* position, Vec2 destination = position[i] + vec2Size4; Vec2 _vertices[] = {origin, Vec2(destination.x, origin.y), destination, Vec2(origin.x, destination.y), origin}; - _drawPolygon(_vertices, 5, color, color, false, 0.0f, true); + _drawPolygon(_vertices, 5, color, color, false, pointSize, true); } break; default: @@ -1374,7 +1192,7 @@ void DrawNode::_drawPoint(const Vec2& position, const Color& color, const DrawNode::PointType pointType) { - if (properties.drawOrder == true) + if (_preserveDrawOrder) { float pointSize4 = pointSize * 0.25f; Vec2 vec2Size4 = Vec2(pointSize4, pointSize4); @@ -1398,17 +1216,6 @@ void DrawNode::_drawPoint(const Vec2& position, default: break; } - - return; - } - - if (properties.drawOrder == true) - { - float pointSize4 = pointSize * 0.25f; - Vec2 origin = position - Vec2(pointSize4, pointSize4); - Vec2 destination = position + Vec2(pointSize4, pointSize4); - Vec2 _vertices[] = {origin, Vec2(destination.x, origin.y), destination, Vec2(origin.x, destination.y)}; - _drawPolygon(_vertices, 4, color, color, false, 0.0f, true); } else { @@ -1431,14 +1238,14 @@ void DrawNode::_drawPie(const Vec2& center, DrawMode drawMode, float thickness) { -#define DEGREES 360 +#define CIRCLE_DEGREES 360 // Not a real line! if (startAngle == endAngle) return; // Its a circle? - if (MAX((startAngle - endAngle), (endAngle - startAngle)) == DEGREES) + if (MAX((startAngle - endAngle), (endAngle - startAngle)) == CIRCLE_DEGREES) { switch (drawMode) { @@ -1446,12 +1253,10 @@ void DrawNode::_drawPie(const Vec2& center, _drawCircle(center, radius, 0.0f, 360, false, scaleX, scaleY, borderColor, fillColor, true, thickness); break; case DrawMode::Outline: - _drawCircle(center, radius, 0.0f, 360, false, scaleX, scaleY, borderColor, Color::TRANSPARENT, true, - thickness); + _drawCircle(center, radius, 0.0f, 360, false, scaleX, scaleY, borderColor, Color(), true, thickness); break; case DrawMode::Line: - _drawCircle(center, radius, 0.0f, 360, false, scaleX, scaleY, borderColor, Color::TRANSPARENT, true, - thickness); + _drawCircle(center, radius, 0.0f, 360, false, scaleX, scaleY, borderColor, Color(), true, thickness); break; case DrawMode::Semi: _drawCircle(center, radius, 0.0f, 360, false, scaleX, scaleY, borderColor, fillColor, true, thickness); @@ -1463,9 +1268,9 @@ void DrawNode::_drawPie(const Vec2& center, } else { - const float coef = 2.0f * (float)M_PI / DEGREES; + const float coef = 2.0f * (float)M_PI / CIRCLE_DEGREES; - tlx::pod_vector _vertices(DEGREES + 2); + tlx::pod_vector _vertices(CIRCLE_DEGREES + 2); int n = 0; float rads = 0.0f; @@ -1476,7 +1281,7 @@ void DrawNode::_drawPie(const Vec2& center, std::swap(endAngle, startAngle); } - for (int i = 0; i <= DEGREES; i++) + for (int i = 0; i <= CIRCLE_DEGREES; i++) { if (startAngle <= i && endAngle >= i) { @@ -1495,7 +1300,7 @@ void DrawNode::_drawPie(const Vec2& center, case DrawMode::Fill: _vertices[n++] = center; _vertices[n++] = _vertices[0]; - _drawPolygon(_vertices.data(), n, fillColor, Color::TRANSPARENT, true, 0, false); + _drawPolygon(_vertices.data(), n, fillColor, Color(), true, 0, false); _drawPoly(_vertices.data(), n, false, borderColor, thickness, true); break; case DrawMode::Outline: @@ -1507,7 +1312,7 @@ void DrawNode::_drawPie(const Vec2& center, _drawPoly(_vertices.data(), n, false, borderColor, thickness, true); break; case DrawMode::Semi: - if (fillColor != Color::TRANSPARENT) + if (fillColor != Color()) _drawPolygon(_vertices.data(), n, fillColor, borderColor, true, 0, false); _drawPoly(_vertices.data(), n, true, borderColor, thickness, true); break; @@ -1528,7 +1333,7 @@ tlx::pod_vector DrawNode::_transform(const Vec2* _vertices, unsigned int& } tlx::pod_vector vert(count + closedCounter); - if (properties.transform == false) + if (!_localTransformEnabled) { memcpy(vert.data(), _vertices, count * sizeof(Vec2)); if (closedCounter) @@ -1538,7 +1343,7 @@ tlx::pod_vector DrawNode::_transform(const Vec2* _vertices, unsigned int& return vert; } - applyTransform(_vertices, vert.data(), count); + applyLocalTransform(_vertices, vert.data(), count); if (closedCounter) { @@ -1548,63 +1353,44 @@ tlx::pod_vector DrawNode::_transform(const Vec2* _vertices, unsigned int& return vert; } -void DrawNode::applyTransform(const Vec2* from, Vec2* to, unsigned int count) +void DrawNode::applyLocalTransform(const Vec2* from, Vec2* to, unsigned int count) const { - if (properties.transform == false) + if (!_localTransformEnabled) return; - auto scale = properties.scale; - auto position = properties.position; - - if (properties.rotation == 0.0f) + if (_localRotationRad == 0.0f) { for (unsigned int i = 0; i < count; i++) { - to[i].x = from[i].x * scale.x + position.x; - to[i].y = from[i].y * scale.y + position.y; + to[i].x = from[i].x * _localScale.x + _localPosition.x; + to[i].y = from[i].y * _localScale.y + _localPosition.y; } } else { - const float sinRot = sin(properties.rotation); - const float cosRot = cos(properties.rotation); - auto center = properties.center; + const float sinRot = sin(_localRotationRad); + const float cosRot = cos(_localRotationRad); // https://stackoverflow.com/questions/2259476/rotating-a-point-about-another-point-2d for (unsigned int i = 0; i < count; i++) { // translate point to origin - float x = from[i].x - center.x; - float y = from[i].y - center.y; + float x = from[i].x - _localPivot.x; + float y = from[i].y - _localPivot.y; - // rotate point + // rotate point (counter clockwise) float rx = x * cosRot - y * sinRot; float ry = x * sinRot + y * cosRot; // translate point back - x = rx + center.x; - y = ry + center.y; + x = rx + _localPivot.x; + y = ry + _localPivot.y; // scale and position - to[i].x = x * scale.x + position.x; - to[i].y = y * scale.y + position.y; + to[i].x = x * _localScale.x + _localPosition.x; + to[i].y = y * _localScale.y + _localPosition.y; } } } -void DrawNode::Properties::setDefaultValues() -{ - auto fac = Director::getInstance()->getContentScaleFactor(); - factor = fac; - - scale = Vec2(1.0f, 1.0f); - center = Vec2(0.0f, 0.0f); - rotation = 0.0f; - position = Vec2(0.0f, 0.0f); - drawOrder = false; -}; - -#if defined(_WIN32) -# pragma pop_macro("TRANSPARENT") -#endif } // namespace ax diff --git a/axmol/2d/DrawNode.h b/axmol/2d/DrawNode.h index f8d3fae12149..68904c9357fc 100644 --- a/axmol/2d/DrawNode.h +++ b/axmol/2d/DrawNode.h @@ -489,9 +489,9 @@ class AX_DLL DrawNode : public Node, public BlendProtocol */ void drawColoredTriangle(const Vec2* vertices3, const Color* color3); - void drawTriangle(const Vec2* vertices3, const Color& color); - void drawTriangle(const Vec2& p1, const Vec2& p2, const Vec2& p3, const Color& color); + void drawTriangle(const Vec2* vertices3, const Color& color, float thickness = 1.0f); + void drawTriangle(const Vec2& p1, const Vec2& p2, const Vec2& p3, const Color& color, float thickness = 1.0f); void drawSolidTriangle(const Vec2* vertices3, const Color& fillColor, @@ -582,15 +582,9 @@ class AX_DLL DrawNode : public Node, public BlendProtocol // Internal function _drawDot void _drawDot(const Vec2& pos, float radius, const Color& color); - // Internal function _drawTriangle + // Internal function _drawColoredTriangle // Note: modifies supplied vertex array - void _drawTriangle(Vec2* vertices3, - const Color& borderColor, - const Color& fillColor, - bool solid = true, - float thickness = 0.0f); - - void _drawColoredTriangle(Vec2* vertices3, const Color* color3); + void _drawColoredTriangle(const Vec2* vertices3, const Color* color3); // Internal function _drawAStar void _drawAStar(const Vec2& center, @@ -663,96 +657,91 @@ class AX_DLL DrawNode : public Node, public BlendProtocol */ tlx::pod_vector _transform(const Vec2* vertices, unsigned int& count, bool closedPolygon = false); - void applyTransform(const Vec2* from, Vec2* to, unsigned int count); - -private: - AX_DISALLOW_COPY_AND_ASSIGN(DrawNode); + void applyLocalTransform(const Vec2* from, Vec2* to, unsigned int count) const; + /// Advanced settings public: - class AX_DLL Properties + float getThicknessScale() const { return _thicknessScale; } + void setThicknessScale(float s) { - public: - float factor; /// thickness scale factor - - // transforming stuff - Vec2 scale; - Vec2 center; - float rotation; - Vec2 position; - - // Drawing flags - bool transform = false; - bool drawOrder = false; - - /** Set the DrawNode drawOrder - * - * @param drawOrder. true/false = On/Off - * Its for performance there - * false = cocos2dx behaviour => faster but works only on 1.0f thickness - - */ - void setDrawOrder(bool dO) { drawOrder = dO; }; - - /** Get the DrawNode drawOrder - * - */ - bool getDrawOrder(void) { return drawOrder; }; - - /** Set the DrawNode transform - * - * @param transform. true/false = On/Off - * - */ - void setTransform(bool t) { transform = t; }; - - /** Get the DrawNode transform - * - */ - bool getTransform(void) { return transform; }; - - /** Set the DrawNode scale for each drawing primitive after this. - - */ - void setScale(Vec2 s) { scale = s; }; - - /** Set the DrawNode rotation for each drawing primitive after this. + _thicknessScale = s; + _linesDirty = _trianglesDirty = true; + } - */ - void setRotation(float r) { rotation = r; }; - - /** Get the DrawNode rotation for each drawing primitive after this. - - */ - float getRotation() { return rotation; }; - - /** Set the DrawNode center of rotation for each drawing primitive after this. + bool isLocalTransformEnabled() const { return _localTransformEnabled; } + void setLocalTransformEnabled(bool e) + { + _localTransformEnabled = e; + _linesDirty = _trianglesDirty = true; + } - */ - void setCenter(Vec2 c) { center = c; }; + void setLocalScale(const Vec2& s) + { + _localScale = s; + _trianglesDirty = _linesDirty = true; + } + const Vec2& getLocalScale() const { return _localScale; } - /** Get the DrawNode center of rotation for each drawing primitive after this. + void setLocalPivot(const Vec2& c) + { + _localPivot = c; + _trianglesDirty = _linesDirty = true; + } + const Vec2& getLocalPivot() const { return _localPivot; } - */ - Vec2 getCenter() { return center; }; + void setLocalRotation(float a) + { + _localRotation = a; + _localRotationRad = AX_DEGREES_TO_RADIANS(_localRotation); + _trianglesDirty = _linesDirty = true; + } + float getLocalRotation() const { return _localRotation; } - /** Set the DrawNode position for each drawing primitive after this. + void setLocalPosition(const Vec2& p) + { + _localPosition = p; + _trianglesDirty = _linesDirty = true; + } + const Vec2& getLocalPosition() const { return _localPosition; } - */ - void setPosition(Vec2 p) { position = p; }; + void setPreserveDrawOrder(bool v) + { + _preserveDrawOrder = v; + _trianglesDirty = _linesDirty = true; + } + bool isPreserveDrawOrder() const { return _preserveDrawOrder; } - /** Get the DrawNode position for drawing primitive. + // convenience: reset to defaults + void resetAdvancedSettings() + { + _thicknessScale = 1.0f; + _localScale = Vec2(1.0f, 1.0f); + _localPivot = Vec2::ZERO; + _localRotation = 0.0f; + _localRotationRad = 0.0f; + _localPosition = Vec2::ZERO; + _preserveDrawOrder = false; + _localTransformEnabled = false; + _trianglesDirty = _linesDirty = _pointsDirty = true; + } - */ - Vec2 getPosition() { return position; }; +protected: + // thickness scale (was factor) + float _thicknessScale{1.0f}; - /** Set all default DrawNode properties. + // optional local transform applied to primitives when enabled + Vec2 _localScale{1.0f, 1.0f}; + Vec2 _localPivot{0.0f, 0.0f}; + float _localRotation{0.0f}; // local rotation in degrees + float _localRotationRad{0.0f}; // local rotation in radians (cached for efficiency) + Vec2 _localPosition{0.0f, 0.0f}; - */ - void setDefaultValues(); - float getFactor() { return factor; }; - void setFactor(float fac) { factor = fac; }; + // flags + bool _localTransformEnabled{false}; + bool _preserveDrawOrder{false}; - } properties; +private: + AX_DISALLOW_COPY_AND_ASSIGN(DrawNode); }; /** @} */ diff --git a/axmol/2d/Label.cpp b/axmol/2d/Label.cpp index d6e9af3d367a..7e849f53022b 100644 --- a/axmol/2d/Label.cpp +++ b/axmol/2d/Label.cpp @@ -1523,8 +1523,7 @@ void Label::enableUnderline() _lineDrawNode = DrawNode::create(); _lineDrawNode->setGlobalZOrder(getGlobalZOrder()); _lineDrawNode->setOpacity(_displayedColor.a); - _lineDrawNode->properties.setFactor(_lineDrawNode->properties.getFactor() * - 2.0f); // 2.0f: Makes the line smaller + _lineDrawNode->setThicknessScale(_lineDrawNode->getThicknessScale() * 0.5f); // 0.5f: Makes the line smaller addChild(_lineDrawNode, 100000); } } @@ -1542,8 +1541,7 @@ void Label::enableStrikethrough() _lineDrawNode = DrawNode::create(); _lineDrawNode->setGlobalZOrder(getGlobalZOrder()); _lineDrawNode->setOpacity(_displayedColor.a); - _lineDrawNode->properties.setFactor(_lineDrawNode->properties.getFactor() * - 2.0f); // 2.0f: Makes the line smaller + _lineDrawNode->setThicknessScale(_lineDrawNode->getThicknessScale() * 0.5f); // 0.5f: Makes the line smaller addChild(_lineDrawNode, 100000); } } diff --git a/tests/cpp-tests/Source/DrawNodeTest/DrawNodeTest.cpp b/tests/cpp-tests/Source/DrawNodeTest/DrawNodeTest.cpp index 1402211dd636..3363c53edf33 100644 --- a/tests/cpp-tests/Source/DrawNodeTest/DrawNodeTest.cpp +++ b/tests/cpp-tests/Source/DrawNodeTest/DrawNodeTest.cpp @@ -26,13 +26,13 @@ THE SOFTWARE. #include "DrawNodeTest.h" #include "axmol/renderer/Renderer.h" #include "axmol/renderer/CustomCommand.h" +#include -#if defined(_WIN32) -# pragma push_macro("TRANSPARENT") -# undef TRANSPARENT -#endif +#include "extensions/ExtensionMacros.h" +#include "ImGui/ImGuiPresenter.h" USING_NS_AX; +USING_NS_AX_EXT; using namespace std; // clang-format off @@ -1331,18 +1331,93 @@ float verticesFB[] = { 14.540f, 3.373f, 14.330f, 3.236f, 14.050f, 3.047f, 13.730f, 2.800f, 13.360f, 2.489f, 12.950f, 2.107f, 12.520f, 1.649f, 0.842f, 1.649f, 27.220f, 1.649f, 27.220f, 1.052f}; + +static Vec2 horse[] = { + {415, 25.4}, {406.6, 41.3}, {398.7, 48.1}, {393.9, 65.8}, {367.9, 107.7}, {364.1, 130.6}, {370.2, 142}, + {381.5, 143}, {396, 149.2}, {439.5, 179.6}, {452, 201.5}, {452, 231.2}, {461.1, 240.3}, {477.3, 247}, + {531.4, 254}, {574.8, 267.2}, {659.3, 316.4}, {677.9, 336}, {690.2, 337.9}, {773.4, 336}, {805.5, 313.6}, + {817.2, 301.9}, {820.3, 292.7}, {840, 279}, {840, 263.2}, {845.1, 258}, {870.2, 257}, {884.6, 260.3}, + {887.1, 269.2}, {880.6, 283.3}, {862.4, 296.3}, {862.5, 296.4}, {829.2, 332.7}, {822.2, 335.5}, {807.3, 354.5}, + {791.8, 363.8}, {770.3, 370.4}, {793.5, 382}, {806.7, 382.9}, {831.9, 372.3}, {852, 355.2}, {866.7, 351.3}, + {876.9, 333.9}, {908.6, 337.1}, {917, 341.8}, {917, 354.9}, {898, 372.8}, {878.9, 376.8}, {870.1, 385.7}, + {835.1, 399.7}, {825.2, 410.7}, {814.5, 415}, {789.7, 417}, {754.7, 405}, {734.9, 405}, {734, 422.3}, + {726.8, 445.9}, {701, 479.6}, {701, 554.6}, {706.5, 567.5}, {713.4, 571.8}, {730.2, 567.9}, {748.5, 577}, + {780.7, 577}, {790.6, 573.7}, {809.9, 594.1}, {811.1, 609.7}, {792.2, 631.6}, {742.7, 654.9}, {709.9, 664.7}, + {692.7, 679}, {671, 679}, {671, 674.3}, {677, 666}, {648.2, 679.1}, {641.1, 677.3}, {650.1, 658.2}, + {641.9, 655.8}, {622.4, 635.3}, {580.3, 572}, {546.1, 503.6}, {543.8, 483.2}, {557, 482.1}, {557, 481.9}, + {545.4, 471.3}, {525.6, 435.5}, {508.6, 419.5}, {477.1, 402.8}, {477.1, 402.7}, {425.4, 390.9}, {373.1, 368.8}, + {352.7, 355.5}, {321.1, 321}, {308.1, 321}, {289.3, 326}, {263.8, 326}, {216.2, 315}, {177.2, 323}, + {154.8, 323}, {111.9, 314.8}, {106.5, 307.7}, {134.4, 302}, {158.4, 290.1}, {169.1, 288.2}, {118.5, 281}, + {39, 252.4}, {39, 244.1}, {75, 243}, {126.2, 243}, {148.9, 247.8}, {134.3, 229.1}, {125.1, 210.7}, + {116, 175.3}, {116, 156.8}, {122.5, 153.5}, {158.3, 196.5}, {215.9, 241.2}, {235.5, 251}, {240, 251.4}, + {236.5, 248.3}, {224.5, 229.5}, {209.6, 222}, {212.5, 211.9}, {242.4, 213}, {257, 219.3}, {282.3, 238.5}, + {308.4, 266.3}, {310.1, 249.4}, {340.9, 195.6}, {340, 185.7}, {331.7, 175.6}, {295.9, 160.7}, {285.7, 150.5}, + {295.2, 123.1}, {304.2, 111}, {315, 75.7}, {315, 15}, {321.3, 10}, {363.1, 11.1}, {362, 34.7}, + {352.9, 46.7}, {349, 69.8}, {355, 58.4}, {356, 43.3}, {365.9, 29.4}, {364.9, 11.1}, {413.9, 8.9}, +}; + +static Vec2 spider[] = { + {233.9, 47.1}, {240, 78.8}, {239, 122}, {245, 162.7}, {255.7, 196.9}, {271.8, 221}, {285.9, 253.4}, + {290, 274.8}, {290, 299.1}, {298, 306.2}, {381.3, 350.8}, {386.7, 349.5}, {386.1, 345.9}, {327.2, 288}, + {324.9, 278.8}, {327.7, 272.2}, {315.2, 254.9}, {308, 230.4}, {300, 150.9}, {305.1, 129.4}, {317.3, 101.8}, + {324.5, 94.6}, {334.2, 98.8}, {328, 146.3}, {328.9, 187.6}, {345.9, 227.4}, {349, 243.9}, {348, 260.2}, + {370.5, 283.7}, {394.4, 316.5}, {406.9, 325.5}, {427, 310.2}, {443.9, 303.9}, {466.9, 310.2}, {482.9, 323.1}, + {491.3, 324.7}, {543, 266.1}, {550.1, 220.3}, {561.2, 200}, {565, 186}, {566, 139.3}, {560.8, 98.5}, + {570.4, 95.8}, {575.6, 99.7}, {594, 142.6}, {592, 193.2}, {585, 234.5}, {578.8, 254.9}, {568.9, 268.6}, + {568, 287.9}, {508.8, 346.9}, {508.3, 350.2}, {512.6, 350.9}, {566.1, 319.2}, {596.8, 306.3}, {604, 299.1}, + {605, 271.7}, {609.1, 254.4}, {622.2, 223}, {639.3, 197.9}, {651, 160.6}, {659.1, 55.1}, {671.6, 42.5}, + {684.4, 49.5}, {688.9, 56.2}, {697, 100}, {691, 141.4}, {672.9, 214.2}, {673, 214.3}, {668, 252.5}, + {660.8, 273.8}, {642.6, 306.2}, {634.1, 315.7}, {629.5, 317.2}, {634.2, 331.3}, {627.4, 341.5}, {613.8, 348.8}, + {526, 378.7}, {524.9, 379.8}, {549.7, 379}, {636, 367}, {660.5, 369.8}, {664.2, 358.1}, {683.4, 329.7}, + {717.7, 294.5}, {732.6, 284.4}, {752.2, 259}, {779.2, 210}, {809.3, 131.9}, {814.2, 127}, {820.8, 127}, + {826.9, 133.1}, {828, 145.1}, {818.9, 184.7}, {810.1, 203.1}, {813, 211.8}, {812, 224.6}, {781.7, 278}, + {734.6, 349.2}, {708.3, 377.5}, {690.8, 389.9}, {678.5, 392.6}, {674.7, 403.1}, {665.1, 412.7}, {653.3, 417}, + {548.1, 410}, {537.4, 411.8}, {560.7, 421.1}, {560.6, 421.1}, {623.8, 439.1}, {658.4, 457.9}, {673.4, 455.9}, + {681.6, 461}, {685.8, 461}, {692.4, 448.8}, {716.7, 423.4}, {755.7, 399.4}, {775.6, 380.6}, {821.4, 321.8}, + {848.5, 270.5}, {859.6, 264.4}, {867.1, 274.5}, {864.9, 288.5}, {856.8, 310.9}, {840.9, 336.5}, {840, 352.5}, + {835.7, 361.1}, {748.3, 460.5}, {718.8, 478.9}, {701.2, 483.7}, {690.3, 497.6}, {675.4, 504}, {662.2, 504}, + {651.3, 493.1}, {642, 495}, {628.3, 491.9}, {541.1, 446.3}, {588.5, 494.6}, {655.5, 570.7}, {666.8, 584.1}, + {669.5, 595}, {677.8, 595}, {694, 609.3}, {722.9, 585.3}, {764.9, 565.2}, {814.9, 517.3}, {828.4, 511.1}, + {857.4, 505}, {875.7, 495.9}, {887, 498.4}, {887, 508.7}, {881.3, 515.6}, {851.9, 529.8}, {851.8, 529.7}, + {823.1, 549.5}, {823.2, 549.6}, {798.2, 569.6}, {755.2, 611.6}, {734.7, 622.9}, {706.2, 627.8}, {701.5, 636.4}, + {689.6, 644}, {660.2, 645}, {649.1, 633.9}, {648.1, 623.4}, {638.9, 619.7}, {624.5, 605.3}, {533.6, 488.3}, + {531, 528.3}, {524.9, 550.7}, {513, 573.4}, {515, 605.5}, {506.3, 619.2}, {499, 611.8}, {499, 597.9}, + {495.9, 595.5}, {480, 607.8}, {458.1, 616.7}, {449.3, 627.8}, {437, 617.8}, {413.9, 608.7}, {401.3, 597.1}, + {397.7, 597.7}, {394.8, 615.1}, {388.5, 619.9}, {380, 606.5}, {381.9, 572.4}, {372.1, 554.8}, {365, 530.4}, + {359.6, 490}, {274.5, 601.3}, {258.1, 618.8}, {246.8, 621.5}, {245.9, 634.9}, {234.7, 645.1}, {220.8, 644}, + {205.5, 644}, {198.7, 640.6}, {187.9, 626.8}, {164.4, 623.9}, {141.8, 612.7}, {84.6, 559.5}, {84.6, 559.4}, + {49.1, 534.7}, {49.1, 534.8}, {16.8, 517.6}, {9.1, 509.9}, {7.8, 499.5}, {18.2, 496.9}, {47.4, 510}, + {63.4, 510}, {74, 514.2}, {99.3, 532.5}, {127.1, 563.3}, {172, 585.3}, {192.4, 600.6}, {199, 609}, + {201.2, 609}, {213, 597.2}, {224.4, 594.3}, {228.2, 583.1}, {236.5, 571.7}, {349.8, 450.6}, {337.7, 454.9}, + {260.5, 494}, {243.6, 494.9}, {228.4, 505.1}, {217.3, 502.9}, {204.6, 496.6}, {195.9, 483.8}, {179.3, 480.9}, + {152.8, 464.6}, {133.5, 445.4}, {72.4, 377.3}, {61.3, 362}, {40.1, 319.8}, {26.9, 278.1}, {29.4, 267.2}, + {40.1, 265.9}, {68.6, 315.8}, {114.4, 376.6}, {135.1, 397.3}, {158.1, 409.3}, {178.3, 424.5}, {204.6, 451.8}, + {209.8, 460.5}, {220.7, 455.9}, {233.5, 457.8}, {248.1, 447.2}, {359.2, 410.7}, {353.8, 410}, {271.1, 417}, + {238.6, 417}, {230.9, 413.7}, {223.4, 407.3}, {215.6, 391.8}, {207.3, 390.9}, {186.7, 377.6}, {162.4, 352.2}, + {99.3, 255}, {82, 223.4}, {83.9, 201.2}, {73.1, 176.6}, {67, 146}, {69.3, 131.1}, {84.4, 129.9}, + {108.8, 197.1}, {142.7, 260.9}, {167.2, 290.3}, {183.3, 300.4}, {202.5, 319.7}, {218.7, 339.9}, {234.1, 368.8}, + {254, 367}, {367.8, 380.2}, {365, 377.7}, {290.2, 352.9}, {265.3, 340.4}, {261.9, 326.9}, {265.5, 316.8}, + {253.5, 309.4}, {239.2, 283.8}, {223, 236.4}, {218, 195.2}, {218, 195.1}, {205, 147.4}, {200, 110.1}, + {203, 71.6}, {208.7, 55.7}, {209, 55.7}, {209, 49.2}, {217.1, 40}, {227.9, 40}, +}; + // clang-format on DrawNodeTests::DrawNodeTests() { ADD_TEST_CASE(DrawNodeCircleTest); + ADD_TEST_CASE(DrawNodeSolidCircleTest); + ADD_TEST_CASE(DrawNodePolygonTest); + ADD_TEST_CASE(DrawNodeSpLinesTest); ADD_TEST_CASE(DrawNodeSpLinesOpenClosedTest); ADD_TEST_CASE(DrawNodeAxmolTest2); #if defined(AX_PLATFORM_PC) ADD_TEST_CASE(CandyMixEeffect); + ADD_TEST_CASE(DrawNodePointTest); #endif + ADD_TEST_CASE(DrawNodePictureTest); ADD_TEST_CASE(DrawNodeJellyFishTest); ADD_TEST_CASE(DrawNodeMorphTest_Polygon); @@ -1361,7 +1436,7 @@ DrawNodeTests::DrawNodeTests() DrawNodeBaseTest::DrawNodeBaseTest() { auto director = Director::getInstance(); - director->setClearColor(Color::TRANSPARENT); + director->setClearColor(Color()); origin = director->getVisibleOrigin(); size = director->getVisibleSize(); @@ -1389,92 +1464,93 @@ DrawNodeBaseTest::DrawNodeBaseTest() if (!drawNode) { drawNode = DrawNode::create(); - drawNode->properties.setTransform(true); + drawNode->setLocalTransformEnabled(true); addChild(drawNode); - } - menuItemDrawOrder->setFontSize(10); - menuItemTransform->setFontSize(10); - menuItemDrawOrder = MenuItemFont::create("drawOrder: false", AX_CALLBACK_1(DrawNodeBaseTest::setDrawOrder, this)); - menuItemTransform = MenuItemFont::create("transform: true", AX_CALLBACK_1(DrawNodeBaseTest::setTransform, this)); - auto menu = Menu::create(menuItemDrawOrder, menuItemTransform, nullptr); - menu->alignItemsVerticallyWithPadding(4); - menu->setPosition(Vec2(size.x - 50, size.y / 2 - 20)); - addChild(menu, 1000); -} - -void DrawNodeBaseTest::generateDataPoints() -{ - for (int i = 0; i < n; ++i) - { - float yy1 = RandomHelper::random_real(defY - dev, defY + dev); - float yy2 = RandomHelper::random_real(defY2 - dev, defY2 + dev); - pts->replaceControlPoint(Vec2(margin + i * (screen.width - 3 * margin) / n, yy1), i); - pts2->replaceControlPoint(Vec2(margin + i * (screen.width - 3 * margin) / n, yy2), i); + ns = drawNode->getScale(); + ps = drawNode->getLocalScale(); + pf = drawNode->getThicknessScale(); + thickness = 1; + pa = drawNode->getLocalRotation(); + as = 0; + ae = 200; + drawOrder = true; + transform = false; } } -void DrawNodeBaseTest::setTransform(Object* sender) +void DrawNodeBaseTest::onEnter() { - bool ret = drawNode->properties.getTransform(); - if (ret) - { - menuItemTransform->setString("transform: false"); - drawNode->properties.setTransform(false); - } - else - { - menuItemTransform->setString("transform: true"); - drawNode->properties.setTransform(true); - } + TestCase::onEnter(); + + auto* presenter = ImGuiPresenter::getInstance(); + presenter->addFont(FileUtils::getInstance()->fullPathForFilename("fonts/arial.ttf")); + presenter->enableDPIScale(); + presenter->addRenderLoop("#DrawNode", AX_CALLBACK_0(DrawNodeBaseTest::onDrawImGui, this), this); } -void DrawNodeBaseTest::setDrawOrder(Object* sender) +void DrawNodeBaseTest::onExit() { - bool ret = drawNode->properties.getDrawOrder(); - if (ret) + auto presenter = ImGuiPresenter::getInstance(); + if (presenter) { - menuItemDrawOrder->setString("drawOrder: false"); - drawNode->properties.setDrawOrder(false); - } - else - { - menuItemDrawOrder->setString("drawOrder: true"); - drawNode->properties.setDrawOrder(true); + presenter->removeRenderLoop("#DrawNode"); + presenter->clearFonts(); } + + TestCase::onExit(); } -void DrawNodeBaseTest::listviewCallback(ax::Object* sender, ax::ui::ListView::EventType type) +void DrawNodeBaseTest::generateDataPoints() { - // clear all text to white - auto listview = static_cast(sender); - for (auto&& item : listview->getItems()) + for (int i = 0; i < n; ++i) { - static_cast(item)->setColor(ax::Color32::WHITE); + float yy1 = RandomHelper::random_real(defY - dev, defY + dev); + float yy2 = RandomHelper::random_real(defY2 - dev, defY2 + dev); + pts->replaceControlPoint(Vec2(margin + i * (screen.width - 3 * margin) / n, yy1), i); + pts2->replaceControlPoint(Vec2(margin + i * (screen.width - 3 * margin) / n, yy2), i); } - _currentSeletedItemIndex = (int)listview->getCurSelectedIndex(); - listview->getItem(_currentSeletedItemIndex)->setColor(ax::Color32::RED); } -void DrawNodeBaseTest::onChangedRadioButtonSelect(ui::RadioButton* radioButton, ui::RadioButton::EventType type) +void DrawNodeBaseTest::onDrawImGui() { - if (radioButton == nullptr) - return; - - switch (type) + if (flagGUI != -1) { - case ui::RadioButton::EventType::SELECTED: - { - selectedRadioButton = radioButton->getTag(); - break; - } + if (ImGui::Begin("DrawNode::properties. Dialog")) + { + if (flagGUI == 1) + { + const char* items[drawMethodes::LAST]; + int i = 0; + for (i; i < (drawMethodes::LAST); i++) + { + items[i] = drawMethods[i].c_str(); + } + ImGui::Combo("##", &_currentSeletedItemIndex, items, i); + } + float _po[2] = {po.x, po.y}; + ImGui::BeginDisabled(); + ImGui::DragFloat2("Position", _po); + ImGui::EndDisabled(); + ImGui::SliderFloat("Thickness", &thickness, 0.0f, 10.0f); + ImGui::SliderFloat("Factor", &pf, 0.0f, 10.0f); + ImGui::SliderFloat("Node::Scale", &ns, 0.0f, 10.0f); + ImGui::Checkbox("drawOrder", &drawOrder); + ImGui::SameLine(); + ImGui::Checkbox("transform", &transform); + float _ps[2] = {ps.x, ps.y}; + ImGui::DragFloat2("Scale", _ps); + ps = Vec2(_ps[0], _ps[1]); + ImGui::SliderFloat("Angle", &pa, 0.0f, 360.0f); + + if (flagGUI == 2) + { + ImGui::SliderFloat("Angle Start", &as, 0.0f, 360.0f); + ImGui::SliderFloat("Angle End", &ae, 0.0f, 360.0f); + } - case ui::RadioButton::EventType::UNSELECTED: - { - break; - } - default: - break; + ImGui::End(); + } } } @@ -1492,90 +1568,12 @@ void DrawNodeBaseTest::drawDirection(const Vec2* vec, const int size, Vec2 offse { for (size_t i = 0; i < size; i++) { - auto label = Label::createWithTTF(std::to_string(i).c_str(), "fonts/Marker Felt.ttf", 10); + auto label = Label::createWithTTF(std::to_string(i).c_str(), "fonts/Marker Felt.ttf", 8); addChild(label); label->setPosition(vec[i] + offset); } } -void DrawNodeBaseTest::changeEndAngle(ax::Object* pSender, ax::ui::Slider::EventType type) -{ - if (type == ax::ui::Slider::EventType::ON_PERCENTAGE_CHANGED) - { - slider[sliderType::AngleEnd] = dynamic_cast(pSender); - sliderValue[sliderType::AngleEnd] = slider[sliderType::AngleEnd]->getPercent() * 3.6; - sliderLabel[sliderType::AngleEnd]->setString("endAngle: (" + - Value(sliderValue[sliderType::AngleEnd]).asString() + ")"); - } -} - -void DrawNodeBaseTest::changeStartAngle(ax::Object* pSender, ax::ui::Slider::EventType type) -{ - if (type == ax::ui::Slider::EventType::ON_PERCENTAGE_CHANGED) - { - slider[sliderType::AngleStart] = dynamic_cast(pSender); - sliderValue[sliderType::AngleStart] = slider[sliderType::AngleStart]->getPercent() * 3.6; - sliderLabel[sliderType::AngleStart]->setString("startAngle: (" + - Value(sliderValue[sliderType::AngleStart]).asString() + ")"); - } -} - -void DrawNodeBaseTest::changeRotation(ax::Object* pSender, ax::ui::Slider::EventType type) -{ - if (type == ax::ui::Slider::EventType::ON_PERCENTAGE_CHANGED) - { - slider[sliderType::Rotation] = dynamic_cast(pSender); - sliderValue[sliderType::Rotation] = slider[sliderType::Rotation]->getPercent() * 3.6; - sliderLabel[sliderType::Rotation]->setString("Rotation: (" + - Value(sliderValue[sliderType::Rotation]).asString() + ")"); - } -} - -void DrawNodeBaseTest::changeThickness(ax::Object* pSender, ax::ui::Slider::EventType type) -{ - if (type == ax::ui::Slider::EventType::ON_PERCENTAGE_CHANGED) - { - slider[sliderType::Thickness] = dynamic_cast(pSender); - sliderValue[sliderType::Thickness] = slider[sliderType::Thickness]->getPercent() * 0.1; - sliderLabel[sliderType::Thickness]->setString("Thickness: (" + - Value(sliderValue[sliderType::Thickness]).asString() + ")"); - } -} - -void DrawNodeBaseTest::initSliders() -{ - _currentSeletedItemIndex = 0; - - std::string text[sliderType::sliderTypeLast] = {"AngleStart", "AngleEnd", "Rotation", "Thickness"}; - - auto ttfConfig = TTFConfig("fonts/arial.ttf", 5); - for (int i = 0; i < (sliderType::sliderTypeLast); i++) - { - slider[i] = ax::ui::Slider::create(); - slider[i]->setAnchorPoint(Vec2::ANCHOR_MIDDLE_LEFT); - slider[i]->loadBarTexture("cocosui/sliderTrack.png"); - slider[i]->loadSlidBallTextures("ccs-res/cocosui/sliderballnormal.png", "ccs-res/cocosui/sliderballpressed.png", - ""); - slider[i]->loadProgressBarTexture("cocosui/sliderProgress.png"); - slider[i]->setPosition(Vec2(size.width - slider[i]->getContentSize().x / 2 - 10, size.height / 6 + i * 16)); - slider[i]->setPercent(sliderValue[i]); - - slider[i]->setEnabled(false); - slider[i]->setScale(0.5f); - addChild(slider[i], 20); - - sliderLabel[i] = Label::createWithTTF(ttfConfig, text[i] + ": (" + Value(sliderValue[i]).asString() + ")"); - sliderLabel[i]->setAnchorPoint(Vec2::ANCHOR_MIDDLE_LEFT); - sliderLabel[i]->setPosition(slider[i]->getPosition() + Vec2(0, 8)); - addChild(sliderLabel[i], 20); - } - - slider[sliderType::AngleStart]->addEventListener(AX_CALLBACK_2(DrawNodeBaseTest::changeStartAngle, this)); - slider[sliderType::AngleEnd]->addEventListener(AX_CALLBACK_2(DrawNodeBaseTest::changeEndAngle, this)); - slider[sliderType::Rotation]->addEventListener(AX_CALLBACK_2(DrawNodeBaseTest::changeRotation, this)); - slider[sliderType::Thickness]->addEventListener(AX_CALLBACK_2(DrawNodeBaseTest::changeThickness, this)); -} - DrawNodeMorphTest_SolidPolygon::DrawNodeMorphTest_SolidPolygon() { const float coef = 2.0f * (float)M_PI / segments; @@ -1586,9 +1584,8 @@ DrawNodeMorphTest_SolidPolygon::DrawNodeMorphTest_SolidPolygon() for (size_t n = 0; n < 10; n++) { - drawNodeArray[n] = DrawNode::create(); - drawNodeArray[n]->properties.setTransform(true); + drawNodeArray[n]->setLocalTransformEnabled(true); addChild(drawNodeArray[n]); drawNodeArray[n]->setPosition( Vec2(AXRANDOM_MINUS1_1() * size.width / 4, AXRANDOM_MINUS1_1() * size.height / 4) + Vec2(100, 100)); @@ -1641,14 +1638,11 @@ DrawNodeMorphTest_SolidPolygon::DrawNodeMorphTest_SolidPolygon() verticesObj2[n][i++] = center + Vec2(x, 50); } } - - initSliders(); - slider[sliderType::Thickness]->setEnabled(true); - scheduleUpdate(); } void DrawNodeMorphTest_SolidPolygon::update(float dt) { + for (int n = 0; n < 10; n++) { drawNodeArray[n]->clear(); @@ -1677,23 +1671,13 @@ void DrawNodeMorphTest_SolidPolygon::update(float dt) state[n] = !state[n]; } - drawNodeArray[n]->properties.setScale(Vec2(0.5f, 0.5f)); - drawNodeArray[n]->drawSolidPolygon(verticesObjMorph[n], segments, color[n], sliderValue[sliderType::Thickness], - Color::YELLOW); + drawNodeArray[n]->setLocalScale(Vec2(0.5f, 0.5f)); + drawNodeArray[n]->drawSolidPolygon(verticesObjMorph[n], segments, color[n], thickness, Color::YELLOW); } } void DrawNodeMorphTest_SolidPolygon::onEnter() { - for (int i = 0; i < sliderType::sliderTypeLast; i++) - { - sliderValue[i] = 1; - slider[i]->setPercent(sliderValue[i]); - } - - sliderValue[sliderType::Thickness] = 10; - slider[sliderType::Thickness]->setPercent(sliderValue[sliderType::Thickness]); - DrawNodeBaseTest::onEnter(); } @@ -1718,7 +1702,7 @@ DrawNodeMorphTest_Polygon::DrawNodeMorphTest_Polygon() for (size_t n = 0; n < 10; n++) { drawNodeArray[n] = DrawNode::create(); - drawNodeArray[n]->properties.setTransform(true); + drawNodeArray[n]->setLocalTransformEnabled(true); addChild(drawNodeArray[n]); drawNodeArray[n]->setPosition( Vec2(AXRANDOM_MINUS1_1() * size.width / 4, AXRANDOM_MINUS1_1() * size.height / 4) + Vec2(100, 100)); @@ -1772,9 +1756,6 @@ DrawNodeMorphTest_Polygon::DrawNodeMorphTest_Polygon() } } - initSliders(); - slider[sliderType::Thickness]->setEnabled(true); - scheduleUpdate(); } void DrawNodeMorphTest_Polygon::update(float dt) @@ -1807,22 +1788,18 @@ void DrawNodeMorphTest_Polygon::update(float dt) state[n] = !state[n]; } - drawNodeArray[n]->properties.setScale(Vec2(0.5f, 0.5f)); - drawNodeArray[n]->drawPoly(verticesObjMorph[n], segments, true, color[n], sliderValue[sliderType::Thickness]); + drawNodeArray[n]->setLocalTransformEnabled(transform); + drawNodeArray[n]->setPreserveDrawOrder(drawOrder); + drawNodeArray[n]->setLocalScale(ps); + drawNodeArray[n]->setThicknessScale(pf); + drawNodeArray[n]->setLocalRotation(pa); + drawNodeArray[n]->setLocalRotation(pa); + drawNodeArray[n]->drawPoly(verticesObjMorph[n], segments, true, color[n], thickness); } } void DrawNodeMorphTest_Polygon::onEnter() { - for (int i = 0; i < sliderType::sliderTypeLast; i++) - { - sliderValue[i] = 1; - slider[i]->setPercent(sliderValue[i]); - } - - sliderValue[sliderType::Thickness] = 10; - slider[sliderType::Thickness]->setPercent(sliderValue[sliderType::Thickness]); - DrawNodeBaseTest::onEnter(); } @@ -1838,6 +1815,7 @@ string DrawNodeMorphTest_Polygon::subtitle() const DrawNodePictureTest::DrawNodePictureTest() { + ns = 0.4; scheduleUpdate(); } @@ -1845,7 +1823,7 @@ void DrawNodePictureTest::update(float dt) { DrawNodeBaseTest::update(dt); - static float rot = 0.1f; + static float rot = 0.0f; static int count = 0; static bool wait = false; @@ -1853,8 +1831,8 @@ void DrawNodePictureTest::update(float dt) if (!wait) { - rot += 0.05; - if (rot >= 6) + rot += 5.0f; + if (rot >= 343) { rot = count = 0; wait = true; @@ -1885,11 +1863,11 @@ void DrawNodePictureTest::update(float dt) vertices[n - 3] = Vec2(sph_xx[sph_la + n], sph_yy[sph_la + n]); } drawNode->setPosition(Vec2(420, 280)); - drawNode->setScale(0.4); + drawNode->setScale(ns); drawNode->setAnchorPoint(Vec2::ANCHOR_MIDDLE); drawNode->setRotation(180); - drawNode->properties.setCenter(vertices[0]); - drawNode->properties.setRotation(rot); + drawNode->setLocalPivot(vertices[0]); + drawNode->setLocalRotation(rot); drawNode->drawPolygon(vertices, sph_cmb - 3, color, 0.f, Color::random().withAlpha(0.5f), true); sph_la += sph_cmb; @@ -1904,7 +1882,7 @@ string DrawNodePictureTest::title() const string DrawNodePictureTest::subtitle() const { - return "Properties (Rotation) Test"; + return "properties. (Rotation) Test"; } // orginal source from here: https://forum.lazarus.freepascal.org/index.php/topic,71851.0.html @@ -1988,18 +1966,23 @@ string DrawNodeJellyFishTest::subtitle() const DrawNodeLineDrawTest::DrawNodeLineDrawTest() { - initSliders(); - slider[sliderType::Thickness]->setEnabled(true); - scheduleUpdate(); } void DrawNodeLineDrawTest::update(float dt) { - DrawNodeBaseTest::update(dt); + // DrawNodeBaseTest::update(dt); drawNode->clear(); + flagGUI = 0; + drawNode->setScale(ns); + drawNode->setLocalScale(ps); + drawNode->setThicknessScale(pf); + drawNode->setLocalRotation(pa); + drawNode->setPreserveDrawOrder(drawOrder); + drawNode->setLocalTransformEnabled(transform); + float segments = 36.0f; int radius = 100; float angle = 360 / segments; @@ -2011,25 +1994,14 @@ void DrawNodeLineDrawTest::update(float dt) float x = radius * cosf(rads) + center.x; float y = radius * sinf(rads) + center.y; - drawNode->drawLine(center - Vec2(20, 40), Vec2(x, y) - Vec2(20, 40), Color::RED, - sliderValue[sliderType::Thickness]); - drawNode->drawLine(center + Vec2(120, 20), Vec2(x, y) + Vec2(120, 20), Color::BLUE, - sliderValue[sliderType::Thickness]); - drawNode->drawLine(center - Vec2(130, 110), Vec2(x, y) - Vec2(130, 110), Color::GREEN, - sliderValue[sliderType::Thickness]); + drawNode->drawLine(center - Vec2(20, 40), Vec2(x, y) - Vec2(20, 40), Color::RED, thickness); + drawNode->drawLine(center + Vec2(120, 20), Vec2(x, y) + Vec2(120, 20), Color::BLUE, thickness); + drawNode->drawLine(center - Vec2(130, 110), Vec2(x, y) - Vec2(130, 110), Color::GREEN, thickness); } } void DrawNodeLineDrawTest::onEnter() { - for (int i = 0; i < sliderType::sliderTypeLast; i++) - { - sliderValue[i] = 1; - slider[i]->setPercent(sliderValue[i]); - } - sliderValue[sliderType::Thickness] = 10; - slider[sliderType::Thickness]->setPercent(sliderValue[sliderType::Thickness]); - DrawNodeBaseTest::onEnter(); } @@ -2045,9 +2017,6 @@ string DrawNodeLineDrawTest::subtitle() const DrawNodeThicknessTest::DrawNodeThicknessTest() { - initSliders(); - slider[sliderType::Thickness]->setEnabled(true); - scheduleUpdate(); } @@ -2057,23 +2026,18 @@ void DrawNodeThicknessTest::update(float dt) drawNode->clear(); - drawNode->drawCircle(VisibleRect::center(), 60, AX_DEGREES_TO_RADIANS(77), 30, false, Color::GREEN, - sliderValue[sliderType::Thickness]); + drawNode->drawCircle(VisibleRect::center(), 60, AX_DEGREES_TO_RADIANS(77), 30, false, Color::GREEN, thickness); - drawNode->drawLine(Vec2(0.0f, size.height), Vec2(size.width, size.height - 20), Color::YELLOW, - sliderValue[sliderType::Thickness]); - drawNode->drawLine(Vec2(0.0f, 0.0f), Vec2(size.width, size.height - 20), Color::YELLOW, - sliderValue[sliderType::Thickness]); + drawNode->drawLine(Vec2(0.0f, size.height), Vec2(size.width, size.height - 20), Color::YELLOW, thickness); + drawNode->drawLine(Vec2(0.0f, 0.0f), Vec2(size.width, size.height - 20), Color::YELLOW, thickness); // drawNode a rectangles - drawNode->drawRect(Vec2(123, 123), Vec2(227, 227), Color(1, 1, 0, 1), sliderValue[sliderType::Thickness]); - drawNode->drawRect(Vec2(115, 130), Vec2(130, 115), Vec2(115, 100), Vec2(100, 115), Color::MAGENTA, - sliderValue[sliderType::Thickness]); + drawNode->drawRect(Vec2(123, 123), Vec2(227, 227), Color(1, 1, 0, 1), thickness); + drawNode->drawRect(Vec2(115, 130), Vec2(130, 115), Vec2(115, 100), Vec2(100, 115), Color::MAGENTA, thickness); drawNode->drawLine(Vec2(200.0f, size.height - 20), Vec2(size.width - 100, size.height - 20), Color::YELLOW, - sliderValue[sliderType::Thickness]); - drawNode->drawLine(Vec2(300.0f, 100.0f), Vec2(size.width - 200, size.height - 120), Color::GREEN, - sliderValue[sliderType::Thickness]); + thickness); + drawNode->drawLine(Vec2(300.0f, 100.0f), Vec2(size.width - 200, size.height - 120), Color::GREEN, thickness); Vec2 vertices24[] = { {45.750000f, 144.375000f}, {75.500000f, 136.875000f}, {75.500000f, 159.125000f}, {100.250000f, 161.375000f}, @@ -2090,34 +2054,31 @@ void DrawNodeThicknessTest::update(float dt) {135.250000f, 108.625000f}, {151.000000f, 124.125000f}, {90.500000f, 131.875000f}, {113.250000f, 120.875000f}, {88.000000f, 116.875000f}, {106.000000f, 103.875000f}, {88.000000f, 97.875000f}, }; - drawNode->drawPolygon(vertices24, sizeof(vertices24) / sizeof(vertices24[0]), Color::TRANSPARENT, - sliderValue[sliderType::Thickness] / 2, Color::RED); + drawNode->drawPolygon(vertices24, sizeof(vertices24) / sizeof(vertices24[0]), Color(), thickness / 2, Color::RED); // open random color poly Vec2 vertices[] = {Vec2(0.0f, 0.0f), Vec2(50.0f, 50.0f), Vec2(100.0f, 50.0f), Vec2(100.0f, 100.0f), Vec2(50.0f, 100.0f)}; - drawNode->drawPoly(vertices, 5, false, Color::random().withAlpha(1.0f), sliderValue[sliderType::Thickness]); + drawNode->drawPoly(vertices, 5, false, Color::random().withAlpha(1.0f), thickness); // closed random color poly Vec2 vertices2[] = {Vec2(30.0f, 130.0f), Vec2(30.0f, 230.0f), Vec2(50.0f, 200.0f)}; - drawNode->drawPoly(vertices2, 3, true, Color::random().withAlpha(1.0f), sliderValue[sliderType::Thickness]); + drawNode->drawPoly(vertices2, 3, true, Color::random().withAlpha(1.0f), thickness); // drawNode some beziers drawNode->drawQuadBezier(Vec2(size.width - 150, size.height - 150), Vec2(size.width - 70, size.height - 10), - Vec2(size.width - 10, size.height - 10), 10, Color::BLUE, - sliderValue[sliderType::Thickness]); + Vec2(size.width - 10, size.height - 10), 10, Color::BLUE, thickness); drawNode->drawQuadBezier(Vec2(0.0f + 100, size.height - 100), Vec2(size.width / 2, size.height / 2), - Vec2(size.width - 100, size.height - 100), 50, Color::RED, - sliderValue[sliderType::Thickness]); + Vec2(size.width - 100, size.height - 100), 50, Color::RED, thickness); drawNode->drawCubicBezier(VisibleRect::center(), Vec2(VisibleRect::center().x + 30, VisibleRect::center().y + 50), Vec2(VisibleRect::center().x + 60, VisibleRect::center().y - 50), VisibleRect::right(), - 100, Color::WHITE, sliderValue[sliderType::Thickness]); + 100, Color::WHITE, thickness); drawNode->drawCubicBezier(Vec2(size.width - 250, 40.0f), Vec2(size.width - 70, 100.0f), Vec2(size.width - 30, 250.0f), Vec2(size.width - 10, size.height - 50), 10, Color::GRAY, - sliderValue[sliderType::Thickness]); + thickness); auto array = ax::PointArray::create(20); array->addControlPoint(Vec2(0.0f, 0.0f)); @@ -2127,7 +2088,7 @@ void DrawNodeThicknessTest::update(float dt) array->addControlPoint(Vec2(80.0f, size.height - 80)); array->addControlPoint(Vec2(80.0f, 80.0f)); array->addControlPoint(Vec2(size.width / 2, size.height / 2)); - drawNode->drawCardinalSpline(array, 0.5f, 50, Color::MAGENTA, sliderValue[sliderType::Thickness]); + drawNode->drawCardinalSpline(array, 0.5f, 50, Color::MAGENTA, thickness); auto array2 = ax::PointArray::create(20); array2->addControlPoint(Vec2(size.width / 2, 30.0f)); @@ -2135,7 +2096,7 @@ void DrawNodeThicknessTest::update(float dt) array2->addControlPoint(Vec2(size.width - 80, size.height - 80)); array2->addControlPoint(Vec2(size.width / 2, size.height - 80)); array2->addControlPoint(Vec2(size.width / 2, 30.0f)); - drawNode->drawCatmullRom(array2, 50, Color::ORANGE, sliderValue[sliderType::Thickness]); + drawNode->drawCatmullRom(array2, 50, Color::ORANGE, thickness); auto s = Director::getInstance()->getCanvasSize(); @@ -2289,16 +2250,6 @@ void DrawNodeThicknessTest::update(float dt) void DrawNodeThicknessTest::onEnter() { - for (int i = 0; i < sliderType::sliderTypeLast; i++) - { - sliderValue[i] = 1; - slider[i]->setPercent(sliderValue[i]); - } - // sliderValue[sliderType::Counter] = 100; - // slider[sliderType::Counter]->setPercent(sliderValue[sliderType::Counter]); - sliderValue[sliderType::Thickness] = 10; - slider[sliderType::Thickness]->setPercent(sliderValue[sliderType::Thickness]); - DrawNodeBaseTest::onEnter(); } @@ -2314,9 +2265,6 @@ string DrawNodeThicknessTest::subtitle() const DrawNodeThicknessStressTest::DrawNodeThicknessStressTest() { - initSliders(); - slider[sliderType::Thickness]->setEnabled(true); - scheduleUpdate(); } @@ -2350,7 +2298,7 @@ void DrawNodeThicknessStressTest::update(float dt) {135.250000f, 108.625000f}, {151.000000f, 124.125000f}, {90.500000f, 131.875000f}, {113.250000f, 120.875000f}, {88.000000f, 116.875000f}, {106.000000f, 103.875000f}, {88.000000f, 97.875000f}, }; - drawNode->drawPolygon(vertices24, sizeof(vertices24) / sizeof(vertices24[0]), Color::TRANSPARENT, negativThickness, + drawNode->drawPolygon(vertices24, sizeof(vertices24) / sizeof(vertices24[0]), Color(), negativThickness, Color::RED); // open random color poly @@ -2360,7 +2308,7 @@ void DrawNodeThicknessStressTest::update(float dt) // closed random color poly Vec2 vertices2[] = {Vec2(30.0f, 130.0f), Vec2(30.0f, 230.0f), Vec2(50.0f, 200.0f)}; - drawNode->drawPoly(vertices2, 3, true, Color::random().withAlpha(1.0f), negativThickness); + drawNode->drawPoly(vertices2, 3, true, Color::RED, negativThickness); // drawNode some beziers drawNode->drawQuadBezier(Vec2(size.width - 150, size.height - 150), Vec2(size.width - 70, size.height - 10), @@ -2390,15 +2338,14 @@ void DrawNodeThicknessStressTest::update(float dt) auto s = Director::getInstance()->getCanvasSize(); - drawNode->drawPoint(Vec2(s.width / 2 - 120, s.height / 2 - 120), negativThickness, - Color(AXRANDOM_0_1(), AXRANDOM_0_1(), AXRANDOM_0_1(), 1)); + drawNode->drawPoint(Vec2(s.width / 2 - 120, s.height / 2 - 120), negativThickness, Color::WHITE); // drawNode 4 small points Vec2 position[] = {Vec2(60, 60), Vec2(70, 70), Vec2(60, 70), Vec2(70, 60)}; - drawNode->drawPoints(position, 4, 5, Color(AXRANDOM_0_1(), AXRANDOM_0_1(), AXRANDOM_0_1(), 1), DrawNode::Rect); + drawNode->drawPoints(position, 4, 5, Color::ORANGE, DrawNode::Rect); Vec2 position1[] = {Vec2(100, 100), Vec2(170, 170), Vec2(260, 170), Vec2(170, 260)}; - drawNode->drawPoints(position1, 4, 25, Color(AXRANDOM_0_1(), AXRANDOM_0_1(), AXRANDOM_0_1(), 1), DrawNode::Rect); + drawNode->drawPoints(position1, 4, 25, Color::MAGENTA, DrawNode::Rect); // drawNode a rectangle drawNode->drawRect(Vec2(23, 23), Vec2(7, 7), Color(1, 1, 0, 1), negativThickness); @@ -2444,22 +2391,7 @@ void DrawNodeThicknessStressTest::update(float dt) drawNode->drawSegment(Vec2(20.0f, s.height), Vec2(20.0f, s.height / 2), 10, Color(0.0f, 1.0f, 0.0f, 1.0f)); // drawNode triangle - drawNode->drawTriangle(Vec2(10.0f, 10.0f), Vec2(70.0f, 30.0f), Vec2(100.0f, 140.0f), - Color(AXRANDOM_0_1(), AXRANDOM_0_1(), AXRANDOM_0_1(), 0.5f)); -} - -void DrawNodeThicknessStressTest::onEnter() -{ - for (int i = 0; i < sliderType::sliderTypeLast; i++) - { - sliderValue[i] = 1; - slider[i]->setPercent(sliderValue[i]); - } - - sliderValue[sliderType::Thickness] = 5; - slider[sliderType::Thickness]->setPercent(sliderValue[sliderType::Thickness]); - - DrawNodeBaseTest::onEnter(); + drawNode->drawTriangle(Vec2(10.0f, 10.0f), Vec2(70.0f, 30.0f), Vec2(100.0f, 140.0f), Color::GREEN); } string DrawNodeThicknessStressTest::title() const @@ -2469,72 +2401,50 @@ string DrawNodeThicknessStressTest::title() const string DrawNodeThicknessStressTest::subtitle() const { - return ""; + return "Thickness: -99999999.9999"; } DrawNodePieTest::DrawNodePieTest() { - initSliders(); - slider[sliderType::AngleStart]->setEnabled(true); - slider[sliderType::AngleEnd]->setEnabled(true); - slider[sliderType::Rotation]->setEnabled(true); - slider[sliderType::Thickness]->setEnabled(true); - scheduleUpdate(); } void DrawNodePieTest::update(float dt) { - DrawNodeBaseTest::update(dt); + flagGUI = 2; drawNode->clear(); + drawNode->setScale(ns); + drawNode->setLocalScale(ps); + drawNode->setThicknessScale(pf); + drawNode->setLocalRotation(pa); + drawNode->setPreserveDrawOrder(drawOrder); + drawNode->setLocalTransformEnabled(transform); + // Filled - drawNode->drawPie(VisibleRect::center() - Vec2(190.0f, -35.0f), 40, sliderValue[sliderType::Rotation], - sliderValue[sliderType::AngleStart], sliderValue[sliderType::AngleEnd], 1.0f, 1.0f, Color::RED, - Color::BLUE, drawNode->DrawMode::Fill, sliderValue[sliderType::Thickness]); + drawNode->drawPie(VisibleRect::center() - Vec2(190.0f, -35.0f), 40, pa, as, ae, 1.0f, 1.0f, Color::RED, Color::BLUE, + drawNode->DrawMode::Fill, thickness); // Outlined - drawNode->drawPie(VisibleRect::center() - Vec2(95.0f, -35.0f), 40, sliderValue[sliderType::Rotation], - sliderValue[sliderType::AngleStart], sliderValue[sliderType::AngleEnd], 1.0f, 1.0f, - Color::TRANSPARENT, Color::BLUE, drawNode->DrawMode::Outline, sliderValue[sliderType::Thickness]); + drawNode->drawPie(VisibleRect::center() - Vec2(95.0f, -35.0f), 40, pa, as, ae, 1.0f, 1.0f, Color(), Color::BLUE, + drawNode->DrawMode::Outline, thickness); // Line - drawNode->drawPie(VisibleRect::center() + Vec2(0.0f, 35.0f), 40, sliderValue[sliderType::Rotation], - sliderValue[sliderType::AngleStart], sliderValue[sliderType::AngleEnd], 1.0f, 1.0f, - Color::TRANSPARENT, Color::BLUE, drawNode->DrawMode::Line, sliderValue[sliderType::Thickness]); + drawNode->drawPie(VisibleRect::center() + Vec2(0.0f, 35.0f), 40, pa, as, ae, 1.0f, 1.0f, Color(), Color::BLUE, + drawNode->DrawMode::Line, thickness); // Semi - drawNode->drawPie(VisibleRect::center() + Vec2(95.0f, 35.0f), 40, sliderValue[sliderType::Rotation], - sliderValue[sliderType::AngleStart], sliderValue[sliderType::AngleEnd], 1.0f, 1.0f, - Color::TRANSPARENT, Color::BLUE, drawNode->DrawMode::Semi, sliderValue[sliderType::Thickness]); + drawNode->drawPie(VisibleRect::center() + Vec2(95.0f, 35.0f), 40, pa, as, ae, 1.0f, 1.0f, Color(), Color::BLUE, + drawNode->DrawMode::Semi, thickness); // Semi (Filled) - drawNode->drawPie(VisibleRect::center() + Vec2(190.0f, 35.0f), 40, sliderValue[sliderType::Rotation], - sliderValue[sliderType::AngleStart], sliderValue[sliderType::AngleEnd], 1.0f, 1.0f, Color::RED, - Color::BLUE, drawNode->DrawMode::Semi, sliderValue[sliderType::Thickness]); + drawNode->drawPie(VisibleRect::center() + Vec2(190.0f, 35.0f), 40, pa, as, ae, 1.0f, 1.0f, Color::RED, Color::BLUE, + drawNode->DrawMode::Semi, thickness); } void DrawNodePieTest::onEnter() { - for (int i = 0; i < sliderType::sliderTypeLast; i++) - { - sliderValue[i] = 1; - slider[i]->setPercent(sliderValue[i]); - } - - sliderValue[sliderType::AngleStart] = 10; - slider[sliderType::AngleStart]->setPercent(sliderValue[sliderType::AngleStart]); - - sliderValue[sliderType::AngleEnd] = 100; - slider[sliderType::AngleEnd]->setPercent(sliderValue[sliderType::AngleEnd]); - - sliderValue[sliderType::Rotation] = 10; - slider[sliderType::Rotation]->setPercent(sliderValue[sliderType::Rotation]); - - sliderValue[sliderType::Thickness] = 10; - slider[sliderType::Thickness]->setPercent(sliderValue[sliderType::Thickness]); - DrawNodeBaseTest::onEnter(); } @@ -2553,17 +2463,9 @@ DrawNodeMethodsTest::DrawNodeMethodsTest() static const float BUTTON_WIDTH = 30; static float startPosX = 0; - auto listview = createListView(); - listview->setPosition(Vec2(0.0f, 40.0f)); - addChild(listview); - - drawNode->setScale(0.5); + drawNode->setScale(ns); drawNode->setPosition(center); - initSliders(); - slider[sliderType::Thickness]->setEnabled(true); - slider[sliderType::Rotation]->setEnabled(true); - labelRound = Label::createWithTTF("DrawNode::Round", "fonts/arial.ttf", 12); addChild(labelRound, 1); labelRound->setVisible(false); @@ -2577,32 +2479,6 @@ DrawNodeMethodsTest::DrawNodeMethodsTest() scheduleUpdate(); } -ax::ui::ListView* DrawNodeMethodsTest::createListView() -{ - auto listview = ax::ui::ListView::create(); - Vec2 contentSize = {0, 0}; - for (size_t i = 0; i < (drawMethodes::LAST); i++) - { - auto ui = ax::ui::Text::create(); - ui->setString(drawMethods[i].c_str()); - contentSize.x = MAX(ui->getContentSize().x, contentSize.x); - contentSize.y = MAX(ui->getContentSize().y, contentSize.y); - ui->setTouchEnabled(true); - listview->pushBackCustomItem(ui); - } - - listview->setContentSize(contentSize * (drawMethodes::LAST)); - listview->setCurSelectedIndex(0); - listview->setTouchEnabled(true); - listview->addEventListener( - (ui::ListView::ccListViewCallback)AX_CALLBACK_2(DrawNodeBaseTest::listviewCallback, this)); - listview->setTag(100); - - listview->getItem(_currentSeletedItemIndex)->setColor(Color32::RED); - - return listview; -} - void DrawNodeMethodsTest::update(float dt) { drawAll(); @@ -2610,27 +2486,18 @@ void DrawNodeMethodsTest::update(float dt) void DrawNodeMethodsTest::onEnter() { - for (int i = 0; i < sliderType::sliderTypeLast; i++) - { - sliderValue[i] = 1; - slider[i]->setPercent(sliderValue[i]); - } - sliderValue[sliderType::Thickness] = 10; - slider[sliderType::Thickness]->setPercent(sliderValue[sliderType::Thickness]); - sliderValue[sliderType::Rotation] = 0; - slider[sliderType::Rotation]->setPercent(sliderValue[sliderType::Rotation]); - DrawNodeBaseTest::onEnter(); + flagGUI = 1; } std::string DrawNodeMethodsTest::title() const { - return "DrawNode Stress Tests"; + return "DrawNode properties. Tests"; } string DrawNodeMethodsTest::subtitle() const { - return ""; + return "Scale,Factor,Thickness,Rotation,DrawOrder,Transform"; } void DrawNodeMethodsTest::drawAll() @@ -2643,7 +2510,13 @@ void DrawNodeMethodsTest::drawAll() } drawNode->clear(); - drawNode->properties.setDefaultValues(); + + drawNode->setScale(ns); + drawNode->setLocalScale(ps); + drawNode->setThicknessScale(pf); + drawNode->setLocalRotation(pa); + drawNode->setPreserveDrawOrder(drawOrder); + drawNode->setLocalTransformEnabled(transform); labelRound->setVisible(false); labelSquare->setVisible(false); @@ -2653,10 +2526,11 @@ void DrawNodeMethodsTest::drawAll() { case drawMethodes::Line: { - for (int i = 0; i < 100; i++) + for (int i = 0; i < 30; i++) { - drawNode->drawLine(Vec2(-size.x / 2, -size.y / 2 + i * 4), Vec2(size.x - 50, -size.y / 2 + i * 4), - Color::random().withAlpha(1.0f), sliderValue[sliderType::Thickness]); + float yPos = -size.y / 2.5 + i * 11; + drawNode->drawLine(Vec2(-size.x / 2, yPos), Vec2(size.x - 50, yPos), Color::random().withAlpha(1.0f), + thickness); } break; @@ -2667,8 +2541,7 @@ void DrawNodeMethodsTest::drawAll() for (int i = 0; i < 100; i++) { rec = Vec2(i * 3, i * 3); - drawNode->drawRect(center / 2 - rec, center / 2 + rec, Color::random().withAlpha(1.0f), - sliderValue[sliderType::Thickness]); + drawNode->drawRect(center / 2 - rec, center / 2 + rec, Color::random().withAlpha(1.0f), thickness); } break; @@ -2678,7 +2551,7 @@ void DrawNodeMethodsTest::drawAll() for (int i = 0; i < 100; i++) { drawNode->drawCircle(VisibleRect::center(), 3 * i, AX_DEGREES_TO_RADIANS(90), i, false, 1.0f, 1.0f, - Color::random().withAlpha(1.0f), sliderValue[sliderType::Thickness]); + Color::random().withAlpha(1.0f), thickness); } break; @@ -2686,11 +2559,9 @@ void DrawNodeMethodsTest::drawAll() case drawMethodes::QuadBezier: { drawNode->drawQuadBezier(Vec2(size.width - 150, size.height - 150), Vec2(size.width - 70, size.height - 10), - Vec2(size.width - 10, size.height - 10), 10, Color::BLUE, - sliderValue[sliderType::Thickness]); + Vec2(size.width - 10, size.height - 10), 10, Color::BLUE, thickness); drawNode->drawQuadBezier(Vec2(0.0f + 100, size.height - 100), Vec2(size.width / 2, size.height / 2), - Vec2(size.width - 100, size.height - 100), 50, Color::RED, - sliderValue[sliderType::Thickness]); + Vec2(size.width - 100, size.height - 100), 50, Color::RED, thickness); for (int i = 0; i < 360;) { @@ -2698,8 +2569,8 @@ void DrawNodeMethodsTest::drawAll() Vec2 p2 = pts->getControlPointAtIndex(i++); Vec2 p3 = pts->getControlPointAtIndex(i); - drawNode->properties.setPosition(Vec2(-100, -100)); - drawNode->drawQuadBezier(p1, p2, p3, 30, Color::RED, sliderValue[sliderType::Thickness]); + drawNode->setLocalPosition(Vec2(-100, -100)); + drawNode->drawQuadBezier(p1, p2, p3, 30, Color::RED, thickness); } for (int i = 0; i < 360;) @@ -2708,8 +2579,8 @@ void DrawNodeMethodsTest::drawAll() Vec2 p2 = pts2->getControlPointAtIndex(i++); Vec2 p3 = pts2->getControlPointAtIndex(i); - drawNode->properties.setPosition(Vec2(-100, -100)); - drawNode->drawQuadBezier(p1, p2, p3, 30, Color::GREEN, sliderValue[sliderType::Thickness]); + drawNode->setLocalPosition(Vec2(-100, -100)); + drawNode->drawQuadBezier(p1, p2, p3, 30, Color::GREEN, thickness); } break; @@ -2719,10 +2590,10 @@ void DrawNodeMethodsTest::drawAll() drawNode->drawCubicBezier(VisibleRect::center(), Vec2(VisibleRect::center().x + 30, VisibleRect::center().y + 50), Vec2(VisibleRect::center().x + 60, VisibleRect::center().y - 50), - VisibleRect::right(), 20, Color::WHITE, sliderValue[sliderType::Thickness]); + VisibleRect::right(), 20, Color::WHITE, thickness); drawNode->drawCubicBezier(Vec2(size.width - 250, 40.0f), Vec2(size.width - 70, 100.0f), Vec2(size.width - 30, 250.0f), Vec2(size.width - 10, size.height - 50), 20, - Color::GRAY, sliderValue[sliderType::Thickness]); + Color::GRAY, thickness); for (int i = 0; i < 360;) { @@ -2730,8 +2601,8 @@ void DrawNodeMethodsTest::drawAll() Vec2 p2 = pts->getControlPointAtIndex(i++); Vec2 p3 = pts->getControlPointAtIndex(i++); Vec2 p4 = pts->getControlPointAtIndex(i); - drawNode->properties.setPosition(Vec2(-100, -100)); - drawNode->drawCubicBezier(p1, p2, p3, p4, 120, Color::RED, sliderValue[sliderType::Thickness]); + drawNode->setLocalPosition(Vec2(-100, -100)); + drawNode->drawCubicBezier(p1, p2, p3, p4, 120, Color::RED, thickness); } for (int i = 0; i < 360;) @@ -2740,8 +2611,8 @@ void DrawNodeMethodsTest::drawAll() Vec2 p2 = pts2->getControlPointAtIndex(i++); Vec2 p3 = pts2->getControlPointAtIndex(i++); Vec2 p4 = pts2->getControlPointAtIndex(i); - drawNode->properties.setPosition(Vec2(-100, -100)); - drawNode->drawCubicBezier(p1, p2, p3, p4, 120, Color::GREEN, sliderValue[sliderType::Thickness]); + drawNode->setLocalPosition(Vec2(-100, -100)); + drawNode->drawCubicBezier(p1, p2, p3, p4, 120, Color::GREEN, thickness); } break; @@ -2757,7 +2628,7 @@ void DrawNodeMethodsTest::drawAll() array->addControlPoint(Vec2(80.0f, size.height - 80)); array->addControlPoint(Vec2(80.0f, 80.0f)); array->addControlPoint(Vec2(size.width / 2, size.height / 2)); - drawNode->drawCardinalSpline(array, 0.5f, 120, Color::MAGENTA, sliderValue[sliderType::Thickness]); + drawNode->drawCardinalSpline(array, 0.5f, 120, Color::MAGENTA, thickness); auto array2 = ax::PointArray::create(5); array2->addControlPoint(Vec2(size.width / 2, 80.0f)); @@ -2765,11 +2636,11 @@ void DrawNodeMethodsTest::drawAll() array2->addControlPoint(Vec2(size.width - 80, size.height - 80)); array2->addControlPoint(Vec2(size.width / 2, size.height - 80)); array2->addControlPoint(Vec2(size.width / 2, 80.0f)); - drawNode->drawCardinalSpline(array2, 5.0f, 120, Color::ORANGE, sliderValue[sliderType::Thickness]); + drawNode->drawCardinalSpline(array2, 5.0f, 120, Color::ORANGE, thickness); - drawNode->properties.setPosition(Vec2(-100, -100)); - drawNode->drawCardinalSpline(pts, 0.001f, 360, Color::RED, sliderValue[sliderType::Thickness]); - drawNode->drawCardinalSpline(pts2, 0.001f, 360, Color::GREEN, sliderValue[sliderType::Thickness]); + drawNode->setLocalPosition(Vec2(-100, -100)); + drawNode->drawCardinalSpline(pts, 0.001f, 360, Color::RED, thickness); + drawNode->drawCardinalSpline(pts2, 0.001f, 360, Color::GREEN, thickness); break; } @@ -2781,7 +2652,7 @@ void DrawNodeMethodsTest::drawAll() array2->addControlPoint(Vec2(size.width - 80, size.height - 80)); array2->addControlPoint(Vec2(size.width / 2, size.height - 80)); array2->addControlPoint(Vec2(size.width / 2, 80.0f)); - drawNode->drawCatmullRom(array2, 20, Color::ORANGE, sliderValue[sliderType::Thickness]); + drawNode->drawCatmullRom(array2, 20, Color::ORANGE, thickness); auto array = ax::PointArray::create(7); array->addControlPoint(Vec2(0.0f, 0.0f)); @@ -2791,89 +2662,81 @@ void DrawNodeMethodsTest::drawAll() array->addControlPoint(Vec2(80.0f, size.height - 80)); array->addControlPoint(Vec2(80.0f, 80.0f)); array->addControlPoint(Vec2(size.width / 2, size.height / 2)); - drawNode->drawCatmullRom(array, 20, Color::MAGENTA, sliderValue[sliderType::Thickness]); + drawNode->drawCatmullRom(array, 20, Color::MAGENTA, thickness); - drawNode->properties.setPosition(Vec2(-100, -100)); - drawNode->drawCatmullRom(pts, 360, Color::RED, sliderValue[sliderType::Thickness]); - drawNode->drawCatmullRom(pts2, 360, Color::GREEN, sliderValue[sliderType::Thickness]); + drawNode->setLocalPosition(Vec2(-100, -100)); + drawNode->drawCatmullRom(pts, 360, Color::RED, thickness); + drawNode->drawCatmullRom(pts2, 360, Color::GREEN, thickness); break; } case drawMethodes::Poly: { Vec2 vertices[5] = {{0.0f, 0.0f}, {50.0f, 50.0f}, {100.0f, 50.0f}, {100.0f, 100.0f}, {50.0f, 100.0f}}; - drawNode->properties.setPosition(Vec2(-200, -300)); - drawNode->drawPoly(vertices, 5, false, Color::BLUE, sliderValue[sliderType::Thickness]); + drawNode->setLocalPosition(Vec2(-200, -300)); + drawNode->drawPoly(vertices, 5, false, Color::BLUE, thickness); Vec2 vertices2[3] = {{30.0f, 130.0f}, {30.0f, 230.0f}, {50.0f, 200.0f}}; - drawNode->drawPoly(vertices2, 3, true, Color::GREEN, sliderValue[sliderType::Thickness]); - - drawNode->properties.setDefaultValues(); - drawNode->drawPoly(vertices1, sizeof(vertices1) / sizeof(vertices1[0]), true, Color::RED, - sliderValue[sliderType::Thickness]); - - drawNode->properties.setPosition(Vec2(0, -300)); - drawNode->properties.setRotation(sliderValue[sliderType::Rotation]); - drawNode->drawPoly(vertices1, sizeof(vertices1) / sizeof(vertices1[0]), true, Color::GREEN, - sliderValue[sliderType::Thickness]); - drawNode->properties.setPosition(Vec2(-100, -300)); - drawNode->properties.setRotation(sliderValue[sliderType::Rotation]); - drawNode->properties.setCenter(vertices1[0]); - drawNode->drawPoly(vertices1, sizeof(vertices1) / sizeof(vertices1[0]), true, Color::MAGENTA, - sliderValue[sliderType::Thickness]); - drawNode->properties.setPosition(Vec2(200, 0)); - drawNode->drawPoly(vertices1, sizeof(vertices1) / sizeof(vertices1[0]), true, Color::RED, - sliderValue[sliderType::Thickness]); - drawNode->properties.setPosition(Vec2(0.0f, -300.0f)); - drawNode->properties.setRotation(rotation / 10.0f); - drawNode->properties.setScale(Vec2(2.0f, 2.0f)); - drawNode->properties.setCenter(vertices1[4]); - drawNode->drawPoly(vertices1, sizeof(vertices1) / sizeof(vertices1[0]), true, Color::BLUE, - sliderValue[sliderType::Thickness]); - drawNode->properties.setRotation(rotation); - drawNode->drawPoly(vertices1, sizeof(vertices1) / sizeof(vertices1[0]), true, Color::YELLOW, - sliderValue[sliderType::Thickness]); - drawNode->properties.setRotation(-rotation / 5); - drawNode->drawPoly(vertices1, sizeof(vertices1) / sizeof(vertices1[0]), true, Color::WHITE, - sliderValue[sliderType::Thickness]); - - drawNode->properties.setDefaultValues(); - drawNode->drawPoly(vertices1, sizeof(vertices1) / sizeof(vertices1[0]), true, Color::GREEN, - sliderValue[sliderType::Thickness]); + drawNode->drawPoly(vertices2, 3, true, Color::GREEN, thickness); + + drawNode->resetAdvancedSettings(); + drawNode->drawPoly(vertices1, sizeof(vertices1) / sizeof(vertices1[0]), true, Color::RED, thickness); + + drawNode->setLocalPosition(Vec2(0, -300)); + drawNode->setLocalRotation(pa); + drawNode->drawPoly(vertices1, sizeof(vertices1) / sizeof(vertices1[0]), true, Color::GREEN, thickness); + drawNode->setLocalPosition(Vec2(-100, -300)); + drawNode->setLocalRotation(pa); + drawNode->setLocalPivot(vertices1[0]); + drawNode->drawPoly(vertices1, sizeof(vertices1) / sizeof(vertices1[0]), true, Color::MAGENTA, thickness); + drawNode->setLocalPosition(Vec2(200, 0)); + drawNode->drawPoly(vertices1, sizeof(vertices1) / sizeof(vertices1[0]), true, Color::RED, thickness); + drawNode->setLocalPosition(Vec2(0.0f, -200.0f)); + drawNode->setLocalRotation(rotation / 10.0f); + drawNode->setLocalScale(Vec2(5.0f, 5.0f)); + drawNode->setLocalPivot(vertices1[4]); + drawNode->drawPoly(vertices1, sizeof(vertices1) / sizeof(vertices1[0]), true, Color::BLUE, thickness); + drawNode->setLocalRotation(rotation); + drawNode->drawPoly(vertices1, sizeof(vertices1) / sizeof(vertices1[0]), true, Color::YELLOW, thickness); + drawNode->setLocalRotation(-rotation / 5); + drawNode->drawPoly(vertices1, sizeof(vertices1) / sizeof(vertices1[0]), true, Color::WHITE, thickness); + + drawNode->resetAdvancedSettings(); + drawNode->drawPoly(vertices1, sizeof(vertices1) / sizeof(vertices1[0]), true, Color::GREEN, thickness); break; } case drawMethodes::Polygon: { - drawNode->properties.setPosition(Vec2(0, -300)); - drawNode->properties.setRotation(sliderValue[sliderType::Rotation]); - drawNode->drawPolygon(vertices1, sizeof(vertices1) / sizeof(vertices1[0]), Color::GREEN, - sliderValue[sliderType::Thickness], Color::YELLOW); - drawNode->properties.setPosition(Vec2(-100, -300)); - drawNode->properties.setRotation(sliderValue[sliderType::Rotation]); - drawNode->properties.setCenter(vertices1[0]); - drawNode->drawPolygon(vertices1, sizeof(vertices1) / sizeof(vertices1[0]), Color::MAGENTA, - sliderValue[sliderType::Thickness], Color::GRAY); - drawNode->properties.setPosition(Vec2(200, 0)); - drawNode->drawPolygon(vertices1, sizeof(vertices1) / sizeof(vertices1[0]), Color::RED, - sliderValue[sliderType::Thickness], Color::YELLOW); - - drawNode->properties.setPosition(Vec2(0.0f, -300.0f)); - drawNode->properties.setRotation(rotation / 10.0f); - drawNode->properties.setScale(Vec2(2.0f, 2.0f)); - drawNode->properties.setCenter(vertices1[4]); - drawNode->drawPolygon(vertices1, sizeof(vertices1) / sizeof(vertices1[0]), Color::BLUE, - sliderValue[sliderType::Thickness], Color::WHITE); - drawNode->properties.setRotation(rotation); - drawNode->drawPolygon(vertices1, sizeof(vertices1) / sizeof(vertices1[0]), Color::YELLOW, - sliderValue[sliderType::Thickness], Color::GREEN); + drawNode->setLocalPosition(Vec2(0, -300)); + drawNode->setLocalRotation(pa); + drawNode->drawPolygon(vertices1, sizeof(vertices1) / sizeof(vertices1[0]), Color::GREEN, thickness, + Color::YELLOW); + drawNode->setLocalPosition(Vec2(-100, -300)); + drawNode->setLocalRotation(pa); + drawNode->setLocalPivot(vertices1[0]); + drawNode->drawPolygon(vertices1, sizeof(vertices1) / sizeof(vertices1[0]), Color::MAGENTA, thickness, + Color::GRAY); + drawNode->setLocalPosition(Vec2(200, 0)); + drawNode->drawPolygon(vertices1, sizeof(vertices1) / sizeof(vertices1[0]), Color::RED, thickness, + Color::YELLOW); + + drawNode->setLocalPosition(Vec2(0.0f, -300.0f)); + drawNode->setLocalRotation(rotation / 10.0f); + drawNode->setLocalScale(Vec2(2.0f, 2.0f)); + drawNode->setLocalPivot(vertices1[4]); + drawNode->drawPolygon(vertices1, sizeof(vertices1) / sizeof(vertices1[0]), Color::BLUE, thickness, + Color::WHITE); + drawNode->setLocalRotation(rotation); + drawNode->drawPolygon(vertices1, sizeof(vertices1) / sizeof(vertices1[0]), Color::YELLOW, thickness, + Color::GREEN); ; - drawNode->properties.setRotation(-rotation / 5); - drawNode->drawPolygon(vertices1, sizeof(vertices1) / sizeof(vertices1[0]), Color::WHITE, - sliderValue[sliderType::Thickness], Color::YELLOW); + drawNode->setLocalRotation(-rotation / 5); + drawNode->drawPolygon(vertices1, sizeof(vertices1) / sizeof(vertices1[0]), Color::WHITE, thickness, + Color::YELLOW); - drawNode->properties.setDefaultValues(); - drawNode->drawPolygon(vertices1, sizeof(vertices1) / sizeof(vertices1[0]), Color::GREEN, - sliderValue[sliderType::Thickness], Color::BLUE); + drawNode->resetAdvancedSettings(); + drawNode->drawPolygon(vertices1, sizeof(vertices1) / sizeof(vertices1[0]), Color::GREEN, thickness, + Color::BLUE); break; } @@ -2881,8 +2744,8 @@ void DrawNodeMethodsTest::drawAll() { for (int i = 0; i < 100; i++) { - drawNode->drawDot(Vec2(AXRANDOM_MINUS1_1() * 400 + 200, AXRANDOM_MINUS1_1() * 400), - 20 + sliderValue[sliderType::Thickness], Color::random().withAlpha(1.0f)); + drawNode->drawDot(Vec2(AXRANDOM_MINUS1_1() * 400 + 200, AXRANDOM_MINUS1_1() * 400), 20 + thickness, + Color::random().withAlpha(1.0f)); } break; @@ -2891,8 +2754,8 @@ void DrawNodeMethodsTest::drawAll() { for (int i = 0; i < 100; i++) { - drawNode->drawPoint(Vec2(AXRANDOM_MINUS1_1() * 400 + 200, AXRANDOM_MINUS1_1() * 400), - 30 + sliderValue[sliderType::Thickness], Color::random().withAlpha(1.0f)); + drawNode->drawPoint(Vec2(AXRANDOM_MINUS1_1() * 400 + 200, AXRANDOM_MINUS1_1() * 400), 30 + thickness, + Color::random().withAlpha(1.0f)); } break; } @@ -2910,7 +2773,7 @@ void DrawNodeMethodsTest::drawAll() 60 + AXRANDOM_MINUS1_1() * VisibleRect::rightTop().y / 2}, {70 + AXRANDOM_MINUS1_1() * VisibleRect::rightTop().x, 70 + AXRANDOM_MINUS1_1() * VisibleRect::rightTop().y / 2}}; - drawNode->drawPoints(position, 4, 10 + 2 * sliderValue[sliderType::Thickness], + drawNode->drawPoints(position, 4, 10 + 2 * thickness, Color(AXRANDOM_0_1(), AXRANDOM_0_1(), AXRANDOM_0_1(), 1)); } break; @@ -2918,21 +2781,21 @@ void DrawNodeMethodsTest::drawAll() case drawMethodes::Triangle: { static Color color3[] = {Color::GREEN, Color::BLUE, Color::RED}; - drawNode->properties.setPosition(center); - drawNode->properties.setScale(Vec2(10, 10)); + drawNode->setLocalPosition(center); + // drawNode->setLocalScale(Vec2(10, 10)); { - drawNode->drawTriangle(Vec2(AXRANDOM_MINUS1_1(), AXRANDOM_MINUS1_1()) * 20, - Vec2(AXRANDOM_MINUS1_1(), AXRANDOM_MINUS1_1()) * 20, - Vec2(AXRANDOM_MINUS1_1(), AXRANDOM_MINUS1_1()) * 20, Color::RED); + drawNode->drawTriangle(Vec2(AXRANDOM_MINUS1_1(), AXRANDOM_MINUS1_1()) * 200, + Vec2(AXRANDOM_MINUS1_1(), AXRANDOM_MINUS1_1()) * 200, + Vec2(AXRANDOM_MINUS1_1(), AXRANDOM_MINUS1_1()) * 200, Color::RED, thickness); } - { - Vec2 triangle[] = {Vec2(AXRANDOM_MINUS1_1(), AXRANDOM_MINUS1_1()) * 20, - Vec2(AXRANDOM_MINUS1_1(), AXRANDOM_MINUS1_1()) * 20, - Vec2(AXRANDOM_MINUS1_1(), AXRANDOM_MINUS1_1()) * 20}; + //{ + // Vec2 triangle[] = {Vec2(AXRANDOM_MINUS1_1(), AXRANDOM_MINUS1_1()) * 20, + // Vec2(AXRANDOM_MINUS1_1(), AXRANDOM_MINUS1_1()) * 20, + // Vec2(AXRANDOM_MINUS1_1(), AXRANDOM_MINUS1_1()) * 20}; - drawNode->drawColoredTriangle(triangle, color3); - } + // drawNode->drawColoredTriangle(triangle, color3); + //} break; } case drawMethodes::SolidTriangle: @@ -2940,18 +2803,17 @@ void DrawNodeMethodsTest::drawAll() static Vec2 triangle[] = {Vec2(AXRANDOM_MINUS1_1(), AXRANDOM_MINUS1_1()) * 30, Vec2(AXRANDOM_MINUS1_1(), AXRANDOM_MINUS1_1()) * 30, Vec2(AXRANDOM_MINUS1_1(), AXRANDOM_MINUS1_1()) * 30}; - drawNode->properties.setPosition(center); - drawNode->properties.setScale(Vec2(10, 10)); - // for (int i = 0; i < 10; i++) + drawNode->setLocalPosition(center); + { drawNode->drawSolidTriangle(Vec2(AXRANDOM_MINUS1_1(), AXRANDOM_MINUS1_1()) * 20, Vec2(AXRANDOM_MINUS1_1(), AXRANDOM_MINUS1_1()) * 20, Vec2(AXRANDOM_MINUS1_1(), AXRANDOM_MINUS1_1()) * 20, Color::RED, Color::BLUE, - sliderValue[sliderType::Thickness]); + thickness); - drawNode->properties.setPosition(center - Vec2(200, 200)); - drawNode->drawSolidTriangle(triangle, Color::GREEN, Color::BLUE, sliderValue[sliderType::Thickness]); + drawNode->setLocalPosition(center - Vec2(200, 200)); + drawNode->drawSolidTriangle(triangle, Color::GREEN, Color::BLUE, thickness); } break; } @@ -2963,18 +2825,22 @@ void DrawNodeMethodsTest::drawAll() int yy1 = 150; int yy = 0; - drawNode->drawSegment(Vec2(-150.0f, yy - yy1), Vec2(200, yy - yy1), 20 + 5 * sliderValue[sliderType::Thickness], - Color::GREEN, DrawNode::Round, DrawNode::Round); + + drawNode->drawSegment(Vec2(-150.0f, yy - yy1 - 40), Vec2(200, yy - yy1 - 40), thickness, Color::MAGENTA, + DrawNode::Round, DrawNode::Round); + + drawNode->drawSegment(Vec2(-150.0f, yy - yy1), Vec2(200, yy - yy1), 20 + 5 * thickness, Color::GREEN, + DrawNode::Round, DrawNode::Round); labelRound->setPosition(Vec2(250.0f, 85)); yy += 170; - drawNode->drawSegment(Vec2(-150.0f, yy - yy1), Vec2(200, yy - yy1), 20 + 5 * sliderValue[sliderType::Thickness], - Color::BLUE, DrawNode::Square, DrawNode::Square); + drawNode->drawSegment(Vec2(-150.0f, yy - yy1), Vec2(200, yy - yy1), 20 + 5 * thickness, Color::BLUE, + DrawNode::Square, DrawNode::Square); labelSquare->setPosition(Vec2(250.0f, 170)); yy += 170; - drawNode->drawSegment(Vec2(-150.0f, yy - yy1), Vec2(200, yy - yy1), 20 + 5 * sliderValue[sliderType::Thickness], - Color::RED, DrawNode::Butt, DrawNode::Butt); + drawNode->drawSegment(Vec2(-150.0f, yy - yy1), Vec2(200, yy - yy1), 20 + 5 * thickness, Color::RED, + DrawNode::Butt, DrawNode::Butt); labelButt->setPosition(Vec2(250.0f, 255)); break; @@ -2986,31 +2852,29 @@ void DrawNodeMethodsTest::drawAll() float thickness = 2.0f; - drawNode->drawSolidCircle( - VisibleRect::center(), AXRANDOM_0_1() * 200, AX_DEGREES_TO_RADIANS(AXRANDOM_MINUS1_1() * 90), 10, 1.0f, - 1.0f, Color::random().withAlpha(1.0f), sliderValue[sliderType::Thickness], Color::random().withAlpha(1.0f)); + drawNode->drawSolidCircle(VisibleRect::center(), AXRANDOM_0_1() * 200, + AX_DEGREES_TO_RADIANS(AXRANDOM_MINUS1_1() * 90), 10, 1.0f, 1.0f, + Color::random().withAlpha(1.0f), thickness, Color::random().withAlpha(1.0f)); drawNode->drawSolidCircle(VisibleRect::center() + pos, AXRANDOM_0_1() * 200, AX_DEGREES_TO_RADIANS(AXRANDOM_MINUS1_1() * 90), 10, 1.0f, 1.0f, - Color::random().withAlpha(1.0f), sliderValue[sliderType::Thickness], - Color::random().withAlpha(1.0f)); + Color::random().withAlpha(1.0f), thickness, Color::random().withAlpha(1.0f)); drawNode->drawSolidCircle(VisibleRect::center() - pos, AXRANDOM_0_1() * 200, AX_DEGREES_TO_RADIANS(AXRANDOM_MINUS1_1() * 90), 10, 1.0f, 1.0f, - Color::random().withAlpha(1.0f), sliderValue[sliderType::Thickness], - Color::random().withAlpha(1.0f)); + Color::random().withAlpha(1.0f), thickness, Color::random().withAlpha(1.0f)); // for (int i = 5; i > 1; i--) //{ // drawNode->drawSolidCircle( // VisibleRect::center(), 3 * i, AX_DEGREES_TO_RADIANS(90), AXRANDOM_0_1() * 20.f + 20.f, 1.0f, 1.0f, - // Color::random().withAlpha(1.0f), sliderValue[sliderType::Thickness], + // Color::random().withAlpha(1.0f), thickness, // Color(AXRANDOM_0_1(), AXRANDOM_0_1(), AXRANDOM_0_1(), 0.5f)); // drawNode->drawSolidCircle( // VisibleRect::center() + pos, AXRANDOM_0_1() * 200, AX_DEGREES_TO_RADIANS(AXRANDOM_MINUS1_1() * 90), // 10, 1.0f, 1.0f, Color::random().withAlpha(1.0f), - // sliderValue[sliderType::Thickness], Color::random().withAlpha(1.0f)); + // thickness, Color::random().withAlpha(1.0f)); //} break; @@ -3018,19 +2882,19 @@ void DrawNodeMethodsTest::drawAll() case drawMethodes::SolidPoly: { Vec2 ppp = Vec2(AXRANDOM_MINUS1_1() * size.x / 2, AXRANDOM_MINUS1_1() * size.y / 2); - drawNode->properties.setPosition(Vec2(ppp)); + drawNode->setLocalPosition(Vec2(ppp)); - drawNode->properties.setPosition(Vec2(0.0f, -300.0f)); - drawNode->properties.setRotation(rotation / 10.0f); - drawNode->properties.setScale(Vec2(2.0f, 2.0f)); - drawNode->properties.setCenter(vertices1[4]); + drawNode->setLocalPosition(Vec2(0.0f, -300.0f)); + drawNode->setLocalRotation(rotation / 10.0f); + drawNode->setLocalScale(Vec2(2.0f, 2.0f)); + drawNode->setLocalPivot(vertices1[4]); drawNode->drawSolidPoly(vertices1, sizeof(vertices1) / sizeof(vertices1[0]), Color::BLUE); - drawNode->properties.setRotation(rotation); + drawNode->setLocalRotation(rotation); drawNode->drawSolidPoly(vertices1, sizeof(vertices1) / sizeof(vertices1[0]), Color::YELLOW); - drawNode->properties.setRotation(-rotation / 5); + drawNode->setLocalRotation(-rotation / 5); drawNode->drawSolidPoly(vertices1, sizeof(vertices1) / sizeof(vertices1[0]), Color::WHITE); - drawNode->properties.setDefaultValues(); + drawNode->resetAdvancedSettings(); drawNode->drawSolidPoly(vertices1, sizeof(vertices1) / sizeof(vertices1[0]), Color::GREEN); break; @@ -3041,9 +2905,8 @@ void DrawNodeMethodsTest::drawAll() { Vec2 pos = Vec2(-100, -100) + Vec2(AXRANDOM_MINUS1_1() * VisibleRect::rightTop().x, AXRANDOM_MINUS1_1() * VisibleRect::rightTop().y); - drawNode->drawSolidRect( - pos, pos + Vec2(20.0f * sliderValue[sliderType::Thickness], 20.0f * sliderValue[sliderType::Thickness]), - Color(AXRANDOM_0_1(), AXRANDOM_0_1(), AXRANDOM_0_1(), 0.5f), sliderValue[sliderType::Thickness]); + drawNode->drawSolidRect(pos, pos + Vec2(20.0f * thickness, 20.0f * thickness), + Color(AXRANDOM_0_1(), AXRANDOM_0_1(), AXRANDOM_0_1(), 0.5f), thickness); } break; @@ -3056,40 +2919,39 @@ void DrawNodeMethodsTest::drawAll() Vec2 gear3 = {200.f, 200.f}; Vec2 gear4 = {size.width - 200, size.height - 200}; - drawNode->properties.setRotation(rotation + 45); - drawNode->properties.setCenter(gear1); + drawNode->setLocalRotation(rotation + 45); + drawNode->setLocalPivot(gear1); drawNode->drawStar(Vec2(gear1), 30, 60, 8, Color::BLUE, 4.0); - drawNode->properties.setRotation(-rotation); - drawNode->properties.setCenter(gear2); + drawNode->setLocalRotation(-rotation); + drawNode->setLocalPivot(gear2); drawNode->drawStar(gear2, 30, 60, 8, Color::GREEN, 4.0); - drawNode->properties.setDefaultValues(); - drawNode->drawLine(gear2, gear1, Color::RED, sliderValue[sliderType::Thickness]); // line - drawNode->properties.setCenter(gear4); - drawNode->properties.setRotation(rotation + 45); + drawNode->resetAdvancedSettings(); + drawNode->drawLine(gear2, gear1, Color::RED, thickness); // line + drawNode->setLocalPivot(gear4); + drawNode->setLocalRotation(rotation + 45); drawNode->drawStar(gear3, 30, 60, 18, Color::RED, 1.0); - drawNode->drawLine(gear3, gear4, Color::YELLOW, sliderValue[sliderType::Thickness]); // line + drawNode->drawLine(gear3, gear4, Color::YELLOW, thickness); // line // drawNode->properties.setDefaultValues(); - drawNode->properties.setRotation(rotation - 45); - drawNode->properties.setCenter(gear4); + drawNode->setLocalRotation(rotation - 45); + drawNode->setLocalPivot(gear4); drawNode->drawStar(gear4, 40, 60, 60, Color::GREEN, 1.0); - drawNode->properties.setRotation(rotation); - drawNode->properties.setCenter(Vec2(-110, 250)); + drawNode->setLocalRotation(rotation); + drawNode->setLocalPivot(Vec2(-110, 250)); drawNode->drawStar(Vec2(-110, 250), 30, 70, 5, Color::GREEN, 1.0); - drawNode->properties.setCenter(Vec2(-150, 100)); + drawNode->setLocalPivot(Vec2(-150, 100)); drawNode->drawStar(Vec2(-150, 100), 80, 100, 40, Color::GREEN, 1.0); - drawNode->properties.setCenter(Vec2(-150, -100)); + drawNode->setLocalPivot(Vec2(-150, -100)); drawNode->drawStar(Vec2(-150, -100), 5, 70, 3, Color::GREEN, 1.0); - drawNode->properties.setRotation(0); + drawNode->setLocalRotation(0); for (int i = 0; i < 10; i++) { Vec2 ppp = Vec2(AXRANDOM_MINUS1_1() * size.x / 2, AXRANDOM_MINUS1_1() * size.y / 2); - drawNode->properties.setPosition(Vec2(ppp)); - drawNode->drawStar( - Vec2::ZERO, 40, 60, AXRANDOM_0_1() * 60 + 3, - Color(AXRANDOM_0_1(), AXRANDOM_0_1(), AXRANDOM_0_1(), sliderValue[sliderType::Thickness])); + drawNode->setLocalPosition(Vec2(ppp)); + drawNode->drawStar(Vec2::ZERO, 40, 60, AXRANDOM_0_1() * 60 + 3, + Color(AXRANDOM_0_1(), AXRANDOM_0_1(), AXRANDOM_0_1(), thickness)); } break; } @@ -3100,37 +2962,37 @@ void DrawNodeMethodsTest::drawAll() Vec2 gear3 = {200.f, 200.f}; Vec2 gear4 = {size.width - 200, size.height - 200}; - drawNode->properties.setRotation(rotation + 45); - drawNode->properties.setCenter(gear1); + drawNode->setLocalRotation(rotation + 45); + drawNode->setLocalPivot(gear1); drawNode->drawSolidStar(Vec2(gear1), 30, 60, 8, Color::BLUE, Color::YELLOW, 4.0); - drawNode->properties.setRotation(-rotation); - drawNode->properties.setCenter(gear2); + drawNode->setLocalRotation(-rotation); + drawNode->setLocalPivot(gear2); drawNode->drawSolidStar(gear2, 30, 60, 8, Color::GREEN, Color::YELLOW, 4.0); - drawNode->properties.setDefaultValues(); - drawNode->drawLine(gear2, gear1, Color::RED, sliderValue[sliderType::Thickness]); // line - drawNode->properties.setCenter(gear4); - drawNode->properties.setRotation(rotation + 45); + drawNode->resetAdvancedSettings(); + drawNode->drawLine(gear2, gear1, Color::RED, thickness); // line + drawNode->setLocalPivot(gear4); + drawNode->setLocalRotation(rotation + 45); drawNode->drawSolidStar(gear3, 30, 60, 18, Color::RED, Color::YELLOW, 1.0); - drawNode->drawLine(gear3, gear4, Color::YELLOW, sliderValue[sliderType::Thickness]); // line - drawNode->properties.setDefaultValues(); - drawNode->properties.setRotation(rotation - 45); - drawNode->properties.setCenter(gear4); + drawNode->drawLine(gear3, gear4, Color::YELLOW, thickness); // line + drawNode->resetAdvancedSettings(); + drawNode->setLocalRotation(rotation - 45); + drawNode->setLocalPivot(gear4); drawNode->drawSolidStar(gear4, 40, 60, 60, Color::GREEN, Color::YELLOW, 1.0); - drawNode->properties.setRotation(rotation); - drawNode->properties.setCenter(Vec2(-110, 250)); + drawNode->setLocalRotation(rotation); + drawNode->setLocalPivot(Vec2(-110, 250)); drawNode->drawSolidStar(Vec2(-110, 250), 30, 70, 5, Color::GREEN, Color::YELLOW, 1.0); - drawNode->properties.setCenter(Vec2(-150, 100)); + drawNode->setLocalPivot(Vec2(-150, 100)); drawNode->drawSolidStar(Vec2(-150, 100), 80, 100, 40, Color::GREEN, Color::YELLOW, 1.0); - drawNode->properties.setCenter(Vec2(-150, -100)); + drawNode->setLocalPivot(Vec2(-150, -100)); drawNode->drawSolidStar(Vec2(-150, -100), 5, 70, 3, Color::GREEN, Color::YELLOW, 1.0); - drawNode->properties.setRotation(0); + drawNode->setLocalRotation(0); for (int i = 0; i < 10; i++) { Vec2 ppp = Vec2(AXRANDOM_MINUS1_1() * size.x / 2, AXRANDOM_MINUS1_1() * size.y / 2); - drawNode->properties.setPosition(Vec2(ppp)); + drawNode->setLocalPosition(Vec2(ppp)); drawNode->drawSolidStar(Vec2::ZERO, 40, 60, AXRANDOM_0_1() * 60 + 3, Color::random().withAlpha(1.0f), Color::random().withAlpha(1.0f)); } @@ -3145,7 +3007,7 @@ void DrawNodeMethodsTest::drawAll() DrawNodeDrawInWrongOrder_Issue1888::DrawNodeDrawInWrongOrder_Issue1888() { - drawNode->properties.setDrawOrder(true); + drawNode->setPreserveDrawOrder(true); scheduleUpdate(); } @@ -3216,7 +3078,7 @@ DrawNodeAxmolTest2::DrawNodeAxmolTest2() } drawNode = DrawNode::create(); - drawNode->properties.setTransform(true); + drawNode->setLocalTransformEnabled(true); addChild(drawNode, 10); scheduleUpdate(); @@ -3273,7 +3135,7 @@ void DrawNodeAxmolTest2::update(float dt) void DrawNodeAxmolTest2::drawAllv2(DrawNode* drawNode, bool drawOrder) { - drawNode->properties.setDrawOrder(drawOrder); + drawNode->setPreserveDrawOrder(drawOrder); drawNode->drawPoint(Vec2(size.width / 2 - 120, size.height / 2 - 120), 10, Color(AXRANDOM_0_1(), AXRANDOM_0_1(), AXRANDOM_0_1(), 1)); @@ -3434,13 +3296,166 @@ string DrawNodeAxmolTest2::subtitle() const return ""; } +DrawNodePolygonTest::DrawNodePolygonTest() +{ + ax::DrawNode* drawNode = ax::DrawNode::create(); + addChild(drawNode); + drawNode->setLocalTransformEnabled(true); + drawNode->setScale(0.3f); + drawNode->setLocalPosition(Vec2(150, 590)); + drawNode->setLocalScale({0.4f, 0.4f}); + drawNode->drawSolidPolygon(horse, sizeof(horse) / sizeof(horse[0]), Color::WHITE, 3.0f, Color::RED); + drawNode->setLocalPosition(Vec2(30, 200)); + drawNode->setLocalScale({1.0f, 1.0f}); + drawNode->drawPoly(horse, sizeof(horse) / sizeof(horse[0]), true, Color::GREEN, 20.0f); + drawNode->setLocalPosition(Vec2(700, 220)); + drawNode->setLocalScale({0.1f, 0.1f}); + drawNode->drawSolidPolygon(spider, sizeof(spider) / sizeof(spider[0]), Color::YELLOW, 2.0f, Color::RED); + drawNode->setLocalScale({0.2f, 0.2f}); + drawNode->setLocalPosition(Vec2(880, 200)); + drawNode->drawPoly(spider, sizeof(spider) / sizeof(spider[0]), true, Color::RED); + drawNode->setLocalScale({0.4f, 0.4f}); + drawNode->setLocalPosition(Vec2(1100, 160)); + drawNode->drawPoly(spider, sizeof(spider) / sizeof(spider[0]), true, Color::RED, true); + drawNode->setLocalScale({0.7f, 0.7f}); + drawNode->setLocalPosition(Vec2(1260, 340)); + drawNode->setLocalRotation(45); + drawNode->drawSolidPolygon(spider, sizeof(spider) / sizeof(spider[0]), Color::YELLOW, 5.0f, Color::RED); +} + +std::string DrawNodePolygonTest::title() const +{ + return "Polygon Test"; +} + +std::string DrawNodePolygonTest::subtitle() const +{ + return ""; +} + +DrawNodeCircleTest::DrawNodeCircleTest() +{ + drawNode->setLocalPosition(Vec2(100, -10)); + for (int i = 3; i <= 24; i++) + { + drawNode->drawCircle(center, 5 * i, AX_DEGREES_TO_RADIANS(90), i, false, 1.0f, 1.0f, Color::WHITE); + } + drawNode->drawCircle(center, 130, AX_DEGREES_TO_RADIANS(90), 48, false, 1.0f, 1.0f, Color::MAGENTA); + + drawNode->setLocalPosition(Vec2(-10, 10)); + for (size_t i = 0; i < 3; i++) + { + drawNode->drawCircle(Vec2(120, 150), 85 - 18.8 * i, AX_DEGREES_TO_RADIANS(90), 5, false, 1.0f, 1.0f, + Color::BLUE, 3.0f); + } + + drawNode->setLocalPivot(Vec2(120, 150)); + for (int i = 0; i < 5; i++) + { + drawNode->setLocalRotation(360 / 5 * i); + drawNode->drawSolidCircle(Vec2(120, 197), 10, 0, 36, 1.0f, 1.0f, Color::BLUE); + drawNode->drawSolidCircle(Vec2(120, 215), 12, 0, 36, 1.0f, 1.0f, Color::BLUE); + drawNode->drawSolidCircle(Vec2(120, 235), 16, 0, 36, 1.0f, 1.0f, Color::BLUE); + } +} + +std::string DrawNodeCircleTest::title() const +{ + return "Circle Test"; +} + +std::string DrawNodeCircleTest::subtitle() const +{ + return "Axmol, '3...20', '48'-Corner"; +} + +DrawNodeSolidCircleTest::DrawNodeSolidCircleTest() +{ + showCircles(); + + autoTestLabel = Label::createWithTTF("Slow is on ", "fonts/arial.ttf", 16); + auto autoTestItem = MenuItemLabel::create(autoTestLabel, [=](Object* sender) { + static std::string text = "Fast"; + if (fast) + { + fast = false; + text = "Slow is on"; + + showCircles(); + } + else + { + fast = true; + text = "Fast is on"; + showCircles(); + } + // autoTestLabel->setString(text); + rect = autoTestLabel->getBoundingBox(); + }); + + autoTestItem->setPosition(Vec2(VisibleRect::center().x, VisibleRect::top().y - 100)); + + auto menu = Menu::create(autoTestItem, nullptr); + menu->setPosition(Vec2::ZERO); + addChild(menu, 1); +} + +void DrawNodeSolidCircleTest::showCircles() +{ + static float radius = 20; + drawNode->clear(); + + auto start = std::chrono::high_resolution_clock::now(); + for (int i = 0; i < 10000; i++) + { + Vec2 pos = VisibleRect::center() + Vec2((VisibleRect::center().x - 50) * AXRANDOM_MINUS1_1(), + (VisibleRect::center().y - 50) * AXRANDOM_MINUS1_1()); + // drawNode->drawSolidCircle(pos, radius, 0, 36, + // Color(AXRANDOM_0_1(), AXRANDOM_0_1(), AXRANDOM_0_1(), AXRANDOM_0_1() + 0.1f)); + pos = VisibleRect::center() + Vec2((VisibleRect::center().x - 50) * AXRANDOM_MINUS1_1(), + (VisibleRect::center().y - 50) * AXRANDOM_MINUS1_1()); + + Color color = Color(AXRANDOM_0_1(), AXRANDOM_0_1(), AXRANDOM_0_1(), AXRANDOM_0_1() + 0.1f); + // float radius = 10 + AXRANDOM_0_1() * 80; + if (fast) + { + //; drawNode->drawSolidCircle(pos, radius, color); + } + else + { + drawNode->drawSolidCircle(pos, radius, 0, 36, color); + } + } + auto end = std::chrono::high_resolution_clock::now(); + duration = std::chrono::duration_cast(end - start); + AXLOGD("Duration: {}", duration.count()); + if (autoTestLabel) + { + autoTestLabel->setString(std::to_string(duration.count())); + } + + drawNode->setPreserveDrawOrder(true); + rect = {190, 205, 100, 30}; + //; drawNode->drawSolidRect(rect, (fast) ? Color::GREEN : Color::RED); +} + +std::string DrawNodeSolidCircleTest::title() const +{ + return "SolidCircle Stress Test"; +} + +std::string DrawNodeSolidCircleTest::subtitle() const +{ + return "10000 Circles"; +} + DrawNodeIssueTester::DrawNodeIssueTester() { static Vec2 vertices[] = {Vec2(0.0f, 0.0f), Vec2(50.0f, 50.0f), Vec2(100.0f, 50.0f), Vec2(100.0f, 100.0f), Vec2(50.0f, 100.0f)}; int verticesCount = 5; - drawNode->properties.setPosition(Vec2(5, 150)); + drawNode->setLocalPosition(Vec2(5, 150)); drawNode->drawPoly(vertices, verticesCount, false, Color::GREEN); auto draw = DrawNode::create(); @@ -3448,33 +3463,32 @@ DrawNodeIssueTester::DrawNodeIssueTester() draw->setPosition(70, 150); draw->drawPoly(vertices, verticesCount, false, Color::BLUE); - drawNode->properties.setPosition(Vec2(140, 150)); + drawNode->setLocalPosition(Vec2(140, 150)); drawNode->drawPoly(vertices, verticesCount, false, Color::RED); - drawNode->properties.setPosition(Vec2(200, 150)); + drawNode->setLocalPosition(Vec2(200, 150)); drawNode->drawPoly(vertices, verticesCount, false, Color::RED, 3); drawNode->drawPoly(vertices, verticesCount, false, Color::WHITE); - drawNode->properties.setPosition(Vec2(270, 150)); + drawNode->setLocalPosition(Vec2(270, 150)); drawNode->drawPoly(vertices, verticesCount, false, Color(0.0f, 0.5f, 0.5f, 0.5f), 10); drawNode->drawPoly(vertices, verticesCount, false, Color::BLACK); float thick = 0.0f; float y = -90.0f; - drawNode->properties.setPosition(Vec2(270, 100)); + drawNode->setLocalPosition(Vec2(270, 100)); for (int i = 0; i < 32; i++) { thick += 0.5f; y += thick + 1; drawNode->drawLine(Vec2(140, y), Vec2(180, y), Color::random().withAlpha(1.0f), thick); } - drawNode->drawPie(Vec2(-220, 150), 20, 0, 100, 300, 1, 1, Color::TRANSPARENT, Color::BLUE, DrawNode::DrawMode::Line, - 10); + drawNode->drawPie(Vec2(-220, 150), 20, 0, 100, 300, 1, 1, Color(), Color::BLUE, DrawNode::DrawMode::Line, 10); - drawNode->properties.setPosition(Vec2(50, -100)); + drawNode->setLocalPosition(Vec2(50, -100)); for (int i = 2; i < 30; i++) { drawNode->drawCircle(center, 5 * i, AX_DEGREES_TO_RADIANS(90), i, false, 1.0f, 1.0f, @@ -3485,14 +3499,14 @@ DrawNodeIssueTester::DrawNodeIssueTester() int n = 0; Vec2 pos = {100, 210}; float scale = 3.0f; - drawNode->properties.setPosition(Vec2(-90, -160)); + drawNode->setLocalPosition(Vec2(-90, -160)); for (size_t i = 0; i < sizeof(verticesFB) / sizeof(verticesFB[0]); i += 4) { drawNode->drawLine(Vec2(verticesFB[i] * scale, verticesFB[i + 1] * scale) + pos, Vec2(verticesFB[i + 2] * scale, verticesFB[i + 3] * scale) + pos, Color::RED, 0.5f); } - drawNode->properties.setPosition(VisibleRect::center() - Vec2(100, 50)); + drawNode->setLocalPosition(VisibleRect::center() - Vec2(100, 50)); drawNode->drawSolidCircle(Vec2::ZERO, 40, AX_DEGREES_TO_RADIANS(-90), 30, 1.0f, 1.0f, Color::GREEN, 6, Color::BLUE, false); drawNode->drawSolidCircle(Vec2(100, 0), 40, AX_DEGREES_TO_RADIANS(-90), 30, 1.0f, 1.0f, Color::RED, 6, Color::BLUE, @@ -3502,6 +3516,19 @@ DrawNodeIssueTester::DrawNodeIssueTester() drawNode->drawCircle(Vec2(0, 100), 40, AX_DEGREES_TO_RADIANS(-90), 30, false, 1.0f, 1.0f, Color::RED, 6); + Label* labelSize[10]; + y = 0; + for (int i = 0; i < 10; i++) + { + float fs = (i + 1) * 3; + labelSize[i] = Label::createWithTTF("UNDERLINE/STRIKE...", "fonts/arial.ttf", fs); + labelSize[i]->setPosition(300, 300 - 50 - y); + y += (i + 2) * 3; + labelSize[i]->enableUnderline(); + labelSize[i]->enableStrikethrough(); + addChild(labelSize[i]); + } + // scheduleUpdate(); } @@ -3517,7 +3544,7 @@ void DrawNodeIssueTester::update(float dt) string DrawNodeIssueTester::title() const { - return ""; + return "Playground"; } string DrawNodeIssueTester::subtitle() const @@ -3525,46 +3552,10 @@ string DrawNodeIssueTester::subtitle() const return ""; } -DrawNodeCircleTest::DrawNodeCircleTest() -{ - drawNode->properties.setPosition(Vec2(100, 0)); - for (int i = 3; i <= 8; i++) - { - drawNode->drawCircle(center, 10 * i, AX_DEGREES_TO_RADIANS(90), i, false, 1.0f, 1.0f, Color::WHITE); - } - drawNode->drawCircle(center, 90, AX_DEGREES_TO_RADIANS(90), 36, false, 1.0f, 1.0f, Color::WHITE); - - for (size_t i = 0; i < 3; i++) - { - drawNode->properties.setPosition(Vec2(0, 0)); - drawNode->drawCircle(Vec2(120, 150), 80 - 19 * i, AX_DEGREES_TO_RADIANS(90), 5, false, 1.0f, 1.0f, Color::BLUE, - 3.0f); - } - - drawNode->properties.setCenter(Vec2(120, 150)); - for (int i = 0; i < 5; i++) - { - drawNode->properties.setRotation(AX_DEGREES_TO_RADIANS(360 / 5 * i)); - drawNode->drawSolidCircle(Vec2(120, 195), 10, 0, 36, 1.0f, 1.0f, Color::BLUE); - drawNode->drawSolidCircle(Vec2(120, 210), 12, 0, 36, 1.0f, 1.0f, Color::BLUE); - drawNode->drawSolidCircle(Vec2(120, 230), 16, 0, 36, 1.0f, 1.0f, Color::BLUE); - } -} - -std::string DrawNodeCircleTest::title() const -{ - return "Circle Test"; -} - -std::string DrawNodeCircleTest::subtitle() const -{ - return "Axmol, N-Corner, Circle"; -} - DrawNodeSpLinesTest::DrawNodeSpLinesTest() { drawNode = DrawNode::create(); - drawNode->properties.setTransform(true); + drawNode->setLocalTransformEnabled(true); addChild(drawNode, 30); screen = Director::getInstance()->getVisibleSize(); @@ -3602,6 +3593,8 @@ std::string DrawNodeSpLinesTest::subtitle() const void DrawNodeSpLinesTest::update(float dt) { + static int xlabel = 0; + static float step = 0; drawNode->clear(); // Issue #2302 @@ -3616,13 +3609,28 @@ void DrawNodeSpLinesTest::update(float dt) drawNode->drawCardinalSpline(pts, 0.5f, 360, Color::RED, 5.0f); drawNode->drawCardinalSpline(pts2, 0.5f, 360, Color::GREEN, 2.0f); - int i1 = RandomHelper::random_int(0, n - 1); - int i2 = RandomHelper::random_int(0, n - 1); + step += dt; + if (step > 0.2) + { + step = 0; + xlabel++; + if (xlabel > n - 1) + { + xlabel = 0; + } + } + + int i1 = xlabel; + int i2 = n - 1 - xlabel; + drawNode->drawLine(pts->getControlPointAtIndex(i1) - Vec2(0, 30), pts->getControlPointAtIndex(i1) + Vec2(0, 30), + Color::YELLOW, 2.0f); drawNode->drawDot(pts->getControlPointAtIndex(i1), 7, Color(0, 1, 0, 0.3)); drawNode->drawDot(pts->getControlPointAtIndex(i1), 4, Color::GREEN); - drawNode->drawDot(pts2->getControlPointAtIndex(i2), 7, Color(0, 1, 0, 0.3)); - drawNode->drawDot(pts2->getControlPointAtIndex(i2), 4, Color::GREEN); + drawNode->drawLine(pts2->getControlPointAtIndex(i2) - Vec2(0, 30), pts2->getControlPointAtIndex(i2) + Vec2(0, 30), + Color::YELLOW, 2.0f); + drawNode->drawDot(pts2->getControlPointAtIndex(i2), 7, Color(1, 0, 0, 0.3)); + drawNode->drawDot(pts2->getControlPointAtIndex(i2), 4, Color::RED); } DrawNodeSpLinesOpenClosedTest::DrawNodeSpLinesOpenClosedTest() @@ -3632,11 +3640,11 @@ DrawNodeSpLinesOpenClosedTest::DrawNodeSpLinesOpenClosedTest() _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this); drawNodeCP = DrawNode::create(); - drawNodeCP->properties.setTransform(true); + drawNodeCP->setLocalTransformEnabled(true); addChild(drawNodeCP, 50); drawNode = DrawNode::create(); - drawNode->properties.setTransform(true); + drawNode->setLocalTransformEnabled(true); addChild(drawNode, 30); screen = Director::getInstance()->getVisibleSize(); @@ -3727,6 +3735,53 @@ void DrawNodeSpLinesOpenClosedTest::update(float dt) } #if defined(AX_PLATFORM_PC) + +DrawNodePointTest::DrawNodePointTest() +{ + Vec2 visibleSize = Director::getInstance()->getVisibleSize(); + + // drawNode->clear(); + // DrawNodeBaseTest::update(dt); + + // _subtitle = "please wait"; + Color color = Color::RED; + int delta = 10; + int xx = 0; + int yy = 0; + for (unsigned int y = 0; y < visibleSize.height; y += delta) + { + color = Color::RED; + if (y % 3 == 0) + { + color = Color::BLUE; + } + for (unsigned int x = 0; x < visibleSize.width; x += delta) + { + if (x % 4 == 0) + { + color = Color::RED; + } + Vec2 pos = {(float)x + delta / 2, (float)y + delta / 2}; + drawNode->drawPoint(pos, delta - 1, color, ax::DrawNode::Circle); + xx++; + } + yy++; + } + // scheduleUpdate(); +} + +std::string DrawNodePointTest::title() const +{ + return "Performance: POINT"; +} + +std::string DrawNodePointTest::subtitle() const +{ + return ""; +} + +void DrawNodePointTest::update(float dt) {} + CandyMixEeffect::CandyMixEeffect() { static const float BUTTON_WIDTH = 30; @@ -3808,6 +3863,6 @@ void CandyMixEeffect::update(float dt) } #endif -#if defined(_WIN32) -# pragma pop_macro("TRANSPARENT") -#endif +// #if defined(_WIN32) +// # pragma pop_macro("TRANSPARENT") +// #endif diff --git a/tests/cpp-tests/Source/DrawNodeTest/DrawNodeTest.h b/tests/cpp-tests/Source/DrawNodeTest/DrawNodeTest.h index 601bc4084c11..b915139f5ddd 100644 --- a/tests/cpp-tests/Source/DrawNodeTest/DrawNodeTest.h +++ b/tests/cpp-tests/Source/DrawNodeTest/DrawNodeTest.h @@ -35,14 +35,6 @@ class DrawNodeBaseTest : public TestCase { protected: - enum sliderType - { - AngleStart = 0, - AngleEnd, - Rotation, - Thickness, - sliderTypeLast - }; enum drawMethodes { Line = 0, @@ -94,22 +86,26 @@ class DrawNodeBaseTest : public TestCase public: DrawNodeBaseTest(); - void onChangedRadioButtonSelect(ax::ui::RadioButton* radioButton, ax::ui::RadioButton::EventType type); - void listviewCallback(ax::Object* sender, ax::ui::ListView::EventType type); - void setDrawOrder(Object* sender); - void setTransform(Object* sender); - void update(float dt) override; + void onDrawImGui(); + void onExit() override; + void onEnter() override; virtual std::string title() const override; void drawDirection(const ax::Vec2* vec, const int size, ax::Vec2 offset); - void initSliders(); - - void changeStartAngle(ax::Object* pSender, ax::ui::Slider::EventType type); - void changeEndAngle(ax::Object* pSender, ax::ui::Slider::EventType type); - void changeRotation(ax::Object* pSender, ax::ui::Slider::EventType type); - void changeThickness(ax::Object* pSender, ax::ui::Slider::EventType type); + float ns; // drawNode->getScale; + ax::Vec2 po; // drawNode->_localPosition + ax::Vec2 ps; // drawNode->_localScale + float pf; // drawNode->_thicknessScale + float thickness; + float pa; // drawNode->_localRotation + float as; // angle start + float ae; // angle end + bool drawOrder; + bool transform; + int flagGUI = -1; + ax::Scene* _target = nullptr; // using from https://github.com/intmainreturn00/AwesomeNode/ void generateDataPoints(); @@ -126,19 +122,6 @@ class DrawNodeBaseTest : public TestCase protected: int _currentSeletedItemIndex = 0; - // UI stuff - ax::ui::Slider* slider[sliderType::sliderTypeLast]; - ax::Label* sliderLabel[sliderType::sliderTypeLast]; - float sliderValue[sliderType::sliderTypeLast]; - - ax::ui::RadioButtonGroup* _radioButtonGroup; - ax::Layer* _uiLayer; - ax::ui::Layout* _widget; - int selectedRadioButton; - - ax::MenuItemFont* menuItemDrawOrder; - ax::MenuItemFont* menuItemTransform; - // DrawNode stuff ax::DrawNode* drawNode = nullptr; ax::DrawNode* drawNodeArray[10]; @@ -256,12 +239,6 @@ class DrawNodeLineDrawTest : public DrawNodeBaseTest void update(float dt) override; void onEnter() override; - -private: - // ax::Label* _lineWidthLabel; - // float lineWidth = 0; - ax::Label* _thicknessLabel; - float thickness = 1.0f; }; class DrawNodeVersionsTest : public DrawNodeBaseTest @@ -307,6 +284,7 @@ class DrawNodePieTest : public DrawNodeBaseTest class DrawNodeMethodsTest : public DrawNodeBaseTest { + public: CREATE_FUNC(DrawNodeMethodsTest); @@ -406,7 +384,7 @@ class DrawNodeThicknessStressTest : public DrawNodeBaseTest virtual std::string subtitle() const override; void update(float dt) override; - void onEnter() override; + // void onEnter() override; void changeThreshold(Object* pSender, ax::ui::Slider::EventType type); void changeLineWidth(Object* pSender, ax::ui::Slider::EventType type); @@ -442,6 +420,35 @@ class DrawNodeCircleTest : public DrawNodeBaseTest virtual std::string subtitle() const override; }; +class DrawNodeSolidCircleTest : public DrawNodeBaseTest +{ +public: + CREATE_FUNC(DrawNodeSolidCircleTest); + + DrawNodeSolidCircleTest(); + void showCircles(); + + virtual std::string title() const override; + virtual std::string subtitle() const override; + +private: + bool fast; + std::chrono::microseconds duration; + ax::Label* autoTestLabel = nullptr; + ax::Rect rect; +}; + +class DrawNodePolygonTest : public DrawNodeBaseTest +{ +public: + CREATE_FUNC(DrawNodePolygonTest); + + DrawNodePolygonTest(); + + virtual std::string title() const override; + virtual std::string subtitle() const override; +}; + class DrawNodeSpLinesOpenClosedTest : public DrawNodeBaseTest { public: @@ -462,7 +469,43 @@ class DrawNodeSpLinesOpenClosedTest : public DrawNodeBaseTest ax::PointArray* array; }; +class DrawNodeRoundRectTest : public DrawNodeBaseTest +{ +public: + CREATE_FUNC(DrawNodeRoundRectTest); + + DrawNodeRoundRectTest(); + + virtual std::string title() const override; + virtual std::string subtitle() const override; +}; + +class DrawNodeButtonTest : public DrawNodeBaseTest +{ +public: + CREATE_FUNC(DrawNodeButtonTest); + + DrawNodeButtonTest(); + + virtual std::string title() const override; + virtual std::string subtitle() const override; +}; + #if defined(AX_PLATFORM_PC) + +class DrawNodePointTest : public DrawNodeBaseTest +{ +public: + CREATE_FUNC(DrawNodePointTest); + + DrawNodePointTest(); + + virtual std::string title() const override; + virtual std::string subtitle() const override; + + void update(float dt) override; +}; + class CandyMixEeffect : public DrawNodeBaseTest { public: diff --git a/tests/cpp-tests/Source/LabelTest/LabelTest.cpp b/tests/cpp-tests/Source/LabelTest/LabelTest.cpp index 8bc16eb8cd8f..a259dd199071 100644 --- a/tests/cpp-tests/Source/LabelTest/LabelTest.cpp +++ b/tests/cpp-tests/Source/LabelTest/LabelTest.cpp @@ -3640,49 +3640,6 @@ LabelUnderlineStrikethroughMultiline::LabelUnderlineStrikethroughMultiline() { auto s = Director::getInstance()->getCanvasSize(); - TTFConfig ttfConf("fonts/arial.ttf", 40, GlyphCollection::DYNAMIC, nullptr, true); - - // Glow SDF (GPU) - auto label1 = Label::createWithTTF(ttfConf, "Glow1", TextHAlignment::CENTER, s.width); - label1->setPosition(Vec2(s.width / 2, s.height * 0.7)); - label1->setTextColor(Color32::GREEN); - label1->enableGlow(Color32::YELLOW); - label1->enableUnderline(); - label1->enableStrikethrough(); - addChild(label1); - - // Glow normal(CPU) - ttfConf.distanceFieldEnabled = false; - auto label2 = Label::createWithTTF(ttfConf, "Glow2", TextHAlignment::CENTER, s.width); - label2->setPosition(Vec2(s.width / 2, s.height * 0.6)); - label2->setTextColor(Color32::GREEN); - label2->enableGlow(Color32::YELLOW); - label2->enableUnderline(); - label2->enableStrikethrough(); - addChild(label2); - - // Outline SDF(GPU) - ttfConf.distanceFieldEnabled = true; - ttfConf.outlineSize = 2; - auto label3 = Label::createWithTTF(ttfConf, "Outline1", TextHAlignment::CENTER, s.width); - label3->setPosition(Vec2(s.width / 2, s.height * 0.48)); - label3->setTextColor(Color32::RED); - label3->enableOutline(Color32::BLUE); - label3->enableUnderline(); - label3->enableStrikethrough(); - addChild(label3); - - // Outline normal(CPU by freetype2) - ttfConf.distanceFieldEnabled = false; - ttfConf.outlineSize = 2; - auto label4 = Label::createWithTTF(ttfConf, "Outline2", TextHAlignment::CENTER, s.width); - label4->setPosition(Vec2(s.width / 2, s.height * 0.36)); - label4->setTextColor(Color32::RED); - label4->enableOutline(Color32::BLUE, 2); - label4->enableUnderline(); - label4->enableStrikethrough(); - addChild(label4); - std::string font = "fonts/arial.ttf"; // ttf @@ -3690,7 +3647,7 @@ LabelUnderlineStrikethroughMultiline::LabelUnderlineStrikethroughMultiline() ttfConfig.underline = true; ttfConfig.strikethrough = true; - const int count = 7; + const int count = 11; Label* labels[count]; labels[0] = Label::createWithSystemFont("SystemFont TextVAlignment::TOP\nusing setTextColor(255, 0, 255, 100)", @@ -3722,9 +3679,49 @@ LabelUnderlineStrikethroughMultiline::LabelUnderlineStrikethroughMultiline() Label::createWithTTF("TTF setTextColor(*RED*)\nwith multiline 1\nand a much more longer multiline 2", font, 14); labels[6]->setTextColor(Color32::RED); + TTFConfig ttfConf("fonts/arial.ttf", 40, GlyphCollection::DYNAMIC, nullptr, true); + + // Glow SDF (GPU) + labels[7] = Label::createWithTTF(ttfConf, "Glow1", TextHAlignment::CENTER, s.width); + labels[7]->setPosition(Vec2(s.width / 2, s.height * 0.7)); + labels[7]->setTextColor(Color32::GREEN); + labels[7]->enableGlow(Color32::YELLOW); + labels[7]->enableUnderline(); + labels[7]->enableStrikethrough(); + + // Glow normal(CPU) + ttfConf.distanceFieldEnabled = false; + labels[8] = Label::createWithTTF(ttfConf, "Glow2", TextHAlignment::CENTER, s.width); + labels[8]->setPosition(Vec2(s.width / 2, s.height * 0.6)); + labels[8]->setTextColor(Color32::GREEN); + labels[8]->enableGlow(Color32::YELLOW); + labels[8]->enableUnderline(); + labels[8]->enableStrikethrough(); + + // Outline SDF(GPU) + ttfConf.distanceFieldEnabled = true; + ttfConf.outlineSize = 2; + labels[9] = Label::createWithTTF(ttfConf, "Outline1", TextHAlignment::CENTER, s.width); + labels[9]->setPosition(Vec2(s.width / 2, s.height * 0.48)); + labels[9]->setTextColor(Color32::RED); + labels[9]->enableOutline(Color32::BLUE); + labels[9]->enableUnderline(); + labels[9]->enableStrikethrough(); + + // Outline normal(CPU by freetype2) + ttfConf.distanceFieldEnabled = false; + ttfConf.outlineSize = 2; + labels[10] = Label::createWithTTF(ttfConf, "Outline2", TextHAlignment::CENTER, s.width); + labels[10]->setPosition(Vec2(s.width / 2, s.height * 0.36)); + labels[10]->setTextColor(Color32::RED); + labels[10]->enableOutline(Color32::BLUE, 2); + labels[10]->enableUnderline(); + labels[10]->enableStrikethrough(); + for (int i = 0; i < count; i++) { - labels[i]->setPosition(Vec2(labels[i]->getBoundingBox().getMaxX() + 10, s.height * 0.13f * (i + 1))); + if (i < 7) + labels[i]->setPosition(Vec2(labels[i]->getBoundingBox().getMaxX() + 10, s.height * 0.13f * (i + 1))); labels[i]->enableUnderline(); labels[i]->enableStrikethrough(); addChild(labels[i]); @@ -3789,11 +3786,8 @@ std::string LabelUnderlineStrikethroughMultiline::title() const std::string LabelUnderlineStrikethroughMultiline::subtitle() const { return ""; - // Underline + Strikethrough + Color on TTF and BMfont with multiline "; } -/// - LabelStrikethrough::LabelStrikethrough() { auto s = Director::getInstance()->getCanvasSize(); diff --git a/tests/cpp-tests/Source/controller.cpp b/tests/cpp-tests/Source/controller.cpp index e46f997a281d..fdb3f5314eae 100644 --- a/tests/cpp-tests/Source/controller.cpp +++ b/tests/cpp-tests/Source/controller.cpp @@ -62,7 +62,8 @@ class RootTests : public TestList addTest("Box2D - Basic", []() { return new Box2DTests(); }); - // Box2DTestBed is only works on PC platforms, because it requires glfw which is not available on mobile platforms + // Box2DTestBed is only works on PC platforms, because it requires glfw which is not available on mobile + // platforms #if AX_ENABLE_EXT_IMGUI && defined(AX_PLATFORM_PC) addTest("Box2D - TestBed", []() { return new Box2DTestBedTests(); }); #endif @@ -89,7 +90,9 @@ class RootTests : public TestList addTest("BillBoard", []() { return new BillBoardTests(); }); addTest("Camera3D", []() { return new Camera3DTests(); }); addTest("Clipping", []() { return new ClippingNodeTests(); }); +#if AX_ENABLE_EXT_IMGUI addTest("DrawNode", []() { return new DrawNodeTests(); }); +#endif addTest("Label", []() { return new NewLabelTests(); }); addTest("Layer", []() { return new LayerTests(); }); addTest("Light", []() { return new LightTests(); }); diff --git a/tests/cpp-tests/Source/tests.h b/tests/cpp-tests/Source/tests.h index d2ec5bf891eb..70aaba73ca87 100644 --- a/tests/cpp-tests/Source/tests.h +++ b/tests/cpp-tests/Source/tests.h @@ -71,7 +71,9 @@ #include "CurrentLanguageTest/CurrentLanguageTest.h" #include "DataVisitorTest/DataVisitorTest.h" #include "NetworkTest/NetworkTest.h" -#include "DrawNodeTest/DrawNodeTest.h" +#if AX_ENABLE_EXT_IMGUI +# include "DrawNodeTest/DrawNodeTest.h" +#endif #include "EffectsAdvancedTest/EffectsAdvancedTest.h" #include "EffectsTest/EffectsTest.h" #include "ExtensionsTest/ExtensionsTest.h"