sourceextensions/canvas/lib/Canvas.xtl
1⍝# Canvas.xtl -- the facade of the canvas extension: a native window
2⍝# showing X_eTaL arrays as pixels, with keys, clicks and frame ticks back.
3⍝# Import: "cv:" u_se< "Canvas"
4⍝# Run with xetal-x, which links canvas and serves its windows on the main
5⍝# thread (xetal-x --ext DIR puts this directory on XETAL_PATH).
6⍝# Each signature line is written out by the binding macro (lib/Ffi.xtlm).
7
8ᶠᶠⁱ⁼u̲se< "Ffi"
9
10⍝# title cv:o_pen! width height: a window that size (in points); its id.
11"o_pen! : text int -> int" ᶠᶠⁱb̲ind< "canvas/open"
12⍝# id cv:s_how! pixels: draw an n by m matrix (gray) or an n by m by 3
13⍝# array (red, green, blue), each from 0 (dark) to 1 (bright); a Bool
14⍝# matrix draws its 1s white. Scaled to the window; the id.
15"s_how! : int float -> int" ᶠᶠⁱb̲ind< "canvas/show"
16⍝# cv:n_ext! id: the next event, waiting at most a frame (1/60 s):
17⍝# "frame", "key Space", "key q", "key ArrowLeft", "click ROW COL"
18⍝# (where in the array shown, from 1), or "close".
19"n_ext! : int -> text" ᶠᶠⁱb̲ind< "canvas/next"
20⍝# cv:c_lose! id: close the window; 1.
21"c_lose! : int -> int" ᶠᶠⁱb̲ind< "canvas/close"
22
23⍝# The native package behind these functions.
24ˡpackage ← "canvas"
ᶠᶠⁱb̲ind< expands to
ˡo̲pen! ← { a b → pa ← a ⎕N̲PUT "ext:canvas/open?text" pb ← (f̲ormat r̲avel f̲loor b) ⎕N̲PUT "ext:canvas/open?int=" c̲at f̲ormat s̲hape b f̲loor f̲irst n̲umbers ⎕N̲GET "ext:canvas/open" }
ᶠᶠⁱb̲ind< expands to
ˡs̲how! ← { a b → pa ← (f̲ormat r̲avel f̲loor a) ⎕N̲PUT "ext:canvas/show?int=" c̲at f̲ormat s̲hape a pb ← (f̲ormat r̲avel f̲loat b) ⎕N̲PUT "ext:canvas/show?float=" c̲at f̲ormat s̲hape b f̲loor f̲irst n̲umbers ⎕N̲GET "ext:canvas/show" }
ᶠᶠⁱb̲ind< expands to
ˡn̲ext! ← { a → pa ← (f̲ormat r̲avel f̲loor a) ⎕N̲PUT "ext:canvas/next?int=" c̲at f̲ormat s̲hape a ⎕N̲GET "ext:canvas/next" }
ᶠᶠⁱb̲ind< expands to
ˡc̲lose! ← { a → pa ← (f̲ormat r̲avel f̲loor a) ⎕N̲PUT "ext:canvas/close?int=" c̲at f̲ormat s̲hape a f̲loor f̲irst n̲umbers ⎕N̲GET "ext:canvas/close" }