Fix drawing img on collapsed nodes

This commit is contained in:
pythongosssss 2023-02-25 12:41:36 +00:00 committed by GitHub
parent d4486f8284
commit b6487b3ec9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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);
}
}
}
};