feat(image-annotate): 选区编辑 + 便利版 UI + 单张输出预设(1.1.0)
This commit is contained in:
1 parent
b9ace636ef
commit
662d7eae77
22 files changed
+3795
-343
No files matched your search
@@ -38,28 +38,20 @@ import { updateCursor } from './events.js'
|
||||
drawPlacementPreview()
|
||||
}
|
||||
|
||||
/** 确认图片放置:创建新位图图层并绘制图片 */
|
||||
export function confirmImagePlacement() {
|
||||
if (!S.placingImage) return
|
||||
const { img, x, y, w, h } = S.placingImage
|
||||
const placementRotation = S.placingImage.rotation || 0
|
||||
S.placingImage = null
|
||||
S.placingHandle = null
|
||||
S.placingStart = null
|
||||
clearOverlay()
|
||||
// 创建图层
|
||||
/** 图片参数 → 新位图图层(放置确认与「直接落层」共用) */
|
||||
function commitImageAsLayer(img, x, y, w, h, rotation) {
|
||||
const id = 'L' + Date.now() + Math.floor(Math.random() * 1000)
|
||||
const canvas = createLayerCanvas()
|
||||
const ctx = canvas.getContext('2d', { willReadFrequently: true })
|
||||
ctx.clearRect(0, 0, S.imgW, S.imgH)
|
||||
const layer = {
|
||||
id,
|
||||
name: '图层 ' + (S.layers.length + 1), image: img, x, y, w, h, rotation: placementRotation, transformable: true,
|
||||
name: '图层 ' + (S.layers.length + 1), image: img, x, y, w, h, rotation: rotation || 0, transformable: true,
|
||||
canvas,
|
||||
ctx,
|
||||
opacity: 1,
|
||||
visible: true,
|
||||
locked: false,
|
||||
locked: false,
|
||||
// 与矢量对象 / 空白图层共用同一个 z 计数器(旧值 S.layers.length 会和 ++S.zCounter 撞车,
|
||||
// 导致粘贴的截图与图形 z 相同:排序按钮交换 z 无效、命中测试选错对象)
|
||||
z: ++S.zCounter
|
||||
@@ -71,9 +63,41 @@ import { updateCursor } from './events.js'
|
||||
setActiveLayer(id)
|
||||
updateLayerCanvasStyles()
|
||||
renderLayerPanel()
|
||||
return layer
|
||||
}
|
||||
|
||||
/** 确认图片放置:创建新位图图层并绘制图片 */
|
||||
export function confirmImagePlacement() {
|
||||
if (!S.placingImage) return
|
||||
const { img, x, y, w, h } = S.placingImage
|
||||
const placementRotation = S.placingImage.rotation || 0
|
||||
S.placingImage = null
|
||||
S.placingHandle = null
|
||||
S.placingStart = null
|
||||
clearOverlay()
|
||||
commitImageAsLayer(img, x, y, w, h, placementRotation)
|
||||
updateCursor()
|
||||
}
|
||||
|
||||
/**
|
||||
* 便利版:粘贴 / 导入图片一步落层,不再要求 Enter 二次确认。
|
||||
* 默认原大但不超过画布 50%、居中;要调整大小/位置直接切选择工具拖手柄。
|
||||
* 整步有快照,Ctrl+Z 可撤销,Esc 也能当作「后悔」的兜底。
|
||||
*/
|
||||
export function placeImageDirectly(img) {
|
||||
const iw = img.naturalWidth || img.width
|
||||
const ih = img.naturalHeight || img.height
|
||||
const ratio = Math.min((S.imgW * 0.5) / iw, (S.imgH * 0.5) / ih, 1)
|
||||
const w = Math.max(10, Math.round(iw * ratio))
|
||||
const h = Math.max(10, Math.round(ih * ratio))
|
||||
const layer = commitImageAsLayer(img, Math.round((S.imgW - w) / 2), Math.round((S.imgH - h) / 2), w, h, 0)
|
||||
// 粘贴常发生在刚点过工具按钮之后;若焦点还停在按钮上,用户习惯性补按 Enter
|
||||
// 会激活那个按钮(最坏情况是「还原原图」)。落层后主动把焦点还给画布。
|
||||
try { if (document.activeElement && document.activeElement.blur) document.activeElement.blur() } catch (e) { /* ignore */ }
|
||||
if (S.renderAll) S.renderAll()
|
||||
return layer
|
||||
}
|
||||
|
||||
/** 取消图片放置 */
|
||||
export function cancelImagePlacement() {
|
||||
S.placingImage = null
|
||||
|
||||
Reference in new issue
Block a user