feat: 渲染元素新增自我变换模式

This commit is contained in:
AncTe committed 2026-11-10 19:46:18 +08:00
1 parent 67fcf15ea5
commit 7fb4cb3c4b
3 files changed
+23 -4

No files matched your search

+2 -3
View File
@@ -19,7 +19,6 @@ import {
RectREllipseParams,
ITexture
} from '@motajs/render';
import { Ref } from 'vue';
export interface BaseProps {
/** 元素的横坐标 */
@@ -48,14 +47,14 @@ export interface BaseProps {
hidden?: boolean;
/** 元素的变换矩阵 */
transform?: Transform;
/** 是否启用自我变换模式,自我变换模式下,元素盒子本身不会经过变换,但其内容会经过变换后再绘制 */
selfTransform?: boolean;
/** 元素的定位模式 */
type?: RenderPosition;
/** 是否启用缓存,用处较少,主要用于一些默认不启用缓存的元素的特殊优化 */
cache?: boolean;
/** 是否不启用缓存,优先级大于 cache,用处较少,主要用于一些特殊优化 */
nocache?: boolean;
/** 是否启用变换矩阵下穿,下穿模式下,当前元素会使用由父元素传递过来的变换矩阵,而非元素自身的 */
fall?: boolean;
/** 这个元素的唯一标识符,不可重复 */
id?: string;
/** 这个元素的不透明度 */
+13 -1
View File
@@ -58,6 +58,8 @@ export abstract class RenderItem
height: number = 200;
/** 该元素的变换矩阵 */
transform: Transform = new Transform();
/** 是否为自我变换模式 */
selfTransform: boolean = false;
/** 渲染锚点,(0,0)表示左上角,(1,1)表示右下角 */
anchorX: number = 0;
/** 渲染锚点,(0,0)表示左上角,(1,1)表示右下角 */
@@ -204,11 +206,15 @@ export abstract class RenderItem
const ctx = canvas.ctx;
ctx.save();
transformCanvas(canvas, tran);
ctx.filter = this.filter;
ctx.globalAlpha = this.alpha;
ctx.globalCompositeOperation = this.composite;
if (this.enableCache && this.cache) {
if (this.selfTransform) {
transformCanvas(this.cache, tran);
} else {
transformCanvas(canvas, tran);
}
const { width, height } = this.cache!;
if (this.cacheDirty) {
this.cache.clear();
@@ -218,6 +224,7 @@ export abstract class RenderItem
ctx.imageSmoothingEnabled = false;
ctx.drawImage(this.cache.canvas, ax, ay, width, height);
} else {
transformCanvas(canvas, tran);
ctx.imageSmoothingEnabled = this.antiAliasing;
ctx.translate(ax, ay);
this.render(canvas, tran);
@@ -340,6 +347,11 @@ export abstract class RenderItem
this.y = transform.y;
}
setSelfTransform(self: boolean): void {
this.selfTransform = self;
this.update();
}
/**
* 设置本元素的滤镜
* @param filter 滤镜
+8
View File
@@ -99,6 +99,8 @@ export interface IRenderItem
readonly position: RenderPosition;
/** 元素变换矩阵 */
readonly transform: Transform;
/** 是否使用自我变换模式,该模式下元素盒子本身不会经过变换,但其内容会经过变换后再绘制 */
readonly selfTransform: boolean;
/** 是否是高清画布 */
readonly highResolution: boolean;
@@ -232,6 +234,12 @@ export interface IRenderItem
*/
setTransform(transform: Transform): void;
/**
* 是否使用自我变换模式,自我变换模式下,元素盒子本身不会经过变换,但其内容会经过变换后再绘制
* @param self 是否为自我变换模式
*/
setSelfTransform(self: boolean): void;
/**
* 隐藏此元素
*/