本文整理汇总了TypeScript中app/model/layers.LayerUtil.getCanvasTransformsForGroupLayer方法的典型用法代码示例。如果您正苦于以下问题:TypeScript LayerUtil.getCanvasTransformsForGroupLayer方法的具体用法?TypeScript LayerUtil.getCanvasTransformsForGroupLayer怎么用?TypeScript LayerUtil.getCanvasTransformsForGroupLayer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app/model/layers.LayerUtil
的用法示例。
在下文中一共展示了LayerUtil.getCanvasTransformsForGroupLayer方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1:
const layerChildren = layer.children.map((l: GroupLayer | PathLayer | ClipPathLayer): Layer => {
if (l instanceof GroupLayer) {
const flattenedTransform = Matrix.flatten([
layerTransform,
...LayerUtil.getCanvasTransformsForGroupLayer(l),
]);
const { sx, sy } = flattenedTransform.getScaling();
const degrees = flattenedTransform.getRotation();
const { tx, ty } = flattenedTransform.getTranslation();
const newLayer = l.clone();
newLayer.pivotX = 0;
newLayer.pivotY = 0;
newLayer.translateX = tx;
newLayer.translateY = ty;
newLayer.rotation = degrees;
newLayer.scaleX = sx;
newLayer.scaleY = sy;
return newLayer;
}
const path = l.pathData;
if (!path || !l.pathData.getPathString()) {
return l;
}
const clonedLayer = l.clone();
clonedLayer.pathData = path
.mutate()
.transform(layerTransform)
.build();
return clonedLayer;
});
示例2: flattenGroupLayer
/**
* Merges the specified group layer into its children layers.
* TODO: make it possible to merge groups that contain animation blocks?
*/
flattenGroupLayer(layerId: string) {
const vl = this.getVectorLayer();
const layer = vl.findLayerById(layerId) as GroupLayer;
if (!layer.children.length) {
return;
}
const layerTransform = Matrix.flatten(LayerUtil.getCanvasTransformsForGroupLayer(layer));
const layerChildren = layer.children.map((l: GroupLayer | PathLayer | ClipPathLayer): Layer => {
if (l instanceof GroupLayer) {
const flattenedTransform = Matrix.flatten([
layerTransform,
...LayerUtil.getCanvasTransformsForGroupLayer(l),
]);
const { sx, sy } = flattenedTransform.getScaling();
const degrees = flattenedTransform.getRotation();
const { tx, ty } = flattenedTransform.getTranslation();
const newLayer = l.clone();
newLayer.pivotX = 0;
newLayer.pivotY = 0;
newLayer.translateX = tx;
newLayer.translateY = ty;
newLayer.rotation = degrees;
newLayer.scaleX = sx;
newLayer.scaleY = sy;
return newLayer;
}
const path = l.pathData;
if (!path || !l.pathData.getPathString()) {
return l;
}
const clonedLayer = l.clone();
clonedLayer.pathData = path
.mutate()
.transform(layerTransform)
.build();
return clonedLayer;
});
const layerChildrenIds = new Set(layerChildren.map(l => l.id));
const parent = LayerUtil.findParent(vl, layerId).clone();
const children = [...parent.children];
children.splice(_.findIndex(parent.children, l => l.id === layerId), 1, ...layerChildren);
parent.children = children;
const actions: Action[] = [
new SetVectorLayer(LayerUtil.updateLayer(vl, parent)),
...this.buildCleanupLayerIdActions(layerId),
];
const newAnimation = this.getAnimation().clone();
// TODO: show a dialog if the user is about to unknowingly delete any blocks?
newAnimation.blocks = newAnimation.blocks.filter(b => b.layerId !== layerId);
// TODO: also attempt to merge children group animation blocks?
newAnimation.blocks = newAnimation.blocks.map(b => {
if (!(b instanceof PathAnimationBlock) || !layerChildrenIds.has(b.layerId)) {
return b;
}
const block = b.clone();
block.fromValue = block.fromValue
.mutate()
.transform(layerTransform)
.build();
block.toValue = block.toValue
.mutate()
.transform(layerTransform)
.build();
return block;
});
actions.push(new SetAnimation(newAnimation));
this.store.dispatch(new BatchAction(...actions));
}