喵嗚(Mew,@meow 8.0)的前端(從詞法到展開)已經完成,可以在實驗場試寫;還沒有執行階段,也沒有任何已出貨的宿主,喵撲的主題工坊今天用的是 @meow 6.0。
繪圖 API
draw.*、box.*、a11y 需要 draw 能力,只能在 view 和它呼叫的函式裡用(效果 draws)。除了鍵盤主題與 kit,所有宿主都有 draw。簽名的唯一定義在 HOSTS.md §3;下表由前端的宿主函式表產生。
draw
| 函式 | 參數 | 回傳 | 能力 | 效果 |
|---|---|---|---|---|
draw.clear | c: color | nothing | draw | draws |
draw.rect | x: numy: numw: numh: numc: color{outline: num, to: color, angle: num}? | nothing | draw | draws |
draw.rrect | x: numy: numw: numh: numr: numc: color{outline: num, to: color, angle: num}? | nothing | draw | draws |
draw.circle | cx: numcy: numr: numc: color{outline: num, to: color, angle: num}? | nothing | draw | draws |
draw.ellipse | cx: numcy: numrx: numry: numc: color{outline: num, to: color, angle: num}? | nothing | draw | draws |
draw.tri | x0: numy0: numx1: numy1: numx2: numy2: numc: color{outline: num, to: color, angle: num}? | nothing | draw | draws |
draw.poly | points: [vec2; N]c: color{outline: num, to: color, angle: num}? | nothing | draw | draws |
draw.line | x0: numy0: numx1: numy1: numc: color{width: num}? | nothing | draw | draws |
draw.arc | cx: numcy: numr: numa0: numa1: numc: color{width: num}? | nothing | draw | draws |
draw.text | t: textx: numy: num{size: num, color: color, align: "left" | "center" | "right", baseline: "top" | "middle" | "alphabetic", weight: "regular" | "bold"}? | nothing | draw | draws |
draw.number | n: numx: numy: num{size: num, color: color, align: "left" | "center" | "right", baseline: "top" | "middle" | "alphabetic", weight: "regular" | "bold"}? | nothing | draw | draws |
draw.textWidth | t: textsize: num | num | draw | pure |
draw.sprite | s: ref spritecx: numcy: num{scale: num, rot: num, flipX: bool}? | nothing | draw | draws |
draw.cat | who: "mimimo" | "momo"pose: "sit" | "walk" | "run" | "sleep" | …cx: numcy: numsize: num{rot: num, flipX: bool}? | nothing | draw cats | draws |
draw.icon | name: "phone" | "mail" | "camera" | "music" | …cx: numcy: numsize: numc: color | nothing | draw | draws |
draw.shade | x: numy: numw: numh: numf: ref fn | nothing | draw | draws |
draw.push | nothing | draw | draws | |
draw.pop | nothing | draw | draws | |
draw.translate | dx: numdy: num | nothing | draw | draws |
draw.rotate | a: num | nothing | draw | draws |
draw.scale | sx: numsy: num | nothing | draw | draws |
draw.alpha | a: num | nothing | draw | draws |
draw.clip | x: numy: numw: numh: num | nothing | draw | draws |
draw.clock | x: numy: num{size: num, color: color, align: "left" | "center" | "right", baseline: "top" | "middle" | "alphabetic", weight: "regular" | "bold", format: "hm" | "h" | "m" | "weekday" | …}? | nothing | draw | draws,只在烘焙 view 的宿主 |
draw.timer | x: numy: num{until: num, size: num, color: color, align: "left" | "center" | "right", baseline: "top" | "middle" | "alphabetic", weight: "regular" | "bold"}? | nothing | draw | draws,只在烘焙 view 的宿主 |
draw.progress | x: numy: numw: numh: numc: color{from: num, until: num}? | nothing | draw | draws,只在烘焙 view 的宿主 |
a11y | t: text{value: num}? | nothing | draw | draws |
rand
| 函式 | 參數 | 回傳 | 能力 | 效果 |
|---|---|---|---|---|
rand.next | num | rand | rand | |
rand.range | lo: numhi: num | num | rand | rand |
rand.int | lo: numhi: num | num | rand | rand |
rand.chance | p: num | bool | rand | rand |
time
| 函式 | 參數 | 回傳 | 能力 | 效果 |
|---|---|---|---|---|
time.every | seconds: num | bool | time | reads_time |
clock
| 函式 | 參數 | 回傳 | 能力 | 效果 |
|---|---|---|---|---|
clock.at | hour: numminute: num | num | clock | reads_data,只在烘焙 view 的宿主 |
pad
| 函式 | 參數 | 回傳 | 能力 | 效果 |
|---|---|---|---|---|
pad.cols | row: num | num | pads | reads_data |
pad.rect | i: num | {x: num, y: num, w: num, h: num} | pads | reads_data |
pad.center | i: num | vec2 | pads | reads_data |
pad.row | i: num | num | pads | reads_data |
pad.col | i: num | num | pads | reads_data |
pad.index | row: numcol: num | num | pads | reads_data |
pad.at | x: numy: num | num | pads | reads_data |
pad.down | i: num | bool | pads | reads_data |
pad.held | i: num | num | pads | reads_data |
touch
| 函式 | 參數 | 回傳 | 能力 | 效果 |
|---|---|---|---|---|
touch.down | id: num | bool | touch | reads_data |
touch.pos | id: num | vec2 | touch | reads_data |
sfx
| 函式 | 參數 | 回傳 | 能力 | 效果 |
|---|---|---|---|---|
sfx.play | name: "pop" | "chime" | "thud" | "drip" | …{gain: num}? | nothing | sfx | sfx |
sfx.note | degree: num{scale: "theme" | "pentatonic" | "major", voice: "theme" | "musicBox" | "kalimba" | "guzheng" | …, octave: num, gain: num}? | nothing | sfx | sfx |
haptic
| 函式 | 參數 | 回傳 | 能力 | 效果 |
|---|---|---|---|---|
haptic.tap | strength: "light" | "medium" | "heavy" | nothing | haptic | haptic |
可讀的值
| 名稱 | 型別 | 能力 | 備註 |
|---|---|---|---|
time.tick | num | time | |
time.dt | num | time | |
time.t | num | time | |
time.rate | num | time | |
box.w | num | draw | |
box.h | num | draw | |
pad.count | num | pads | 宿主常數 |
pad.rows | num | pads | 宿主常數 |
pad.anyDown | bool | pads | |
touch.count | num | touch |
選項記錄
| 記錄 | 欄位(都可省略) |
|---|---|
Fill | outline: num to: color angle: num |
TextOpts | size: num color: color align: "center" | "left" | "right" baseline: "alphabetic" | "middle" | "top" weight: "bold" | "regular" |
LineOpts | width: num |
SpriteOpts | scale: num rot: num flipX: bool |
CatOpts | rot: num flipX: bool |
ClockOpts | size: num color: color align: "center" | "left" | "right" baseline: "alphabetic" | "middle" | "top" weight: "bold" | "regular" format: "h" | "hm" | "m" | "monthDay" | "weekday" |
TimerOpts | until: num size: num color: color align: "center" | "left" | "right" baseline: "alphabetic" | "middle" | "top" weight: "bold" | "regular" |
ProgressOpts | from: num until: num |
A11yOpts | value: num |
PlayOpts | gain: num |
NoteOpts | scale: "major" | "pentatonic" | "theme" voice: "bubble" | "glass" | "guzheng" | "hangDrum" | "kalimba" | "musicBox" | "retro8bit" | "theme" | … octave: num gain: num |
模型
立即模式:view 裡每一個 draw.* 呼叫往繪圖清單附加一個指令。view 結束後,宿主原生重播這份清單,VM 不碰像素。後畫的蓋住先畫的。
繪圖清單(MDL1)、編碼器與三個重播器都還沒有實作。
簽名慣例
- 命名空間.動詞,camelCase:
draw.rrect、sfx.play。 - 沒有「影響下一個呼叫」的修飾(沒有
draw.setColor、draw.stroke()、draw.gradient())。外框、漸層用選項記錄。唯一的狀態是成對的draw.push()/draw.pop()。 - 參數順序固定:幾何 → 顏色 → 選項記錄。
- 少用的參數放在最後一個選項記錄裡:
draw.text(t, x, y, {size: 12, color: kit.ink, align: "center"})。選項的每個欄位都有預設值,可以省略;未知的欄位是E-TYP-011,附合法欄位清單。 - 每個封閉集合的字串參數(姿勢、圖示、音色、觸覺強度)都是列舉型別,寫錯是
E-TYP-006,列出全部合法值。 - 名字參照參數寫成
ref sprite、ref fn,而且函式參照放在幾何之後:draw.shade(x, y, w, h, f)。
選項
- 填色形狀(
rect、rrect、circle、ellipse、tri、poly)的選項:outline(大於 0 時只畫這個寬度的外框,不填色)、to(線性漸層的終點色)、angle(漸層方向)。 line、arc的選項是{width: …};arc只有線,沒有扇形填色。- 文字的選項:
size、color、align("left"、"center"、"right")、baseline("top"、"middle"、"alphabetic")、weight("regular"、"bold")。 draw.textWidth(t, size)是pure;規格要求三個重播器量出相同的寬度(可行性未驗證)。
文字
draw.text收text:fmt(…)的結果、片語L.*,或在有text能力的宿主寫字串字面量。沒有text能力的宿主寫字面量是E-CAP-003。draw.number(n, x, y, {…})四捨五入成整數,最多 6 位數。- 每個
view的數字字形合計 ≤ 32(未驗證);超過的文字指令被丟掉。
變換、透明度、裁切
draw.push()
draw.translate(dx, dy) draw.rotate(a) draw.scale(sx, sy)
draw.alpha(a) draw.clip(x, y, w, h)
draw.pop()
這五個呼叫只能出現在 draw.push() 與對應的 draw.pop() 之間,pop 時全部還原。在 push 之外用是 E-EFF-006;push/pop 不成對(靜態判斷得出的情況)是 E-EFF-007。變換堆疊深度 ≤ 8、裁切巢狀 ≤ 4(未驗證)。
@meow 8.0 for keyboard.canvas
view {
draw.clear(kit.deck)
draw.rotate(15deg)
draw.rect(140, 60, 40, 40, kit.accent)
}
E-EFF-006@meow 8.0 for keyboard.canvas
view {
draw.clear(kit.deck)
draw.push()
draw.translate(160, 80)
draw.rotate(15deg)
draw.rect(-20, -20, 40, 40, kit.accent)
draw.pop()
a11y(L.cat)
}
角度是弧度,順時針為正(y 向下);可以寫 15deg。
sprite
@meow 8.0 for keyboard.canvas
sprite snack 7x5 [kit.accent, kit.deck] {
.11..1.
1111.11
1211111
1111.11
.11..1.
}
view {
draw.clear(kit.deck)
draw.sprite(snack, 160, 80, {scale: 3})
}
sprite 名字 寬x高 [調色盤] { 像素列 }。寬x高中間沒有空白。- 每一列是
.與1–7:.透明,數字是調色盤的第幾個顏色。列寬要等於寬、列數要等於高,否則E-SPR-001。 - 調色盤只能是
kit.*顏色(E-SPR-002),所以 sprite 會跟著佈景走。 - 最大 16×16,每個元件最多 16 個(未驗證)。
- 在
draw.sprite(snack, …)裡用裸名引用;不能存進變數。縮放用最近鄰。
貓、圖示
draw.cat(who: Cat, pose: Pose, cx, cy, size, {rot, flipX})
draw.icon(name: Icon, cx, cy, size, c)
貓是第一方美術,由宿主畫,程式只選角色和姿勢;要寫 cats 能力(推斷得出)。圖示是第一方的線條圖。角色、姿勢、圖示的列舉在列舉與常數。每個姿勢與圖示的美術還沒畫。
著色器填色
draw.shade(x, y, w, h, f) 用一個能上 GPU 的純函式填一塊矩形。輸入按名字綁定:uv、time、accent、dark,沒有任何打字衍生的輸入。
- 每個
view最多 1 個,計入面積預算。 - 每個喵罐最多 2 個不同的函式可以當目標(
E-LIM-004)。 - 在不能即時跑著色器的地方(iOS 的重播、Android API 33 以下、所有烘焙宿主),它是匯入時由主 app 烘好的靜態貼圖。
a11y
a11y(t, {value}) 是這個 view 的無障礙描述。每個 view 最多 1 次(第二次起被忽略,Studio 給 W-A11Y-002),≤ 48 個字形(未驗證)。value 讓螢幕閱讀器在片語後面唸一個數字:a11y(L.score, {value: state.score})。
夾限與面積
不論程式傳什麼值,編碼器在計費之前會夾限幾何參數:座標、線寬(0.25–32)、文字大小(6–96,鍵盤畫布 8–40)、圖示與貓與 sprite 的邊長(不超過畫面短邊的 2 倍)。這些夾限值都是未驗證的起始值。夾限不是錯誤,東西只是比預期小。
每個 view 有面積預算:1 個面積單位是畫面面積的 1/64。填色類按套用變換與裁切之後的包圍盒計(至少 1 單位);線、弧按「(長度 + 寬度) × 寬度」計;文字按字形數與大小計。超過預算的指令被丟掉(R-AREA)。這是為了管住燃料和指令數都管不到的重播成本。各宿主的面積預算未驗證,見限制與預算。
自我更新的元件
draw.clock、draw.timer、draw.progress 只在烘焙宿主(小工具、動態島、鎖定畫面、圖示)可用,見 Nyadeco(喵扮)元件。
