From eef4af8087cdcd471fb15e255e04941d0919946c Mon Sep 17 00:00:00 2001 From: pythongosssss <125205205+pythongosssss@users.noreply.github.com> Date: Sat, 19 Aug 2023 16:02:01 +0100 Subject: [PATCH] Add lock icon to locked nodes closes #41 --- js/locking.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/js/locking.js b/js/locking.js index 9e18308..64cafe2 100644 --- a/js/locking.js +++ b/js/locking.js @@ -78,6 +78,18 @@ app.registerExtension({ return opts; }; }, + setup() { + const drawNodeShape = LGraphCanvas.prototype.drawNodeShape; + LGraphCanvas.prototype.drawNodeShape = function (node, ctx, size, fgcolor, bgcolor, selected, mouse_over) { + const res = drawNodeShape.apply(this, arguments); + + if (node[LOCKED]) { + ctx.fillText("🔒", node.size[0] - 20, -10); + } + + return res; + }; + }, async beforeRegisterNodeDef(nodeType) { const nodesArray = (nodes) => { if (nodes) { @@ -93,6 +105,7 @@ app.registerExtension({ for (const node of nodes) { delete node[LOCKED]; } + app.graph.setDirtyCanvas(true, false); } function lockNode(nodes) { nodes = nodesArray(nodes); @@ -120,6 +133,8 @@ app.registerExtension({ // And then lock each element if required lockArray(sz, () => !!node[LOCKED]); } + + app.graph.setDirtyCanvas(true, false); } // Add menu options for lock/unlock