Compare commits

..

No commits in common. "d535fe82c0570345dd93f947bdc4247d2243a29e" and "feecb3a380c203b0cee970a3e99e5d53a8c820a0" have entirely different histories.

3 changed files with 27 additions and 81 deletions

View File

@ -233,19 +233,20 @@ export abstract class RenderItem<E extends ERenderItemEvent = ERenderItemEvent>
protected needUpdate: boolean = false; protected needUpdate: boolean = false;
/** 该元素的变换矩阵 */ private _transform: Transform = new Transform();
transform: Transform = new Transform(); /** 设置该渲染元素的模型变换矩阵 */
set transform(value: Transform) {
this._transform = value;
this.update();
}
/** 获取该渲染元素的模型变换矩阵 */
get transform() {
this.update();
return this._transform;
}
/** 该渲染元素的子元素 */ /** 该渲染元素的子元素 */
children: Set<RenderItem<ERenderItemEvent>> = new Set(); children: Set<RenderItem<ERenderItemEvent>> = new Set();
get x() {
return this.transform.x;
}
get y() {
return this.transform.y;
}
/** 渲染缓存信息 */ /** 渲染缓存信息 */
protected cache: MotaOffscreenCanvas2D = new MotaOffscreenCanvas2D(); protected cache: MotaOffscreenCanvas2D = new MotaOffscreenCanvas2D();
/** 是否需要更新缓存 */ /** 是否需要更新缓存 */
@ -266,7 +267,6 @@ export abstract class RenderItem<E extends ERenderItemEvent = ERenderItemEvent>
this.transformFallThrough = transformFallThrough; this.transformFallThrough = transformFallThrough;
this.type = type; this.type = type;
this.transform.bind(this);
this.cache.withGameScale(true); this.cache.withGameScale(true);
} }
@ -315,7 +315,7 @@ export abstract class RenderItem<E extends ERenderItemEvent = ERenderItemEvent>
if (this.hidden) return; if (this.hidden) return;
this.emit('beforeRender', transform); this.emit('beforeRender', transform);
this.needUpdate = false; this.needUpdate = false;
const tran = this.transformFallThrough ? transform : this.transform; const tran = this.transformFallThrough ? transform : this._transform;
const ax = -this.anchorX * this.width; const ax = -this.anchorX * this.width;
const ay = -this.anchorY * this.height; const ay = -this.anchorY * this.height;

View File

@ -13,7 +13,7 @@ import { ElementNamespace, ComponentInternalInstance } from 'vue';
* Line BezierCurve QuadraticCurve * Line BezierCurve QuadraticCurve
*/ */
export interface ILineProperty { interface ILineProperty {
/** 线宽 */ /** 线宽 */
lineWidth: number; lineWidth: number;
/** 线的虚线设置 */ /** 线的虚线设置 */
@ -28,8 +28,8 @@ export interface ILineProperty {
miterLimit: number; miterLimit: number;
} }
export interface IGraphicProperty extends ILineProperty { interface IGraphicProperty extends ILineProperty {
/** 渲染模式,参考 {@link GraphicMode} */ /** 渲染模式,可选 {@link GraphicMode.Fill}, {@link GraphicMode.Stroke}, {@link GraphicMode.All} */
mode: GraphicMode; mode: GraphicMode;
/** 填充样式 */ /** 填充样式 */
fill: CanvasStyle; fill: CanvasStyle;
@ -74,22 +74,10 @@ export abstract class GraphicItemBase
setLineOption(options: Partial<ILineProperty>) {} setLineOption(options: Partial<ILineProperty>) {}
/** /**
* *
* @param style * @param style
*/ */
setFillStyle(style: CanvasStyle) {} setStyle(style: CanvasStyle) {}
/**
*
* @param style
*/
setStrokeStyle(style: CanvasStyle) {}
/**
*
* @param rule
*/
setFillRule(rule: CanvasFillRule) {}
/** /**
* *
@ -97,15 +85,6 @@ export abstract class GraphicItemBase
*/ */
setMode(mode: GraphicMode) {} setMode(mode: GraphicMode) {}
/**
*
* @param canvas
*/
protected setCanvasState(canvas: MotaOffscreenCanvas2D) {
const ctx = canvas.ctx;
ctx.fillStyle = this.fill; // 示例后面的都按这个写不需要save restore写完把这个注释删了
}
patchProp( patchProp(
key: string, key: string,
prevValue: any, prevValue: any,
@ -123,28 +102,18 @@ export class Rect extends GraphicItemBase {
protected render( protected render(
canvas: MotaOffscreenCanvas2D, canvas: MotaOffscreenCanvas2D,
transform: Transform transform: Transform
): void { ): void {}
const ctx = canvas.ctx;
this.setCanvasState(canvas);
ctx.beginPath();
ctx.rect(this.x, this.y, this.width, this.height);
switch (this.mode) { patchProp(
case GraphicMode.Fill: key: string,
ctx.fill(this.fillRule); prevValue: any,
break; nextValue: any,
case GraphicMode.Stroke: namespace?: ElementNamespace,
ctx.stroke(); parentComponent?: ComponentInternalInstance | null
break; ): void {
case GraphicMode.FillAndStroke: switch (key) {
ctx.fill(this.fillRule);
ctx.stroke();
break;
case GraphicMode.StrokeAndFill:
ctx.stroke();
ctx.fill(this.fillRule);
break;
} }
super.patchProp(key, prevValue, nextValue, namespace, parentComponent);
} }
} }

View File

@ -1,9 +1,5 @@
import { mat3, ReadonlyMat3, ReadonlyVec3, vec2, vec3 } from 'gl-matrix'; import { mat3, ReadonlyMat3, ReadonlyVec3, vec2, vec3 } from 'gl-matrix';
export interface ITransformUpdatable {
update(): void;
}
export class Transform { export class Transform {
mat: mat3 = mat3.create(); mat: mat3 = mat3.create();
@ -16,17 +12,6 @@ export class Transform {
/** 有没有对这个Transform进行过修改用于优化常规表现 */ /** 有没有对这个Transform进行过修改用于优化常规表现 */
private modified: boolean = false; private modified: boolean = false;
/** 绑定的可更新元素 */
bindedObject?: ITransformUpdatable;
/**
* update
* @param obj
*/
bind(obj?: ITransformUpdatable) {
this.bindedObject = obj;
}
/** /**
* *
*/ */
@ -48,7 +33,6 @@ export class Transform {
this.scaleX *= x; this.scaleX *= x;
this.scaleY *= y; this.scaleY *= y;
this.modified = true; this.modified = true;
this.bindedObject?.update();
} }
/** /**
@ -59,7 +43,6 @@ export class Transform {
this.x += x; this.x += x;
this.y += y; this.y += y;
this.modified = true; this.modified = true;
this.bindedObject?.update();
} }
/** /**
@ -73,7 +56,6 @@ export class Transform {
this.rad -= n * Math.PI * 2; this.rad -= n * Math.PI * 2;
} }
this.modified = true; this.modified = true;
this.bindedObject?.update();
} }
/** /**
@ -84,7 +66,6 @@ export class Transform {
this.scaleX = x; this.scaleX = x;
this.scaleY = y; this.scaleY = y;
this.modified = true; this.modified = true;
this.bindedObject?.update();
} }
/** /**
@ -95,7 +76,6 @@ export class Transform {
this.x = x; this.x = x;
this.y = y; this.y = y;
this.modified = true; this.modified = true;
this.bindedObject?.update();
} }
/** /**
@ -105,7 +85,6 @@ export class Transform {
mat3.rotate(this.mat, this.mat, rad - this.rad); mat3.rotate(this.mat, this.mat, rad - this.rad);
this.rad = rad; this.rad = rad;
this.modified = true; this.modified = true;
this.bindedObject?.update();
} }
/** /**
@ -131,7 +110,6 @@ export class Transform {
mat3.fromValues(a, b, 0, c, d, 0, e, f, 1) mat3.fromValues(a, b, 0, c, d, 0, e, f, 1)
); );
this.calAttributes(); this.calAttributes();
this.bindedObject?.update();
} }
/** /**
@ -153,7 +131,6 @@ export class Transform {
) { ) {
mat3.set(this.mat, a, b, 0, c, d, 0, e, f, 1); mat3.set(this.mat, a, b, 0, c, d, 0, e, f, 1);
this.calAttributes(); this.calAttributes();
this.bindedObject?.update();
} }
/** /**