← 都来码 / Dolaima← 例程索引ada/bgi/demo_bgi.adb 原文

ada/bgi/demo_bgi.adb · 1836 字节 · 下载原文

-- demo_bgi.adb —— 第 3 层:传统图形接口(BGI / `initgraph` 那一套)
-- demo_bgi.adb -- Layer 3: the classic graphics interface (BGI)
--
-- 固定 640×480 画布 + 16 色索引色:`initgraph` 开窗,`SetColor(4)` 是"4 号色"而不是 RGB。
-- Fixed 640x480 canvas + 16 indexed colours: `initgraph` opens the window and
-- `SetColor(4)` means "palette index 4", not RGB.
--
-- 跑法 / How to run:
--   手机  vml run examples/ada/bgi/demo_bgi.adb
--   桌面  vmlcli Examples/ada/bgi/demo_bgi.adb --frames /tmp/bgi
--
-- ⚠ `InitGraph(gd, gm, path)` 的前两个实参是 C 的 `int*`。Ada 没有取地址符,
--    这里用 `vml_alloc` 拿一块地址(`vmlsys.adb` 的声明),两个 int 槽分别放在 +0/+4。
-- ⚠ The first two arguments of `InitGraph(gd, gm, path)` are C `int*`. Ada has no
--    address-of operator, so `vml_alloc` supplies the block (declared in `vmlsys.adb`);
--    the two int slots live at +0 and +4. `path` is ignored here, so 0 is fine.
--
-- 声明来自 `Lib/ada/bgi.adb` 与 `Lib/ada/vmlsys.adb`(都是 GenLib 生成的)。
-- Declarations come from `Lib/ada/bgi.adb` and `Lib/ada/vmlsys.adb` (GenLib output).

with VML_UI;
with bgi;
with vmlsys;

procedure Demo_Bgi is
   Gd : Integer := 0;
   Gm : Integer := 0;
   K : Integer := 0;
begin
   Gd := vml_alloc(16);
   Gm := Gd + 4;
   K := InitGraph(Gd, Gm, 0);

   K := SetBkColor(0);
   K := ClearDevice();

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

   K := ui_2d_present();
   K := CloseGraph();
end Demo_Bgi;