From: Ian Jackson Date: Sat, 3 Apr 2021 22:10:24 +0000 (+0100) Subject: js: Handle special_count of zero X-Git-Tag: otter-0.5.0~213 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=f25da2363d83672f7761b08c260079c7c682c13b;p=otter.git js: Handle special_count of zero Signed-off-by: Ian Jackson --- diff --git a/templates/script.ts b/templates/script.ts index 2cd23735..6a1f163d 100644 --- a/templates/script.ts +++ b/templates/script.ts @@ -820,7 +820,7 @@ function drag_mousedown(e : MouseEvent, shifted: boolean) { return [piece]; } - if (true) { + if (special_count == null) { let target = e.target as SVGGraphicsElement; // we check this just now! let piece: PieceId | undefined = target.dataset.piece; if (piece) { @@ -828,6 +828,25 @@ function drag_mousedown(e : MouseEvent, shifted: boolean) { } else { clicked = []; } + } else if (special_count == 0) { + let clickpos = mouseevent_pos(e); + let uelem = pieces_marker; + for (;;) { + uelem = uelem.nextElementSibling as any; + if (uelem == defs_marker) { + clicked = []; + break; + } + let piece = uelem.dataset.piece!; + let p = pieces[piece]!; + if (p_bbox_contains(p, clickpos)) { + clicked = clicked_one(piece); + break; + } + } + } else { + mouseevent_pos(e); + return; } if (!clicked.length) { @@ -892,6 +911,16 @@ function mouseevent_pos(e: MouseEvent): Pos { return pos; } +function p_bbox_contains(p: PieceInfo, test: Pos) { + let ctr = piece_xy(p); + for (let i of [0,1]) { + let offset = test[i] - ctr[i]; + if (offset < p.bbox[0][i] || offset > p.bbox[1][i]) + return false; + } + return true; +} + function ungrab_all() { for (let tpiece of Object.keys(pieces)) { let tp = pieces[tpiece]!;