c/old/old_gfx_shapes.c · 3863 字节 · 下载原文
/* old_gfx_shapes.c —— 圆/椭圆/多边形(图形界面)
* old_gfx_shapes.c -- circles / ellipses / polygons (graphical window)
*
* 类别:graphic
* Category: graphic
* 兼容面:`ui_2d_circle`(填充与描边)/ `ui_2d_ellipse` / `ui_2d_polygon` / `ui_2d_polyline`
* Compatibility: `ui_2d_circle` (fill and stroke) / `ui_2d_ellipse` / `ui_2d_polygon` / `ui_2d_polyline`
* —— 对应 BGI 的 `circle`/`ellipse`/`fillpoly`/`drawpoly`
* -- the counterpart of BGI's `circle` / `ellipse` / `fillpoly` / `drawpoly`
* 出处:自写。
* Origin: self-written.
*
* ⚠ **顶点数组必须写成具名局部数组,不能用复合字面量** ——
* ⚠ **The vertex array must be written as a named local array; a compound literal will not do** --
* `ui_2d_polygon((int[]){…}, …)` 本前端**仍不支持**(~~而且不报错~~ —— **2026-10-04 复验:已改成硬失败**):
* `ui_2d_polygon((int[]){...}, ...)` is **still unsupported by this front end** (~~and it reported no error~~ -- **re-checked 2026-10-04: now a hard failure**):
* ~~算不出字面量的地址,会把上一个寄存器的值当成指针传下去 ⇒ 宿主越界读、多边形静默不画。~~
* ~~the address of the literal could not be computed, so the previous register value was passed down as a pointer => the host read out of bounds and the polygon was silently not drawn.~~
* 现在直接报语法错误并告诉你改法,编不出"静默不画"的程序了;**顶点仍必须写成具名数组**。
* It now reports a syntax error and the fix; the "silently draws nothing" program can no longer be built. **The vertex must still be a named array.**
* (见 `Examples/c/draw_prims.c` 的说明与 CHANGELOG v0.96.182。)
* (See the notes in `Examples/c/draw_prims.c` and CHANGELOG v0.96.182.)
*/
#include <vml_ui.h>
#define W 320
#define H 240
int main(void)
{
/* 具名数组 —— 见文件头的 ⚠ */
/* Named arrays -- see the warning at the top of the file */
int tri[6] = { 160, 20, 60, 140, 260, 140 };
int zig[14] = { 20, 200, 60, 170, 100, 200, 140, 170,
180, 200, 220, 170, 260, 200 };
int quad[8] = { 230, 40, 300, 60, 280, 120, 220, 100 };
int msg;
int lang; /* 界面语言:开局查一次 */
/* UI language: queried once at start */
lang = ui_scr_get_language();
ui_win_open(lang == 0 ? "老式绘图:圆/多边形" : "Old-style gfx: circles / polygons", W, H);
ui_2d_clear(0x101820);
/* 圆:空心 / 实心 / 粗描边 */
/* Circles: hollow / filled / thick stroke */
ui_2d_circle(60, 60, 40, 0xE06C75, 0, 2);
ui_2d_circle(160, 60, 40, 0x98C379, 1, 1);
ui_2d_circle(260, 60, 40, 0x61AFEF, 0, 6);
/* 椭圆(不是正圆 —— 长短轴不同) */
/* Ellipses (not perfect circles -- the two axes differ) */
ui_2d_ellipse(80, 130, 60, 30, 0xE5C07B, 0, 2);
ui_2d_ellipse(240, 130, 50, 25, 0xC678DD, 1, 1);
/* 多边形:填充三角 + 描边四边形 */
/* Polygons: a filled triangle + a stroked quadrilateral */
ui_2d_polygon(tri, 3, 0x56B6C2, 0xFFFFFF, 2, 0);
ui_2d_polygon(quad, 4, 0x000000, 0xD19A66, 3, 0);
/* 折线:**必须开口**,不能连回起点 */
/* Polyline: it **must stay open** -- it must not connect back to the start point */
ui_2d_polyline(zig, 7, 0xABB2BF, 2, 0);
ui_2d_present();
/* 画完等关窗(同 old_gfx_lines:立刻关会让快照随窗口一起没掉)*/
/* Wait for the window to close after drawing (same as old_gfx_lines: closing right away loses the snapshot with the window) */
while (!ui_win_is_closed())
ui_msg_wait(&msg, 0);
ui_win_close();
return 0;
}