mirror of
https://github.com/motajs/template.git
synced 2026-11-21 04:04:30 +08:00
feat: 渲染元素新增自我变换模式
This commit is contained in:
1 parent
67fcf15ea5
commit
7fb4cb3c4b
3 files changed
+23
-4
No files matched your search
@@ -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 滤镜
|
||||
|
||||
@@ -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;
|
||||
|
||||
/**
|
||||
* 隐藏此元素
|
||||
*/
|
||||
|
||||
Reference in new issue
Block a user