Example #1
0
 public static void AdjustPathForAnimations(PathElement pathElement, SceneEditTransaction editTransaction)
 {
     using (pathElement.ViewModel.ForceBaseValue())
     {
         System.Windows.Media.Geometry geometry1 = (System.Windows.Media.Geometry)pathElement.GetLocalOrDefaultValueAsWpf(PathElement.DataProperty);
         PathGeometry pathGeometry = new PathGeometry();
         pathGeometry.AddGeometry(geometry1);
         Rect bounds = PathCommandHelper.InflateRectByStrokeWidth(pathGeometry.Bounds, pathElement, false);
         PropertyReference propertyReference = PathCommandHelper.GetPathDataPropertyReference(pathElement.Platform);
         Rect            maxAnimatedExtent   = PathCommandHelper.FindMaxAnimatedExtent((SceneElement)pathElement, bounds, propertyReference);
         double          num1             = Math.Min(0.0, maxAnimatedExtent.Left);
         double          num2             = Math.Min(0.0, maxAnimatedExtent.Top);
         Vector          vector           = new Vector(-num1, -num2);
         ILayoutDesigner designerForChild = pathElement.ViewModel.GetLayoutDesignerForChild((SceneElement)pathElement, true);
         editTransaction.Update();
         Rect childRect = designerForChild.GetChildRect((BaseFrameworkElement)pathElement);
         childRect.X     += num1;
         childRect.Y     += num2;
         childRect.Width  = Math.Max(maxAnimatedExtent.Width, childRect.Width);
         childRect.Height = Math.Max(maxAnimatedExtent.Height, childRect.Height);
         designerForChild.SetChildRect((BaseFrameworkElement)pathElement, childRect);
         Transform    transform = (Transform) new TranslateTransform(vector.X, vector.Y);
         PathGeometry geometry2 = PathGeometryUtilities.TransformGeometry((System.Windows.Media.Geometry)pathGeometry, transform);
         if (!pathElement.DesignerContext.ActiveDocument.ProjectContext.IsCapabilitySet(PlatformCapability.IsWpf))
         {
             PathGeometryUtilities.EnsureOnlySingleSegmentsInGeometry(geometry2);
         }
         pathElement.PathGeometry = geometry2;
         PathCommandHelper.TransformPointKeyframes((SceneElement)pathElement, propertyReference, transform);
         pathElement.SetValueAsWpf(ShapeElement.StretchProperty, (object)(Stretch)(pathElement.HasVertexAnimations ? 0 : 1));
     }
 }
Example #2
0
        public static List <PathElement> ReleaseCompoundPaths(PathElement pathElement, SceneEditTransaction editTransaction)
        {
            List <PathElement> list              = new List <PathElement>();
            PathGeometry       pathGeometry1     = pathElement.PathGeometry;
            Transform          geometryTransform = pathElement.GeometryTransform;
            ISceneNodeCollection <SceneNode> collectionContainer = pathElement.GetCollectionContainer();
            int num            = collectionContainer.IndexOf((SceneNode)pathElement);
            int oldFigureIndex = 0;

            foreach (PathFigure original in pathGeometry1.Figures)
            {
                PathFigure   pathFigure    = PathFigureUtilities.Copy(original, geometryTransform);
                PathGeometry pathGeometry2 = new PathGeometry();
                if (pathGeometry1.Transform != null && pathGeometry1.Transform.Value != Matrix.Identity)
                {
                    pathGeometry2.Transform = pathGeometry1.Transform.Clone();
                }
                if (pathGeometry2.FillRule != pathGeometry1.FillRule)
                {
                    pathGeometry2.FillRule = pathGeometry1.FillRule;
                }
                pathGeometry2.Figures.Add(pathFigure);
                DocumentNode node         = pathElement.DocumentNode.Clone(pathElement.DocumentContext);
                PathElement  pathElement1 = (PathElement)pathElement.ViewModel.GetSceneNode(node);
                collectionContainer.Insert(num++, (SceneNode)pathElement1);
                Rect extent = pathGeometry2.Bounds;
                extent = PathCommandHelper.InflateRectByStrokeWidth(extent, pathElement1, false);
                Vector vector = new Vector(-extent.Left, -extent.Top);
                PathCommandHelper.ReplacePathGeometry(pathElement1, pathGeometry2, editTransaction);
                Matrix transformToElement = pathElement.GetComputedTransformToElement((SceneElement)pathElement1);
                transformToElement.OffsetX += vector.X;
                transformToElement.OffsetY += vector.Y;
                PropertyReference propertyReference = PathCommandHelper.GetPathDataPropertyReference(pathElement.Platform);
                PathCommandHelper.TransferPathFigureAnimations(pathElement, pathElement1, propertyReference, oldFigureIndex, 0, (Transform) new MatrixTransform(transformToElement));
                PathCommandHelper.AdjustPathForAnimations(pathElement1, editTransaction);
                list.Add(pathElement1);
                ++oldFigureIndex;
            }
            string name = pathElement.Name;

            pathElement.ViewModel.ElementSelectionSet.RemoveSelection((SceneElement)pathElement);
            pathElement.ViewModel.AnimationEditor.DeleteAllAnimationsInSubtree((SceneElement)pathElement);
            pathElement.Remove();
            foreach (SceneNode sceneNode in list)
            {
                sceneNode.Name = name;
            }
            return(list);
        }
Example #3
0
        public static void MakeCompoundPath(PathElement mainElement, List <PathElement> otherElements, SceneEditTransaction editTransaction)
        {
            PathElement              pathElement       = otherElements[otherElements.Count - 1];
            ISceneElementCollection  elementCollection = (ISceneElementCollection) new SceneElementCollection();
            PathAnimationMovePackage animationMove     = new PathAnimationMovePackage();
            PathGeometry             pathGeometry      = new PathGeometry();

            System.Windows.Media.Geometry geometry1 = (System.Windows.Media.Geometry)mainElement.TransformedGeometry;
            pathGeometry.AddGeometry(geometry1);
            foreach (PathElement oldElement in otherElements)
            {
                System.Windows.Media.Geometry geometry2 = (System.Windows.Media.Geometry)oldElement.TransformedGeometry;
                Matrix    transformToElement            = oldElement.GetComputedTransformToElement((SceneElement)mainElement);
                bool      isIdentity = transformToElement.IsIdentity;
                Transform transform  = isIdentity ? Transform.Identity : (Transform) new MatrixTransform(transformToElement);
                transform.Freeze();
                if (!isIdentity)
                {
                    GeometryGroup geometryGroup = new GeometryGroup();
                    geometryGroup.Children.Add(geometry2);
                    geometryGroup.Transform = transform;
                    geometry2 = (System.Windows.Media.Geometry)geometryGroup;
                }
                int count = pathGeometry.Figures.Count;
                pathGeometry.AddGeometry(geometry2);
                int num = pathGeometry.Figures.Count - count;
                PropertyReference propertyReference = PathCommandHelper.GetPathDataPropertyReference(oldElement.Platform);
                for (int oldFigureIndex = 0; oldFigureIndex < num; ++oldFigureIndex)
                {
                    PathCommandHelper.TransferPathFigureAnimations(oldElement, mainElement, propertyReference, oldFigureIndex, count + oldFigureIndex, transform, animationMove);
                }
                elementCollection.Add((SceneElement)oldElement);
            }
            animationMove.Remove();
            Transform transform1 = PathCommandHelper.ReplacePathGeometry(mainElement, pathGeometry, editTransaction);

            animationMove.ApplyTransformToNewAnimations(transform1);
            animationMove.Add();
            PathCommandHelper.AdjustPathForAnimations(mainElement, editTransaction);
            foreach (SceneElement element in (IEnumerable <SceneElement>)elementCollection)
            {
                element.ViewModel.AnimationEditor.DeleteAllAnimationsInSubtree(element);
                element.ViewModel.RemoveElement((SceneNode)element);
            }
        }
Example #4
0
        public static Transform ReplacePathGeometry(PathElement pathElement, PathGeometry pathGeometry, SceneEditTransaction editTransaction)
        {
            Transform transform1 = Transform.Identity;

            using (pathElement.ViewModel.ForceBaseValue())
            {
                if (pathGeometry == null)
                {
                    pathElement.ClearLocalValue(PathElement.DataProperty);
                }
                else
                {
                    editTransaction.Update();
                    ILayoutDesigner designerForChild = pathElement.ViewModel.GetLayoutDesignerForChild((SceneElement)pathElement, true);
                    Rect            childRect        = designerForChild.GetChildRect((BaseFrameworkElement)pathElement);
                    Path            path             = pathElement.Path;
                    Transform       transform2       = path == null ? (Transform)null : path.RenderTransform;
                    Point           point1           = path == null ? new Point(0.0, 0.0) : path.RenderTransformOrigin;
                    double          num           = path == null || path.Stroke == null ? 0.0 : path.StrokeThickness;
                    Rect            bounds        = pathGeometry.Bounds;
                    PathGeometry    pathGeometry1 = new PathGeometry();
                    pathGeometry1.AddGeometry((System.Windows.Media.Geometry)pathGeometry);
                    Rect   rect1   = PathCommandHelper.InflateRectByStrokeWidth(pathGeometry1.Bounds, pathElement, false);
                    Vector vector1 = new Vector(-rect1.Left, -rect1.Top);
                    transform1 = (Transform) new TranslateTransform(vector1.X, vector1.Y);
                    PathGeometry pathGeometry2 = PathGeometryUtilities.TransformGeometry((System.Windows.Media.Geometry)pathGeometry1, transform1);
                    pathElement.PathGeometry = pathGeometry2;
                    PropertyReference propertyReference = PathCommandHelper.GetPathDataPropertyReference(pathElement.Platform);
                    PathCommandHelper.TransformPointKeyframes((SceneElement)pathElement, propertyReference, transform1);
                    if (!bounds.IsEmpty)
                    {
                        bounds.Inflate(num / 2.0, num / 2.0);
                        Rect rect2 = new Rect(childRect.Left + bounds.Left, childRect.Top + bounds.Top, bounds.Width, bounds.Height);
                        editTransaction.Update();
                        designerForChild.SetChildRect((BaseFrameworkElement)pathElement, rect2);
                        if (pathElement.IsSet(Base2DElement.RenderTransformOriginProperty) != PropertyState.Set)
                        {
                            if (transform2 != null)
                            {
                                if (transform2.Value.IsIdentity)
                                {
                                    goto label_15;
                                }
                            }
                            else
                            {
                                goto label_15;
                            }
                        }
                        Vector vector2 = childRect.TopLeft + new Vector(point1.X * childRect.Width, point1.Y * childRect.Height) - rect2.TopLeft;
                        Point  point2  = new Point(0.0, 0.0);
                        if (rect2.Width != 0.0)
                        {
                            point2.X = vector2.X / rect2.Width;
                        }
                        if (rect2.Height != 0.0)
                        {
                            point2.Y = vector2.Y / rect2.Height;
                        }
                        pathElement.RenderTransformOrigin = point2;
                    }
                }
            }
label_15:
            return(transform1);
        }