mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-02-10 05:22:34 +08:00
Enable brush preview for key and slider events
This commit is contained in:
parent
45b049669b
commit
1f9e88fcd1
@ -185,6 +185,7 @@ class MaskEditorDialog extends ComfyDialog {
|
||||
|
||||
var brush_size_slider = this.createLeftSlider(self, "Thickness", "20px", (event) => {
|
||||
self.brush_size = event.target.value;
|
||||
self.updateBrushPreview(self, null, null);
|
||||
});
|
||||
|
||||
this.element.appendChild(imgCanvas);
|
||||
@ -322,6 +323,8 @@ class MaskEditorDialog extends ComfyDialog {
|
||||
} else if (event.key === '[') {
|
||||
self.brush_size = Math.max(self.brush_size-2, 1);
|
||||
}
|
||||
|
||||
self.updateBrushPreview(self, null, null);
|
||||
}
|
||||
|
||||
static handleMouseUp(event) {
|
||||
@ -329,6 +332,18 @@ class MaskEditorDialog extends ComfyDialog {
|
||||
MaskEditorDialog.instance.drawing_mode = false;
|
||||
}
|
||||
|
||||
updateBrushPreview(self) {
|
||||
const brush = self.brush;
|
||||
|
||||
var centerX = self.cursorX;
|
||||
var centerY = self.cursorY;
|
||||
|
||||
brush.style.width = (self.brush_size - 1) * 2 + "px";
|
||||
brush.style.height = (self.brush_size - 1) * 2 + "px";
|
||||
brush.style.left = (centerX - self.brush_size) + "px";
|
||||
brush.style.top = (centerY - self.brush_size) + "px";
|
||||
}
|
||||
|
||||
handleWheelEvent(self, event) {
|
||||
if(event.deltaY < 0)
|
||||
self.brush_size = Math.min(self.brush_size+2, 100);
|
||||
@ -337,19 +352,14 @@ class MaskEditorDialog extends ComfyDialog {
|
||||
|
||||
self.brush_slider_input.value = self.brush_size;
|
||||
|
||||
const brush = this.brush;
|
||||
brush.style.width = (this.brush_size - 1) * 2 + "px";
|
||||
brush.style.height = (this.brush_size - 1) * 2 + "px";
|
||||
brush.style.left = (event.pageX - this.brush_size) + "px";
|
||||
brush.style.top = (event.pageY - this.brush_size) + "px";
|
||||
self.updateBrushPreview(self);
|
||||
}
|
||||
|
||||
draw_move(self, event) {
|
||||
const brush = this.brush;
|
||||
brush.style.width = (this.brush_size - 1) * 2 + "px";
|
||||
brush.style.height = (this.brush_size - 1) * 2 + "px";
|
||||
brush.style.left = (event.pageX - this.brush_size) + "px";
|
||||
brush.style.top = (event.pageY - this.brush_size) + "px";
|
||||
this.cursorX = event.pageX;
|
||||
this.cursorY = event.pageY;
|
||||
|
||||
this.updateBrushPreview(self);
|
||||
|
||||
if (event instanceof TouchEvent || event.buttons === 1) {
|
||||
event.preventDefault();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user