47
47
NS_AX_EXT_BEGIN
48
48
49
49
50
-
51
50
/* * Is a polygon convex?
52
51
* @param verts A pointer to point coordinates.
53
52
* @param count The number of verts measured in points.
@@ -149,13 +148,13 @@ DrawNodeEx::~DrawNodeEx()
149
148
{
150
149
AX_SAFE_FREE (_bufferTriangle);
151
150
152
- #if defined(DRAWNODE_DRAW_LINE_POINT )
151
+ #if defined(AX_ENABLE_DRAWNODE_DRAW_LINE_POINT )
153
152
AX_SAFE_FREE (_bufferPoint);
154
153
AX_SAFE_FREE (_bufferLine);
155
154
#endif
156
155
157
156
freeShaderInternal (_customCommandTriangle);
158
- #if defined(DRAWNODE_DRAW_LINE_POINT )
157
+ #if defined(AX_ENABLE_DRAWNODE_DRAW_LINE_POINT )
159
158
freeShaderInternal (_customCommandPoint);
160
159
freeShaderInternal (_customCommandLine);
161
160
#endif
@@ -191,7 +190,7 @@ void DrawNodeEx::ensureCapacityTriangle(int count)
191
190
}
192
191
}
193
192
194
- #if defined(DRAWNODE_DRAW_LINE_POINT )
193
+ #if defined(AX_ENABLE_DRAWNODE_DRAW_LINE_POINT )
195
194
void DrawNodeEx::ensureCapacityPoint (int count)
196
195
{
197
196
AXASSERT (count >= 0 , " capacity must be >= 0" );
@@ -230,7 +229,7 @@ bool DrawNodeEx::init()
230
229
ensureCapacityTriangle (512 );
231
230
_dirtyTriangle = true ;
232
231
233
- #if defined(DRAWNODE_DRAW_LINE_POINT )
232
+ #if defined(AX_ENABLE_DRAWNODE_DRAW_LINE_POINT )
234
233
ensureCapacityPoint (64 );
235
234
ensureCapacityLine (256 );
236
235
_dirtyLine = true ;
@@ -244,7 +243,7 @@ void DrawNodeEx::updateShader()
244
243
{
245
244
updateShaderInternal (_customCommandTriangle, backend::ProgramType::POSITION_COLOR_LENGTH_TEXTURE,
246
245
CustomCommand::DrawType::ARRAY, CustomCommand::PrimitiveType::TRIANGLE);
247
- #if defined(DRAWNODE_DRAW_LINE_POINT )
246
+ #if defined(AX_ENABLE_DRAWNODE_DRAW_LINE_POINT )
248
247
updateShaderInternal (_customCommandPoint, backend::ProgramType::POSITION_COLOR_TEXTURE_AS_POINTSIZE,
249
248
CustomCommand::DrawType::ARRAY, CustomCommand::PrimitiveType::POINT);
250
249
@@ -324,7 +323,7 @@ void DrawNodeEx::draw(Renderer* renderer, const Mat4& transform, uint32_t flags)
324
323
_customCommandTriangle.init (_globalZOrder);
325
324
renderer->addCommand (&_customCommandTriangle);
326
325
}
327
- #if defined(DRAWNODE_DRAW_LINE_POINT )
326
+ #if defined(AX_ENABLE_DRAWNODE_DRAW_LINE_POINT )
328
327
if (_bufferCountPoint)
329
328
{
330
329
updateBlendState (_customCommandPoint);
@@ -345,16 +344,16 @@ void DrawNodeEx::draw(Renderer* renderer, const Mat4& transform, uint32_t flags)
345
344
346
345
void DrawNodeEx::drawPoint (const Vec2& position, const float pointSize, const Color4B& color)
347
346
{
348
- #if defined(DRAWNODE_DRAW_LINE_POINT )
347
+ #if defined(AX_ENABLE_DRAWNODE_DRAW_LINE_POINT )
349
348
if (_drawOrder == true )
350
349
{
351
350
#endif
352
351
drawSolidCircle (position, pointSize, 0 .f , 12 , 1 .f , 1 .f , color, 0 .f , color);
353
- #if defined(DRAWNODE_DRAW_LINE_POINT )
352
+ #if defined(AX_ENABLE_DRAWNODE_DRAW_LINE_POINT )
354
353
return ;
355
354
}
356
355
#endif
357
- #if defined(DRAWNODE_DRAW_LINE_POINT )
356
+ #if defined(AX_ENABLE_DRAWNODE_DRAW_LINE_POINT )
358
357
ensureCapacityPoint (1 );
359
358
360
359
V2F_C4B_T2F* point = _bufferPoint + _bufferCountPoint;
@@ -377,19 +376,19 @@ void DrawNodeEx::drawPoints(const Vec2* position,
377
376
const float pointSize,
378
377
const Color4B& color)
379
378
{
380
- #if defined(DRAWNODE_DRAW_LINE_POINT )
379
+ #if defined(AX_ENABLE_DRAWNODE_DRAW_LINE_POINT )
381
380
if (_drawOrder == true )
382
381
{
383
382
#endif
384
383
for (unsigned int i = 0 ; i < numberOfPoints; i++)
385
384
{
386
385
drawSolidCircle (position[i], pointSize, 0 .f , 12 , 1 .f , 1 .f , color, 0 .f , color);
387
386
}
388
- #if defined(DRAWNODE_DRAW_LINE_POINT )
387
+ #if defined(AX_ENABLE_DRAWNODE_DRAW_LINE_POINT )
389
388
return ;
390
389
}
391
390
#endif
392
- #if defined(DRAWNODE_DRAW_LINE_POINT )
391
+ #if defined(AX_ENABLE_DRAWNODE_DRAW_LINE_POINT )
393
392
ensureCapacityPoint (numberOfPoints);
394
393
395
394
V2F_C4B_T2F* point = _bufferPoint + _bufferCountPoint;
@@ -415,16 +414,16 @@ void DrawNodeEx::drawLine(const Vec2& origin, const Vec2& destination, const Col
415
414
}
416
415
else
417
416
{
418
- #if defined(DRAWNODE_DRAW_LINE_POINT )
417
+ #if defined(AX_ENABLE_DRAWNODE_DRAW_LINE_POINT )
419
418
if (_drawOrder == true )
420
419
{
421
420
#endif
422
421
drawSegment (origin, destination, thickness / 3 , color);
423
- #if defined(DRAWNODE_DRAW_LINE_POINT )
422
+ #if defined(AX_ENABLE_DRAWNODE_DRAW_LINE_POINT )
424
423
return ;
425
424
}
426
425
#endif
427
- #if defined(DRAWNODE_DRAW_LINE_POINT )
426
+ #if defined(AX_ENABLE_DRAWNODE_DRAW_LINE_POINT )
428
427
Vec2 line[2 ] = { origin, destination };
429
428
Vec2* _vertices = transform (line, 2 );
430
429
@@ -476,16 +475,16 @@ void DrawNodeEx::drawPoly(const Vec2* poli,
476
475
}
477
476
else
478
477
{
479
- #if defined(DRAWNODE_DRAW_LINE_POINT )
478
+ #if defined(AX_ENABLE_DRAWNODE_DRAW_LINE_POINT )
480
479
if (_drawOrder == true )
481
480
{
482
481
#endif
483
482
_drawPolygon (poli, numberOfPoints, Color4B::TRANSPARENT, thickness / 3 , color, closePolygon);
484
- #if defined(DRAWNODE_DRAW_LINE_POINT )
483
+ #if defined(AX_ENABLE_DRAWNODE_DRAW_LINE_POINT )
485
484
return ;
486
485
}
487
486
#endif
488
- #if defined(DRAWNODE_DRAW_LINE_POINT )
487
+ #if defined(AX_ENABLE_DRAWNODE_DRAW_LINE_POINT )
489
488
Vec2* _vertices = transform (poli, numberOfPoints);
490
489
491
490
unsigned int vertex_count;
@@ -762,7 +761,7 @@ void DrawNodeEx::drawRect(const Vec2& p1,
762
761
}
763
762
}
764
763
765
- void DrawNodeEx::drawSegment (const Vec2& from, const Vec2& to, float radius, const Color4B& color, DrawNodeEx::EndType endType )
764
+ void DrawNodeEx::drawSegment (const Vec2& from, const Vec2& to, float radius, const Color4B& color, DrawNodeEx::EndType etStart, DrawNodeEx::EndType etEnd )
766
765
{
767
766
Vec2 line[2 ] = { from, to };
768
767
Vec2* _vertices = transform (line, 2 );
@@ -790,9 +789,9 @@ void DrawNodeEx::drawSegment(const Vec2& from, const Vec2& to, float radius, con
790
789
791
790
//
792
791
Color4B col = color;
793
- switch (endType)
792
+ // End
793
+ switch (etEnd)
794
794
{
795
-
796
795
case DrawNodeEx::EndType::Butt:
797
796
break ;
798
797
@@ -841,8 +840,8 @@ void DrawNodeEx::drawSegment(const Vec2& from, const Vec2& to, float radius, con
841
840
{v5, col, Tex2F (n)},
842
841
};
843
842
844
- // End
845
- switch (endType )
843
+ // Start
844
+ switch (etStart )
846
845
{
847
846
case DrawNodeEx::EndType::Butt:
848
847
break ;
@@ -938,11 +937,18 @@ void DrawNodeEx::drawPie(const Vec2& center,
938
937
DrawMode drawMode,
939
938
float thickness)
940
939
{
941
- // not a real line!
940
+ #define DEGREES 360
941
+ bool _circle = false ;
942
+
943
+ // Not a real line!
942
944
if (startAngle == endAngle)
943
945
return ;
944
946
945
- #define DEGREES 360
947
+ // Its a circle?
948
+ if (MAX ((startAngle - endAngle), (endAngle-startAngle)) == DEGREES)
949
+ {
950
+ _circle = true ;
951
+ }
946
952
947
953
const float coef = 2 .0f * (float )M_PI / DEGREES;
948
954
Vec2* vertices = _abuf.get <Vec2>(DEGREES + 2 );
@@ -953,9 +959,7 @@ void DrawNodeEx::drawPie(const Vec2& center,
953
959
954
960
if (startAngle > endAngle)
955
961
{
956
- int tmp = endAngle;
957
- endAngle = startAngle;
958
- startAngle = tmp;
962
+ std::swap (endAngle, startAngle);
959
963
}
960
964
961
965
for (int i = 0 ; i <= DEGREES; i++)
@@ -976,17 +980,28 @@ void DrawNodeEx::drawPie(const Vec2& center,
976
980
{
977
981
case DrawMode::Fill:
978
982
vertices[n++] = center;
983
+ if (_circle)
984
+ {
985
+ this ->drawSolidCircle (center, radius, 0 , 36 , scaleX, scaleY, fillColor, thickness, borderColor);
986
+ break ;
987
+ }
979
988
_drawPolygon (vertices, n, fillColor, thickness, borderColor, true );
980
989
break ;
981
990
case DrawMode::Outline:
982
991
vertices[n++] = center;
992
+ if (_circle)
993
+ {
994
+ this ->drawCircle (center, radius, 0 , 36 , false , scaleX, scaleY, borderColor, thickness);
995
+ break ;
996
+ }
983
997
_drawPolygon (vertices, n, Color4B::TRANSPARENT, thickness, borderColor, true );
984
998
break ;
985
999
case DrawMode::Line:
1000
+ vertices[n++] = center;
986
1001
_drawPolygon (vertices, n, Color4B::TRANSPARENT, thickness, borderColor, false );
987
1002
break ;
988
1003
case DrawMode::Semi:
989
- _drawPolygon (vertices, n, fillColor, thickness, borderColor, true );
1004
+ _drawPolygon (vertices, n- 1 , fillColor, thickness, borderColor, true );
990
1005
break ;
991
1006
992
1007
default :
@@ -1091,7 +1106,7 @@ void DrawNodeEx::clear()
1091
1106
{
1092
1107
_bufferCountTriangle = 0 ;
1093
1108
_dirtyTriangle = true ;
1094
- #if defined(DRAWNODE_DRAW_LINE_POINT )
1109
+ #if defined(AX_ENABLE_DRAWNODE_DRAW_LINE_POINT )
1095
1110
_bufferCountLine = 0 ;
1096
1111
_dirtyLine = true ;
1097
1112
_bufferCountPoint = 0 ;
@@ -1137,16 +1152,13 @@ void DrawNodeEx::_drawPolygon(const Vec2* verts,
1137
1152
unsigned int count,
1138
1153
const Color4B& fillColor,
1139
1154
float borderWidth,
1140
- const Color4B& borderColo ,
1155
+ const Color4B& borderColor ,
1141
1156
bool closedPolygon)
1142
1157
{
1143
1158
AXASSERT (count >= 0 , " invalid count value" );
1144
1159
1145
1160
Vec2* _vertices = transform (verts, count);
1146
-
1147
- bool outline = (borderColo.a > 0 .0f && borderWidth > 0 .0f );
1148
-
1149
- Color4B borderColor = borderColo;
1161
+ bool outline = (borderColor.a > 0 .0f && borderWidth > 0 .0f );
1150
1162
1151
1163
auto triangle_count = outline ? (3 * count - 2 ) : (count - 2 );
1152
1164
auto vertex_count = 3 * triangle_count;
@@ -1225,39 +1237,7 @@ void DrawNodeEx::_drawPolygon(const Vec2* verts,
1225
1237
extrude[i] = { offset, n2 };
1226
1238
}
1227
1239
1228
- int i = 0 ;
1229
- int j = (i + 1 ) % count;
1230
- Vec2 v0 = _vertices[i];
1231
- Vec2 v1 = _vertices[j];
1232
-
1233
- Vec2 n0 = extrude[i].n ;
1234
-
1235
- Vec2 offset0 = extrude[i].offset ;
1236
- Vec2 offset1 = extrude[j].offset ;
1237
-
1238
- Vec2 inner0 = v0 - offset0 * borderWidth;
1239
- Vec2 inner1 = v1 - offset1 * borderWidth;
1240
- Vec2 outer0 = v0 + offset0 * borderWidth;
1241
- Vec2 outer1 = v1 + offset1 * borderWidth;
1242
- borderColor = borderColo;
1243
- // if (i >= (count - 1) && !closedPolygon) // /-2 ??
1244
- // {
1245
- // borderColor = Color4B::TRANSPARENT;
1246
- // }
1247
-
1248
- V2F_C4B_T2F_Triangle tmp1 = { {inner0, borderColor, Tex2F (-n0)},
1249
- {inner1, borderColor, Tex2F (-n0)},
1250
- {outer1, borderColor, Tex2F (n0)} };
1251
- *cursor++ = tmp1;
1252
-
1253
- V2F_C4B_T2F_Triangle tmp2 = { {inner0, borderColor, Tex2F (-n0)},
1254
- {outer0, borderColor, Tex2F (n0)},
1255
- {outer1, borderColor, Tex2F (n0)} };
1256
- *cursor++ = tmp2;
1257
-
1258
-
1259
-
1260
- for (unsigned int i = 1 ; i < (count - 1 ); i++)
1240
+ for (unsigned int i = 0 ; i < (count - 2 ); i++)
1261
1241
{
1262
1242
int j = (i + 1 ) % count;
1263
1243
Vec2 v0 = _vertices[i];
@@ -1272,11 +1252,6 @@ void DrawNodeEx::_drawPolygon(const Vec2* verts,
1272
1252
Vec2 inner1 = v1 - offset1 * borderWidth;
1273
1253
Vec2 outer0 = v0 + offset0 * borderWidth;
1274
1254
Vec2 outer1 = v1 + offset1 * borderWidth;
1275
- borderColor = borderColo;
1276
- // if (i >= (count - 1) && !closedPolygon) // /-2 ??
1277
- // {
1278
- // borderColor = Color4B::TRANSPARENT;
1279
- // }
1280
1255
1281
1256
V2F_C4B_T2F_Triangle tmp1 = { {inner0, borderColor, Tex2F (-n0)},
1282
1257
{inner1, borderColor, Tex2F (-n0)},
@@ -1289,35 +1264,35 @@ void DrawNodeEx::_drawPolygon(const Vec2* verts,
1289
1264
*cursor++ = tmp2;
1290
1265
}
1291
1266
1292
- i = count - 1 ;
1293
- j = (i + 1 ) % count;
1294
- v0 = _vertices[i];
1295
- v1 = _vertices[j];
1267
+ // drawPie stuff
1268
+ for (unsigned int i = count - 2 ; i <= (count - 1 ); i++)
1269
+ {
1270
+ int j = (i + 1 ) % count;
1271
+ Vec2 v0 = _vertices[i];
1272
+ Vec2 v1 = _vertices[j];
1273
+
1274
+ Vec2 n0 = extrude[i].n ;
1296
1275
1297
- n0 = extrude[i].n ;
1276
+ Vec2 offset0 = extrude[i].offset ;
1277
+ Vec2 offset1 = extrude[j].offset ;
1298
1278
1299
- offset0 = extrude[i].offset ;
1300
- offset1 = extrude[j].offset ;
1279
+ Vec2 inner0 = v0 - offset0 * borderWidth;
1280
+ Vec2 inner1 = v1 - offset1 * borderWidth;
1281
+ Vec2 outer0 = v0 + offset0 * borderWidth;
1282
+ Vec2 outer1 = v1 + offset1 * borderWidth;
1301
1283
1302
- inner0 = v0 - offset0 * borderWidth;
1303
- inner1 = v1 - offset1 * borderWidth;
1304
- outer0 = v0 + offset0 * borderWidth;
1305
- outer1 = v1 + offset1 * borderWidth;
1306
- borderColor = borderColo;
1307
- // if (i >= (count - 1) && !closedPolygon) // /-2 ??
1308
- // {
1309
- // borderColor = Color4B::TRANSPARENT;
1310
- // }
1284
+ Color4B borderColorTemp = (!closedPolygon) ? Color4B::TRANSPARENT : borderColor;
1311
1285
1312
- tmp1 = { {inner0, borderColor , Tex2F (-n0)},
1313
- {inner1, borderColor , Tex2F (-n0)},
1314
- {outer1, borderColor , Tex2F (n0)} };
1315
- *cursor++ = tmp1;
1286
+ V2F_C4B_T2F_Triangle tmp1 = { {inner0, borderColorTemp , Tex2F (-n0)},
1287
+ {inner1, borderColorTemp , Tex2F (-n0)},
1288
+ {outer1, borderColorTemp , Tex2F (n0)} };
1289
+ *cursor++ = tmp1;
1316
1290
1317
- tmp2 = { {inner0, borderColor, Tex2F (-n0)},
1318
- {outer0, borderColor, Tex2F (n0)},
1319
- {outer1, borderColor, Tex2F (n0)} };
1320
- *cursor++ = tmp2;
1291
+ V2F_C4B_T2F_Triangle tmp2 = { {inner0, borderColorTemp, Tex2F (-n0)},
1292
+ {outer0, borderColorTemp, Tex2F (n0)},
1293
+ {outer1, borderColorTemp, Tex2F (n0)} };
1294
+ *cursor++ = tmp2;
1295
+ }
1321
1296
1322
1297
free (extrude);
1323
1298
}
@@ -1351,16 +1326,16 @@ void DrawNodeEx::_drawPoly(const Vec2* poli,
1351
1326
}
1352
1327
else
1353
1328
{
1354
- #if defined(DRAWNODE_DRAW_LINE_POINT )
1329
+ #if defined(AX_ENABLE_DRAWNODE_DRAW_LINE_POINT )
1355
1330
if (_drawOrder == true )
1356
1331
{
1357
1332
#endif
1358
1333
_drawPolygon (poli, numberOfPoints, Color4B::TRANSPARENT, thickness / 3 , color, false );
1359
- #if defined(DRAWNODE_DRAW_LINE_POINT )
1334
+ #if defined(AX_ENABLE_DRAWNODE_DRAW_LINE_POINT )
1360
1335
return ;
1361
1336
}
1362
1337
#endif
1363
- #if defined(DRAWNODE_DRAW_LINE_POINT )
1338
+ #if defined(AX_ENABLE_DRAWNODE_DRAW_LINE_POINT )
1364
1339
Vec2* _vertices = transform (poli, numberOfPoints);
1365
1340
1366
1341
unsigned int vertex_count;
0 commit comments