defineButton method
DefineButton2(タグ34)。CondKeyPress=keyPressのButtonCondAction 1個と、
shapeId指定時はヒット/アップ兼用のButtonRecordを持つボタンを定義する。
Implementation
void defineButton(
int id, {
required int keyPress,
required Uint8List actions,
int? shapeId,
}) {
final recordBytes = <int>[];
if (shapeId != null) {
final rec = BitWriter();
rec.writeUI8(0x01 | 0x08); // stateUp | stateHitTest
rec.writeUI16(shapeId);
rec.writeUI16(1); // depth
_writeMatrixTranslateOnly(rec, 0, 0);
_writeIdentityCxform(rec);
recordBytes.addAll(rec.toBytes());
}
recordBytes.add(0); // ButtonRecord terminator
final header = BitWriter();
header.writeUI16(id);
header.writeUI8(0); // flags (trackAsMenu)
// actionOffset: offsetフィールド自身の位置からCondActionRecord先頭までの距離
final offsetValue = 2 + recordBytes.length;
header.writeUI16(offsetValue);
final cond = (keyPress & 0x7F) << 9;
final condBytes = <int>[
0, 0, // size=0 → タグ末尾までを最終レコードとして扱う
cond & 0xFF, (cond >> 8) & 0xFF,
...actions,
];
final body = <int>[
...header.toBytes(),
...recordBytes,
...condBytes,
];
_writeTag(TagCode.defineButton2, Uint8List.fromList(body));
}