深度画布调整属性设置
This commit is contained in:
@@ -101,6 +101,10 @@ export class AISelectboxToolManager {
|
||||
this.canvasManager.canvas.remove(this.indicatorObject)
|
||||
this.indicatorObject = null
|
||||
}
|
||||
resetDemoObject() {
|
||||
this.clearDemoObject()
|
||||
this.createDemoObject()
|
||||
}
|
||||
// 创建临时画布对象
|
||||
async createStaticCanvas(object: fabric.Object) {
|
||||
if (!this.demoObject) this.createDemoObject()
|
||||
|
||||
@@ -3,7 +3,7 @@ import { fabric } from 'fabric-with-all'
|
||||
import { createId } from '../../tools/tools'
|
||||
import { exportObjectsToImage, exportObjectToThumbnail } from '../tools/exportMethod'
|
||||
import { OperationType, BlendMode } from '../tools/layerHelper'
|
||||
import { getArrowPath, cloneObjects, getStarArr } from '../tools/canvasMethod'
|
||||
import { getArrowPath, getLinePath, cloneObjects, getStarArr } from '../tools/canvasMethod'
|
||||
|
||||
export class LayerManager {
|
||||
stateManager: any
|
||||
@@ -274,25 +274,27 @@ export class LayerManager {
|
||||
}
|
||||
/** 创建直线图层 */
|
||||
async createLineLayer(options?: any, isRecord = true, isActive = true) {
|
||||
const line = [options?.x1 || 0, options?.y1 || 0, options?.x2 || 100, options?.y2 || 0]
|
||||
delete options.x1
|
||||
delete options.y1
|
||||
delete options.x2
|
||||
delete options.y2
|
||||
const lineObject = new fabric.Line(line, {
|
||||
stroke: 'black', // 线条颜色
|
||||
strokeWidth: 2, // 线条粗细
|
||||
const width = options?.width || 100
|
||||
const height = options?.height || 2
|
||||
delete options.width
|
||||
delete options.height
|
||||
const arrowObject = new fabric.Path(getLinePath(width, height), {
|
||||
stroke: '#000', // 只设置边框颜色
|
||||
strokeWidth: 2, // 边框宽度
|
||||
fill: 'transparent', // 不填充
|
||||
strokeLineCap: 'round',
|
||||
strokeLineJoin: 'round',
|
||||
...(options || {}),
|
||||
info: {
|
||||
id: createId("line"),
|
||||
name: '直线图层',
|
||||
...(options?.info || {}),
|
||||
}
|
||||
})
|
||||
this.setLayerPosition(lineObject, options)
|
||||
await this.canvasManager.add(lineObject, isRecord)
|
||||
if (isActive) this.setActiveID(lineObject.info.id)
|
||||
return lineObject
|
||||
});
|
||||
this.setLayerPosition(arrowObject, options)
|
||||
await this.canvasManager.add(arrowObject, isRecord)
|
||||
if (isActive) this.setActiveID(arrowObject.info.id)
|
||||
return arrowObject
|
||||
}
|
||||
/** 创建椭圆图层 */
|
||||
async createEllipseLayer(options?: any, isRecord = true, isActive = true) {
|
||||
@@ -353,18 +355,18 @@ export class LayerManager {
|
||||
/** 创建箭头图层 */
|
||||
async createArrowLayer(options?: any, isRecord = true, isActive = true) {
|
||||
const width = options?.width || 100
|
||||
const height = options?.height || 10
|
||||
const strokeWidth = options?.strokeWidth || 4
|
||||
delete options.width
|
||||
delete options.height
|
||||
const arrowObject = new fabric.Path(getArrowPath(width, height), {
|
||||
delete options.strokeWidth
|
||||
const arrowObject = new fabric.Path(getArrowPath(width, strokeWidth), {
|
||||
stroke: '#000', // 只设置边框颜色
|
||||
strokeWidth: 3, // 边框宽度
|
||||
strokeWidth, // 边框宽度
|
||||
fill: 'transparent', // 不填充
|
||||
strokeLineCap: 'round',
|
||||
strokeLineJoin: 'round',
|
||||
...(options || {}),
|
||||
info: {
|
||||
id: createId("star"),
|
||||
id: createId("arrow"),
|
||||
name: '箭头图层',
|
||||
...(options?.info || {}),
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { OperationType, OperationTypes } from "../tools/layerHelper";
|
||||
import { getStarArr, getArrowPath, distance, angleBetweenPointsDegrees } from "../tools/canvasMethod";
|
||||
import { getStarArr, getArrowPath, getLinePath, distance, angleBetweenPointsDegrees } from "../tools/canvasMethod";
|
||||
import { fabric } from 'fabric-with-all'
|
||||
/** 形状管理器 */
|
||||
export class ShapeToolManager {
|
||||
@@ -136,22 +136,47 @@ export class ShapeToolManager {
|
||||
|
||||
/** 绘制直线 */
|
||||
downLine() {
|
||||
const line = new fabric.Line([this.startX, this.startY, this.startX, this.startY], {
|
||||
stroke: 'black', // 线条颜色
|
||||
strokeWidth: 2 // 线条粗细
|
||||
})
|
||||
return line
|
||||
// const line = new fabric.Line([this.startX, this.startY, this.startX, this.startY], {
|
||||
// stroke: 'black', // 线条颜色
|
||||
// strokeWidth: 2 // 线条粗细
|
||||
// })
|
||||
// return line
|
||||
return new fabric.Path();
|
||||
}
|
||||
moveLine({ x, y }) {
|
||||
this.demoObject.set({
|
||||
x1: this.startX,
|
||||
y1: this.startY,
|
||||
x2: x,
|
||||
y2: y,
|
||||
})
|
||||
// this.demoObject.set({
|
||||
// x1: this.startX,
|
||||
// y1: this.startY,
|
||||
// x2: x,
|
||||
// y2: y,
|
||||
// })
|
||||
const width = distance(this.startX, this.startY, x, y)
|
||||
const angle = angleBetweenPointsDegrees(this.startX, this.startY, x, y)
|
||||
this.canvasManager.canvas.remove(this.demoObject)
|
||||
const arrow = new fabric.Path(getLinePath(width, 2), {
|
||||
left: this.startX,
|
||||
top: this.startY,
|
||||
stroke: '#000', // 只设置边框颜色
|
||||
strokeWidth: 2, // 边框宽度
|
||||
fill: 'transparent', // 不填充
|
||||
strokeLineCap: 'round',
|
||||
strokeLineJoin: 'round',
|
||||
originY: 'center',
|
||||
angle: angle,
|
||||
});
|
||||
this.canvasManager.canvas.add(arrow)
|
||||
this.demoObject = arrow
|
||||
}
|
||||
upLine(object) {
|
||||
this.layerManager.createLineLayer(object)
|
||||
if (object.originY !== "center") {
|
||||
this.layerManager.createLineLayer({
|
||||
left: this.startX,
|
||||
top: this.startY,
|
||||
})
|
||||
} else {
|
||||
this.layerManager.createLineLayer(object)
|
||||
}
|
||||
// this.layerManager.createLineLayer(object)
|
||||
}
|
||||
|
||||
/** 绘制椭圆 */
|
||||
@@ -228,11 +253,11 @@ export class ShapeToolManager {
|
||||
const width = distance(this.startX, this.startY, x, y)
|
||||
const angle = angleBetweenPointsDegrees(this.startX, this.startY, x, y)
|
||||
this.canvasManager.canvas.remove(this.demoObject)
|
||||
const arrow = new fabric.Path(getArrowPath(width, 10), {
|
||||
const arrow = new fabric.Path(getArrowPath(width, 4), {
|
||||
left: this.startX,
|
||||
top: this.startY,
|
||||
stroke: '#000', // 只设置边框颜色
|
||||
strokeWidth: 3, // 边框宽度
|
||||
strokeWidth: 4, // 边框宽度
|
||||
fill: 'transparent', // 不填充
|
||||
strokeLineCap: 'round',
|
||||
strokeLineJoin: 'round',
|
||||
@@ -247,7 +272,7 @@ export class ShapeToolManager {
|
||||
this.layerManager.createArrowLayer({
|
||||
left: this.startX,
|
||||
top: this.startY,
|
||||
}, true)
|
||||
})
|
||||
} else {
|
||||
this.layerManager.createArrowLayer(object)
|
||||
}
|
||||
|
||||
@@ -73,7 +73,6 @@ export class StateManager {
|
||||
/** 记录状态 */
|
||||
recordState() {
|
||||
if (this.running.value) return
|
||||
console.log("recordState")
|
||||
this.running.value = true
|
||||
if (this.historyIndex.value < this.historyList.value.length - 1) {
|
||||
this.historyList.value.splice(this.historyIndex.value + 1)
|
||||
|
||||
Reference in New Issue
Block a user