当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript LayerUtil.updateLayer方法代码示例

本文整理汇总了TypeScript中app/model/layers.LayerUtil.updateLayer方法的典型用法代码示例。如果您正苦于以下问题:TypeScript LayerUtil.updateLayer方法的具体用法?TypeScript LayerUtil.updateLayer怎么用?TypeScript LayerUtil.updateLayer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在app/model/layers.LayerUtil的用法示例。


在下文中一共展示了LayerUtil.updateLayer方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: swapLayers

 /**
  * Replaces an existing layer in the tree with a new layer. Note that
  * this method assumes that both layers still have the same children layers.
  */
 swapLayers(layerId: string, newLayer: Layer) {
   if (layerId === newLayer.id) {
     this.updateLayer(newLayer);
     return;
   }
   const vl = this.getVectorLayer();
   const parent = LayerUtil.findParent(vl, layerId).clone();
   const layerIndex = _.findIndex(parent.children, l => l.id === layerId);
   const children = [...parent.children];
   children.splice(layerIndex, 1, newLayer);
   parent.children = children;
   const actions: Action[] = [
     new SetVectorLayer(LayerUtil.updateLayer(vl, parent)),
     ...this.buildCleanupLayerIdActions(layerId),
   ];
   const animation = this.getAnimation();
   const oldLayerBlocks = animation.blocks.filter(b => b.layerId === layerId);
   const newAnimatableProperties = new Set(newLayer.animatableProperties.keys());
   // Preserve any blocks that are still animatable with the new layer.
   const newLayerBlocks = oldLayerBlocks
     .filter(b => newAnimatableProperties.has(b.propertyName))
     .map(b => {
       b = b.clone();
       b.layerId = newLayer.id;
       return b;
     });
   const newAnimation = animation.clone();
   newAnimation.blocks = [
     ...animation.blocks.filter(b => b.layerId !== layerId),
     ...newLayerBlocks,
   ];
   actions.push(new SetAnimation(newAnimation));
   this.store.dispatch(new BatchAction(...actions));
 }
开发者ID:arpitsaan,项目名称:ShapeShifter,代码行数:38,代码来源:layertimeline.service.ts

示例2:

 tempSelLayers.filter(layer => layer instanceof GroupLayer).forEach(groupLayer => {
   // Move children into parent.
   const parent = LayerUtil.findParent(vl, groupLayer.id).clone();
   const indexInParent = Math.max(
     0,
     _.findIndex(parent.children, l => l.id === groupLayer.id),
   );
   const newChildren = [...parent.children];
   newChildren.splice(indexInParent, 0, ...groupLayer.children);
   parent.children = newChildren;
   vl = LayerUtil.updateLayer(vl, parent);
   newSelectedLayers.splice(0, 0, ...groupLayer.children);
   // Delete the parent.
   vl = LayerUtil.removeLayers(vl, groupLayer.id);
 });
开发者ID:arpitsaan,项目名称:ShapeShifter,代码行数:15,代码来源:layertimeline.service.ts

示例3: AnimationRenderer

 (vl, anim, block) => {
   if (!block) {
     return undefined;
   }
   // Note this is a bit dangerous because the renderer interpolates paths
   // and that causes all mutated path state to be lost if we aren't careful.
   // There are currently checks in PathProperty.ts to avoid this by returning
   // the start and end path when the interpolated fraction is 0 and 1 respectively.
   const renderer = new AnimationRenderer(vl, anim);
   const timeMillis = getTimeFn(block);
   // First interpolate the entire vector layer.
   const renderedVl = renderer.setCurrentTime(timeMillis);
   // TODO: this is hacky! the real solution is to not clear path state after interpolations
   // Replace the interpolated value with the block's to/from value.
   const layer = vl.findLayerById(block.layerId).clone() as MorphableLayer;
   layer.pathData = timeMillis === block.startTime ? block.fromValue : block.toValue;
   return LayerUtil.updateLayer(renderedVl, layer);
 },
开发者ID:arpitsaan,项目名称:ShapeShifter,代码行数:18,代码来源:selectors.ts

示例4: groupOrUngroupSelectedLayers

  /**
   * Groups or ungroups the selected layers.
   */
  groupOrUngroupSelectedLayers(shouldGroup: boolean) {
    let selectedLayerIds = this.getSelectedLayerIds();
    if (!selectedLayerIds.size) {
      return;
    }
    let vl = this.getVectorLayer();

    // Sort selected layers by order they appear in tree.
    let tempSelLayers = Array.from(selectedLayerIds).map(id => vl.findLayerById(id));
    const selLayerOrdersMap: Dictionary<number> = {};
    let n = 0;
    vl.walk(layer => {
      if (_.find(tempSelLayers, l => l.id === layer.id)) {
        selLayerOrdersMap[layer.id] = n;
        n++;
      }
    });
    tempSelLayers.sort((a, b) => selLayerOrdersMap[a.id] - selLayerOrdersMap[b.id]);

    if (shouldGroup) {
      // Remove any layers that are descendants of other selected layers,
      // and remove the vectorLayer itself if selected.
      tempSelLayers = tempSelLayers.filter(layer => {
        if (layer instanceof VectorLayer) {
          return false;
        }
        let p = LayerUtil.findParent(vl, layer.id);
        while (p) {
          if (_.find(tempSelLayers, l => l.id === p.id)) {
            return false;
          }
          p = LayerUtil.findParent(vl, p.id);
        }
        return true;
      });

      if (!tempSelLayers.length) {
        return;
      }

      // Find destination parent and insertion point.
      const firstSelectedLayerParent = LayerUtil.findParent(vl, tempSelLayers[0].id).clone();
      const firstSelectedLayerIndexInParent = _.findIndex(
        firstSelectedLayerParent.children,
        l => l.id === tempSelLayers[0].id,
      );

      // Remove all selected items from their parents and move them into a new parent.
      const newGroup = new GroupLayer({
        name: LayerUtil.getUniqueLayerName([vl], 'group'),
        children: tempSelLayers,
      });
      const parentChildren = [...firstSelectedLayerParent.children];
      parentChildren.splice(firstSelectedLayerIndexInParent, 0, newGroup);
      _.remove(parentChildren, child =>
        _.find(tempSelLayers, selectedLayer => selectedLayer.id === child.id),
      );
      firstSelectedLayerParent.children = parentChildren;
      vl = LayerUtil.updateLayer(vl, firstSelectedLayerParent);
      selectedLayerIds = new Set([newGroup.id]);
    } else {
      // Ungroup selected groups layers.
      const newSelectedLayers: Layer[] = [];
      tempSelLayers.filter(layer => layer instanceof GroupLayer).forEach(groupLayer => {
        // Move children into parent.
        const parent = LayerUtil.findParent(vl, groupLayer.id).clone();
        const indexInParent = Math.max(
          0,
          _.findIndex(parent.children, l => l.id === groupLayer.id),
        );
        const newChildren = [...parent.children];
        newChildren.splice(indexInParent, 0, ...groupLayer.children);
        parent.children = newChildren;
        vl = LayerUtil.updateLayer(vl, parent);
        newSelectedLayers.splice(0, 0, ...groupLayer.children);
        // Delete the parent.
        vl = LayerUtil.removeLayers(vl, groupLayer.id);
      });
      selectedLayerIds = new Set(newSelectedLayers.map(l => l.id));
    }
    this.store.dispatch(
      new BatchAction(new SetVectorLayer(vl), new SetSelectedLayers(selectedLayerIds)),
    );
  }
开发者ID:arpitsaan,项目名称:ShapeShifter,代码行数:87,代码来源:layertimeline.service.ts

示例5: 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));
 }
开发者ID:arpitsaan,项目名称:ShapeShifter,代码行数:72,代码来源:layertimeline.service.ts

示例6: updateLayer

 /**
  * Updates an existing layer in the tree.
  */
 updateLayer(layer: Layer) {
   this.store.dispatch(new SetVectorLayer(LayerUtil.updateLayer(this.getVectorLayer(), layer)));
 }
开发者ID:arpitsaan,项目名称:ShapeShifter,代码行数:6,代码来源:layertimeline.service.ts


注:本文中的app/model/layers.LayerUtil.updateLayer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。