fix: 修复多个已知问题

This commit is contained in:
bighuixiang
2025-06-29 23:29:47 +08:00
parent 6fc2a8fc57
commit 4a95f27966
41 changed files with 2266 additions and 351 deletions

View File

@@ -18,7 +18,7 @@ import { CustomPenBrush } from "./types/CustomPenBrush";
import { RibbonBrush } from "./types/RibbonBrush";
import { ShadedBrush } from "./types/ShadedBrush";
// import { SketchyBrush } from "./types/SketchyBrush";
import { SpraypaintBrush } from "./types/SpraypaintBrush";
// import { SpraypaintBrush } from "./types/SpraypaintBrush";
/**
* 笔刷管理器
@@ -116,53 +116,53 @@ export class BrushManager {
category: "基础笔刷",
});
// brushRegistry.register("sketchy", SketchyBrush);
brushRegistry.register("spraypaint", SpraypaintBrush, {
name: "Spraypaint",
description: "喷漆笔刷,模拟喷漆效果",
category: "基础笔刷",
});
// brushRegistry.register("spraypaint", SpraypaintBrush, {
// name: "Spraypaint",
// description: "喷漆笔刷,模拟喷漆效果",
// category: "基础笔刷",
// });
// // 注册喷枪笔刷
// brushRegistry.register(
// "spray",
// class SprayBrush extends PencilBrush {
// constructor(canvas, options = {}) {
// super(canvas, {
// id: "spray",
// name: "喷枪",
// description: "模拟喷枪效果,创建散点效果",
// category: "基础笔刷",
// ...options,
// });
// }
brushRegistry.register(
"spray",
class SprayBrush extends PencilBrush {
constructor(canvas, options = {}) {
super(canvas, {
id: "spray",
name: "Spray",
description: "模拟喷枪效果,创建散点效果",
category: "基础笔刷",
...options,
});
}
// create() {
// this.brush = new fabric.SprayBrush(this.canvas);
// this.configure(this.brush, this.options);
// return this.brush;
// }
create() {
this.brush = new fabric.SprayBrush(this.canvas);
this.configure(this.brush, this.options);
return this.brush;
}
// configure(brush, options = {}) {
// super.configure(brush, options);
configure(brush, options = {}) {
super.configure(brush, options);
// if (options.density !== undefined) {
// brush.density = options.density;
// }
if (options.density !== undefined) {
brush.density = options.density;
}
// if (options.randomOpacity !== undefined) {
// brush.randomOpacity = options.randomOpacity;
// }
if (options.randomOpacity !== undefined) {
brush.randomOpacity = options.randomOpacity;
}
// if (options.dotWidth !== undefined) {
// brush.dotWidth = options.dotWidth;
// }
// }
// },
// {
// name: "喷枪",
// description: "模拟喷枪效果,创建散点效果",
// }
// );
if (options.dotWidth !== undefined) {
brush.dotWidth = options.dotWidth;
}
}
},
{
name: "喷枪",
description: "模拟喷枪效果,创建散点效果",
}
);
// 注册橡皮擦笔刷
brushRegistry.register(
"eraser",
@@ -387,6 +387,13 @@ export class BrushManager {
width: this.brushStore.state.size,
opacity: this.brushStore.state.opacity,
// 阴影相关配置
shadowEnabled: this.brushStore.state.shadowEnabled,
shadowColor: this.brushStore.state.shadowColor,
shadowWidth: this.brushStore.state.shadowWidth,
shadowOffsetX: this.brushStore.state.shadowOffsetX,
shadowOffsetY: this.brushStore.state.shadowOffsetY,
// 材质笔刷特有配置
textureEnabled: this.brushStore.state.textureEnabled,
texturePath: this.brushStore.state.texturePath,
@@ -522,16 +529,23 @@ export class BrushManager {
// 限制透明度范围
const brushOpacity = Math.max(0.05, Math.min(1, opacity));
// 更新笔刷透明度
this.canvas.freeDrawingBrush.opacity = brushOpacity;
// 不再设置fabric笔刷的opacity属性而是通过颜色的RGBA值来实现透明度
// this.canvas.freeDrawingBrush.opacity = brushOpacity;
// 更新活动笔刷
// 更新活动笔刷配置,使用当前颜色和新的透明度
if (this.activeBrush) {
const currentColor = this.brushStore.state.color;
this.activeBrush.configure(this.canvas.freeDrawingBrush, {
color: currentColor,
opacity: brushOpacity,
});
}
// 确保上下文透明度始终为1避免全局透明度问题
if (this.canvas.contextTop) {
this.canvas.contextTop.globalAlpha = 1;
}
// 更新Store
this.brushStore.setBrushOpacity(brushOpacity);
@@ -842,6 +856,16 @@ export class BrushManager {
return this.canvas.freeDrawingBrush;
}
/**
* 更新笔刷阴影设置
*/
updateShadow() {
if (this.activeBrush && this.activeBrush.updateShadow) {
this.activeBrush.updateShadow();
}
}
/**
* 创建橡皮擦
* @returns {Object} 橡皮擦笔刷