feat: 优化填充组图层背景命令,重构填充对象创建逻辑
This commit is contained in:
@@ -123,29 +123,42 @@ export class FillGroupLayerBackgroundCommand extends Command {
|
|||||||
scaleX: clippingMaskFabricObject.scaleX || 1,
|
scaleX: clippingMaskFabricObject.scaleX || 1,
|
||||||
scaleY: clippingMaskFabricObject.scaleY || 1,
|
scaleY: clippingMaskFabricObject.scaleY || 1,
|
||||||
});
|
});
|
||||||
this.newFill.clipPath = clippingMaskFabricObject; // 设置填充的遮罩
|
} else {
|
||||||
this.newFill.dirty = true; // 标记为脏,以便重新
|
this.newFill = new fabric.Rect({
|
||||||
this.canvas.add(this.newFill);
|
width: this.canvasManager?.canvasWidth?.value || this.canvas.width,
|
||||||
this.firstObj = this.newFill;
|
height: this.canvasManager?.canvasHeight?.value || this.canvas.height,
|
||||||
layer.fabricObjects = [
|
left: this.canvas.width / 2 || 0,
|
||||||
this.newFill.toObject(["id", "layerId"]) || this.newFill,
|
top: this.canvas.height / 2 || 0,
|
||||||
];
|
fill: this.fillColor,
|
||||||
layer.fill = null; // this.newFill.toObject(["id", "layerId"]);
|
layerId: this.layerId,
|
||||||
layer.fillColor = this.fillColor;
|
id: this.oldFill?.id || generateId("fill-"),
|
||||||
// 取消激活对象
|
selectable: false,
|
||||||
|
evented: false,
|
||||||
this.canvas.discardActiveObject(); // 取消当前活动对象
|
originX: "center",
|
||||||
// 重新排序
|
originY: "center",
|
||||||
await this.layerManager?.sortLayersWithTool?.();
|
});
|
||||||
// 更新画布上对象的可选择状态
|
|
||||||
await this.layerManager?.updateLayersObjectsInteractivity?.();
|
|
||||||
this.canvas.renderAll();
|
|
||||||
|
|
||||||
this.canvasManager.thumbnailManager?.generateLayerThumbnail(
|
|
||||||
this.layer.id
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
this.newFill.clipPath = clippingMaskFabricObject; // 设置填充的遮罩
|
||||||
|
this.newFill.dirty = true; // 标记为脏,以便重新
|
||||||
|
this.canvas.add(this.newFill);
|
||||||
|
this.firstObj = this.newFill;
|
||||||
|
layer.fabricObjects = [
|
||||||
|
this.newFill.toObject(["id", "layerId"]) || this.newFill,
|
||||||
|
];
|
||||||
|
layer.fill = null; // this.newFill.toObject(["id", "layerId"]);
|
||||||
|
layer.fillColor = this.fillColor;
|
||||||
|
// 取消激活对象
|
||||||
|
|
||||||
|
this.canvas.discardActiveObject(); // 取消当前活动对象
|
||||||
|
// 重新排序
|
||||||
|
await this.layerManager?.sortLayersWithTool?.();
|
||||||
|
// 更新画布上对象的可选择状态
|
||||||
|
await this.layerManager?.updateLayersObjectsInteractivity?.();
|
||||||
|
this.canvas.renderAll();
|
||||||
|
|
||||||
|
this.canvasManager.thumbnailManager?.generateLayerThumbnail(
|
||||||
|
this.layer.id
|
||||||
|
);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const canvasObj = findObjectById(this.canvas, firstObj?.id)?.object;
|
const canvasObj = findObjectById(this.canvas, firstObj?.id)?.object;
|
||||||
|
|||||||
Reference in New Issue
Block a user