@@ -909,18 +909,17 @@ void DrawNode::_drawPolygon(const Vec2* verts,
909
909
}
910
910
if (outline )
911
911
{
912
+ float width = thickness / properties.factor ;
912
913
if (thickness != 1 .0f || properties.drawOrder )
913
914
{
914
- thickness *= properties.factor ;
915
-
916
915
for (unsigned int i = 1 ; i < (count); i++)
917
916
{
918
917
Vec2 a = _vertices[i - 1 ];
919
918
Vec2 b = _vertices[i];
920
919
Vec2 n = ((b - a).getPerp ()).getNormalized ();
921
920
Vec2 t = n.getPerp ();
922
- Vec2 nw = n * thickness ;
923
- Vec2 tw = t * thickness ;
921
+ Vec2 nw = n * width ;
922
+ Vec2 tw = t * width ;
924
923
Vec2 v0 = b - (nw + tw);
925
924
Vec2 v1 = b + (nw - tw);
926
925
Vec2 v2 = b - nw;
@@ -1001,10 +1000,10 @@ void DrawNode::_drawPolygon(const Vec2* verts,
1001
1000
Vec2 offset0 = extrude[i].offset ;
1002
1001
Vec2 offset1 = extrude[j].offset ;
1003
1002
1004
- Vec2 inner0 = v0 - offset0 * thickness ;
1005
- Vec2 inner1 = v1 - offset1 * thickness ;
1006
- Vec2 outer0 = v0 + offset0 * thickness ;
1007
- Vec2 outer1 = v1 + offset1 * thickness ;
1003
+ Vec2 inner0 = v0 - offset0 * width ;
1004
+ Vec2 inner1 = v1 - offset1 * width ;
1005
+ Vec2 outer0 = v0 + offset0 * width ;
1006
+ Vec2 outer1 = v1 + offset1 * width ;
1008
1007
1009
1008
triangles[ii++] = {{inner0, borderColor, -n0}, {inner1, borderColor, -n0}, {outer1, borderColor, n0}};
1010
1009
@@ -1055,25 +1054,26 @@ void DrawNode::_drawSegment(const Vec2& from,
1055
1054
DrawNode::EndType etStart,
1056
1055
DrawNode::EndType etEnd)
1057
1056
{
1058
- Vec2 vertices[ 2 ] = {from, to};
1059
- applyTransform (vertices, vertices, 2 ) ;
1057
+ if (thickness < 1 . 0f )
1058
+ thickness = 1 . 0f ;
1060
1059
1061
1060
if (thickness == 1 .0f && !properties.drawOrder )
1062
1061
{
1063
- auto line = expandBufferAndGetPointer (_lines, 2 );
1064
- _linesDirty = true ;
1065
-
1066
- line[0 ] = {vertices[0 ], color, Vec2::ZERO};
1067
- line[1 ] = {vertices[1 ], color, Vec2::ZERO};
1062
+ _drawLine (from, to, color); // fastest way to draw a line
1068
1063
}
1069
1064
else
1070
1065
{
1066
+ Vec2 vertices[2 ] = {from, to};
1067
+ applyTransform (vertices, vertices, 2 );
1068
+
1069
+ float width = thickness / (2 * properties.factor );
1070
+
1071
1071
Vec2 a = vertices[0 ];
1072
1072
Vec2 b = vertices[1 ];
1073
1073
Vec2 n = ((b - a).getPerp ()).getNormalized ();
1074
1074
Vec2 t = n.getPerp ();
1075
- Vec2 nw = n * thickness ;
1076
- Vec2 tw = t * thickness ;
1075
+ Vec2 nw = n * width ;
1076
+ Vec2 tw = t * width ;
1077
1077
Vec2 v0 = b - (nw + tw);
1078
1078
Vec2 v1 = b + (nw - tw);
1079
1079
Vec2 v2 = b - nw;
@@ -1177,6 +1177,19 @@ void DrawNode::_drawSegment(const Vec2& from,
1177
1177
}
1178
1178
}
1179
1179
}
1180
+ // Internal function _drawLine => thickness is always 1 (fastes way to draw a line)
1181
+ void DrawNode::_drawLine (const Vec2& from, const Vec2& to, const Color4B& color)
1182
+ {
1183
+ Vec2 vertices[2 ] = {from, to};
1184
+ applyTransform (vertices, vertices, 2 );
1185
+
1186
+
1187
+ auto line = expandBufferAndGetPointer (_lines, 2 );
1188
+ _linesDirty = true ;
1189
+
1190
+ line[0 ] = {vertices[0 ], color, Vec2::ZERO};
1191
+ line[1 ] = {vertices[1 ], color, Vec2::ZERO};
1192
+ }
1180
1193
1181
1194
void DrawNode::_drawDot (const Vec2& pos, float radius, const Color4B& color)
1182
1195
{
@@ -1572,6 +1585,18 @@ void DrawNode::applyTransform(const Vec2* from, Vec2* to, unsigned int count)
1572
1585
}
1573
1586
}
1574
1587
1588
+ void DrawNode::Properties::setDefaultValues ()
1589
+ {
1590
+ auto fac = Director::getInstance ()->getContentScaleFactor ();
1591
+ factor = fac;
1592
+
1593
+ scale = Vec2 (1 .0f , 1 .0f );
1594
+ center = Vec2 (0 .0f , 0 .0f );
1595
+ rotation = 0 .0f ;
1596
+ position = Vec2 (0 .0f , 0 .0f );
1597
+ drawOrder = false ;
1598
+ };
1599
+
1575
1600
#if defined(_WIN32)
1576
1601
# pragma pop_macro("TRANSPARENT")
1577
1602
#endif
0 commit comments