端帽(Cap)决定开放路径端点的形状,连接(Join)决定路径拐角处的过渡方式。
| 常量 / 函数 | 说明 |
|---|---|
#define XGE_SHAPE_EX_CAP_BUTT 0 | 平切端帽 |
#define XGE_SHAPE_EX_CAP_ROUND 1 | 圆形端帽 |
#define XGE_SHAPE_EX_CAP_SQUARE 2 | 方形端帽 |
#define XGE_SHAPE_EX_JOIN_MITER 0 | 尖角连接 |
#define XGE_SHAPE_EX_JOIN_ROUND 1 | 圆角连接 |
#define XGE_SHAPE_EX_JOIN_BEVEL 2 | 斜切连接 |
int xgeShapeExStrokeCap(xge_shape_ex pShape, int iCap) | 设置端帽样式 |
int xgeShapeExStrokeCapGet(xge_shape_ex pShape, int* pCap) | 获取端帽样式 |
int xgeShapeExStrokeJoin(xge_shape_ex pShape, int iJoin) | 设置连接样式 |
int xgeShapeExStrokeJoinGet(xge_shape_ex pShape, int* pJoin) | 获取连接样式 |
gcc -O2 -I. -o ch47.exe ch47_main.c build\xge.lib -lm -lws2_32 -liphlpapi -lgdi32 -luser32 -lshell32 -lopengl32 -lole32 -lwinmm -lavrt
.\ch47.exe
int caps[] = { XGE_SHAPE_EX_CAP_BUTT, XGE_SHAPE_EX_CAP_ROUND, XGE_SHAPE_EX_CAP_SQUARE };
int joins[] = { XGE_SHAPE_EX_JOIN_MITER, XGE_SHAPE_EX_JOIN_ROUND, XGE_SHAPE_EX_JOIN_BEVEL };
for (int i = 0; i < 3; i++) {
xge_shape_ex s = NULL;
xgeShapeExCreate(&s);
// 开放折线路径
xgeShapeExMoveTo(s, 100, 100+i*150);
xgeShapeExLineTo(s, 350, 50+i*150);
xgeShapeExLineTo(s, 600, 100+i*150);
xgeShapeExStrokeColor(s, 0x4FD8C2FF);
xgeShapeExStrokeWidth(s, 12.0f);
xgeShapeExStrokeCap(s, caps[i]);
xgeShapeExStrokeJoin(s, joins[i]);
xgeShapeExDraw(s, 0.25f);
xgeShapeExDestroy(s);
}将以下代码保存为 ch47_main.c,编译后运行即可看到端帽与连接样式对比:
#include "xge.h"
static int onFrame(void* pUser) {
(void)pUser;
xgeClear(0x081114FF);
int caps[] = { XGE_SHAPE_EX_CAP_BUTT, XGE_SHAPE_EX_CAP_ROUND, XGE_SHAPE_EX_CAP_SQUARE };
int joins[] = { XGE_SHAPE_EX_JOIN_MITER, XGE_SHAPE_EX_JOIN_ROUND, XGE_SHAPE_EX_JOIN_BEVEL };
for (int i = 0; i < 3; i++) {
xge_shape_ex s = NULL;
xgeShapeExCreate(&s);
// 开放折线路径
xgeShapeExMoveTo(s, 100, 100+i*160);
xgeShapeExLineTo(s, 350, 50+i*160);
xgeShapeExLineTo(s, 600, 100+i*160);
xgeShapeExStrokeColor(s, 0x4FD8C2FF);
xgeShapeExStrokeWidth(s, 14.0f);
xgeShapeExStrokeCap(s, caps[i]);
xgeShapeExStrokeJoin(s, joins[i]);
xgeShapeExDraw(s, 0.25f);
xgeShapeExDestroy(s);
}
return XGE_OK;
}
int main(void) {
xge_desc_t d = {0};
d.iWidth = 800;
d.iHeight = 600;
d.sTitle = "ch47 - Cap & Join";
d.iFlags = XGE_INIT_VSYNC;
xgeInit(&d);
xgeRun(onFrame, NULL);
xgeUnit();
return 0;
}