Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 修复 drawpoly(), ege_drawpoly() 在绘制形成多边形的闭合折线时首尾连接处无拐角的情况 #172

Merged
merged 3 commits into from
May 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions src/egegapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,16 @@ void drawpoly(int numpoints, const int* polypoints, PIMAGE pimg)
{
PIMAGE img = CONVERT_IMAGE(pimg);
if (img) {
Polyline(img->m_hDC, (POINT*)polypoints, numpoints);
const POINT* points = (const POINT*)polypoints;
/* 闭合曲线, 转为绘制带边框无填充多边形 */
if ((numpoints > 3) && (points[0].x == points[numpoints-1].x)
&& (points[0].y == points[numpoints-1].y)) {
HBRUSH oldBrush = (HBRUSH)SelectObject(img->m_hDC, GetStockObject(NULL_BRUSH));
Polygon(img->m_hDC, points, numpoints - 1);
SelectObject(img->m_hDC, oldBrush);
} else {
Polyline(img->m_hDC, (POINT*)polypoints, numpoints);
}
}
CONVERT_IMAGE_END;
}
Expand Down Expand Up @@ -1286,7 +1295,14 @@ void ege_drawpoly(int numpoints, ege_point* polypoints, PIMAGE pimg)
}
Gdiplus::Graphics* graphics = img->getGraphics();
Gdiplus::Pen* pen = img->getPen();
graphics->DrawLines(pen, (Gdiplus::PointF*)polypoints, numpoints);

/* 当首尾顶点为同一坐标时转成多边形,否则绘制折线 */
if (numpoints > 3 && polypoints[0].x == polypoints[numpoints-1].x
&& polypoints[0].y == polypoints[numpoints-1].y) {
graphics->DrawPolygon(pen, (Gdiplus::PointF*)polypoints, numpoints - 1);
} else {
graphics->DrawLines(pen, (Gdiplus::PointF*)polypoints, numpoints);
}
}
CONVERT_IMAGE_END;
}
Expand Down
Loading