<?php
// demo_bgi.php —— 第 3 层：传统图形接口（BGI / `initgraph` 那一套）
// demo_bgi.php -- Layer 3: the classic graphics interface (BGI)
//
// 固定 640×480 画布 + 16 色索引色：`SetColor(4)` 是"4 号色"而不是 RGB。
// Fixed 640x480 canvas + 16 indexed colours: `SetColor(4)` is palette index 4, not RGB.
//
// 跑法 / How to run:
//   手机  vml run examples/php/bgi/demo_bgi.php
//   桌面  vmlcli Examples/php/bgi/demo_bgi.php --frames /tmp/bgi
//
// ⚠ `InitGraph($gd, $gm, $path)` 的前两个实参是 C 的 `int*`。本前端没有取地址符，
//    用 `vml_alloc`（`vmlsys.php` 的声明）拿一块地址，两个 int 槽放在 +0 / +4。
// ⚠ The first two arguments of InitGraph are C `int*`; `vml_alloc` (declared in
//    vmlsys.php) supplies the block with the two int slots at +0 and +4.
//    声明文件：`Lib/php/bgi.php` / `Lib/php/vmlsys.php`（GenLib 生成）。
//    Declarations: Lib/php/bgi.php and Lib/php/vmlsys.php (GenLib output).

require 'vml_ui.php';
require 'bgi.php';
require 'vmlsys.php';

$gd = vml_alloc(16);
$gm = $gd + 4;
InitGraph($gd, $gm, "");

SetBkColor(0);
ClearDevice();

SetColor(4);                       // 4 = 红 / red
Line(20, 20, 300, 200);
SetColor(14);                      // 14 = 黄 / yellow
Circle(320, 240, 60);
SetColor(10);                      // 10 = 亮绿 / light green
Rectangle(40, 40, 220, 160);
OutTextXY(30, 30, "demo_bgi.php");

ui_2d_present();
CloseGraph();
