From b6487b3ec9c5d9e53ec8209d5d086740ec2bf0a5 Mon Sep 17 00:00:00 2001 From: pythongosssss <125205205+pythongosssss@users.noreply.github.com> Date: Sat, 25 Feb 2023 12:41:36 +0000 Subject: [PATCH] Fix drawing img on collapsed nodes --- webshit/index.html | 56 ++++++++++++++++++++++++---------------------- 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/webshit/index.html b/webshit/index.html index 778ea760..a21e4697 100644 --- a/webshit/index.html +++ b/webshit/index.html @@ -265,39 +265,41 @@ function onObjectInfo(json) { } MyNode.prototype.onDrawBackground = function(ctx) { - const output = nodeOutputs[this.id + ""]; - if(output && output.images) { - const src = output.images[0]; - if(this.src !== src) { - this.img = null; - this.src = src; - const img = new Image(); - img.src = "/view/" + src; - img.onload = () => { - graph.setDirtyCanvas(true); - this.img = img; - if(this.size[1] < 100) { - this.size[1] = 250; + if(!this.flags.collapsed) { + const output = nodeOutputs[this.id + ""]; + if(output && output.images) { + const src = output.images[0]; + if(this.src !== src) { + this.img = null; + this.src = src; + const img = new Image(); + img.src = "/view/" + src; + img.onload = () => { + graph.setDirtyCanvas(true); + this.img = img; + if(this.size[1] < 100) { + this.size[1] = 250; + } } } - } - if(this.img) { - let w = this.img.naturalWidth; - let h = this.img.naturalHeight; - let dw = this.size[0]; - let dh = this.size[1]; + if(this.img) { + let w = this.img.naturalWidth; + let h = this.img.naturalHeight; + let dw = this.size[0]; + let dh = this.size[1]; - const scaleX = dw / w; - const scaleY = dh / h; - const scale = Math.min(scaleX, scaleY, 1); + const scaleX = dw / w; + const scaleY = dh / h; + const scale = Math.min(scaleX, scaleY, 1); - w *= scale; - h *= scale; + w *= scale; + h *= scale; - let x = (dw - w) / 2; - let y = (dh - h) / 2; + let x = (dw - w) / 2; + let y = (dh - h) / 2; - ctx.drawImage(this.img, x, y, w, h); + ctx.drawImage(this.img, x, y, w, h); + } } } };