diff --git a/src/egegapi.cpp b/src/egegapi.cpp index a2a9aab..7e1527d 100644 --- a/src/egegapi.cpp +++ b/src/egegapi.cpp @@ -1070,31 +1070,38 @@ void solidrect(int left, int top, int right, int bottom, PIMAGE pimg) CONVERT_IMAGE_END } -void bar3d(int x1, int y1, int x2, int y2, int depth, int topFlag, PIMAGE pimg) -{ - --x2; - --y2; - { - int pt[20] = { - x2, y2, - x2, y1, - x1, y1, - x1, y2, - x2, y2, - x2 + depth, y2 - depth, - x2 + depth, y1 - depth, - x1 + depth, y1 - depth, - x1, y1, +void bar3d(int left, int top, int right, int bottom, int depth, int topFlag, PIMAGE pimg) +{ + /* 6个外边界顶点(从左上角开始逆时针数) */ + POINT boundVertexes[6] = { + {left, top}, + {left, bottom}, + {right, bottom}, + {right + depth, bottom - depth}, + {right + depth, top - depth}, + {left + depth, top - depth}, }; - bar(x1, y1, x2, y2, pimg); - if (topFlag) { - drawpoly(9, pt, pimg); - line(x2, y1, x2 + depth, y1 - depth, pimg); - } else { - drawpoly(7, pt, pimg); - } + + bar(left, top, right, bottom, pimg); + + line_cap_type startCap, endCap; + getlinecap(&startCap, &endCap, pimg); + setlinecap(LINECAP_FLAT, pimg); + + if (topFlag) { + /* 正面右上边界的3个顶点 */ + POINT sideVertexes[3] = {{left, top}, {right, top}, {right, bottom}}; + polygon(6, (const int*)boundVertexes, pimg); + polyline(3, (const int*)&sideVertexes, pimg); + line(right, top, right + depth, top - depth, pimg); + } else { + /* 只绘制与底部相连的 5 条边 */ + polyline(5, (const int*)boundVertexes, pimg); + line(right, top, right, bottom, pimg); } + + setlinecap(startCap, endCap, pimg); } void drawpoly(int numOfPoints, const int* points, PIMAGE pimg)