Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7360b17842 |
@@ -1,5 +1,50 @@
|
||||
# DEVLOG - ComfyUI-Workflow-Studio
|
||||
|
||||
## 2026-06-25: v0.3.54 — Image Edit Shape ツール追加・Models タブ overlay バグ修正
|
||||
|
||||
**変更ファイル**: `static/js/image-edit/ShapeTool.js`(新規), `static/js/image-edit-tab.js`, `templates/index.html`, `static/js/models-tab.js`
|
||||
|
||||
### Image Edit Tab — Shape ツール(□ / S キー)
|
||||
|
||||
Eagle Comic Creator の画像編集タブ形状描画機能を移植。
|
||||
|
||||
**対応形状**
|
||||
- **Rect** — 矩形(Rounded チェックで角丸)
|
||||
- **Ellipse** — 楕円
|
||||
- **Line** — 直線(Stroke None 非表示 / 常にストローク有効)
|
||||
- **FreeLine** — フリーハンド曲線(旧 Curve。Stroke None 非表示 / 常にストローク有効)
|
||||
|
||||
**Tool Options バー**
|
||||
- Shape ドロップダウン、Rounded チェック(Rect/Ellipse のみ表示)
|
||||
- Fill: None チェック + カラーピッカー(Line/FreeLine 時は非表示)
|
||||
- Stroke: None チェック + カラーピッカー + 幅入力(Line/FreeLine 時は None チェック非表示)
|
||||
- Opacity スライダー、↩ Undo ボタン
|
||||
|
||||
**動作**
|
||||
- ドラッグ中: overlayCanvas に青い破線でプレビュー表示(FreeLine はリアルタイム描画)
|
||||
- ドラッグ離す: 確定 → 独立した draw レイヤーとして LayerManager に追加 → Undo 1操作で除去可
|
||||
- `ShapeTool.drawShape(ctx, shapeObj)` スタティックメソッドでレイヤー canvas に描画
|
||||
|
||||
**実装ファイル**
|
||||
- `static/js/image-edit/ShapeTool.js`(新規): ShapeTool クラス(プレビュー・確定・静的描画メソッド)
|
||||
- `image-edit-tab.js`: import・TOOL_DEFS 追加・`_setActiveTool`/`_activateCurrentTool`/`_renderToolOptions`/マウスハンドラー/`_initCanvases` を更新
|
||||
- `templates/index.html`: □ ツールボタン追加
|
||||
|
||||
**ヘルプ更新**
|
||||
- Image Edit Tab Tools セクション: Shape ツールの説明を追加
|
||||
- Image Edit Keyboard Shortcuts: `S: Shape tool` を追記(ヘルプ内・グローバル Shortcuts ページ)
|
||||
- `image-edit-tab.js` キーボードハンドラーに `s` → `"shape"` を追加(ヘルプ記載と実装を一致)
|
||||
|
||||
### Models タブ — overlay ボタン非更新バグ修正
|
||||
|
||||
`async` イベントハンドラー内で `await` 後に `e.currentTarget` が `null` になる問題を 2箇所修正。
|
||||
|
||||
- **B(Batch)ボタン** — 前回修正済み
|
||||
- **S(Stack)ボタン** — `await toggleStack()` 後に `e.currentTarget.classList.toggle()` を呼んでいたため `TypeError` が発生し黄色に変わらなかった → `const btn = e.currentTarget` を await 前に保存して修正
|
||||
- **⏸ enable/disable ボタン** — 非 async ハンドラーで `renderModelGrid()` 経由の再描画を使用しており問題なし(確認のみ)
|
||||
|
||||
---
|
||||
|
||||
## 2026-06-25: v0.3.53 — Image Edit Tab 実装・レイヤーロック・ギャラリー保存
|
||||
|
||||
**変更ファイル**: `static/js/image-edit-tab.js`, `static/js/image-edit/LayerManager.js`, `static/js/image-edit/SelectTool.js`, `static/js/image-edit/TextTool.js`, `static/css/image-edit-tab.css`, `templates/index.html`, `static/js/gallery-tab.js`, `py/routes/gallery_routes.py`
|
||||
|
||||
@@ -18,7 +18,7 @@ A comprehensive workflow, asset management, and generation UI plugin for [ComfyU
|
||||
- Built-in AI tools (translation and more)
|
||||
|
||||

|
||||

|
||||

|
||||
|
||||
## Screenshots
|
||||
|
||||
@@ -212,16 +212,17 @@ Two independent modes selectable via **[Image Loop] / [Gallery]** toggle buttons
|
||||
- **Layer-based image editor** — compose images with multiple layers (Image, Text, Draw types) and export the composite as PNG
|
||||
- **Loading images** — drag & drop onto the canvas, Upload button, or send from the Gallery tab via the **Image Edit** toolbar button; first image becomes Layer 1 (auto-locked), subsequent images are added as new layers scaled to fit the canvas
|
||||
- **New button** — create a blank canvas with custom dimensions (WxH prompt); clears all existing layers
|
||||
- **Tools** — Select (V), Draw (B), Text (T); tool options bar updates per active tool
|
||||
- **Tools** — Select (V), Draw (B), Text (T), Shape (S); tool options bar updates per active tool
|
||||
- **Select** — click to select; drag to move; drag corner handles to resize; drag circle handle to rotate; Flip H / Flip V / Rotate angle in the options bar; double-click a text layer to re-edit its content
|
||||
- **Draw** — freehand brush; options: color, brush size, blend mode
|
||||
- **Text** — click to place; configure font, size, bold/italic, align, and color; placed as an exact-size text layer sized to the measured bounding box; double-click to re-edit
|
||||
- **Shape** — drag to draw geometric shapes (Rect / Ellipse / Line / FreeLine); options: shape type, Rounded toggle (Rect/Ellipse), Fill color, Stroke color + width, Opacity; each committed shape becomes an independent draw layer; Stroke None hidden for Line/FreeLine (stroke always active)
|
||||
- **Layer panel** — layer list with visibility (👁/🚫) and lock (🔒/🔓) toggles; opacity slider; type icons (🖼 image / T text / ✏ draw); Layer 1 is automatically locked on first image load
|
||||
- **Layer lock** — locked layers show an orange bounding box and 🔒 icon on the canvas; move/resize/rotate are disabled while locked; click the 🔓 button in the layer row to unlock
|
||||
- **Text quality** — text layers are rendered at their measured bounding-box size; resizing with the Select tool regenerates the canvas at the new display resolution so text stays sharp
|
||||
- **Export** — Save PNG (download composite locally); **Save to Gallery** (saves to Gallery root folder with a timestamped default name `wfs-image-YYYYMMDDHHmmss`); **Send to ComfyUI** (uploads to ComfyUI input folder for use in Load Image nodes)
|
||||
- **Canvas navigation** — scroll-wheel zoom, Space + drag to pan; zoom indicator in the bottom bar
|
||||
- **Undo / Redo** — Ctrl+Z / Ctrl+Y (or toolbar buttons); keyboard shortcuts: V (Select), B (Draw), T (Text), Delete (remove selected layer when 2+ exist)
|
||||
- **Undo / Redo** — Ctrl+Z / Ctrl+Y (or toolbar buttons); keyboard shortcuts: V (Select), B (Draw), T (Text), S (Shape), Delete (remove selected layer when 2+ exist)
|
||||
|
||||
### AI TOOL Tab (v0.3.14)
|
||||
- **4-pane layout** — Translation | Chat | TOOLS | Settings; all panes always visible simultaneously; no sub-tab switching required
|
||||
@@ -349,6 +350,10 @@ Click the **camera icon** (next to the W button) in ComfyUI's top bar to capture
|
||||
|
||||
## Changelog
|
||||
|
||||
### v0.3.54
|
||||
- **Image Edit — Shape tool (S)** — new Shape tool added to the Image Edit toolbar; draw Rect, Ellipse, Line, and FreeLine shapes by dragging; each committed shape becomes an independent draw layer that can be undone in a single step; Tool Options: shape type selector, Rounded toggle (Rect/Ellipse only), Fill color + None toggle (hidden for Line/FreeLine), Stroke color + width (Stroke None hidden for Line/FreeLine where stroke is always active), Opacity slider, Undo button; blue dashed outline previews the shape during drag; keyboard shortcut **S** activates the tool
|
||||
- **Models tab — fix B/S overlay buttons not highlighting** — the Batch (B) and Stack (S) card overlay buttons failed to turn yellow after clicking because `e.currentTarget` is nulled by the browser after an `async` event handler yields at `await`; fixed by capturing `const btn = e.currentTarget` before the await in both handlers
|
||||
|
||||
### v0.3.53
|
||||
- **Image Edit Tab** — new layer-based image editing tab with Select / Draw / Text tools, multi-layer compositing, canvas zoom & pan, and Undo/Redo; text layers are sized to exact bounding-box dimensions and regenerated at display resolution on resize to prevent blurring; double-click a text layer to re-edit its content; Gallery tab gains an "Image Edit" toolbar button to send the selected image directly to the editor
|
||||
- **Image Edit — Layer lock** — lock icon (🔒/🔓) on each layer row; locked layers display an orange bounding box and ignore all Select-tool transforms; Layer 1 is auto-locked when the first image is loaded to prevent accidental moves
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
[project]
|
||||
name = "comfyui-workflow-studio"
|
||||
description = "A comprehensive workflow, asset management, and generation UI plugin for ComfyUI. Manage workflows, models, images, and prompts; batch generation and Image Feeder in the GenerateUI tab; library side panel with canvas drag & drop and AI tools."
|
||||
version = "0.3.53"
|
||||
version = "0.3.54"
|
||||
license = "MIT"
|
||||
requires-python = ">= 3.10"
|
||||
dependencies = ["jinja2"]
|
||||
|
||||
@@ -8,12 +8,14 @@ import { LayerManager, Layer } from "./image-edit/LayerManager.js";
|
||||
import { DrawTool } from "./image-edit/DrawTool.js";
|
||||
import { TextTool, TEXT_FONTS } from "./image-edit/TextTool.js";
|
||||
import { SelectTool } from "./image-edit/SelectTool.js";
|
||||
import { ShapeTool } from "./image-edit/ShapeTool.js";
|
||||
import { showToast } from "./app.js";
|
||||
|
||||
const TOOL_DEFS = [
|
||||
{ id: "select", icon: "▲", label: "Select", ready: true },
|
||||
{ id: "draw", icon: "✏", label: "Draw", ready: true },
|
||||
{ id: "text", icon: "T", label: "Text", ready: true },
|
||||
{ id: "shape", icon: "□", label: "Shape", ready: true },
|
||||
{ id: "mask", icon: "🎭", label: "Mask", ready: false },
|
||||
{ id: "blur", icon: "≈", label: "Blur", ready: false },
|
||||
{ id: "filter", icon: "★", label: "Filter", ready: false },
|
||||
@@ -47,6 +49,7 @@ class ImageEditTab {
|
||||
this._compositeMode = false;
|
||||
this._editingTextLayer = null; // テキスト再編集中のレイヤー参照
|
||||
this._initialized = false;
|
||||
this._shapeTool = null;
|
||||
}
|
||||
|
||||
// ── 初期化 ────────────────────────────────────
|
||||
@@ -77,6 +80,7 @@ class ImageEditTab {
|
||||
if (this._activeTool === "draw") this._drawTool?.deactivate();
|
||||
if (this._activeTool === "text") this._textTool?.deactivate();
|
||||
if (this._activeTool === "select") this._selectTool?.deactivate();
|
||||
if (this._activeTool === "shape") this._shapeTool?.deactivate();
|
||||
|
||||
this._activeTool = toolId;
|
||||
|
||||
@@ -101,6 +105,10 @@ class ImageEditTab {
|
||||
} else if (this._activeTool === "select" && this._selectTool) {
|
||||
this._selectTool.setCanvas(overlayCanvas);
|
||||
this._selectTool.activate();
|
||||
} else if (this._activeTool === "shape" && this._shapeTool) {
|
||||
this._shapeTool.setCanvas(overlayCanvas);
|
||||
this._shapeTool.activate();
|
||||
if (overlayCanvas) overlayCanvas.style.cursor = "crosshair";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -243,6 +251,105 @@ class ImageEditTab {
|
||||
this._textTool.italic = !this._textTool.italic; this._renderToolOptions("text");
|
||||
});
|
||||
document.getElementById("ie-text-align")?.addEventListener("change", e => { this._textTool.align = e.target.value; });
|
||||
} else if (toolId === "shape" && this._shapeTool) {
|
||||
const t = this._shapeTool;
|
||||
const isLineKind = ["line", "freeline"].includes(t.shape);
|
||||
const showRounded = ["rect", "ellipse"].includes(t.shape);
|
||||
el.innerHTML = `
|
||||
<div class="ie-opt-group">
|
||||
<label>Shape</label>
|
||||
<select id="ie-shape-kind" class="ie-opt-select">
|
||||
<option value="rect" ${t.shape==="rect" ?"selected":""}>Rect</option>
|
||||
<option value="ellipse" ${t.shape==="ellipse" ?"selected":""}>Ellipse</option>
|
||||
<option value="line" ${t.shape==="line" ?"selected":""}>Line</option>
|
||||
<option value="freeline" ${t.shape==="freeline" ?"selected":""}>FreeLine</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="ie-opt-group" id="ie-shape-rounded-wrap" style="display:${showRounded?"":"none"};">
|
||||
<label><input type="checkbox" id="ie-shape-rounded" ${t.rounded?"checked":""}> Rounded</label>
|
||||
</div>
|
||||
<div class="ie-opt-group" id="ie-shape-fill-wrap" style="display:${isLineKind?"none":""};">
|
||||
<label>Fill</label>
|
||||
<input type="checkbox" id="ie-shape-fill-none" ${t.fillNone?"checked":""}> <span style="font-size:11px;color:var(--wfm-text-secondary);">None</span>
|
||||
<input type="color" id="ie-shape-fill" value="${t.fillColor}" ${t.fillNone?"disabled":""}
|
||||
style="width:28px;height:24px;padding:0;border:1px solid var(--wfm-border);cursor:pointer;border-radius:3px;margin-left:2px;">
|
||||
</div>
|
||||
<div class="ie-opt-group">
|
||||
<label>Stroke</label>
|
||||
<div id="ie-shape-stroke-none-wrap" style="display:${isLineKind?"none":""};">
|
||||
<input type="checkbox" id="ie-shape-stroke-none" ${t.strokeNone?"checked":""}> <span style="font-size:11px;color:var(--wfm-text-secondary);">None</span>
|
||||
</div>
|
||||
<input type="color" id="ie-shape-stroke" value="${t.strokeColor}" ${(!isLineKind && t.strokeNone)?"disabled":""}
|
||||
style="width:28px;height:24px;padding:0;border:1px solid var(--wfm-border);cursor:pointer;border-radius:3px;margin-left:2px;">
|
||||
<input type="number" id="ie-shape-stroke-width" value="${t.strokeWidth}" min="1" max="200" ${(!isLineKind && t.strokeNone)?"disabled":""}
|
||||
style="width:44px;margin-left:2px;" class="ie-opt-input">
|
||||
</div>
|
||||
<div class="ie-opt-group">
|
||||
<label>Opacity</label>
|
||||
<input type="range" id="ie-shape-opacity" min="1" max="100" value="${Math.round(t.opacity*100)}" style="width:70px;">
|
||||
<span id="ie-shape-opacity-lbl">${Math.round(t.opacity*100)}%</span>
|
||||
</div>
|
||||
<div class="ie-opt-group" style="margin-left:8px;">
|
||||
<button class="wfm-btn wfm-btn-sm" id="ie-shape-undo-btn">↩ Undo</button>
|
||||
</div>
|
||||
`;
|
||||
|
||||
const _updateShapeVisibility = () => {
|
||||
const kind = document.getElementById("ie-shape-kind").value;
|
||||
const lineKind = ["line", "freeline"].includes(kind);
|
||||
const rw = document.getElementById("ie-shape-rounded-wrap");
|
||||
const fw = document.getElementById("ie-shape-fill-wrap");
|
||||
const snw = document.getElementById("ie-shape-stroke-none-wrap");
|
||||
if (rw) rw.style.display = ["rect", "ellipse"].includes(kind) ? "" : "none";
|
||||
if (fw) fw.style.display = lineKind ? "none" : "";
|
||||
if (snw) snw.style.display = lineKind ? "none" : "";
|
||||
if (lineKind) {
|
||||
// fill は不要
|
||||
document.getElementById("ie-shape-fill-none").checked = true;
|
||||
document.getElementById("ie-shape-fill").disabled = true;
|
||||
t.fillNone = true;
|
||||
// stroke は常に有効
|
||||
document.getElementById("ie-shape-stroke").disabled = false;
|
||||
document.getElementById("ie-shape-stroke-width").disabled = false;
|
||||
} else {
|
||||
// rect / ellipse: strokeNone に従って再適用
|
||||
const sn = document.getElementById("ie-shape-stroke-none").checked;
|
||||
document.getElementById("ie-shape-stroke").disabled = sn;
|
||||
document.getElementById("ie-shape-stroke-width").disabled = sn;
|
||||
}
|
||||
};
|
||||
|
||||
document.getElementById("ie-shape-kind")?.addEventListener("change", e => {
|
||||
t.shape = e.target.value;
|
||||
_updateShapeVisibility();
|
||||
});
|
||||
document.getElementById("ie-shape-rounded")?.addEventListener("change", e => {
|
||||
t.rounded = e.target.checked;
|
||||
});
|
||||
document.getElementById("ie-shape-fill-none")?.addEventListener("change", e => {
|
||||
t.fillNone = e.target.checked;
|
||||
document.getElementById("ie-shape-fill").disabled = e.target.checked;
|
||||
});
|
||||
document.getElementById("ie-shape-fill")?.addEventListener("input", e => {
|
||||
t.fillColor = e.target.value;
|
||||
});
|
||||
document.getElementById("ie-shape-stroke-none")?.addEventListener("change", e => {
|
||||
t.strokeNone = e.target.checked;
|
||||
document.getElementById("ie-shape-stroke").disabled = e.target.checked;
|
||||
document.getElementById("ie-shape-stroke-width").disabled = e.target.checked;
|
||||
});
|
||||
document.getElementById("ie-shape-stroke")?.addEventListener("input", e => {
|
||||
t.strokeColor = e.target.value;
|
||||
});
|
||||
document.getElementById("ie-shape-stroke-width")?.addEventListener("input", e => {
|
||||
t.strokeWidth = parseFloat(e.target.value) || 1;
|
||||
});
|
||||
document.getElementById("ie-shape-opacity")?.addEventListener("input", e => {
|
||||
t.opacity = parseInt(e.target.value) / 100;
|
||||
document.getElementById("ie-shape-opacity-lbl").textContent = e.target.value + "%";
|
||||
});
|
||||
document.getElementById("ie-shape-undo-btn")?.addEventListener("click", () => this._undo());
|
||||
|
||||
} else {
|
||||
const def = TOOL_DEFS.find(d => d.id === toolId);
|
||||
el.innerHTML = `<span style="font-size:12px;color:var(--wfm-text-secondary);">${def?.label ?? toolId}: coming soon</span>`;
|
||||
@@ -342,6 +449,9 @@ class ImageEditTab {
|
||||
this._loadActiveLayerToCanvas();
|
||||
this._drawTool.onMouseDown(pos.x, pos.y);
|
||||
|
||||
} else if (this._activeTool === "shape" && this._shapeTool) {
|
||||
this._shapeTool.onMouseDown(pos.x, pos.y);
|
||||
|
||||
} else if (this._activeTool === "text" && this._textTool) {
|
||||
// undo・drawCanvasリセットはテキスト確定時(onChange)で行う
|
||||
this._textTool.onMouseDown(pos.x, pos.y);
|
||||
@@ -362,17 +472,20 @@ class ImageEditTab {
|
||||
if (!this._layerMgr) return;
|
||||
const pos = DrawTool.getCanvasPos(refCanvas, e);
|
||||
if (this._activeTool === "draw") this._drawTool?.onMouseMove(pos.x, pos.y);
|
||||
if (this._activeTool === "shape") this._shapeTool?.onMouseMove(pos.x, pos.y);
|
||||
if (this._activeTool === "select") this._selectTool?.onMouseMove(pos.x, pos.y);
|
||||
}
|
||||
|
||||
_onToolMouseUp(e) {
|
||||
if (!this._layerMgr || e.button !== 0) return;
|
||||
if (this._activeTool === "draw") this._drawTool?.onMouseUp();
|
||||
if (this._activeTool === "shape") this._shapeTool?.onMouseUp();
|
||||
if (this._activeTool === "select") this._selectTool?.onMouseUp();
|
||||
}
|
||||
|
||||
_onToolMouseLeave() {
|
||||
if (this._activeTool === "draw") this._drawTool?.onMouseLeave();
|
||||
if (this._activeTool === "shape") this._shapeTool?.onMouseLeave();
|
||||
if (this._activeTool === "select") this._selectTool?.onMouseLeave();
|
||||
}
|
||||
|
||||
@@ -547,6 +660,21 @@ class ImageEditTab {
|
||||
this._refreshLayerList();
|
||||
});
|
||||
|
||||
this._shapeTool = new ShapeTool();
|
||||
this._shapeTool.onChange(shapeObj => {
|
||||
this._saveUndo();
|
||||
const layerName = `Shape ${this._layerMgr.layers.length + 1}`;
|
||||
const layer = this._layerMgr.addLayer("draw", layerName, {
|
||||
contentW: this._canvasW, contentH: this._canvasH,
|
||||
displayW: this._canvasW, displayH: this._canvasH,
|
||||
x: 0, y: 0,
|
||||
});
|
||||
ShapeTool.drawShape(layer.ctx, shapeObj);
|
||||
this._layerMgr.setActive(layer.id);
|
||||
this._updateCompositeView();
|
||||
this._refreshLayerList();
|
||||
});
|
||||
|
||||
this._selectTool = new SelectTool();
|
||||
this._selectTool.setCanvas(overlayCanvas);
|
||||
this._selectTool.onChange(eventType => {
|
||||
@@ -885,6 +1013,7 @@ class ImageEditTab {
|
||||
if (e.key === "v") this._setActiveTool("select");
|
||||
if (e.key === "b") this._setActiveTool("draw");
|
||||
if (e.key === "t") this._setActiveTool("text");
|
||||
if (e.key === "s") this._setActiveTool("shape");
|
||||
// Delete/Backspaceで選択オブジェクト削除
|
||||
if ((e.key === "Delete" || e.key === "Backspace") && this._activeTool === "select") {
|
||||
const layer = this._selectTool?.getSelectedLayer();
|
||||
|
||||
@@ -0,0 +1,229 @@
|
||||
/**
|
||||
* ShapeTool — rect / ellipse / line / freeline drawing tool for Image Edit tab.
|
||||
* Preview is drawn on the overlay canvas; committed shapes become new draw layers.
|
||||
*/
|
||||
export class ShapeTool {
|
||||
constructor() {
|
||||
// shape settings
|
||||
this.shape = "rect";
|
||||
this.rounded = false;
|
||||
this.fillColor = "#ff0000";
|
||||
this.fillNone = false;
|
||||
this.strokeColor = "#000000";
|
||||
this.strokeNone = true;
|
||||
this.strokeWidth = 5;
|
||||
this.opacity = 1.0;
|
||||
|
||||
// internal state
|
||||
this._active = false;
|
||||
this._canvas = null; // overlay canvas (preview)
|
||||
this._ctx = null;
|
||||
this._dragging = false;
|
||||
this._dragStart = null;
|
||||
this._curPt = null;
|
||||
this._points = []; // freeline points
|
||||
|
||||
this._onChange = null;
|
||||
}
|
||||
|
||||
// overlay canvas used for live preview
|
||||
setCanvas(canvas) {
|
||||
this._canvas = canvas;
|
||||
this._ctx = canvas ? canvas.getContext("2d") : null;
|
||||
}
|
||||
|
||||
onChange(cb) { this._onChange = cb; }
|
||||
|
||||
activate() {
|
||||
this._active = true;
|
||||
}
|
||||
|
||||
deactivate() {
|
||||
this._active = false;
|
||||
this._dragging = false;
|
||||
this._clearOverlay();
|
||||
if (this._canvas) this._canvas.style.cursor = "";
|
||||
}
|
||||
|
||||
onMouseDown(x, y) {
|
||||
if (!this._active) return;
|
||||
this._dragging = true;
|
||||
this._dragStart = { x, y };
|
||||
this._curPt = { x, y };
|
||||
this._points = this.shape === "freeline" ? [{ x, y }] : [];
|
||||
}
|
||||
|
||||
onMouseMove(x, y) {
|
||||
if (!this._dragging) return;
|
||||
this._curPt = { x, y };
|
||||
if (this.shape === "freeline") this._points.push({ x, y });
|
||||
this._drawPreview(x, y);
|
||||
}
|
||||
|
||||
onMouseUp() {
|
||||
if (!this._dragging) return;
|
||||
this._dragging = false;
|
||||
this._clearOverlay();
|
||||
this._commit();
|
||||
}
|
||||
|
||||
onMouseLeave() {
|
||||
if (!this._dragging) return;
|
||||
this._dragging = false;
|
||||
this._clearOverlay();
|
||||
this._commit();
|
||||
}
|
||||
|
||||
// ── private ───────────────────────────────────────
|
||||
|
||||
_clearOverlay() {
|
||||
if (this._ctx && this._canvas) {
|
||||
this._ctx.clearRect(0, 0, this._canvas.width, this._canvas.height);
|
||||
}
|
||||
}
|
||||
|
||||
_drawPreview(curX, curY) {
|
||||
if (!this._ctx || !this._canvas) return;
|
||||
const ctx = this._ctx;
|
||||
ctx.clearRect(0, 0, this._canvas.width, this._canvas.height);
|
||||
|
||||
const s = this._dragStart;
|
||||
ctx.save();
|
||||
ctx.globalAlpha = this.opacity;
|
||||
|
||||
if (this.shape === "freeline") {
|
||||
// freeline: always draw with stroke color (strokeNone has no meaning here)
|
||||
if (this._points.length >= 2) {
|
||||
ctx.strokeStyle = this.strokeColor;
|
||||
ctx.lineWidth = this.strokeWidth;
|
||||
ctx.lineCap = "round";
|
||||
ctx.lineJoin = "round";
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(this._points[0].x, this._points[0].y);
|
||||
for (let i = 1; i < this._points.length; i++) ctx.lineTo(this._points[i].x, this._points[i].y);
|
||||
ctx.stroke();
|
||||
}
|
||||
} else {
|
||||
// dashed blue outline for rect / ellipse / line
|
||||
ctx.strokeStyle = "#0077ff";
|
||||
ctx.lineWidth = Math.max(1, this.strokeWidth || 1);
|
||||
ctx.setLineDash([4, 2]);
|
||||
|
||||
const x1 = Math.min(s.x, curX), y1 = Math.min(s.y, curY);
|
||||
const w = Math.abs(curX - s.x), h = Math.abs(curY - s.y);
|
||||
|
||||
if (this.shape === "ellipse") {
|
||||
ctx.beginPath();
|
||||
ctx.ellipse(x1 + w / 2, y1 + h / 2, w / 2, h / 2, 0, 0, Math.PI * 2);
|
||||
ctx.stroke();
|
||||
} else if (this.shape === "line") {
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(s.x, s.y);
|
||||
ctx.lineTo(curX, curY);
|
||||
ctx.stroke();
|
||||
} else {
|
||||
// rect
|
||||
if (this.rounded) {
|
||||
const r = Math.min(w, h) * 0.15;
|
||||
ctx.beginPath();
|
||||
ctx.roundRect(x1, y1, w, h, r);
|
||||
ctx.stroke();
|
||||
} else {
|
||||
ctx.strokeRect(x1, y1, w, h);
|
||||
}
|
||||
}
|
||||
ctx.setLineDash([]);
|
||||
}
|
||||
ctx.restore();
|
||||
}
|
||||
|
||||
_commit() {
|
||||
const s = this._dragStart, c = this._curPt;
|
||||
if (!s || !c) return;
|
||||
|
||||
const isFreehand = this.shape === "freeline";
|
||||
const dx = Math.abs(c.x - s.x), dy = Math.abs(c.y - s.y);
|
||||
if (!isFreehand && dx < 2 && dy < 2) return;
|
||||
if (isFreehand && this._points.length < 2) return;
|
||||
|
||||
const isStrokeMandatory = ["line", "freeline"].includes(this.shape);
|
||||
const shapeObj = {
|
||||
kind: this.shape,
|
||||
s: { ...s },
|
||||
c: { ...c },
|
||||
points: isFreehand ? this._points.map(p => ({ ...p })) : [],
|
||||
fillColor: this.fillNone ? null : this.fillColor,
|
||||
// line / freeline always use stroke; ignore strokeNone
|
||||
strokeColor: (isStrokeMandatory || !this.strokeNone) ? this.strokeColor : null,
|
||||
strokeWidth: (isStrokeMandatory || !this.strokeNone) ? this.strokeWidth : 0,
|
||||
opacity: this.opacity,
|
||||
rounded: this.rounded,
|
||||
};
|
||||
|
||||
this._onChange?.(shapeObj);
|
||||
}
|
||||
|
||||
// ── static renderer (used by onChange callback to bake shape into layer) ──
|
||||
|
||||
static drawShape(ctx, sh) {
|
||||
const { kind, s, c, points, fillColor, strokeColor, strokeWidth, opacity, rounded } = sh;
|
||||
ctx.save();
|
||||
ctx.globalAlpha = opacity ?? 1;
|
||||
|
||||
if (kind === "freeline") {
|
||||
if (strokeColor && strokeWidth > 0 && points.length >= 2) {
|
||||
ctx.strokeStyle = strokeColor;
|
||||
ctx.lineWidth = strokeWidth;
|
||||
ctx.lineCap = "round";
|
||||
ctx.lineJoin = "round";
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(points[0].x, points[0].y);
|
||||
for (let i = 1; i < points.length; i++) ctx.lineTo(points[i].x, points[i].y);
|
||||
ctx.stroke();
|
||||
}
|
||||
} else if (kind === "ellipse") {
|
||||
const x1 = Math.min(s.x, c.x), y1 = Math.min(s.y, c.y);
|
||||
const w = Math.abs(c.x - s.x), h = Math.abs(c.y - s.y);
|
||||
ctx.beginPath();
|
||||
ctx.ellipse(x1 + w / 2, y1 + h / 2, w / 2, h / 2, 0, 0, Math.PI * 2);
|
||||
if (fillColor) { ctx.fillStyle = fillColor; ctx.fill(); }
|
||||
if (strokeColor && strokeWidth > 0) { ctx.strokeStyle = strokeColor; ctx.lineWidth = strokeWidth; ctx.stroke(); }
|
||||
} else if (kind === "line") {
|
||||
if (strokeColor && strokeWidth > 0) {
|
||||
ctx.strokeStyle = strokeColor;
|
||||
ctx.lineWidth = strokeWidth;
|
||||
ctx.lineCap = "round";
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(s.x, s.y);
|
||||
ctx.lineTo(c.x, c.y);
|
||||
ctx.stroke();
|
||||
}
|
||||
} else {
|
||||
// rect
|
||||
const x1 = Math.min(s.x, c.x), y1 = Math.min(s.y, c.y);
|
||||
const w = Math.abs(c.x - s.x), h = Math.abs(c.y - s.y);
|
||||
if (rounded) {
|
||||
const r = Math.min(w, h) * 0.15;
|
||||
ctx.beginPath();
|
||||
ctx.roundRect(x1, y1, w, h, r);
|
||||
} else {
|
||||
ctx.beginPath();
|
||||
ctx.rect(x1, y1, w, h);
|
||||
}
|
||||
if (fillColor) { ctx.fillStyle = fillColor; ctx.fill(); }
|
||||
if (strokeColor && strokeWidth > 0) { ctx.strokeStyle = strokeColor; ctx.lineWidth = strokeWidth; ctx.stroke(); }
|
||||
}
|
||||
ctx.restore();
|
||||
}
|
||||
|
||||
// coordinate helper (same signature as DrawTool.getCanvasPos)
|
||||
static getCanvasPos(canvas, event) {
|
||||
const rect = canvas.getBoundingClientRect();
|
||||
const scaleX = canvas.width / rect.width;
|
||||
const scaleY = canvas.height / rect.height;
|
||||
return {
|
||||
x: (event.clientX - rect.left) * scaleX,
|
||||
y: (event.clientY - rect.top) * scaleY,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1075,17 +1075,19 @@ function renderThumbView(grid, models) {
|
||||
|
||||
card.querySelector(".wfm-batch-btn")?.addEventListener("click", async (e) => {
|
||||
e.stopPropagation();
|
||||
const btn = e.currentTarget;
|
||||
await toggleBatch(modelName);
|
||||
if (state.showBatchOnly) {
|
||||
renderModelGrid();
|
||||
} else {
|
||||
e.currentTarget.classList.toggle("active", isInBatch(modelName));
|
||||
btn.classList.toggle("active", isInBatch(modelName));
|
||||
}
|
||||
});
|
||||
card.querySelector(".wfm-stack-btn")?.addEventListener("click", async (e) => {
|
||||
e.stopPropagation();
|
||||
const btn = e.currentTarget;
|
||||
await toggleStack(modelName);
|
||||
e.currentTarget.classList.toggle("active", isInStack(modelName));
|
||||
btn.classList.toggle("active", isInStack(modelName));
|
||||
});
|
||||
card.querySelector(".wfm-fav-btn").addEventListener("click", (e) => {
|
||||
e.stopPropagation();
|
||||
|
||||
@@ -1269,6 +1269,7 @@
|
||||
<li><b>Select (V):</b> click to select a layer; drag to move; drag corner handles to resize; drag the circle above the top edge to rotate; double-click a text layer to re-edit its content; Tool Options bar shows Flip H / Flip V / Rotate field</li>
|
||||
<li><b>Draw (B):</b> freehand brush drawing onto the active draw layer; Tool Options: color, brush size, blend mode</li>
|
||||
<li><b>Text (T):</b> click on the canvas to place a text input overlay; configure font family, size, bold/italic, align, color in the Tool Options bar; click OK to place the text as an exact-size Text layer; double-click an existing text layer with the Select tool to re-edit</li>
|
||||
<li><b>Shape (S):</b> draw geometric shapes onto the canvas; each committed shape becomes an independent draw layer; Tool Options: <b>Shape</b> type (Rect / Ellipse / Line / FreeLine), <b>Rounded</b> checkbox (Rect / Ellipse only), <b>Fill</b> color + None toggle (hidden for Line / FreeLine), <b>Stroke</b> color + width + None toggle (None hidden for Line / FreeLine where stroke is always active), <b>Opacity</b> slider, <b>↩ Undo</b> button; drag to draw — a blue dashed outline previews the shape; release to commit</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="wfm-help-card">
|
||||
@@ -1306,6 +1307,7 @@
|
||||
<li><b>V</b>: Select tool</li>
|
||||
<li><b>B</b>: Draw tool</li>
|
||||
<li><b>T</b>: Text tool</li>
|
||||
<li><b>S</b>: Shape tool</li>
|
||||
<li><b>Delete</b>: Delete selected layer (requires 2+ layers)</li>
|
||||
<li><b>Ctrl+Z / Ctrl+Y</b>: Undo / Redo</li>
|
||||
<li><b>Space + drag</b>: Pan canvas</li>
|
||||
@@ -1331,6 +1333,7 @@
|
||||
<li>V: Select tool</li>
|
||||
<li>B: Draw tool</li>
|
||||
<li>T: Text tool</li>
|
||||
<li>S: Shape tool</li>
|
||||
<li>Delete: Delete selected layer (requires 2+ layers)</li>
|
||||
<li>Ctrl+Z / Ctrl+Y: Undo / Redo</li>
|
||||
<li>Space + drag: Pan canvas</li>
|
||||
@@ -1528,6 +1531,7 @@
|
||||
<button class="ie-tool-btn active" data-tool="select" title="Select (V)">▲</button>
|
||||
<button class="ie-tool-btn" data-tool="draw" title="Draw (B)">✏</button>
|
||||
<button class="ie-tool-btn" data-tool="text" title="Text (T)">T</button>
|
||||
<button class="ie-tool-btn" data-tool="shape" title="Shape (S)">□</button>
|
||||
<button class="ie-tool-btn ie-tool-placeholder" data-tool="mask" title="Mask">🎭</button>
|
||||
<button class="ie-tool-btn ie-tool-placeholder" data-tool="blur" title="Blur">≈</button>
|
||||
<button class="ie-tool-btn ie-tool-placeholder" data-tool="filter" title="Filter">★</button>
|
||||
|
||||
Reference in New Issue
Block a user