cobol/ui/demo_ui.cob · 3932 字节 · 下载原文
*> demo_ui.cob —— COBOL 第四层:**最新 UI 接口**(宿主 `ui_*` 图元 + 绘图窗口)
*> demo_ui.cob -- COBOL 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/cobol/ui/demo_ui.cob \
*> --screen 480x640 --frames /tmp/cobol_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:
*> ① 库函数用 `CALL "名字" USING …`(实参按值、逆序压栈,前端已处理)。
*> ① call library functions with CALL "name" USING ... (by value, pushed in reverse; the frontend handles it).
*> ② **负数字面量不能直接写在 CALL 的实参位置**(解析器会把它当新语句)⇒ 颜色先放进
*> ② **a negative literal cannot be written directly as a CALL argument** (the parser reads it as a new statement) =>
*> PIC S9(9) 数据项,再按名字传。
*> put colours in PIC S9(9) items first and pass them by name.
*> ③ 颜色是 0xAARRGGBB 作为 32 位有符号整数的十进制值(下面每项后面标了十六进制)。
*> ③ colours are 0xAARRGGBB as signed-32-bit decimals (each item carries its hex value).
IDENTIFICATION DIVISION.
PROGRAM-ID. DEMO-UI.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-W PIC S9(9) VALUE 0.
01 WS-H PIC S9(9) VALUE 0.
01 WS-PW PIC S9(9) VALUE 0.
01 WS-EX PIC S9(9) VALUE 0.
01 WS-CX PIC S9(9) VALUE 0.
01 WS-CY PIC S9(9) VALUE 0.
01 WS-LY PIC S9(9) VALUE 0.
01 WS-FRAME PIC S9(9) VALUE 0.
01 WS-K PIC S9(9) VALUE 0.
01 WS-MSG PIC S9(9) VALUE 0.
01 WS-CLOSE PIC S9(9) VALUE 0.
01 WS-BG PIC S9(9) VALUE -15722464.
01 WS-PANEL PIC S9(9) VALUE -11890471.
01 WS-RED PIC S9(9) VALUE -1618884.
01 WS-LINE PIC S9(9) VALUE -12961206.
01 WS-TEXT PIC S9(9) VALUE -1513232.
01 WS-SUB PIC S9(9) VALUE -6643536.
PROCEDURE DIVISION.
MAIN-PARA.
CALL "ui_win_open_ex" USING "COBOL UI demo" 0 0 0 0
- GIVING WS-K.
CALL "ui_scr_get_w" GIVING WS-W.
CALL "ui_scr_get_h" GIVING WS-H.
IF WS-W <= 0
MOVE 360 TO WS-W
END-IF.
IF WS-H <= 0
MOVE 620 TO WS-H
END-IF.
SUBTRACT 32 FROM WS-W GIVING WS-PW.
SUBTRACT 16 FROM WS-W GIVING WS-EX.
SUBTRACT 80 FROM WS-H GIVING WS-LY.
DIVIDE 2 INTO WS-W GIVING WS-CX.
DIVIDE 2 INTO WS-H GIVING WS-CY.
MOVE 0 TO WS-FRAME.
PERFORM UNTIL WS-FRAME >= 20
CALL "ui_2d_clear" USING WS-BG
CALL "ui_2d_rect" USING 16 16 WS-PW 96 WS-PANEL 1 0 10
CALL "ui_2d_circle" USING WS-CX WS-CY 48 WS-RED 1 0
CALL "ui_2d_line" USING 16 WS-LY WS-EX WS-LY WS-LINE 2
CALL "ui_2d_text" USING 24 30 "COBOL UI demo"
- WS-TEXT 18 0
CALL "ui_2d_text" USING 24 62
- "rect / circle / line / text" WS-SUB 12 0
CALL "ui_2d_present"
ADD 1 TO WS-FRAME
CALL "ui_msg_fetch_wait" USING 40 GIVING WS-MSG
CALL "ui_win_is_closed" GIVING WS-CLOSE
IF WS-CLOSE NOT = 0
MOVE 20 TO WS-FRAME
END-IF
END-PERFORM.
CALL "ui_win_close" GIVING WS-K.
STOP RUN.