fix: 修复多个已知问题
This commit is contained in:
@@ -36,8 +36,137 @@ export class BaseBrush {
|
||||
* @param {Object} brush fabric笔刷实例
|
||||
* @param {Object} options 配置选项
|
||||
*/
|
||||
configure(brush, options) {
|
||||
throw new Error("必须由子类实现configure方法");
|
||||
configure(brush, options = {}) {
|
||||
if (!brush) return;
|
||||
|
||||
// 基础属性配置
|
||||
if (options.width !== undefined) {
|
||||
brush.width = options.width;
|
||||
}
|
||||
|
||||
if (options.color !== undefined && options.opacity !== undefined) {
|
||||
// 使用RGBA颜色而不是设置globalAlpha
|
||||
brush.color = this._createRGBAColor(options.color, options.opacity);
|
||||
brush.opacity = 1; // 保持fabric层面的opacity为1
|
||||
} else if (options.color !== undefined) {
|
||||
brush.color = options.color;
|
||||
} else if (options.opacity !== undefined) {
|
||||
// 如果只设置了透明度,基于当前颜色创建RGBA
|
||||
const currentColor = brush.color || this.options.color || "#000000";
|
||||
brush.color = this._createRGBAColor(currentColor, options.opacity);
|
||||
brush.opacity = 1;
|
||||
}
|
||||
|
||||
// 配置阴影
|
||||
this.configureShadow(brush, options);
|
||||
|
||||
// 确保不使用globalAlpha,避免圆圈绘制问题
|
||||
if (brush.canvas && brush.canvas.contextTop) {
|
||||
brush.canvas.contextTop.globalAlpha = 1;
|
||||
brush.canvas.contextTop.lineCap = "round";
|
||||
brush.canvas.contextTop.lineJoin = "round";
|
||||
brush.canvas.contextTop.globalCompositeOperation = "source-over";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 配置笔刷阴影
|
||||
* @param {Object} brush fabric笔刷实例
|
||||
* @param {Object} options 配置选项
|
||||
*/
|
||||
configureShadow(brush, options = {}) {
|
||||
if (!brush) return;
|
||||
|
||||
// 简化的阴影配置获取方法
|
||||
let shadowConfig = null;
|
||||
|
||||
// 尝试从全局获取BrushStore(在Vue组件中已经导入)
|
||||
if (typeof window !== "undefined" && window.BrushStore) {
|
||||
shadowConfig = window.BrushStore.getShadowConfig();
|
||||
} else {
|
||||
// 如果没有全局BrushStore,尝试从选项中获取
|
||||
if (options.shadowEnabled) {
|
||||
shadowConfig = {
|
||||
color: options.shadowColor || "#000000",
|
||||
blur: options.shadowWidth || 0,
|
||||
offsetX: options.shadowOffsetX || 0,
|
||||
offsetY: options.shadowOffsetY || 0,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
if (shadowConfig) {
|
||||
// 创建fabric.Shadow实例
|
||||
if (typeof fabric !== "undefined" && fabric.Shadow) {
|
||||
brush.shadow = new fabric.Shadow(shadowConfig);
|
||||
}
|
||||
} else {
|
||||
// 清除阴影
|
||||
brush.shadow = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新笔刷阴影设置
|
||||
*/
|
||||
updateShadow() {
|
||||
if (this.brush) {
|
||||
this.configureShadow(this.brush);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建RGBA颜色字符串
|
||||
* @private
|
||||
* @param {String} color 十六进制颜色或已有颜色
|
||||
* @param {Number} opacity 透明度 (0-1)
|
||||
* @returns {String} RGBA颜色字符串
|
||||
*/
|
||||
_createRGBAColor(color, opacity) {
|
||||
// 如果已经是rgba颜色,先提取RGB部分
|
||||
if (color.startsWith("rgba")) {
|
||||
const rgbaMatch = color.match(
|
||||
/rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*[\d.]+)?\)/
|
||||
);
|
||||
if (rgbaMatch) {
|
||||
const [, r, g, b] = rgbaMatch;
|
||||
return `rgba(${r}, ${g}, ${b}, ${opacity})`;
|
||||
}
|
||||
}
|
||||
|
||||
// 如果是rgb颜色,提取RGB部分
|
||||
if (color.startsWith("rgb")) {
|
||||
const rgbMatch = color.match(/rgb\((\d+),\s*(\d+),\s*(\d+)\)/);
|
||||
if (rgbMatch) {
|
||||
const [, r, g, b] = rgbMatch;
|
||||
return `rgba(${r}, ${g}, ${b}, ${opacity})`;
|
||||
}
|
||||
}
|
||||
|
||||
// 处理十六进制颜色
|
||||
if (color.startsWith("#")) {
|
||||
const hex = color.replace("#", "");
|
||||
let r, g, b;
|
||||
|
||||
if (hex.length === 3) {
|
||||
r = parseInt(hex[0] + hex[0], 16);
|
||||
g = parseInt(hex[1] + hex[1], 16);
|
||||
b = parseInt(hex[2] + hex[2], 16);
|
||||
} else if (hex.length === 6) {
|
||||
r = parseInt(hex.substring(0, 2), 16);
|
||||
g = parseInt(hex.substring(2, 4), 16);
|
||||
b = parseInt(hex.substring(4, 6), 16);
|
||||
} else {
|
||||
// 无效的十六进制颜色,使用默认
|
||||
r = g = b = 0;
|
||||
}
|
||||
|
||||
return `rgba(${r}, ${g}, ${b}, ${opacity})`;
|
||||
}
|
||||
|
||||
// 如果是其他格式的颜色,尝试转换(例如颜色名称)
|
||||
// 这里简化处理,实际项目中可以使用更复杂的颜色解析
|
||||
return color; // fallback到原颜色
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -145,23 +274,26 @@ export class BaseBrush {
|
||||
* @returns {Boolean} 是否更新成功
|
||||
*/
|
||||
updateProperty(propId, value) {
|
||||
// 基础实现,可以被子类覆盖以处理特殊属性
|
||||
if (propId === "size") {
|
||||
if (this.brush) {
|
||||
this.brush.width = value;
|
||||
return true;
|
||||
this.configure(this.brush, { width: value });
|
||||
}
|
||||
return true;
|
||||
} else if (propId === "color") {
|
||||
if (this.brush) {
|
||||
this.brush.color = value;
|
||||
return true;
|
||||
this.configure(this.brush, { color: value });
|
||||
}
|
||||
return true;
|
||||
} else if (propId === "opacity") {
|
||||
if (this.brush) {
|
||||
this.brush.opacity = value;
|
||||
return true;
|
||||
this.configure(this.brush, { opacity: value });
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -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} 橡皮擦笔刷
|
||||
|
||||
@@ -427,6 +427,12 @@ import { sprayBrushDataUrl } from "./data/sprayBrushData.js";
|
||||
},
|
||||
|
||||
onMouseDown: function (pointer) {
|
||||
// 添加坐标转换处理画布缩放和偏移
|
||||
pointer.x =
|
||||
pointer.x * this.canvas.getZoom() + this.canvas.viewportTransform[4];
|
||||
pointer.y =
|
||||
pointer.y * this.canvas.getZoom() + this.canvas.viewportTransform[5];
|
||||
|
||||
this._points = [pointer];
|
||||
this._count = 0;
|
||||
|
||||
@@ -449,6 +455,12 @@ import { sprayBrushDataUrl } from "./data/sprayBrushData.js";
|
||||
},
|
||||
|
||||
onMouseMove: function (pointer) {
|
||||
// 添加坐标转换处理画布缩放和偏移
|
||||
pointer.x =
|
||||
pointer.x * this.canvas.getZoom() + this.canvas.viewportTransform[4];
|
||||
pointer.y =
|
||||
pointer.y * this.canvas.getZoom() + this.canvas.viewportTransform[5];
|
||||
|
||||
this._points.push(pointer);
|
||||
|
||||
var i,
|
||||
@@ -985,9 +997,9 @@ import { sprayBrushDataUrl } from "./data/sprayBrushData.js";
|
||||
ctx.globalAlpha = 0.8 * this.opacity;
|
||||
ctx.moveTo(this._lastPoint.x, this._lastPoint.y);
|
||||
let x =
|
||||
content > this._lastPoint.x
|
||||
? content - this._lastPoint.x + content
|
||||
: content * 2 - this._lastPoint.x;
|
||||
this.content > this._lastPoint.x
|
||||
? this.content - this._lastPoint.x + this.content
|
||||
: this.content * 2 - this._lastPoint.x;
|
||||
ctx.lineTo(x, this._lastPoint.y);
|
||||
// ctx.lineTo(pointer.y + lineWidthDiff,pointer.x + lineWidthDiff);
|
||||
ctx.stroke();
|
||||
@@ -997,10 +1009,12 @@ import { sprayBrushDataUrl } from "./data/sprayBrushData.js";
|
||||
},
|
||||
|
||||
onMouseDown: function (pointer) {
|
||||
// 添加坐标转换处理画布缩放和偏移
|
||||
pointer.x =
|
||||
pointer.x * this.canvas.getZoom() + this.canvas.viewportTransform[4];
|
||||
pointer.y =
|
||||
pointer.y * this.canvas.getZoom() + this.canvas.viewportTransform[5];
|
||||
|
||||
this._lastPoint = pointer;
|
||||
this.canvas.contextTop.strokeStyle = this.color;
|
||||
this.canvas.contextTop.lineWidth = this._lineWidth;
|
||||
@@ -1009,10 +1023,12 @@ import { sprayBrushDataUrl } from "./data/sprayBrushData.js";
|
||||
|
||||
onMouseMove: function (pointer) {
|
||||
if (this.canvas._isCurrentlyDrawing) {
|
||||
// 添加坐标转换处理画布缩放和偏移
|
||||
pointer.x =
|
||||
pointer.x * this.canvas.getZoom() + this.canvas.viewportTransform[4];
|
||||
pointer.y =
|
||||
pointer.y * this.canvas.getZoom() + this.canvas.viewportTransform[5];
|
||||
|
||||
this._render(pointer);
|
||||
}
|
||||
},
|
||||
@@ -1022,7 +1038,7 @@ import { sprayBrushDataUrl } from "./data/sprayBrushData.js";
|
||||
this.canvas.contextTop.globalAlpha = 1;
|
||||
this.convertToImg();
|
||||
},
|
||||
}); // End MarkerBrush
|
||||
}); // End MarkerBrush1
|
||||
/**
|
||||
* PenBrush
|
||||
* Based on code by Tennison Chan.
|
||||
|
||||
@@ -87,8 +87,15 @@ export class PencilBrush extends BaseBrush {
|
||||
|
||||
// 调用 convertToImg 方法将绘制内容转换为图片
|
||||
if (typeof this.convertToImg === "function") {
|
||||
// 确保在转换前设置正确的透明度
|
||||
const currentAlpha = ctx.globalAlpha;
|
||||
ctx.globalAlpha = this.opacity || 1;
|
||||
|
||||
this.convertToImg();
|
||||
console.log("PencilBrush: convertToImg called successfully");
|
||||
|
||||
// 恢复透明度
|
||||
ctx.globalAlpha = currentAlpha;
|
||||
} else {
|
||||
console.warn(
|
||||
"convertToImg method not found, falling back to original behavior"
|
||||
@@ -157,31 +164,96 @@ export class PencilBrush extends BaseBrush {
|
||||
brush.width = options.width;
|
||||
}
|
||||
|
||||
if (options.color !== undefined) {
|
||||
if (options.color !== undefined && options.opacity !== undefined) {
|
||||
// 使用RGBA颜色而不是设置globalAlpha
|
||||
brush.color = this._createRGBAColor(options.color, options.opacity);
|
||||
} else if (options.color !== undefined) {
|
||||
brush.color = options.color;
|
||||
} else if (options.opacity !== undefined) {
|
||||
// 如果只设置了透明度,基于当前颜色创建RGBA
|
||||
const currentColor = brush.color || "#000000";
|
||||
brush.color = this._createRGBAColor(currentColor, options.opacity);
|
||||
}
|
||||
|
||||
if (options.opacity !== undefined) {
|
||||
brush.opacity = options.opacity;
|
||||
// 确保不使用globalAlpha,避免圆圈绘制问题
|
||||
if (brush.canvas && brush.canvas.contextTop) {
|
||||
brush.canvas.contextTop.globalAlpha = 1;
|
||||
brush.canvas.contextTop.lineCap = "round";
|
||||
brush.canvas.contextTop.lineJoin = "round";
|
||||
}
|
||||
|
||||
// 特殊属性配置
|
||||
options.decimate = 0;
|
||||
if (options.decimate !== undefined) {
|
||||
brush.decimate = options.decimate;
|
||||
this.decimate = options.decimate;
|
||||
}
|
||||
|
||||
options.strokeLineCap = "round";
|
||||
if (options.strokeLineCap !== undefined) {
|
||||
brush.strokeLineCap = options.strokeLineCap;
|
||||
this.strokeLineCap = options.strokeLineCap;
|
||||
}
|
||||
|
||||
options.strokeLineJoin = "round";
|
||||
if (options.strokeLineJoin !== undefined) {
|
||||
brush.strokeLineJoin = options.strokeLineJoin;
|
||||
this.strokeLineJoin = options.strokeLineJoin;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建RGBA颜色字符串
|
||||
* @private
|
||||
* @param {String} color 十六进制颜色或已有颜色
|
||||
* @param {Number} opacity 透明度 (0-1)
|
||||
* @returns {String} RGBA颜色字符串
|
||||
*/
|
||||
_createRGBAColor(color, opacity) {
|
||||
// 如果已经是rgba颜色,先提取RGB部分
|
||||
if (color.startsWith("rgba")) {
|
||||
const rgbaMatch = color.match(
|
||||
/rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*[\d.]+)?\)/
|
||||
);
|
||||
if (rgbaMatch) {
|
||||
const [, r, g, b] = rgbaMatch;
|
||||
return `rgba(${r}, ${g}, ${b}, ${opacity})`;
|
||||
}
|
||||
}
|
||||
|
||||
// 如果是rgb颜色,提取RGB部分
|
||||
if (color.startsWith("rgb")) {
|
||||
const rgbMatch = color.match(/rgb\((\d+),\s*(\d+),\s*(\d+)\)/);
|
||||
if (rgbMatch) {
|
||||
const [, r, g, b] = rgbMatch;
|
||||
return `rgba(${r}, ${g}, ${b}, ${opacity})`;
|
||||
}
|
||||
}
|
||||
|
||||
// 处理十六进制颜色
|
||||
if (color.startsWith("#")) {
|
||||
const hex = color.replace("#", "");
|
||||
let r, g, b;
|
||||
|
||||
if (hex.length === 3) {
|
||||
r = parseInt(hex[0] + hex[0], 16);
|
||||
g = parseInt(hex[1] + hex[1], 16);
|
||||
b = parseInt(hex[2] + hex[2], 16);
|
||||
} else if (hex.length === 6) {
|
||||
r = parseInt(hex.substring(0, 2), 16);
|
||||
g = parseInt(hex.substring(2, 4), 16);
|
||||
b = parseInt(hex.substring(4, 6), 16);
|
||||
} else {
|
||||
// 无效的十六进制颜色,使用默认
|
||||
r = g = b = 0;
|
||||
}
|
||||
|
||||
return `rgba(${r}, ${g}, ${b}, ${opacity})`;
|
||||
}
|
||||
|
||||
// 如果是其他格式的颜色,尝试转换(例如颜色名称)
|
||||
// 这里简化处理,实际项目中可以使用更复杂的颜色解析
|
||||
return color; // fallback到原颜色
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取笔刷可配置属性
|
||||
* @returns {Array} 可配置属性描述数组
|
||||
@@ -193,69 +265,69 @@ export class PencilBrush extends BaseBrush {
|
||||
|
||||
// 定义铅笔笔刷特有属性
|
||||
const pencilProperties = [
|
||||
{
|
||||
id: "decimate",
|
||||
name: "精细度",
|
||||
type: "slider",
|
||||
defaultValue: this.decimate,
|
||||
min: 0,
|
||||
max: 1,
|
||||
step: 0.1,
|
||||
description: "控制笔触路径的简化程度,值越小路径越精细",
|
||||
category: "铅笔设置",
|
||||
order: 100,
|
||||
},
|
||||
{
|
||||
id: "strokeLineCap",
|
||||
name: "线条端点",
|
||||
type: "select",
|
||||
defaultValue: this.strokeLineCap,
|
||||
options: [
|
||||
{ value: "round", label: "圆形" },
|
||||
{ value: "butt", label: "平直" },
|
||||
{ value: "square", label: "方形" },
|
||||
],
|
||||
description: "线条端点的形状",
|
||||
category: "铅笔设置",
|
||||
order: 110,
|
||||
},
|
||||
{
|
||||
id: "strokeLineJoin",
|
||||
name: "线条连接",
|
||||
type: "select",
|
||||
defaultValue: this.strokeLineJoin,
|
||||
options: [
|
||||
{ value: "round", label: "圆角" },
|
||||
{ value: "bevel", label: "斜角" },
|
||||
{ value: "miter", label: "尖角" },
|
||||
],
|
||||
description: "线条拐角的连接方式",
|
||||
category: "铅笔设置",
|
||||
order: 120,
|
||||
},
|
||||
{
|
||||
id: "smoothingEnabled",
|
||||
name: "启用平滑",
|
||||
type: "checkbox",
|
||||
defaultValue: false,
|
||||
description: "是否对线条进行平滑处理",
|
||||
category: "铅笔设置",
|
||||
order: 130,
|
||||
},
|
||||
{
|
||||
id: "smoothingFactor",
|
||||
name: "平滑程度",
|
||||
type: "slider",
|
||||
defaultValue: 0.5,
|
||||
min: 0,
|
||||
max: 1,
|
||||
step: 0.05,
|
||||
description: "线条平滑的强度",
|
||||
category: "铅笔设置",
|
||||
order: 140,
|
||||
// 只有当smoothingEnabled为true时才显示
|
||||
visibleWhen: { smoothingEnabled: true },
|
||||
},
|
||||
// {
|
||||
// id: "decimate",
|
||||
// name: "精细度",
|
||||
// type: "slider",
|
||||
// defaultValue: this.decimate,
|
||||
// min: 0,
|
||||
// max: 1,
|
||||
// step: 0.1,
|
||||
// description: "控制笔触路径的简化程度,值越小路径越精细",
|
||||
// category: "铅笔设置",
|
||||
// order: 100,
|
||||
// },
|
||||
// {
|
||||
// id: "strokeLineCap",
|
||||
// name: "线条端点",
|
||||
// type: "select",
|
||||
// defaultValue: this.strokeLineCap,
|
||||
// options: [
|
||||
// { value: "round", label: "圆形" },
|
||||
// { value: "butt", label: "平直" },
|
||||
// { value: "square", label: "方形" },
|
||||
// ],
|
||||
// description: "线条端点的形状",
|
||||
// category: "铅笔设置",
|
||||
// order: 110,
|
||||
// },
|
||||
// {
|
||||
// id: "strokeLineJoin",
|
||||
// name: "线条连接",
|
||||
// type: "select",
|
||||
// defaultValue: this.strokeLineJoin,
|
||||
// options: [
|
||||
// { value: "round", label: "圆角" },
|
||||
// { value: "bevel", label: "斜角" },
|
||||
// { value: "miter", label: "尖角" },
|
||||
// ],
|
||||
// description: "线条拐角的连接方式",
|
||||
// category: "铅笔设置",
|
||||
// order: 120,
|
||||
// },
|
||||
// {
|
||||
// id: "smoothingEnabled",
|
||||
// name: "启用平滑",
|
||||
// type: "checkbox",
|
||||
// defaultValue: false,
|
||||
// description: "是否对线条进行平滑处理",
|
||||
// category: "铅笔设置",
|
||||
// order: 130,
|
||||
// },
|
||||
// {
|
||||
// id: "smoothingFactor",
|
||||
// name: "平滑程度",
|
||||
// type: "slider",
|
||||
// defaultValue: 0.5,
|
||||
// min: 0,
|
||||
// max: 1,
|
||||
// step: 0.05,
|
||||
// description: "线条平滑的强度",
|
||||
// category: "铅笔设置",
|
||||
// order: 140,
|
||||
// // 只有当smoothingEnabled为true时才显示
|
||||
// visibleWhen: { smoothingEnabled: true },
|
||||
// },
|
||||
];
|
||||
|
||||
// 合并并返回所有属性
|
||||
|
||||
@@ -73,6 +73,15 @@ export class RibbonBrush extends BaseBrush {
|
||||
|
||||
if (options.opacity !== undefined) {
|
||||
brush.opacity = options.opacity;
|
||||
// 如果启用渐变,更新渐变的第一个颜色
|
||||
if (this.gradient && this.gradientColors.length > 0) {
|
||||
this.gradientColors[0] = this._createRGBAColor(
|
||||
brush.color,
|
||||
options.opacity
|
||||
);
|
||||
this.updateGradient();
|
||||
}
|
||||
brush.canvas.freeDrawingBrush.opacity = options.opacity;
|
||||
}
|
||||
|
||||
// 丝带笔刷特有属性
|
||||
|
||||
@@ -27,8 +27,7 @@ export class TextureBrush extends BaseBrush {
|
||||
this.textureRepeat = options.textureRepeat || "repeat";
|
||||
this.textureScale = options.textureScale || 1;
|
||||
this.textureAngle = options.textureAngle || 0;
|
||||
this.textureOpacity =
|
||||
options.textureOpacity !== undefined ? options.textureOpacity : 1;
|
||||
this.opacity = options.opacity !== undefined ? options.opacity : 1;
|
||||
|
||||
// 预设材质相关
|
||||
this.selectedTextureId = options.selectedTextureId || null;
|
||||
@@ -201,8 +200,8 @@ export class TextureBrush extends BaseBrush {
|
||||
}
|
||||
}
|
||||
|
||||
if (options.textureOpacity !== undefined) {
|
||||
this.textureOpacity = options.textureOpacity;
|
||||
if (options.opacity !== undefined) {
|
||||
this.opacity = options.opacity;
|
||||
// 需要重新应用纹理以应用透明度
|
||||
if (this.selectedTextureId) {
|
||||
this.setTextureById(this.selectedTextureId);
|
||||
@@ -286,9 +285,9 @@ export class TextureBrush extends BaseBrush {
|
||||
canvasTexture.width = width;
|
||||
canvasTexture.height = height;
|
||||
|
||||
// 应用透明度设置
|
||||
if (this.textureOpacity < 1) {
|
||||
ctx.globalAlpha = this.textureOpacity;
|
||||
// 应用纹理透明度设置 - 仅控制纹理的透明度
|
||||
if (this.opacity < 1) {
|
||||
ctx.globalAlpha = this.opacity;
|
||||
}
|
||||
|
||||
// 绘制前应用旋转
|
||||
@@ -310,6 +309,18 @@ export class TextureBrush extends BaseBrush {
|
||||
// 直接设置source属性,这是PatternBrush的标准用法
|
||||
this.brush.source = canvasTexture;
|
||||
|
||||
this.brush.canvas.opacity = this.opacity; // 确保画布不透明
|
||||
|
||||
// 设置笔刷颜色为完全透明的RGBA,避免重复绘制时的叠加效果
|
||||
// 笔刷的透明度通过RGBA颜色控制,而不是通过globalAlpha
|
||||
const brushOpacity = this.brush.opacity || 1;
|
||||
this.brush.color = `rgba(0, 0, 0, ${brushOpacity})`;
|
||||
|
||||
// 确保画布上下文使用完整的透明度,避免圆圈重叠问题
|
||||
// if (this.canvas && this.canvas.contextTop) {
|
||||
// this.canvas.contextTop.globalAlpha = 1;
|
||||
// }
|
||||
|
||||
// 通知画布重绘
|
||||
if (this.canvas && this.canvas.requestRenderAll) {
|
||||
this.canvas.requestRenderAll();
|
||||
@@ -378,8 +389,8 @@ export class TextureBrush extends BaseBrush {
|
||||
* @param {Number} opacity 透明度
|
||||
* @returns {Number} 设置后的透明度
|
||||
*/
|
||||
setTextureOpacity(opacity) {
|
||||
this.textureOpacity = Math.min(1, Math.max(0, opacity));
|
||||
setopacity(opacity) {
|
||||
this.opacity = Math.min(1, Math.max(0, opacity));
|
||||
|
||||
// 重新应用纹理以更新透明度
|
||||
if (this.selectedTextureId) {
|
||||
@@ -388,7 +399,7 @@ export class TextureBrush extends BaseBrush {
|
||||
this.setTexture(this.textureSource);
|
||||
}
|
||||
|
||||
return this.textureOpacity;
|
||||
return this.opacity;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -518,10 +529,10 @@ export class TextureBrush extends BaseBrush {
|
||||
// order: 130,
|
||||
// },
|
||||
// {
|
||||
// id: "textureOpacity",
|
||||
// id: "opacity",
|
||||
// name: "纹理透明度",
|
||||
// type: "slider",
|
||||
// defaultValue: this.textureOpacity,
|
||||
// defaultValue: this.opacity,
|
||||
// min: 0,
|
||||
// max: 1,
|
||||
// step: 0.05,
|
||||
@@ -584,8 +595,8 @@ export class TextureBrush extends BaseBrush {
|
||||
} else if (propId === "textureAngle") {
|
||||
this.setTextureAngle(value);
|
||||
return true;
|
||||
} else if (propId === "textureOpacity") {
|
||||
this.setTextureOpacity(value);
|
||||
} else if (propId === "opacity") {
|
||||
this.setopacity(value);
|
||||
return true;
|
||||
} else if (propId === "uploadTexture") {
|
||||
// 触发上传纹理事件
|
||||
@@ -688,7 +699,7 @@ export class TextureBrush extends BaseBrush {
|
||||
case "scale":
|
||||
return this.setTextureScale(value);
|
||||
case "opacity":
|
||||
return this.setTextureOpacity(value);
|
||||
return this.setopacity(value);
|
||||
case "repeat":
|
||||
return this.setTextureRepeat(value);
|
||||
case "angle":
|
||||
@@ -708,7 +719,7 @@ export class TextureBrush extends BaseBrush {
|
||||
case "scale":
|
||||
return this.textureScale;
|
||||
case "opacity":
|
||||
return this.textureOpacity;
|
||||
return this.opacity;
|
||||
case "repeat":
|
||||
return this.textureRepeat;
|
||||
case "angle":
|
||||
@@ -751,7 +762,7 @@ export class TextureBrush extends BaseBrush {
|
||||
}
|
||||
|
||||
if (presetData.opacity !== undefined) {
|
||||
this.setTextureOpacity(presetData.opacity);
|
||||
this.setopacity(presetData.opacity);
|
||||
}
|
||||
|
||||
if (presetData.repeat !== undefined) {
|
||||
@@ -786,7 +797,7 @@ export class TextureBrush extends BaseBrush {
|
||||
return {
|
||||
textureId: this.selectedTextureId,
|
||||
scale: this.textureScale,
|
||||
opacity: this.textureOpacity,
|
||||
opacity: this.opacity,
|
||||
repeat: this.textureRepeat,
|
||||
angle: this.textureAngle,
|
||||
// 包含笔刷状态
|
||||
@@ -815,7 +826,7 @@ export class TextureBrush extends BaseBrush {
|
||||
}
|
||||
|
||||
if (state.opacity !== undefined) {
|
||||
this.setTextureOpacity(state.opacity);
|
||||
this.setopacity(state.opacity);
|
||||
}
|
||||
|
||||
if (state.repeat !== undefined) {
|
||||
|
||||
Reference in New Issue
Block a user