php/ui/demo_ui.php · 2305 字节 · 下载原文
<?php
// demo_ui.php —— PHP 第四层:**最新 UI 接口**(宿主 ui_* 图元 + 绘图窗口)
// demo_ui.php -- PHP layer 4: **the newest UI interface** (host ui_* primitives + a drawing window)
//
// 跑法(桌面 vmlcli):
// How to run (desktop vmlcli):
// dotnet scripts/vmlcli/bin/Release/net10.0/vmlcli.dll Examples/php/ui/demo_ui.php \
// --screen 480x640 --frames /tmp/php_ui_frames/
//
// ⚠ 要看画面请用 `--frames 目录`:`ui_win_close()` 会把场景置空,`--frame` 事后取不到东西。
// ⚠ Use --frames DIR: ui_win_close() clears the scene, so --frame has nothing to take afterwards.
//
// 本前端的写法要求:
// Coding rules of this frontend:
// ① 库函数直接按名字写(ui_2d_rect(...)),前端发 CALL <原名> 交给链接器。
// ① write library functions by name (ui_2d_rect(...)); the frontend emits CALL <name> for the linker.
// ② `/` 是**浮点除法** ⇒ 圆心坐标要用 intdiv($w, 2)(整数库函数收浮点数会传错通道)。
// ② `/` is **floating division** => use intdiv($w, 2) for the circle centre (integer library calls get the wrong channel).
// ③ 颜色是 0xAARRGGBB 作为 32 位有符号整数的十进制值(每行后面标了十六进制)。
// ③ colours are 0xAARRGGBB as signed-32-bit decimals (each line carries its hex value).
$k = ui_win_open_ex("PHP UI demo", 0, 0, 0, 0);
$w = ui_scr_get_w();
$h = ui_scr_get_h();
if ($w <= 0) { $w = 360; }
if ($h <= 0) { $h = 620; }
$frame = 0;
while ($frame < 20) {
$k = ui_2d_clear(-15722464); // 0xFF101820 深底
$k = ui_2d_rect(16, 16, $w - 32, 96, -11890471, 1, 0, 10); // 0xFF4A90D9 面板
$k = ui_2d_circle(intdiv($w, 2), intdiv($h, 2), 48, -1618884, 1, 0); // 0xFFE74C3C 红圆
$k = ui_2d_line(16, $h - 80, $w - 16, $h - 80, -12961206, 2); // 0xFF3A3A4A 分隔线
$k = ui_2d_text(24, 30, "PHP UI demo", -1513232, 18, 0); // 0xFFE8E8F0 标题
$k = ui_2d_text(24, 62, "rect / circle / line / text", -6643536, 12, 0); // 0xFF9AA0B0
$k = ui_2d_present();
$frame = $frame + 1;
$k = ui_msg_fetch_wait(40);
if (ui_win_is_closed() != 0) {
$frame = 20;
}
}
$k = ui_win_close();
echo "PHP UI demo: done", chr(10);