用任意 Shape 路径作为裁剪区域,支持添加多个裁剪形状及模式控制。
| 函数 | 说明 |
|---|---|
int xgeShapeExClipShapeAdd(xge_shape_ex pShape, xge_shape_ex pClipShape) | 添加形状裁剪 |
int xgeShapeExClipShapeAddEx(xge_shape_ex pShape, xge_shape_ex pClipShape, int iMode) | 添加形状裁剪(含模式) |
int xgeShapeExClipShapeGetCount(xge_shape_ex pShape, int* pCount) | 获取裁剪形状数量 |
int xgeShapeExClipShapeGetAt(xge_shape_ex pShape, int iIndex, xge_shape_ex* ppClipShape) | 获取指定索引裁剪形状 |
int xgeShapeExClipShapeClear(xge_shape_ex pShape) | 清除所有形状裁剪 |
gcc -O2 -I. -o ch59.exe ch59_main.c build\xge.lib -lm -lws2_32 -liphlpapi -lgdi32 -luser32 -lshell32 -lopengl32 -lole32 -lwinmm -lavrt
.\ch59.exe
// 裁剪形状:圆形
xge_shape_ex clipShape = NULL;
xgeShapeExCreate(&clipShape);
xgeShapeExAppendCircle(clipShape, 400, 300, 180, 180, 1);
// 内容:大矩形
xge_shape_ex content = NULL;
xgeShapeExCreate(&content);
xgeShapeExAppendRect(content, 0,0, 800,600, 0,0, 1);
xgeShapeExFillColor(content, 0x4FD8C2FF);
// 应用圆形裁剪
xgeShapeExClipShapeAdd(content, clipShape);
xgeShapeExDraw(content, 0.25f); // 只显示圆形区域将以下代码保存为 ch59_main.c,编译后运行即可看到形状裁剪效果:
#include "xge.h"
static int onFrame(void* pUser) {
(void)pUser;
xgeClear(0x081114FF);
// 裁剪形状:圆形
xge_shape_ex clipShape = NULL;
xgeShapeExCreate(&clipShape);
xgeShapeExAppendCircle(clipShape, 400, 300, 180, 180, 1);
// 内容:彩色渐变矩形
xge_shape_ex content = NULL;
xgeShapeExCreate(&content);
xgeShapeExAppendRect(content, 0,0, 800,600, 0,0, 1);
xge_shape_ex_color_stop_t stops[] = {
{ 0.0f, 0x4FD8C2FF },
{ 1.0f, 0xFFB454FF },
};
xgeShapeExFillLinearGradient(content, 0,0, 800,600,
XGE_SHAPE_EX_GRADIENT_USER_SPACE, stops, 2);
// 应用圆形裁剪
xgeShapeExClipShapeAdd(content, clipShape);
xgeShapeExDraw(content, 0.25f);
xgeShapeExDestroy(content);
xgeShapeExDestroy(clipShape);
return XGE_OK;
}
int main(void) {
xge_desc_t d = {0};
d.iWidth = 800;
d.iHeight = 600;
d.sTitle = "ch59 - Shape Clip";
d.iFlags = XGE_INIT_VSYNC;
xgeInit(&d);
xgeRun(onFrame, NULL);
xgeUnit();
return 0;
}