mirror of
https://github.com/Azornes/Comfyui-LayerForge.git
synced 2026-03-25 14:25:44 -03:00
Last Point yellow
Added a clear first point distinction when drawing a custom shape: if the mouse cursor is near the beginning of a line (the shape can be closed), the first point is drawn in yellow and larger. This allows the user to see when they can close the shape with a single click. The code has been compiled and is ready to use. The functionality works as expected.
This commit is contained in:
@@ -179,8 +179,6 @@ export class BatchPreviewManager {
|
|||||||
this.layers.forEach((layer) => {
|
this.layers.forEach((layer) => {
|
||||||
layer.visible = true;
|
layer.visible = true;
|
||||||
});
|
});
|
||||||
// Clear selection - deselect all layers
|
|
||||||
this.canvas.updateSelection([]);
|
|
||||||
// Update the layers panel to reflect visibility changes
|
// Update the layers panel to reflect visibility changes
|
||||||
if (this.canvas.canvasLayersPanel) {
|
if (this.canvas.canvasLayersPanel) {
|
||||||
this.canvas.canvasLayersPanel.onLayersChanged();
|
this.canvas.canvasLayersPanel.onLayersChanged();
|
||||||
@@ -229,7 +227,11 @@ export class BatchPreviewManager {
|
|||||||
});
|
});
|
||||||
// Show only the current layer
|
// Show only the current layer
|
||||||
layer.visible = true;
|
layer.visible = true;
|
||||||
this.canvas.updateSelection([layer]);
|
// Deselect only this layer if it is selected
|
||||||
|
const selected = this.canvas.canvasSelection.selectedLayers;
|
||||||
|
if (selected && selected.includes(layer)) {
|
||||||
|
this.canvas.updateSelection(selected.filter((l) => l !== layer));
|
||||||
|
}
|
||||||
// Update the layers panel to reflect visibility changes
|
// Update the layers panel to reflect visibility changes
|
||||||
if (this.canvas.canvasLayersPanel) {
|
if (this.canvas.canvasLayersPanel) {
|
||||||
this.canvas.canvasLayersPanel.onLayersChanged();
|
this.canvas.canvasLayersPanel.onLayersChanged();
|
||||||
|
|||||||
@@ -198,6 +198,10 @@ export class CanvasInteractions {
|
|||||||
this.updateCursor(coords.world);
|
this.updateCursor(coords.world);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
// --- DYNAMICZNY PODGLĄD LINII CUSTOM SHAPE ---
|
||||||
|
if (this.canvas.shapeTool.isActive && !this.canvas.shapeTool.shape.isClosed) {
|
||||||
|
this.canvas.render();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
handleMouseUp(e) {
|
handleMouseUp(e) {
|
||||||
const coords = this.getMouseCoordinates(e);
|
const coords = this.getMouseCoordinates(e);
|
||||||
|
|||||||
@@ -114,10 +114,27 @@ export class ShapeTool {
|
|||||||
}
|
}
|
||||||
ctx.stroke();
|
ctx.stroke();
|
||||||
// Draw vertices
|
// Draw vertices
|
||||||
ctx.fillStyle = 'rgba(0, 255, 255, 1)';
|
const mouse = this.canvas.lastMousePosition;
|
||||||
|
const firstPoint = this.shape.points[0];
|
||||||
|
let highlightFirst = false;
|
||||||
|
if (!this.shape.isClosed && this.shape.points.length > 2 && mouse) {
|
||||||
|
const dx = mouse.x - firstPoint.x;
|
||||||
|
const dy = mouse.y - firstPoint.y;
|
||||||
|
const dist = Math.sqrt(dx * dx + dy * dy);
|
||||||
|
if (dist < 10 / this.canvas.viewport.zoom) {
|
||||||
|
highlightFirst = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
this.shape.points.forEach((point, index) => {
|
this.shape.points.forEach((point, index) => {
|
||||||
ctx.beginPath();
|
ctx.beginPath();
|
||||||
ctx.arc(point.x, point.y, 4 / this.canvas.viewport.zoom, 0, 2 * Math.PI);
|
if (index === 0 && highlightFirst) {
|
||||||
|
ctx.arc(point.x, point.y, 8 / this.canvas.viewport.zoom, 0, 2 * Math.PI);
|
||||||
|
ctx.fillStyle = 'yellow';
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ctx.arc(point.x, point.y, 4 / this.canvas.viewport.zoom, 0, 2 * Math.PI);
|
||||||
|
ctx.fillStyle = 'rgba(0, 255, 255, 1)';
|
||||||
|
}
|
||||||
ctx.fill();
|
ctx.fill();
|
||||||
});
|
});
|
||||||
ctx.restore();
|
ctx.restore();
|
||||||
|
|||||||
@@ -234,9 +234,6 @@ export class BatchPreviewManager {
|
|||||||
layer.visible = true;
|
layer.visible = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Clear selection - deselect all layers
|
|
||||||
this.canvas.updateSelection([]);
|
|
||||||
|
|
||||||
// Update the layers panel to reflect visibility changes
|
// Update the layers panel to reflect visibility changes
|
||||||
if (this.canvas.canvasLayersPanel) {
|
if (this.canvas.canvasLayersPanel) {
|
||||||
this.canvas.canvasLayersPanel.onLayersChanged();
|
this.canvas.canvasLayersPanel.onLayersChanged();
|
||||||
@@ -296,9 +293,13 @@ export class BatchPreviewManager {
|
|||||||
|
|
||||||
// Show only the current layer
|
// Show only the current layer
|
||||||
layer.visible = true;
|
layer.visible = true;
|
||||||
|
|
||||||
this.canvas.updateSelection([layer]);
|
// Deselect only this layer if it is selected
|
||||||
|
const selected = this.canvas.canvasSelection.selectedLayers;
|
||||||
|
if (selected && selected.includes(layer)) {
|
||||||
|
this.canvas.updateSelection(selected.filter((l: Layer) => l !== layer));
|
||||||
|
}
|
||||||
|
|
||||||
// Update the layers panel to reflect visibility changes
|
// Update the layers panel to reflect visibility changes
|
||||||
if (this.canvas.canvasLayersPanel) {
|
if (this.canvas.canvasLayersPanel) {
|
||||||
this.canvas.canvasLayersPanel.onLayersChanged();
|
this.canvas.canvasLayersPanel.onLayersChanged();
|
||||||
|
|||||||
@@ -258,6 +258,11 @@ export class CanvasInteractions {
|
|||||||
this.updateCursor(coords.world);
|
this.updateCursor(coords.world);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// --- DYNAMICZNY PODGLĄD LINII CUSTOM SHAPE ---
|
||||||
|
if (this.canvas.shapeTool.isActive && !this.canvas.shapeTool.shape.isClosed) {
|
||||||
|
this.canvas.render();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
handleMouseUp(e: MouseEvent): void {
|
handleMouseUp(e: MouseEvent): void {
|
||||||
|
|||||||
@@ -143,10 +143,27 @@ export class ShapeTool {
|
|||||||
ctx.stroke();
|
ctx.stroke();
|
||||||
|
|
||||||
// Draw vertices
|
// Draw vertices
|
||||||
ctx.fillStyle = 'rgba(0, 255, 255, 1)';
|
const mouse = this.canvas.lastMousePosition;
|
||||||
|
const firstPoint = this.shape.points[0];
|
||||||
|
let highlightFirst = false;
|
||||||
|
if (!this.shape.isClosed && this.shape.points.length > 2 && mouse) {
|
||||||
|
const dx = mouse.x - firstPoint.x;
|
||||||
|
const dy = mouse.y - firstPoint.y;
|
||||||
|
const dist = Math.sqrt(dx * dx + dy * dy);
|
||||||
|
if (dist < 10 / this.canvas.viewport.zoom) {
|
||||||
|
highlightFirst = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this.shape.points.forEach((point, index) => {
|
this.shape.points.forEach((point, index) => {
|
||||||
ctx.beginPath();
|
ctx.beginPath();
|
||||||
ctx.arc(point.x, point.y, 4 / this.canvas.viewport.zoom, 0, 2 * Math.PI);
|
if (index === 0 && highlightFirst) {
|
||||||
|
ctx.arc(point.x, point.y, 8 / this.canvas.viewport.zoom, 0, 2 * Math.PI);
|
||||||
|
ctx.fillStyle = 'yellow';
|
||||||
|
} else {
|
||||||
|
ctx.arc(point.x, point.y, 4 / this.canvas.viewport.zoom, 0, 2 * Math.PI);
|
||||||
|
ctx.fillStyle = 'rgba(0, 255, 255, 1)';
|
||||||
|
}
|
||||||
ctx.fill();
|
ctx.fill();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user