Skip to content

Commit

Permalink
fix bug when painter is created (recreated) not active
Browse files Browse the repository at this point in the history
Fix error when used MyPaint brush then run piping, and select image
added in the Selected mode, get undefined getRetinaScaling property
Fix bug when copy(clipspace) and past, not set correct type, and
drawning mode not switch to selected and drawning.
  • Loading branch information
AlekPet committed Sep 2, 2024
1 parent fce9277 commit 39d20dc
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 16 deletions.
35 changes: 24 additions & 11 deletions PainterNode/js/painter_node.js
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ class Painter {

objectNames.push(o.type);

obEl.addEventListener("click", () => {
obEl.addEventListener("click", (e) => {
// Style active
this.setActiveElement(obEl, list_body);
// Select element
Expand Down Expand Up @@ -1275,7 +1275,8 @@ class Painter {
this.canvas.freeDrawingBrush = new fabric.MyBrushPaintSymmetry(
this.canvas,
this.MyBrushPaintManager.range_brush_pressure,
this.MyBrushPaintManager.currentBrushSettings
this.MyBrushPaintManager.currentBrushSettings,
this
);
} // end BrushMyPaint

Expand Down Expand Up @@ -1704,14 +1705,7 @@ class Painter {
}
},

"object:added": (o) => {
if (["BrushMyPaint"].includes(this.type)) {
if (o.target.type !== "group") this.canvas.remove(o.target);
// this.addToHistory();
this.canvas.renderAll();
this.uploadPaintFile(this.node.name);
}
},
"object:added": (o) => {},

// Object moving event
"object:moving": (o) => {
Expand Down Expand Up @@ -2168,6 +2162,9 @@ function PainterWidget(node, inputName, inputData, app) {
top: 0,
angle: 0,
strokeWidth: 1,
originX: "left",
originY: "top",
pipingImage: true,
});
res(img_);
};
Expand Down Expand Up @@ -2418,6 +2415,9 @@ app.registerExtension({
}

PainterWidget.apply(this, [this, nodeNamePNG, {}, app]);
this.painter.canvas.renderAll();
this.painter.uploadPaintFile(nodeNamePNG);
this.title = `${this.type} - ${this.painter.currentCanvasSize.width}x${this.painter.currentCanvasSize.height}`;

return r;
};
Expand All @@ -2443,11 +2443,24 @@ app.registerExtension({
top: 0,
angle: 0,
strokeWidth: 1,
}).scale(0.3);
});

if (confirm("Resize image for Painter size?")) {
img_.scaleToHeight(this.painter.currentCanvasSize.width);
img_.scaleToWidth(this.painter.currentCanvasSize.height);
}

this.painter.canvas.add(img_).renderAll();
this.painter.uploadPaintFile(this.painter.node.name);
this.painter.canvas.isDrawingMode = false;
this.painter.drawning = false;
this.painter.type = "Image";
this.painter.setActiveElement(
this.painter.painter_shapes_box.querySelector(
"[data-shape=Image]"
),
this.painter.painter_shapes_box
);
};

// Past as background
Expand Down
9 changes: 5 additions & 4 deletions PainterNode/lib/brushes.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ fabric.MyBrushPaintSymmetry = fabric.util.createClass(fabric.SymmetryBrush, {
initialize: function (
canvas,
range_brush_pressure = null,
brushSettings = null
brushSettings = null,
painter
) {
this.callSuper("initialize", canvas);

Expand All @@ -177,7 +178,7 @@ fabric.MyBrushPaintSymmetry = fabric.util.createClass(fabric.SymmetryBrush, {
this.surface = new MypaintSurface(this.canvas);
this.brush = new MypaintBrush(this.brushSettings, this.surface);
this.range_brush_pressure = range_brush_pressure;

this.painter = painter;
this.newGroup();
},

Expand Down Expand Up @@ -292,8 +293,8 @@ fabric.MyBrushPaintSymmetry = fabric.util.createClass(fabric.SymmetryBrush, {
this.canvas.clearContext(this.ctx);
this.group.addWithUpdate(imageCanv);
this.group.setCoords();
this.canvas.add(new fabric.Image("")); // empty object, hook
this.canvas.requestRenderAll();
this.canvas.renderAll();
this.painter.uploadPaintFile(this.painter.node.name);
});

Object.keys(this._options).forEach(
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[project]
name = "comfyui_custom_nodes_alekpet"
description = "Nodes: PoseNode, PainterNode, TranslateTextNode, TranslateCLIPTextEncodeNode, DeepTranslatorTextNode, DeepTranslatorCLIPTextEncodeNode, ArgosTranslateTextNode, ArgosTranslateCLIPTextEncodeNode, PreviewTextNode, HexToHueNode, ColorsCorrectNode, IDENode."
version = "1.0.23"
version = "1.0.24"
license = { file = "LICENSE" }

[project.urls]
Expand Down

0 comments on commit 39d20dc

Please sign in to comment.