Remove all DrawNode setLineWidth() stuff (#2172)

* remove all setLineWitdth stuff

* Update axlua_base_auto.cpp

* Update DrawNode.cpp
This commit is contained in:
aismann 2024-09-23 16:13:12 +02:00 committed by GitHub
parent cf34faa20c
commit f320ba1f66
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 27 additions and 201 deletions

View File

@ -79,7 +79,7 @@ static V2F_C4B_T2F* expandBufferAndGetPointer(axstd::pod_vector<V2F_C4B_T2F>& bu
return buffer.data() + oldSize;
}
DrawNode::DrawNode(float lineWidth) : _lineWidth(lineWidth), _defaultLineWidth(lineWidth)
DrawNode::DrawNode()
{
_blendFunc = BlendFunc::ALPHA_PREMULTIPLIED;
@ -105,9 +105,9 @@ DrawNode::~DrawNode()
freeShaderInternal(_customCommandLine);
}
DrawNode* DrawNode::create(float defaultLineWidth)
DrawNode* DrawNode::create()
{
DrawNode* ret = new DrawNode(defaultLineWidth);
DrawNode* ret = new DrawNode();
if (ret->init())
{
ret->autorelease();
@ -790,8 +790,6 @@ void DrawNode::clear()
_triangles.clear();
_points.clear();
_lines.clear();
_lineWidth = _defaultLineWidth;
}
const BlendFunc& DrawNode::getBlendFunc() const
@ -804,15 +802,7 @@ void DrawNode::setBlendFunc(const BlendFunc& blendFunc)
_blendFunc = blendFunc;
}
void DrawNode::setLineWidth(float lineWidth)
{
_defaultLineWidth = lineWidth;
}
float DrawNode::getLineWidth()
{
return _defaultLineWidth;
}
void DrawNode::visit(Renderer* renderer, const Mat4& parentTransform, uint32_t parentFlags)
{
@ -1035,7 +1025,7 @@ void DrawNode::_drawPoly(const Vec2* verts,
{
if (thickness == 1.0f && !properties.drawOrder)
{
auto _vertices = _transform(verts, count);
auto _vertices = _transform(verts, count, closedPolygon);
unsigned int vertex_count = (closedPolygon) ? 2 * count : 2 * (count - 1);

View File

@ -89,7 +89,7 @@ public:
*
* @return Return an autorelease object.
*/
static DrawNode* create(float defaultLineWidth = DEFAULT_LINE_WIDTH);
static DrawNode* create(void);
// DrawNode();
/** Draw a point.
@ -539,10 +539,6 @@ public:
virtual void visit(Renderer* renderer, const Mat4& parentTransform, uint32_t parentFlags) override;
void setLineWidth(float lineWidth);
// Get CocosStudio guide lines width.
float getLineWidth();
/**
* When isolated is set, the position of the node is no longer affected by parent nodes.
* Which means it will be drawn just like a root node.
@ -551,7 +547,7 @@ public:
bool isIsolated() const { return _isolated; }
DrawNode(float lineWidth = DEFAULT_LINE_WIDTH);
DrawNode();
virtual ~DrawNode();
virtual bool init() override;
@ -585,8 +581,6 @@ protected:
axstd::pod_vector<V2F_C4B_T2F> _points;
axstd::pod_vector<V2F_C4B_T2F> _lines;
float _lineWidth = 1.0f;
float _defaultLineWidth = 1.0f;
private:
// Internal function _drawPoint
@ -691,7 +685,7 @@ public:
class Properties
{
public:
float factor = 0.5f; /// set the lineWidth like Axmol 1.0
float factor = 0.5f; /// thickness factor
// transforming stuff
Vec2 scale;
@ -699,9 +693,6 @@ public:
float rotation;
Vec2 position;
// Thickness stuff
float lineWidth;
float defaultLineWidth = 1.0f;
// Drawing flags
bool transform = false;
@ -779,18 +770,6 @@ public:
*/
Vec2 getPosition() { return position; };
/** Set the DrawNode line width for each drawing primitive after this.
* @js NA
*/
void setLineWidth(float lw) { lineWidth = lw; };
/** Get the DrawNode line width for each drawing primitive after this.
* @js NA
*/
float getLineWidth() { return lineWidth; };
/** Set all default DrawNode properties.
* @js NA
@ -801,7 +780,6 @@ public:
center = Vec2(0.0f, 0.0f);
rotation = 0.0f;
position = Vec2(0.0f, 0.0f);
lineWidth = 1.0f;
drawOrder = false;
};
} properties;

View File

@ -1717,7 +1717,6 @@ void Label::updateContent()
{
// This is the logic for TTF fonts
const float charheight = (_textDesiredHeight / _numberOfLines);
_underlineNode->setLineWidth(charheight / 6);
// atlas font
for (int i = 0; i < _numberOfLines; ++i)
@ -1731,7 +1730,7 @@ void Label::updateContent()
// Github issue #15214. Uses _displayedColor instead of _textColor for the underline.
// This is to have the same behavior of SystemFonts.
_underlineNode->drawLine(Vec2(_linesOffsetX[i], y), Vec2(_linesWidth[i] + _linesOffsetX[i], y),
Color4F(_displayedColor));
Color4F(_displayedColor), charheight / 6);
}
}
else if (_textSprite)
@ -1739,7 +1738,6 @@ void Label::updateContent()
// ...and is the logic for System fonts
float y = 0;
const auto spriteSize = _textSprite->getContentSize();
_underlineNode->setLineWidth(spriteSize.height / 6);
if (_strikethroughEnabled)
// FIXME: system fonts don't report the height of the font correctly. only the size of the texture,
@ -1747,7 +1745,7 @@ void Label::updateContent()
y += spriteSize.height / 2;
// FIXME: Might not work with different vertical alignments
_underlineNode->drawLine(Vec2(0.0f, y), Vec2(spriteSize.width, y),
Color4F(_textSprite->getDisplayedColor()));
Color4F(_textSprite->getDisplayedColor()), spriteSize.height / 6);
}
}

View File

@ -137,8 +137,7 @@ void GGraph::updateShape()
{
if (_lineSize > 0)
{
_shape->setLineWidth(_lineSize);
_shape->drawCircle(Vec2(_size.width / 2, _size.height / 2), _size.width / 2, 0, 360, false, 1, _size.height / _size.width, _lineColor);
_shape->drawCircle(Vec2(_size.width / 2, _size.height / 2), _size.width / 2, 0, 360, false, 1, _size.height / _size.width, _lineColor, _lineSize);
}
_shape->drawSolidCircle(Vec2(_size.width / 2, _size.height / 2), _size.width / 2, 0, 360, 1, _size.height / _size.width, _fillColor);
break;

View File

@ -53486,103 +53486,6 @@ int lua_ax_base_DrawNode_setBlendFunc(lua_State* tolua_S)
return 0;
}
int lua_ax_base_DrawNode_setLineWidth(lua_State* tolua_S)
{
int argc = 0;
ax::DrawNode* cobj = nullptr;
bool ok = true;
#if _AX_DEBUG >= 1
tolua_Error tolua_err;
#endif
#if _AX_DEBUG >= 1
if (!tolua_isusertype(tolua_S,1,"ax.DrawNode",0,&tolua_err)) goto tolua_lerror;
#endif
cobj = (ax::DrawNode*)tolua_tousertype(tolua_S,1,0);
#if _AX_DEBUG >= 1
if (!cobj)
{
tolua_error(tolua_S,"invalid 'cobj' in function 'lua_ax_base_DrawNode_setLineWidth'", nullptr);
return 0;
}
#endif
argc = lua_gettop(tolua_S)-1;
if (argc == 1)
{
double arg0;
ok &= luaval_to_number(tolua_S, 2,&arg0, "ax.DrawNode:setLineWidth");
if(!ok)
{
tolua_error(tolua_S,"invalid arguments in function 'lua_ax_base_DrawNode_setLineWidth'", nullptr);
return 0;
}
cobj->setLineWidth(arg0);
lua_settop(tolua_S, 1);
return 1;
}
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "ax.DrawNode:setLineWidth",argc, 1);
return 0;
#if _AX_DEBUG >= 1
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'lua_ax_base_DrawNode_setLineWidth'.",&tolua_err);
#endif
return 0;
}
int lua_ax_base_DrawNode_getLineWidth(lua_State* tolua_S)
{
int argc = 0;
ax::DrawNode* cobj = nullptr;
bool ok = true;
#if _AX_DEBUG >= 1
tolua_Error tolua_err;
#endif
#if _AX_DEBUG >= 1
if (!tolua_isusertype(tolua_S,1,"ax.DrawNode",0,&tolua_err)) goto tolua_lerror;
#endif
cobj = (ax::DrawNode*)tolua_tousertype(tolua_S,1,0);
#if _AX_DEBUG >= 1
if (!cobj)
{
tolua_error(tolua_S,"invalid 'cobj' in function 'lua_ax_base_DrawNode_getLineWidth'", nullptr);
return 0;
}
#endif
argc = lua_gettop(tolua_S)-1;
if (argc == 0)
{
if(!ok)
{
tolua_error(tolua_S,"invalid arguments in function 'lua_ax_base_DrawNode_getLineWidth'", nullptr);
return 0;
}
auto&& ret = cobj->getLineWidth();
tolua_pushnumber(tolua_S,(lua_Number)ret);
return 1;
}
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "ax.DrawNode:getLineWidth",argc, 0);
return 0;
#if _AX_DEBUG >= 1
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'lua_ax_base_DrawNode_getLineWidth'.",&tolua_err);
#endif
return 0;
}
int lua_ax_base_DrawNode_setIsolated(lua_State* tolua_S)
{
int argc = 0;
@ -53706,19 +53609,6 @@ int lua_ax_base_DrawNode_create(lua_State* tolua_S)
object_to_luaval<ax::DrawNode>(tolua_S, "ax.DrawNode",(ax::DrawNode*)ret);
return 1;
}
if (argc == 1)
{
double arg0;
ok &= luaval_to_number(tolua_S, 2,&arg0, "ax.DrawNode:create");
if(!ok)
{
tolua_error(tolua_S,"invalid arguments in function 'lua_ax_base_DrawNode_create'", nullptr);
return 0;
}
auto&& ret = ax::DrawNode::create(arg0);
object_to_luaval<ax::DrawNode>(tolua_S, "ax.DrawNode",(ax::DrawNode*)ret);
return 1;
}
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d\n ", "ax.DrawNode:create",argc, 0);
return 0;
#if _AX_DEBUG >= 1
@ -53754,23 +53644,6 @@ int lua_ax_base_DrawNode_constructor(lua_State* tolua_S)
toluafix_pushusertype_object(tolua_S, ID, luaID, (void*)cobj,"ax.DrawNode");
return 1;
}
if (argc == 1)
{
double arg0;
ok &= luaval_to_number(tolua_S, 2,&arg0, "ax.DrawNode:DrawNode");
if(!ok)
{
tolua_error(tolua_S,"invalid arguments in function 'lua_ax_base_DrawNode_constructor'", nullptr);
return 0;
}
cobj = new ax::DrawNode(arg0);
cobj->autorelease();
int ID = (int)cobj->_ID ;
int* luaID = &cobj->_luaID ;
toluafix_pushusertype_object(tolua_S, ID, luaID, (void*)cobj,"ax.DrawNode");
return 1;
}
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "ax.DrawNode:DrawNode",argc, 0);
return 0;
@ -53813,8 +53686,6 @@ int lua_register_ax_base_DrawNode(lua_State* tolua_S)
tolua_function(tolua_S,"clear",lua_ax_base_DrawNode_clear);
tolua_function(tolua_S,"getBlendFunc",lua_ax_base_DrawNode_getBlendFunc);
tolua_function(tolua_S,"setBlendFunc",lua_ax_base_DrawNode_setBlendFunc);
tolua_function(tolua_S,"setLineWidth",lua_ax_base_DrawNode_setLineWidth);
tolua_function(tolua_S,"getLineWidth",lua_ax_base_DrawNode_getLineWidth);
tolua_function(tolua_S,"setIsolated",lua_ax_base_DrawNode_setIsolated);
tolua_function(tolua_S,"isIsolated",lua_ax_base_DrawNode_isIsolated);
tolua_function(tolua_S,"create", lua_ax_base_DrawNode_create);

View File

@ -532,7 +532,6 @@ namespace spine {
// Draw bounding rectangle
if (_debugBoundingRect) {
drawNode->setLineWidth(2.0f);
const axmol::Rect brect = getBoundingBox();
const Vec2 points[4] =
{
@ -540,13 +539,12 @@ namespace spine {
{brect.origin.x + brect.size.width, brect.origin.y},
{brect.origin.x + brect.size.width, brect.origin.y + brect.size.height},
{brect.origin.x, brect.origin.y + brect.size.height}};
drawNode->drawPoly(points, 4, true, Color4F::GREEN);
drawNode->drawPoly(points, 4, true, Color4F::GREEN, 2.0f);
}
if (_debugSlots) {
// Slots.
// DrawPrimitives::setDrawColor4B(0, 0, 255, 255);
drawNode->setLineWidth(2.0f);
V3F_C4B_T2F_Quad quad;
for (int i = 0, n = (int)_skeleton->getSlots().size(); i < n; i++) {
Slot *slot = _skeleton->getDrawOrder()[i];
@ -567,19 +565,18 @@ namespace spine {
{worldVertices[2], worldVertices[3]},
{worldVertices[4], worldVertices[5]},
{worldVertices[6], worldVertices[7]}};
drawNode->drawPoly(points, 4, true, Color4F::BLUE);
drawNode->drawPoly(points, 4, true, Color4F::BLUE, 2.0f);
}
}
if (_debugBones) {
// Bone lengths.
drawNode->setLineWidth(2.0f);
for (int i = 0, n = (int)_skeleton->getBones().size(); i < n; i++) {
Bone *bone = _skeleton->getBones()[i];
if (!bone->isActive()) continue;
float x = bone->getData().getLength() * bone->getA() + bone->getWorldX();
float y = bone->getData().getLength() * bone->getC() + bone->getWorldY();
drawNode->drawLine(Vec2(bone->getWorldX(), bone->getWorldY()), Vec2(x, y), Color4F::RED);
drawNode->drawLine(Vec2(bone->getWorldX(), bone->getWorldY()), Vec2(x, y), Color4F::RED, 2.0f);
}
// Bone origins.
auto color = Color4F::BLUE;// Root bone is blue.
@ -593,7 +590,6 @@ namespace spine {
if (_debugMeshes) {
// Meshes.
drawNode->setLineWidth(2.0f);
for (int i = 0, n = (int)_skeleton->getSlots().size(); i < n; ++i) {
Slot *slot = _skeleton->getDrawOrder()[i];
if (!slot->getBone().isActive()) continue;
@ -611,7 +607,7 @@ namespace spine {
worldCoord + (idx0 * 2),
worldCoord + (idx1 * 2),
worldCoord + (idx2 * 2)};
drawNode->drawPoly(v, 3, true, Color4F::YELLOW);
drawNode->drawPoly(v, 3, true, Color4F::YELLOW, 2.0f);
}
VLA_FREE(worldCoord);
}

View File

@ -1083,13 +1083,13 @@ void UniqueChildStencilTest::addChildStencils()
// Child stencil 1
constexpr auto radius = 30.f;
auto* drawNode = DrawNode::create(2);
auto* drawNode = DrawNode::create();
drawNode->drawSolidCircle(Vec2(50, 50), radius, 360, 180, 1, 1, Color4B::MAGENTA);
_parentStencil->addChild(drawNode);
// Child stencil 2
drawNode = DrawNode::create(2);
drawNode = DrawNode::create();
drawNode->drawSolidRect(Vec2(contentSize.width - 75, contentSize.height - 75),
Vec2(contentSize.width - 25, contentSize.height - 25), Color4B::MAGENTA);
_parentStencil->addChild(drawNode);

View File

@ -2150,7 +2150,7 @@ void DrawNodeThicknessTest::update(float dt)
Color4F(AXRANDOM_0_1(), AXRANDOM_0_1(), AXRANDOM_0_1(), 1.0f));
}
drawNode->setLineWidth(4);
drawNode->drawLine(Vec2(0.0f, s.height), Vec2(s.width, s.height - 20), Color4F::YELLOW);
drawNode->drawLine(Vec2(0.0f, 0.0f), Vec2(s.width, s.height - 20), Color4F::YELLOW);
@ -3321,7 +3321,7 @@ void DrawNodeAxmolTest2::drawAllv2(DrawNode* drawNode, bool drawOrder)
Color4F(AXRANDOM_0_1(), AXRANDOM_0_1(), AXRANDOM_0_1(), 1.0f));
}
drawNode->setLineWidth(4);
drawNode->drawLine(Vec2(0.0f, size.height), Vec2(size.width, size.height - 20), Color4F::YELLOW);
drawNode->drawLine(Vec2(0.0f, 0.0f), Vec2(size.width, size.height - 20), Color4F::YELLOW);
}

View File

@ -198,7 +198,6 @@ DrawNodeTest::DrawNodeTest()
auto draw1 = DrawNode::create();
this->addChild(draw1, 10);
draw1->setLineWidth(4);
draw1->drawLine(Vec2(0.0f, s.height), Vec2(s.width, s.height - 20), Color4F::YELLOW);
draw1->drawLine(Vec2(0.0f, 0.0f), Vec2(s.width, s.height - 20), Color4F::YELLOW);
@ -282,7 +281,7 @@ BetterCircleRendering::BetterCircleRendering()
// Add lines to see the correct "scale of the 'rings'" changing the window size
auto draw = DrawNode::create();
draw->setLineWidth(1);
addChild(draw, 10);
for (float y = 0; y < VisibleRect::top().y; y += 10)
@ -294,7 +293,7 @@ BetterCircleRendering::BetterCircleRendering()
drawNode = DrawNode::create();
addChild(drawNode, 10);
lineWidth = 0;
scheduleUpdate();
}
@ -357,7 +356,7 @@ void BetterCircleRendering::initSliders()
void BetterCircleRendering::update(float dt)
{
drawNode->clear();
drawNode->setLineWidth(lineWidth); // value from the slider
// Old behavior => faster but badly rendering if line width > 5 (= rings)
drawNode->drawCircle(VisibleRect::center() + Vec2(120.0f, 0.0f), 60, AX_DEGREES_TO_RADIANS(90), 36, false,

View File

@ -1300,7 +1300,6 @@ LabelTTFDistanceField::LabelTTFDistanceField()
auto borderDraw = DrawNode::create();
label1->addChild(borderDraw);
borderDraw->clear();
borderDraw->setLineWidth(1);
Vec2 vertices[4] = {Vec2::ZERO, Vec2(labelContentSize.width, 0.0f),
Vec2(labelContentSize.width, labelContentSize.height), Vec2(0.0f, labelContentSize.height)};
borderDraw->drawPoly(vertices, 4, true, Color4F::RED);
@ -1315,7 +1314,6 @@ LabelTTFDistanceField::LabelTTFDistanceField()
auto borderDraw2 = DrawNode::create();
label2->addChild(borderDraw2);
borderDraw2->clear();
borderDraw2->setLineWidth(1);
Vec2 vertices2[4] = {Vec2::ZERO, Vec2(labelContentSize2.width, 0.0f),
Vec2(labelContentSize2.width, labelContentSize2.height), Vec2(0.0f, labelContentSize2.height)};
borderDraw2->drawPoly(vertices2, 4, true, Color4F::GREEN);

View File

@ -680,14 +680,13 @@ bool UIListViewTest_ScrollToItem::init()
if (getListViewDirection() == ScrollView::Direction::HORIZONTAL)
{
float halfY = 110;
pNode->drawLine(Vec2(center.x, center.y - halfY), Vec2(center.x, center.y + halfY), Color4F(0, 0, 0, 1));
pNode->drawLine(Vec2(center.x, center.y - halfY), Vec2(center.x, center.y + halfY), Color4F(0, 0, 0, 1), 2.0f);
}
else
{
float halfX = 150;
pNode->drawLine(Vec2(center.x - halfX, center.y), Vec2(center.x + halfX, center.y), Color4F(0, 0, 0, 1));
pNode->drawLine(Vec2(center.x - halfX, center.y), Vec2(center.x + halfX, center.y), Color4F(0, 0, 0, 1), 2.0f);
}
pNode->setLineWidth(2);
_uiLayer->addChild(pNode);
}
@ -752,14 +751,13 @@ bool UIListViewTest_Magnetic::init()
if (getListViewDirection() == ScrollView::Direction::HORIZONTAL)
{
float halfY = 110;
pNode->drawLine(Vec2(center.x, center.y - halfY), Vec2(center.x, center.y + halfY), Color4F(0, 0, 0, 1));
pNode->drawLine(Vec2(center.x, center.y - halfY), Vec2(center.x, center.y + halfY), Color4F(0, 0, 0, 1), 2.0f);
}
else
{
float halfX = 150;
pNode->drawLine(Vec2(center.x - halfX, center.y), Vec2(center.x + halfX, center.y), Color4F(0, 0, 0, 1));
pNode->drawLine(Vec2(center.x - halfX, center.y), Vec2(center.x + halfX, center.y), Color4F(0, 0, 0, 1), 2.0f);
}
pNode->setLineWidth(2);
_uiLayer->addChild(pNode);
}
@ -910,14 +908,13 @@ bool UIListViewTest_Padding::init()
if (getListViewDirection() == ScrollView::Direction::HORIZONTAL)
{
float halfY = 110;
pNode->drawLine(Vec2(center.x, center.y - halfY), Vec2(center.x, center.y + halfY), Color4F(0, 0, 0, 1));
pNode->drawLine(Vec2(center.x, center.y - halfY), Vec2(center.x, center.y + halfY), Color4F(0, 0, 0, 1), 2.0f);
}
else
{
float halfX = 150;
pNode->drawLine(Vec2(center.x - halfX, center.y), Vec2(center.x + halfX, center.y), Color4F(0, 0, 0, 1));
pNode->drawLine(Vec2(center.x - halfX, center.y), Vec2(center.x + halfX, center.y), Color4F(0, 0, 0, 1), 2.0f);
}
pNode->setLineWidth(2);
_uiLayer->addChild(pNode);
}