扇形(Pie)是圆心到弧的封闭区域;弓形(Chord)是弧与弦的封闭区域。用于饼图、技能冷却等。
| 函数 | 说明 |
|---|---|
void xgeShapePieFill(float fX, float fY, float fRadiusX, float fRadiusY, float fStartRadians, float fEndRadians, uint32_t iColor) | 填充扇形 |
void xgeShapePieFillPx(...) | 填充扇形(像素坐标) |
void xgeShapeChordFill(float fX, float fY, float fRadiusX, float fRadiusY, float fStartRadians, float fEndRadians, uint32_t iColor) | 填充弓形 |
void xgeShapeChordFillPx(...) | 填充弓形(像素坐标) |
gcc -O2 -I. -o ch27.exe ch27_main.c build\xge.lib -lm -lws2_32 -liphlpapi -lgdi32 -luser32 -lshell32 -lopengl32 -lole32 -lwinmm -lavrt
.\ch27.exe
float data[] = { 0.35f, 0.25f, 0.20f, 0.20f };
uint32_t colors[] = { 0x4FD8C2FF, 0xFFB454FF, 0xFF6B5EFF, 0x6DB3F2FF };
float start = -3.14159265f / 2.0f; // 从顶部开始
for (int i = 0; i < 4; i++) {
float end = start + data[i] * 2.0f * 3.14159265f;
xgeShapePieFill(400, 300, 150, 150, start, end, colors[i]);
start = end;
}float fCooldown = 0.7f; // 70% 冷却中
float fAngle = fCooldown * 2.0f * 3.14159265f;
// 技能图标底色
xgeShapeCircleFill(100, 500, 30, 0x4FD8C2FF);
// 冷却遮罩(半透明黑扇形)
xgeShapePieFill(100, 500, 30, 30,
-3.14159265f/2, -3.14159265f/2 + fAngle, 0x000000A0);// 弓形(不含圆心的弧段区域)
xgeShapeChordFill(400, 300, 120, 120,
0, 3.14159265f, // 下半圆弓形
0xFFB45480);将以下代码保存为 ch27_main.c,编译后运行即可看到扇形与弓形绘制效果:
#include "xge.h"
static int onFrame(void* pUser) {
(void)pUser;
xgeClear(0x081114FF);
// 扇形(饼图切片)
xgeShapePieFill(250, 250, 120, 0.0f, 120.0f, 0x4FD8C2FF);
xgeShapePieFill(250, 250, 120, 120.0f, 120.0f, 0xFFB454FF);
xgeShapePieFill(250, 250, 120, 240.0f, 120.0f, 0xFF6B5EFF);
// 弓形(圆弧 + 弦围成的区域)
xgeShapeChordFill(550, 350, 100, 30.0f, 150.0f, 0x6DB3F2FF);
return XGE_OK;
}
int main(void) {
xge_desc_t d = {0};
d.iWidth = 800;
d.iHeight = 600;
d.sTitle = "ch27 - Sector & Chord";
d.iFlags = XGE_INIT_VSYNC;
xgeInit(&d);
xgeRun(onFrame, NULL);
xgeUnit();
return 0;
}xgeShapePieFill(cx, cy, r, startAngle, sweepAngle, color) 绘制扇形(饼图切片)。xgeShapeChordFill(cx, cy, r, startAngle, sweepAngle, color) 绘制弓形(圆弧+弦围成)。