MCPcopy
hub / github.com/Lightricks/ComfyUI-LTXVideo / setupEvents

Function setupEvents

web/js/sparse_track_editor.js:473–562  ·  view source on GitHub ↗
(node)

Source from the content-addressed store, hash-verified

471// ---------------------------------------------------------------------------
472
473function setupEvents(node) {
474 const ed = node._ed;
475 const canvas = ed.canvas;
476
477 canvas.addEventListener("pointerdown", (e) => {
478 ed.menu.style.display = "none";
479 if (e.button === 2) return; // right-click handled by contextmenu
480 if (e.button !== 0) return;
481 e.preventDefault();
482 e.stopPropagation();
483 canvas.setPointerCapture(e.pointerId);
484
485 const cp = mouseToCanvas(node, e);
486 const hit = hitTestPoint(node, cp);
487 if (hit) {
488 ed.active = hit.si;
489 ed.drag = { ...hit, pointerId: e.pointerId };
490 canvas.style.cursor = "grabbing";
491 ed.dirty = true;
492 }
493 });
494
495 canvas.addEventListener("pointermove", (e) => {
496 const cp = mouseToCanvas(node, e);
497
498 if (ed.drag) {
499 e.preventDefault();
500 e.stopPropagation();
501 const imgP = canvasToImg(node, cp);
502 imgP.x = Math.max(0, Math.min(ed.imgW, imgP.x));
503 imgP.y = Math.max(0, Math.min(ed.imgH, imgP.y));
504 ed.splines[ed.drag.si][ed.drag.pi] = imgP;
505 ed.dirty = true;
506 syncWidgets(node);
507 return;
508 }
509
510 const hit = hitTestPoint(node, cp);
511 if (hit) {
512 canvas.style.cursor = "grab";
513 ed.hover = hit;
514 } else {
515 canvas.style.cursor = "default";
516 ed.hover = null;
517 }
518 ed.dirty = true;
519 });
520
521 canvas.addEventListener("pointerup", (e) => {
522 if (ed.drag) {
523 e.preventDefault();
524 e.stopPropagation();
525 canvas.releasePointerCapture(e.pointerId);
526 ed.drag = null;
527 canvas.style.cursor = "default";
528 ed.dirty = true;
529 syncWidgets(node);
530 }

Callers 1

initEditorFunction · 0.85

Calls 5

mouseToCanvasFunction · 0.85
hitTestPointFunction · 0.85
canvasToImgFunction · 0.85
syncWidgetsFunction · 0.85
showMenuFunction · 0.85

Tested by

no test coverage detected