Skip to content

Commit 66a053c

Browse files
committed
ImDrawList: DIrect implementation of AddRect() (WIP) (fixup)
1 parent e8faa14 commit 66a053c

File tree

1 file changed

+66
-66
lines changed

1 file changed

+66
-66
lines changed

imgui_draw.cpp

Lines changed: 66 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,7 @@ void ImDrawList::PrimQuadUV(const ImVec2& a, const ImVec2& b, const ImVec2& c, c
742742

743743
#define IM_POLYLINE_PRIM_MAKE_LOCAL() ImDrawVert* IM_POLYLINE_PRIM_VTX_WRITE = this->_VtxWritePtr; ImDrawIdx* IM_POLYLINE_PRIM_IDX_WRITE = this->_IdxWritePtr; unsigned int IM_POLYLINE_PRIM_IDX_BASE = this->_VtxCurrentIdx
744744
#define IM_POLYLINE_PRIM_LOAD_LOCAL() IM_POLYLINE_PRIM_VTX_WRITE = this->_VtxWritePtr; IM_POLYLINE_PRIM_IDX_WRITE = this->_IdxWritePtr; IM_POLYLINE_PRIM_IDX_BASE = this->_VtxCurrentIdx
745-
#define IM_POLYLINE_PRIM_SAVE_LOCAL() this->_VtxWritePtr = IM_POLYLINE_PRIM_VTX_WRITE; this->_IdxWritePtr = IM_POLYLINE_PRIM_IDX_WRITE; this->_VtxCurrentIdx = IM_POLYLINE_PRIM_IDX_BASE
745+
#define IM_POLYLINE_PRIM_SAVE_LOCAL() this->_VtxWritePtr = IM_POLYLINE_PRIM_VTX_WRITE; this->_IdxWritePtr = IM_POLYLINE_PRIM_IDX_WRITE; this->_VtxCurrentIdx = IM_POLYLINE_PRIM_IDX_BASE
746746
#else
747747
#define IM_POLYLINE_PRIM_VTX_WRITE this->_VtxWritePtr
748748
#define IM_POLYLINE_PRIM_IDX_WRITE this->_IdxWritePtr
@@ -1275,79 +1275,79 @@ void ImDrawList::_PolylineThinAntiAliased(const ImDrawListPolyline& polyline)
12751275
if (preferred_join == Miter) IM_LIKELY
12761276
{
12771277
if (cos_theta > IM_POLYLINE_MITER_ANGLE_LIMIT) IM_LIKELY
1278-
{
1279-
// Fill gap between segments with Miter join
1280-
//
1281-
// Left Miter join: Right Miter join:
1282-
//
1283-
// , | ,
1284-
// 6 .' ~ | ~ '. 8
1285-
// 5' .+. | .+. '5
1286-
// +:. '. .' | '. .' .:+
1287-
// | ''..:. .' | '. .:..'' |
1288-
// +--------+-- ~ | ~ --+--------+
1289-
// 3| 7| | |7 |4
1290-
//
1291-
1292-
if (sin_theta < 0.0f)
12931278
{
1294-
IM_POLYLINE_VERTEX(5, p1.x - miter_offset_x, p1.y - miter_offset_y, uv, polyline.fringe_color);
1279+
// Fill gap between segments with Miter join
1280+
//
1281+
// Left Miter join: Right Miter join:
1282+
//
1283+
// , | ,
1284+
// 6 .' ~ | ~ '. 8
1285+
// 5' .+. | .+. '5
1286+
// +:. '. .' | '. .' .:+
1287+
// | ''..:. .' | '. .:..'' |
1288+
// +--------+-- ~ | ~ --+--------+
1289+
// 3| 7| | |7 |4
1290+
//
12951291

1296-
IM_POLYLINE_TRIANGLE_BEGIN(6);
1297-
IM_POLYLINE_TRIANGLE(0, 3, 7, 5);
1298-
IM_POLYLINE_TRIANGLE(1, 5, 7, 6);
1299-
IM_POLYLINE_TRIANGLE_END(6);
1300-
}
1301-
else
1302-
{
1303-
IM_POLYLINE_VERTEX(5, p1.x + miter_offset_x, p1.y + miter_offset_y, uv, polyline.fringe_color);
1292+
if (sin_theta < 0.0f)
1293+
{
1294+
IM_POLYLINE_VERTEX(5, p1.x - miter_offset_x, p1.y - miter_offset_y, uv, polyline.fringe_color);
13041295

1305-
IM_POLYLINE_TRIANGLE_BEGIN(6);
1306-
IM_POLYLINE_TRIANGLE(0, 4, 5, 7);
1307-
IM_POLYLINE_TRIANGLE(1, 5, 8, 7);
1308-
IM_POLYLINE_TRIANGLE_END(6);
1296+
IM_POLYLINE_TRIANGLE_BEGIN(6);
1297+
IM_POLYLINE_TRIANGLE(0, 3, 7, 5);
1298+
IM_POLYLINE_TRIANGLE(1, 5, 7, 6);
1299+
IM_POLYLINE_TRIANGLE_END(6);
1300+
}
1301+
else
1302+
{
1303+
IM_POLYLINE_VERTEX(5, p1.x + miter_offset_x, p1.y + miter_offset_y, uv, polyline.fringe_color);
1304+
1305+
IM_POLYLINE_TRIANGLE_BEGIN(6);
1306+
IM_POLYLINE_TRIANGLE(0, 4, 5, 7);
1307+
IM_POLYLINE_TRIANGLE(1, 5, 8, 7);
1308+
IM_POLYLINE_TRIANGLE_END(6);
13091309
}
13101310
}
13111311
}
13121312
else if (preferred_join == Bevel) IM_UNLIKELY
13131313
{
13141314
if (cos_theta > IM_POLYLINE_MITER_ANGLE_LIMIT) IM_LIKELY
1315-
{
1316-
// Fill gap between segments with Bevel join
1317-
//
1318-
// Left Bevel join: Right Bevel join:
1319-
//
1320-
// , | ,
1321-
// 6 .' ~ | ~ '. 8
1322-
// +. | .+
1323-
// ' '. .' | '. .' '
1324-
// ' '. .' | '. .' '
1325-
// +--------+-- ~ | ~ --+--------+
1326-
// 3| 7| | |7 |4
1327-
//
1315+
{
1316+
// Fill gap between segments with Bevel join
1317+
//
1318+
// Left Bevel join: Right Bevel join:
1319+
//
1320+
// , | ,
1321+
// 6 .' ~ | ~ '. 8
1322+
// +. | .+
1323+
// ' '. .' | '. .' '
1324+
// ' '. .' | '. .' '
1325+
// +--------+-- ~ | ~ --+--------+
1326+
// 3| 7| | |7 |4
1327+
//
13281328

1329-
float bevel_normal_x, bevel_normal_y;
1330-
IM_POLYLINE_BEVEL_NORMAL(bevel_normal_x, bevel_normal_y);
1329+
float bevel_normal_x, bevel_normal_y;
1330+
IM_POLYLINE_BEVEL_NORMAL(bevel_normal_x, bevel_normal_y);
13311331

1332-
float dir_0_x, dir_0_y, dir_1_x, dir_1_y;
1333-
IM_POLYLINE_BEVEL_VECTORS(bevel_normal_x, bevel_normal_y, dir_0_x, dir_0_y, dir_1_x, dir_1_y, half_thickness);
1332+
float dir_0_x, dir_0_y, dir_1_x, dir_1_y;
1333+
IM_POLYLINE_BEVEL_VECTORS(bevel_normal_x, bevel_normal_y, dir_0_x, dir_0_y, dir_1_x, dir_1_y, half_thickness);
13341334

1335-
if (sin_theta < 0.0f)
1336-
{
1337-
IM_POLYLINE_VERTEX(3, p1.x - dir_0_x, p1.y - dir_0_y, uv, polyline.fringe_color);
1338-
IM_POLYLINE_VERTEX(6, p1.x - dir_1_x, p1.y - dir_1_y, uv, polyline.fringe_color);
1335+
if (sin_theta < 0.0f)
1336+
{
1337+
IM_POLYLINE_VERTEX(3, p1.x - dir_0_x, p1.y - dir_0_y, uv, polyline.fringe_color);
1338+
IM_POLYLINE_VERTEX(6, p1.x - dir_1_x, p1.y - dir_1_y, uv, polyline.fringe_color);
13391339

1340-
IM_POLYLINE_TRIANGLE_BEGIN(3);
1341-
IM_POLYLINE_TRIANGLE(0, 3, 7, 6);
1342-
IM_POLYLINE_TRIANGLE_END(3);
1343-
}
1344-
else
1345-
{
1346-
IM_POLYLINE_VERTEX(4, p1.x + dir_0_x, p1.y + dir_0_y, uv, polyline.fringe_color);
1347-
IM_POLYLINE_VERTEX(8, p1.x + dir_1_x, p1.y + dir_1_y, uv, polyline.fringe_color);
1340+
IM_POLYLINE_TRIANGLE_BEGIN(3);
1341+
IM_POLYLINE_TRIANGLE(0, 3, 7, 6);
1342+
IM_POLYLINE_TRIANGLE_END(3);
1343+
}
1344+
else
1345+
{
1346+
IM_POLYLINE_VERTEX(4, p1.x + dir_0_x, p1.y + dir_0_y, uv, polyline.fringe_color);
1347+
IM_POLYLINE_VERTEX(8, p1.x + dir_1_x, p1.y + dir_1_y, uv, polyline.fringe_color);
13481348

1349-
IM_POLYLINE_TRIANGLE_BEGIN(3);
1350-
IM_POLYLINE_TRIANGLE(1, 7, 4, 8);
1349+
IM_POLYLINE_TRIANGLE_BEGIN(3);
1350+
IM_POLYLINE_TRIANGLE(1, 7, 4, 8);
13511351
IM_POLYLINE_TRIANGLE_END(3);
13521352
}
13531353
}
@@ -2719,7 +2719,7 @@ void ImDrawList::AddPolyline(const ImVec2* points, const int points_count, ImU32
27192719
polyline.fringe_thickness = polyline.thickness + fringe_width * 2.0f;
27202720
}
27212721

2722-
if (polyline.thickness <= 0.0f) IM_LIKELY
2722+
if (polyline.thickness <= 0.0f) IM_LIKELY
27232723
this->_PolylineThinAntiAliased(polyline);
27242724
else
27252725
this->_PolylineThickAntiAliased(polyline);
@@ -3426,7 +3426,7 @@ void ImDrawList::AddLine(const ImVec2& p1, const ImVec2& p2, ImU32 col, float th
34263426
// Note we don't render 1 pixels sized rectangles properly.
34273427
void ImDrawList::AddRect(const ImVec2& p_min, const ImVec2& p_max, ImU32 col, float rounding, ImDrawFlags flags, float thickness)
34283428
{
3429-
if ((col & IM_COL32_A_MASK) == 0)
3429+
if ((col & IM_COL32_A_MASK) == 0 || thickness <= 0.0f) IM_UNLIKELY
34303430
return;
34313431

34323432
if (GImGui->IO.KeyCtrl || (flags & 0x80000000u))
@@ -3472,8 +3472,8 @@ if (GImGui->IO.KeyCtrl || (flags & 0x80000000u))
34723472
if (rounding >= 0.5f)
34733473
{
34743474
flags = FixRectCornerFlags(flags);
3475-
rounding = ImMin(rounding, ImFabs(b.x - a.x - half_outer_thickness) * (((flags & ImDrawFlags_RoundCornersTop) == ImDrawFlags_RoundCornersTop) || ((flags & ImDrawFlags_RoundCornersBottom) == ImDrawFlags_RoundCornersBottom) ? 0.5f : 1.0f) - 1.0f);
3476-
rounding = ImMin(rounding, ImFabs(b.y - a.y - half_outer_thickness) * (((flags & ImDrawFlags_RoundCornersLeft) == ImDrawFlags_RoundCornersLeft) || ((flags & ImDrawFlags_RoundCornersRight) == ImDrawFlags_RoundCornersRight) ? 0.5f : 1.0f) - 1.0f);
3475+
rounding = ImMin(rounding, ImFabs(b.x - a.x) * (((flags & ImDrawFlags_RoundCornersTop) == ImDrawFlags_RoundCornersTop) || ((flags & ImDrawFlags_RoundCornersBottom) == ImDrawFlags_RoundCornersBottom) ? 0.5f : 1.0f) - 1.0f);
3476+
rounding = ImMin(rounding, ImFabs(b.y - a.y) * (((flags & ImDrawFlags_RoundCornersLeft) == ImDrawFlags_RoundCornersLeft) || ((flags & ImDrawFlags_RoundCornersRight) == ImDrawFlags_RoundCornersRight) ? 0.5f : 1.0f) - 1.0f);
34773477
}
34783478
if (rounding < 0.5f || (flags & ImDrawFlags_RoundCornersMask_) == ImDrawFlags_RoundCornersNone)
34793479
{
@@ -3494,8 +3494,8 @@ if (GImGui->IO.KeyCtrl || (flags & 0x80000000u))
34943494
}
34953495
else
34963496
{
3497-
const int arc_step = ImMax(1, IM_DRAWLIST_ARCFAST_SAMPLE_MAX / _CalcCircleAutoSegmentCount(rounding));
3498-
const float arc_offset_correction = 0.207107f * _FringeScale; // sqrt(2)/4
3497+
const int arc_step = ImMax(1, IM_DRAWLIST_ARCFAST_SAMPLE_MAX / _CalcCircleAutoSegmentCount(rounding + half_outer_thickness));
3498+
const float arc_offset_correction = 0.207107f * _FringeScale; // sqrt(2)/2
34993499

35003500
#define IM_ADDRECT_EMIT_ARC(P, R, A_MIN, A_MAX) _PathArcToFastEx(P, R, (A_MIN) * IM_DRAWLIST_ARCFAST_SAMPLE_MAX / 12, (A_MAX) * IM_DRAWLIST_ARCFAST_SAMPLE_MAX / 12, arc_step)
35013501
#define IM_ADDRECT_EMIT_ROUNDED_PATH(AX, AY, BX, BY, ROUNDING) \

0 commit comments

Comments
 (0)