Exemplo n.º 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));
     }
 }
Exemplo n.º 2
0
        public override void SetSize(Rect sourceRect, BaseFrameworkElement target, ILayoutDesigner targetLayoutDesigner)
        {
            Rect childRect = targetLayoutDesigner.GetChildRect(target);

            childRect.Height = sourceRect.Height;
            targetLayoutDesigner.SetChildRect(target, childRect, false, true);
        }
Exemplo n.º 3
0
        private void SetGridHeightCore(GridElement grid, double height)
        {
            BaseFrameworkElement sizeElement = this.GetSizeElement((BaseFrameworkElement)grid);

            if (sizeElement.ViewModel.RootNode == sizeElement)
            {
                if (!double.IsNaN(sizeElement.Height))
                {
                    sizeElement.Height = height;
                }
                else
                {
                    if (double.IsNaN((double)sizeElement.GetLocalOrDefaultValue(DesignTimeProperties.DesignHeightProperty)))
                    {
                        return;
                    }
                    sizeElement.SetValue(DesignTimeProperties.DesignHeightProperty, (object)height);
                }
            }
            else
            {
                ILayoutDesigner designerForChild = sizeElement.ViewModel.GetLayoutDesignerForChild((SceneElement)sizeElement, true);
                Rect            rect             = designerForChild.GetChildRect(sizeElement);
                rect = new Rect(rect.Left, rect.Top, rect.Width, height);
                designerForChild.SetChildRect(sizeElement, rect, false, true);
            }
        }
Exemplo n.º 4
0
        public override void Execute()
        {
            BaseFrameworkElement selectedElement = this.SelectedElement;
            SceneViewModel       sceneViewModel1 = this.SceneViewModel;
            bool flag1 = true;
            BaseFrameworkElement frameworkElement = selectedElement;
            int             num1             = flag1 ? true : false;
            ILayoutDesigner designerForChild = sceneViewModel1.GetLayoutDesignerForChild((SceneElement)frameworkElement, num1 != 0);
            SceneNode       parent           = selectedElement.Parent;
            IProperty       propertyForChild = parent.GetPropertyForChild((SceneNode)selectedElement);
            ISceneNodeCollection <SceneNode> collectionForProperty = parent.GetCollectionForProperty((IPropertyId)propertyForChild);
            int index = collectionForProperty.IndexOf((SceneNode)selectedElement);

            if (!BehaviorHelper.EnsureBlendSDKLibraryAssemblyReferenced(this.SceneViewModel, "Microsoft.Expression.Controls") || !ProjectContext.GetProjectContext(selectedElement.ProjectContext).IsTypeSupported(ProjectNeutralTypes.PathListBox))
            {
                return;
            }
            using (this.SceneViewModel.DisableUpdateChildrenOnAddAndRemove())
            {
                SceneViewModel sceneViewModel2    = this.SceneViewModel;
                bool           flag2              = false;
                string         unitMakeLayoutPath = StringTable.UndoUnitMakeLayoutPath;
                int            num2 = flag2 ? true : false;
                using (SceneEditTransaction editTransaction = sceneViewModel2.CreateEditTransaction(unitMakeLayoutPath, num2 != 0))
                {
                    using (this.SceneViewModel.ForceBaseValue())
                    {
                        using (this.SceneViewModel.DisableDrawIntoState())
                        {
                            this.SceneViewModel.ElementSelectionSet.Clear();
                            Rect childRect = designerForChild.GetChildRect(selectedElement);
                            selectedElement.EnsureNamed();
                            PathListBoxElement pathListBoxElement = (PathListBoxElement)this.SceneViewModel.CreateSceneNode(ProjectNeutralTypes.PathListBox);
                            LayoutPathNode     layoutPathNode     = (LayoutPathNode)this.SceneViewModel.CreateSceneNode(ProjectNeutralTypes.LayoutPath);
                            BindingSceneNode   bindingSceneNode   = (BindingSceneNode)this.SceneViewModel.CreateSceneNode(PlatformTypes.Binding);
                            bindingSceneNode.ElementName = selectedElement.Name;
                            layoutPathNode.SetValue(LayoutPathNode.SourceElementProperty, (object)bindingSceneNode.DocumentNode);
                            pathListBoxElement.LayoutPaths.Add((SceneNode)layoutPathNode);
                            if (!collectionForProperty.FixedCapacity.HasValue || collectionForProperty.Count < collectionForProperty.FixedCapacity.Value)
                            {
                                collectionForProperty.Insert(index, (SceneNode)pathListBoxElement);
                            }
                            else
                            {
                                GridElement gridElement = (GridElement)this.SceneViewModel.CreateSceneNode(PlatformTypes.Grid);
                                collectionForProperty[index] = (SceneNode)gridElement;
                                gridElement.Children.Add((SceneNode)pathListBoxElement);
                                gridElement.Children.Add((SceneNode)selectedElement);
                            }
                            editTransaction.Update();
                            designerForChild.SetChildRect((BaseFrameworkElement)pathListBoxElement, childRect);
                            this.SceneViewModel.ElementSelectionSet.SetSelection((SceneElement)pathListBoxElement);
                            editTransaction.Commit();
                        }
                    }
                }
            }
        }
Exemplo n.º 5
0
        protected override void Initialize()
        {
            base.Initialize();
            ILayoutDesigner designerForChild = this.ActiveSceneViewModel.GetLayoutDesignerForChild(this.EditingElement, true);

            this.initialRect      = designerForChild.GetChildRect(this.BaseEditingElement);
            this.initialOverrides = designerForChild.ComputeOverrides(this.BaseEditingElement);
            this.transformHelper  = PathElement.TryCreateTransformHelper(this.EditingElement, this.StartSize);
        }
Exemplo n.º 6
0
        public static Rect GetRoundedUpChildRect(ILayoutDesigner designer, BaseFrameworkElement element)
        {
            IPlatformGeometryHelper geometryHelper = element.Platform.GeometryHelper;
            IViewVisual             visual         = element.ViewObject as IViewVisual;

            if (geometryHelper.NeedRoundupLayoutRect(visual))
            {
                using (IDisposable disposable = LayoutRoundingHelper.TurnOffLayoutRounding(element))
                {
                    if (disposable != null)
                    {
                        Rect childRect = designer.GetChildRect(element);
                        return(geometryHelper.RoundupLayoutRect(childRect));
                    }
                }
            }
            return(designer.GetChildRect(element));
        }
Exemplo n.º 7
0
        public override sealed void Execute()
        {
            BaseFrameworkElement child1            = this.SceneViewModel.ElementSelectionSet.PrimarySelection as BaseFrameworkElement;
            BaseFrameworkElement frameworkElement  = child1.ParentElement as BaseFrameworkElement;
            ILayoutDesigner      designerForParent = frameworkElement.ViewModel.GetLayoutDesignerForParent((SceneElement)frameworkElement, true);
            Rect childRect1 = designerForParent.GetChildRect(child1);

            using (SceneEditTransaction editTransaction = this.SceneViewModel.CreateEditTransaction(this.UndoDescription))
            {
                foreach (BaseFrameworkElement child2 in this.SceneViewModel.ElementSelectionSet.Selection)
                {
                    Rect   childRect2 = designerForParent.GetChildRect(child2);
                    Vector offset     = this.GetOffset(childRect1, childRect2);
                    childRect2.Offset(offset);
                    designerForParent.SetChildRect(child2, childRect2, false, false);
                }
                editTransaction.Commit();
            }
        }
Exemplo n.º 8
0
        protected void MoveDraggedElementsInContainer()
        {
            Point point1 = this.DragCurrentPosition;

            if (this.IsConstraining)
            {
                point1 = this.ConstrainPointToAxis(this.DragStartPosition, this.DragCurrentPosition);
            }
            Point point2 = this.ActiveView.TransformPoint((IViewObject)this.ActiveView.HitTestRoot, this.LayoutContainer.Visual, point1);
            Point point3 = this.ActiveView.TransformPoint((IViewObject)this.ActiveView.HitTestRoot, this.LayoutContainer.Visual, this.DragStartPosition);

            for (int index = 0; index < this.DraggedElements.Count; ++index)
            {
                BaseFrameworkElement child = this.DraggedElements[index];
                if (child.IsViewObjectValid)
                {
                    LayoutOverrides overridesToIgnore = LayoutOverrides.None;
                    if (point1.X != this.DragStartPosition.X)
                    {
                        overridesToIgnore |= LayoutOverrides.CenterHorizontalAlignment;
                    }
                    if (point1.Y != this.DragStartPosition.Y)
                    {
                        overridesToIgnore |= LayoutOverrides.CenterVerticalAlignment;
                    }
                    if (this.Context.IsRecordingKeyframes)
                    {
                        Vector             vector             = point2 - point3;
                        CanonicalTransform canonicalTransform = this.Context.BaseRenderTransforms[index];
                        double             num1 = RoundingHelper.RoundLength(vector.X + canonicalTransform.TranslationX);
                        double             num2 = RoundingHelper.RoundLength(vector.Y + canonicalTransform.TranslationY);
                        if (!object.Equals((object)canonicalTransform.TranslationX, (object)num1))
                        {
                            child.SetValue(child.Platform.Metadata.CommonProperties.RenderTransformTranslationX, (object)num1);
                        }
                        if (!object.Equals((object)canonicalTransform.TranslationY, (object)num2))
                        {
                            child.SetValue(child.Platform.Metadata.CommonProperties.RenderTransformTranslationY, (object)num2);
                        }
                    }
                    else
                    {
                        Point           location         = point2;
                        ILayoutDesigner designerForChild = this.ActiveView.ViewModel.GetLayoutDesignerForChild((SceneElement)child, false);
                        Rect            childRect        = designerForChild.GetChildRect(child);
                        Point           point4           = this.ActiveView.TransformPoint(child.Visual, this.LayoutContainer.Visual, this.Context.Offsets[index]);
                        point4.Offset(-childRect.X, -childRect.Y);
                        location.Offset(-point4.X, -point4.Y);
                        Rect rect = new Rect(location, this.Context.LayoutCacheRecords[index].Rect.Size);
                        designerForChild.SetChildRect(child, rect, this.Context.LayoutCacheRecords[index].Overrides, overridesToIgnore, LayoutOverrides.None);
                    }
                }
            }
            this.Context.Transaction.UpdateEditTransaction();
        }
Exemplo n.º 9
0
        private void NestContents(SceneNode node)
        {
            SceneElement sceneElement1 = (SceneElement)node;
            ISceneNodeCollection <SceneNode> destinationCollection = this.DestinationCollection;
            int count = destinationCollection.Count;

            SceneElement[]      sceneElementArray      = new SceneElement[count];
            LayoutCacheRecord[] layoutCacheRecordArray = new LayoutCacheRecord[count];
            ILayoutDesigner     designerForParent1     = this.SceneNode.ViewModel.GetLayoutDesignerForParent(this.SceneElement, true);
            Rect empty = Rect.Empty;

            for (int index = 0; index < count; ++index)
            {
                BaseFrameworkElement frameworkElement = destinationCollection[index] as BaseFrameworkElement;
                if (frameworkElement != null)
                {
                    layoutCacheRecordArray[index] = designerForParent1.CacheLayout(frameworkElement);
                    empty.Union(designerForParent1.GetChildRect(frameworkElement));
                }
            }
            for (int index = 0; index < count; ++index)
            {
                SceneNode    child         = destinationCollection[index];
                SceneElement sceneElement2 = child as SceneElement;
                if (sceneElement2 != null)
                {
                    sceneElementArray[index] = sceneElement2;
                }
                this.SceneNode.ViewModel.RemoveElement(child);
            }
            destinationCollection.Add((SceneNode)sceneElement1);
            for (int index = 0; index < count; ++index)
            {
                if (sceneElementArray[index] != null)
                {
                    sceneElement1.DefaultContent.Add((SceneNode)sceneElementArray[index]);
                }
            }
            this.SceneNode.ViewModel.Document.OnUpdatedEditTransaction();
            this.SceneNode.DesignerContext.ActiveView.UpdateLayout();
            ILayoutDesigner designerForParent2 = this.SceneNode.ViewModel.GetLayoutDesignerForParent(sceneElement1, true);

            for (int index = 0; index < count; ++index)
            {
                if (sceneElementArray[index] != null && layoutCacheRecordArray[index] != null)
                {
                    designerForParent2.SetLayoutFromCache((BaseFrameworkElement)sceneElementArray[index], layoutCacheRecordArray[index], empty);
                }
            }
            if (sceneElementArray.Length != 1)
            {
                return;
            }
            VisualStateManagerSceneNode.MoveStates(sceneElementArray[0], sceneElement1);
        }
Exemplo n.º 10
0
 public override void Execute()
 {
     PerformanceUtility.StartPerformanceSequence(PerformanceEvent.Make3D);
     try
     {
         using (this.SceneViewModel.DisableUpdateChildrenOnAddAndRemove())
         {
             BaseFrameworkElement frameworkElement = (BaseFrameworkElement)this.SceneViewModel.ElementSelectionSet.PrimarySelection;
             using (SceneEditTransaction editTransaction = this.SceneViewModel.CreateEditTransaction(this.UndoUnitName, false))
             {
                 ILayoutDesigner designerForChild = this.SceneViewModel.GetLayoutDesignerForChild((SceneElement)frameworkElement, true);
                 Rect            childRect        = designerForChild.GetChildRect(frameworkElement);
                 DocumentNode    newValue         = this.CreateValue(frameworkElement);
                 if (newValue == null)
                 {
                     editTransaction.Cancel();
                 }
                 else if (this.CreateResource && this.ProcessAsResource(frameworkElement, newValue) == null)
                 {
                     editTransaction.Cancel();
                 }
                 else
                 {
                     if (this.ShouldReplaceOriginal)
                     {
                         this.SceneViewModel.AnimationEditor.DeleteAllAnimationsInSubtree((SceneElement)frameworkElement);
                         Dictionary <IPropertyId, SceneNode> properties = SceneElementHelper.StoreProperties((SceneNode)frameworkElement, true);
                         this.SceneViewModel.ElementSelectionSet.Clear();
                         BaseFrameworkElement element = this.CreateElement(frameworkElement);
                         using (this.SceneViewModel.ForceBaseValue())
                         {
                             element.Name = frameworkElement.Name;
                             ISceneNodeCollection <SceneNode> collectionForChild = frameworkElement.ParentElement.GetCollectionForChild((SceneNode)frameworkElement);
                             int index = collectionForChild.IndexOf((SceneNode)frameworkElement);
                             frameworkElement.Remove();
                             this.Postprocess(frameworkElement, element, properties, childRect);
                             collectionForChild.Insert(index, (SceneNode)element);
                             SceneElementHelper.ApplyProperties((SceneNode)element, properties);
                             editTransaction.Update();
                             designerForChild.SetChildRect(element, childRect);
                         }
                         this.SceneViewModel.ElementSelectionSet.SetSelection((SceneElement)element);
                     }
                     editTransaction.Commit();
                 }
             }
         }
     }
     finally
     {
         PerformanceUtility.EndPerformanceSequence(PerformanceEvent.Make3D);
     }
 }
        protected override void Initialize()
        {
            base.Initialize();
            ILayoutDesigner designerForChild = this.ActiveSceneViewModel.GetLayoutDesignerForChild(this.EditingElementSet.PrimaryElement, true);

            this.pathTransformHelpers.Clear();
            foreach (SceneElement element in this.EditingElementSet.Elements)
            {
                this.startWidthSet[element]     = element.IsSet(BaseFrameworkElement.WidthProperty) == PropertyState.Set;
                this.startHeightSet[element]    = element.IsSet(BaseFrameworkElement.HeightProperty) == PropertyState.Set;
                this.initialOverrides[element]  = designerForChild.ComputeOverrides((BaseFrameworkElement)element);
                this.initialRects[element]      = designerForChild.GetChildRect((BaseFrameworkElement)element);
                this.initialTransforms[element] = new CanonicalDecomposition(this.StartTransformsDictionary[element]);
                PathElement.PathTransformHelper transformHelper = PathElement.TryCreateTransformHelper(element, this.StartBoundsDictionary[element].Size);
                if (transformHelper != null)
                {
                    this.pathTransformHelpers[element] = transformHelper;
                }
            }
        }
Exemplo n.º 12
0
        public static PathElement ConvertToPath(BaseFrameworkElement element)
        {
            SceneViewModel  viewModel        = element.ViewModel;
            PathGeometry    pathGeometry     = PathConversionHelper.ConvertToPathGeometry((SceneElement)element);
            PathElement     pathElement      = (PathElement)viewModel.CreateSceneNode(PlatformTypes.Path);
            ILayoutDesigner designerForChild = viewModel.GetLayoutDesignerForChild((SceneElement)element, true);
            Rect            childRect        = designerForChild.GetChildRect(element);
            Transform       transform1       = Transform.Identity;

            if (element.IsSet(Base2DElement.RenderTransformProperty) == PropertyState.Set)
            {
                transform1 = (Transform)element.GetComputedValueAsWpf(Base2DElement.RenderTransformProperty);
            }
            Point point1 = new Point(0.5, 0.5);

            if (element.IsSet(Base2DElement.RenderTransformOriginProperty) == PropertyState.Set)
            {
                point1 = (Point)element.GetComputedValueAsWpf(Base2DElement.RenderTransformOriginProperty);
            }
            bool flag = false;

            using (SceneEditTransaction editTransaction = viewModel.CreateEditTransaction(StringTable.UndoUnitConvertToPath, true))
            {
                using (viewModel.ForceBaseValue())
                {
                    pathElement.PathGeometry = pathGeometry;
                    pathElement.SetValueAsWpf(ShapeElement.StretchProperty, (object)Stretch.Fill);
                    Brush textForeground = PathCommandHelper.GetTextForeground(element);
                    if (textForeground != null)
                    {
                        flag = true;
                        pathElement.SetValueAsWpf(ShapeElement.FillProperty, (object)textForeground);
                    }
                    viewModel.AnimationEditor.DeleteAllAnimations((SceneNode)element);
                    Dictionary <IPropertyId, SceneNode> properties         = SceneElementHelper.StoreProperties((SceneNode)element);
                    ISceneNodeCollection <SceneNode>    collectionForChild = element.Parent.GetCollectionForChild((SceneNode)element);
                    int index = collectionForChild.IndexOf((SceneNode)element);
                    collectionForChild[index] = (SceneNode)pathElement;
                    if (flag)
                    {
                        List <IPropertyId> list = new List <IPropertyId>();
                        foreach (KeyValuePair <IPropertyId, SceneNode> keyValuePair in properties)
                        {
                            IPropertyId key = keyValuePair.Key;
                            DependencyPropertyReferenceStep propertyReferenceStep = key as DependencyPropertyReferenceStep;
                            if (propertyReferenceStep != null && !propertyReferenceStep.IsAttachable && (propertyReferenceStep.MemberType != MemberType.DesignTimeProperty && !PlatformTypeHelper.GetDeclaringType((IMember)propertyReferenceStep).IsAssignableFrom(typeof(Path))))
                            {
                                list.Add(key);
                            }
                        }
                        foreach (IPropertyId key in list)
                        {
                            properties.Remove(key);
                        }
                    }
                    SceneElementHelper.ApplyProperties((SceneNode)pathElement, properties);
                }
                if (ProjectNeutralTypes.PrimitiveShape.IsAssignableFrom((ITypeId)element.Type))
                {
                    using (viewModel.ForceBaseValue())
                    {
                        Rect   bounds          = pathGeometry.Bounds;
                        double halfStrokeWidth = PathCommandHelper.GetHalfStrokeWidth(pathElement);
                        bounds.Inflate(halfStrokeWidth / 2.0, halfStrokeWidth / 2.0);
                        if (transform1 != Transform.Identity && bounds.Size != childRect.Size)
                        {
                            Point point2 = (Point)pathElement.GetComputedValueAsWpf(Base2DElement.RenderTransformOriginProperty);
                            Point point3 = new Point(point2.X * childRect.Width, point2.Y * childRect.Height);
                            Point point4 = new Point((point3.X - bounds.X) / bounds.Width, (point3.Y - bounds.Y) / bounds.Height);
                            pathElement.SetValueAsWpf(Base2DElement.RenderTransformOriginProperty, (object)point4);
                        }
                        bounds.Offset(childRect.Left, childRect.Top);
                        editTransaction.Update();
                        designerForChild.SetChildRect((BaseFrameworkElement)pathElement, bounds);
                    }
                }
                if (flag && !pathGeometry.IsEmpty())
                {
                    using (viewModel.ForceBaseValue())
                    {
                        Rect bounds = pathGeometry.Bounds;
                        bounds.Offset(childRect.Left, childRect.Top);
                        Point point2 = new Point(bounds.Left + point1.X * bounds.Width, bounds.Top + point1.Y * bounds.Height);
                        Point point3 = new Point(childRect.Left + childRect.Width * point1.X, childRect.Top + childRect.Height * point1.Y);
                        Point point4 = new TransformGroup()
                        {
                            Children =
                            {
                                (Transform) new TranslateTransform(-point3.X, -point3.Y),
                                transform1,
                                (Transform) new TranslateTransform(point3.X,  point3.Y)
                            }
                        }.Transform(point2);
                        Transform transform2 = (Transform) new CanonicalTransform(transform1)
                        {
                            TranslationX = 0.0,
                            TranslationY = 0.0
                        }.TransformGroup;
                        Rect rect = new Rect(point4.X - bounds.Width * point1.X, point4.Y - bounds.Height * point1.Y, bounds.Width, bounds.Height);
                        pathElement.SetValueAsWpf(Base2DElement.RenderTransformOriginProperty, (object)point1);
                        editTransaction.Update();
                        designerForChild.SetChildRect((BaseFrameworkElement)pathElement, rect);
                        pathElement.RenderTransform = transform2;
                    }
                }
                editTransaction.Commit();
            }
            return(pathElement);
        }
Exemplo n.º 13
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);
        }
Exemplo n.º 14
0
        private void SetLayout(ISceneInsertionPoint insertionPoint, Rect rect, SceneNode node, SceneNode layoutTarget, SceneEditTransaction undo)
        {
            if (!PlatformTypes.UIElement.IsAssignableFrom((ITypeId)node.Type))
            {
                return;
            }
            bool flag1 = false;
            bool flag2 = false;

            if (node.IsSet(BaseFrameworkElement.WidthProperty) == PropertyState.Set && double.IsNaN(rect.Width))
            {
                rect.Width = (double)node.GetLocalOrDefaultValueAsWpf(BaseFrameworkElement.WidthProperty);
                flag1      = true;
            }
            if (node.IsSet(BaseFrameworkElement.HeightProperty) == PropertyState.Set && double.IsNaN(rect.Height))
            {
                rect.Height = (double)node.GetLocalOrDefaultValueAsWpf(BaseFrameworkElement.HeightProperty);
                flag2       = true;
            }
            using (this.ViewModel.ForceBaseValue())
            {
                BaseFrameworkElement child = layoutTarget as BaseFrameworkElement;
                if (child == null)
                {
                    return;
                }
                SetRectMode     setRectMode      = SetRectMode.Default;
                ILayoutDesigner designerForChild = child.ViewModel.GetLayoutDesignerForChild((SceneElement)child, true);
                if (double.IsNaN(rect.Width) || double.IsNaN(rect.Height))
                {
                    setRectMode = SetRectMode.CreateDefault;
                    bool flag3 = PlatformTypes.Control.IsAssignableFrom((ITypeId)node.Type) || PlatformTypes.TextBlock.IsAssignableFrom((ITypeId)node.Type);
                    for (int index = 0; index < DefaultTypeInstantiator.SizeNonExceptions.Length; ++index)
                    {
                        if (DefaultTypeInstantiator.SizeNonExceptions[index].Equals((object)node.Type))
                        {
                            flag3 = false;
                        }
                    }
                    if (!flag3)
                    {
                        BaseFrameworkElement frameworkElement = insertionPoint.SceneNode as BaseFrameworkElement;
                        if (frameworkElement != null)
                        {
                            Rect   computedTightBounds = frameworkElement.GetComputedTightBounds();
                            double val1_1 = 100.0;
                            double val1_2 = 100.0;
                            if (ProjectNeutralTypes.GridSplitter.IsAssignableFrom((ITypeId)node.Type))
                            {
                                val1_1 = 5.0;
                            }
                            else if (PlatformTypes.Button.IsAssignableFrom((ITypeId)node.Type))
                            {
                                val1_1 = 75.0;
                            }
                            else if (PlatformTypes.ComboBox.IsAssignableFrom((ITypeId)node.Type))
                            {
                                val1_1 = 120.0;
                            }
                            if (PlatformTypes.ProgressBar.IsAssignableFrom((ITypeId)node.Type))
                            {
                                val1_2 = 10.0;
                            }
                            else if (PlatformTypes.Button.IsAssignableFrom((ITypeId)node.Type) || PlatformTypes.ComboBox.IsAssignableFrom((ITypeId)node.Type))
                            {
                                val1_2 = double.NaN;
                            }
                            if ((designerForChild.GetWidthConstraintMode(child) & LayoutConstraintMode.CanvasLike) == LayoutConstraintMode.NonOverlappingGridlike)
                            {
                                val1_1 = Math.Min(val1_1, computedTightBounds.Width);
                            }
                            if ((designerForChild.GetHeightConstraintMode(child) & LayoutConstraintMode.CanvasLike) == LayoutConstraintMode.NonOverlappingGridlike)
                            {
                                val1_2 = Math.Min(val1_2, computedTightBounds.Height);
                            }
                            rect = new Rect(rect.Left, rect.Top, double.IsNaN(rect.Width) ? val1_1 : rect.Width, double.IsNaN(rect.Height) ? val1_2 : rect.Height);
                        }
                    }
                }
                LayoutOverrides layoutOverrides   = LayoutOverrides.None;
                LayoutOverrides overridesToIgnore = LayoutOverrides.None;
                Rect            rect1             = rect;
                if (double.IsNaN(rect.Width))
                {
                    layoutOverrides |= LayoutOverrides.Width;
                    rect1.Width      = 0.0;
                }
                else
                {
                    overridesToIgnore |= LayoutOverrides.Width;
                }
                if (double.IsNaN(rect.Height))
                {
                    layoutOverrides |= LayoutOverrides.Height;
                    rect1.Height     = 0.0;
                }
                else
                {
                    overridesToIgnore |= LayoutOverrides.Height;
                }
                designerForChild.SetChildRect(child, rect1, layoutOverrides, overridesToIgnore, LayoutOverrides.None, setRectMode);
                undo.Update();
                IViewVisual viewVisual = child.ViewObject as IViewVisual;
                if (viewVisual == null || !double.IsNaN(rect.Width) && !double.IsNaN(rect.Height))
                {
                    return;
                }
                viewVisual.UpdateLayout();
                Rect childRect = designerForChild.GetChildRect(child);
                if (double.IsNaN(rect.Width) && !flag1)
                {
                    if (viewVisual.RenderSize.Width < 5.0)
                    {
                        rect1.Width        = 100.0;
                        layoutOverrides   &= ~LayoutOverrides.Width;
                        overridesToIgnore |= LayoutOverrides.Width;
                    }
                    else
                    {
                        rect1.Width = childRect.Width;
                    }
                }
                if (double.IsNaN(rect.Height) && !flag2)
                {
                    if (viewVisual.RenderSize.Height < 5.0)
                    {
                        rect1.Height       = 100.0;
                        layoutOverrides   &= ~LayoutOverrides.Height;
                        overridesToIgnore |= LayoutOverrides.Height;
                    }
                    else
                    {
                        rect1.Height = childRect.Height;
                    }
                }
                LayoutOverrides nonExplicitOverrides = LayoutOverrides.None;
                if (PlatformTypes.FlowDocumentScrollViewer.IsAssignableFrom((ITypeId)child.Type) || PlatformTypes.RichTextBox.IsAssignableFrom((ITypeId)child.Type))
                {
                    nonExplicitOverrides = LayoutOverrides.Width;
                }
                designerForChild.SetChildRect(child, rect1, layoutOverrides, overridesToIgnore, nonExplicitOverrides, setRectMode);
            }
        }
Exemplo n.º 15
0
        private SceneNode[] Ungroup(SceneEditTransaction transaction, BaseFrameworkElement group)
        {
            SceneElement parentElement = group.ParentElement;

            if (parentElement == null)
            {
                return(new SceneNode[0]);
            }
            transaction.Update();
            ILayoutDesigner designerForParent1       = this.SceneViewModel.GetLayoutDesignerForParent(parentElement, true);
            Rect            childRect                = designerForParent1.GetChildRect(group);
            Matrix          effectiveRenderTransform = group.GetEffectiveRenderTransform(false);

            SceneNode[] array = new SceneNode[group.DefaultContent.Count];
            group.DefaultContent.CopyTo(array, 0);
            using (this.SceneViewModel.DisableUpdateChildrenOnAddAndRemove())
            {
                Transform[]         transformArray         = new Transform[array.Length];
                Point[]             pointArray             = new Point[array.Length];
                LayoutCacheRecord[] layoutCacheRecordArray = new LayoutCacheRecord[array.Length];
                ILayoutDesigner     designerForParent2     = group.ViewModel.GetLayoutDesignerForParent((SceneElement)group, true);
                for (int index = 0; index < array.Length; ++index)
                {
                    BaseFrameworkElement frameworkElement = array[index] as BaseFrameworkElement;
                    if (frameworkElement != null)
                    {
                        transformArray[index] = (Transform)frameworkElement.GetComputedValueAsWpf(Base2DElement.RenderTransformProperty);
                        pointArray[index]     = frameworkElement.RenderTransformOrigin;
                        designerForParent2.GetChildRect(frameworkElement);
                        LayoutCacheRecord layoutCacheRecord = designerForParent2.CacheLayout(frameworkElement);
                        layoutCacheRecordArray[index] = layoutCacheRecord;
                    }
                }
                int num1;
                if (array.Length == 1 && array[0] is BaseFrameworkElement)
                {
                    int?fixedCapacity = group.DefaultContent.FixedCapacity;
                    num1 = fixedCapacity.GetValueOrDefault() != 1 ? 0 : (fixedCapacity.HasValue ? true : false);
                }
                else
                {
                    num1 = 0;
                }
                bool flag = num1 != 0;
                if (flag)
                {
                    Dictionary <IPropertyId, SceneNode> properties = SceneElementHelper.StoreProperties((SceneNode)group, designerForParent1.GetLayoutProperties(), true);
                    SceneElementHelper.FixElementNameBindingsInStoredProperties((SceneNode)group, array[0], properties);
                    if (!SceneElementHelper.ApplyProperties(array[0], properties))
                    {
                        flag = false;
                    }
                }
                if (array.Length == 1 && array[0] is SceneElement)
                {
                    VisualStateManagerSceneNode.MoveStates((SceneElement)group, (SceneElement)array[0]);
                }
                using (this.SceneViewModel.ForceBaseValue())
                {
                    SceneElement sceneElement = (SceneElement)null;
                    for (int index = 0; index < array.Length; ++index)
                    {
                        BaseFrameworkElement frameworkElement = array[index] as BaseFrameworkElement;
                        if (frameworkElement != null)
                        {
                            if (this.SceneViewModel.LockedInsertionPoint != null && this.SceneViewModel.LockedInsertionPoint.SceneElement == frameworkElement)
                            {
                                sceneElement = (SceneElement)frameworkElement;
                            }
                            DocumentNodeHelper.PreserveFormatting(frameworkElement.DocumentNode);
                            frameworkElement.Remove();
                        }
                    }
                    ISceneNodeCollection <SceneNode> collectionContainer = group.GetCollectionContainer();
                    int index1 = collectionContainer.IndexOf((SceneNode)group);
                    this.SceneViewModel.AnimationEditor.DeleteAllAnimationsInSubtree((SceneElement)group);
                    this.SceneViewModel.RemoveElement((SceneNode)group);
                    Matrix matrix1 = effectiveRenderTransform;
                    matrix1.OffsetX = 0.0;
                    matrix1.OffsetY = 0.0;
                    for (int index2 = array.Length - 1; index2 >= 0; --index2)
                    {
                        BaseFrameworkElement frameworkElement = array[index2] as BaseFrameworkElement;
                        if (frameworkElement != null)
                        {
                            Matrix matrix2 = (transformArray[index2] ?? Transform.Identity).Value;
                            collectionContainer.Insert(index1, (SceneNode)frameworkElement);
                            CanonicalTransform canonicalTransform = new CanonicalTransform((Transform) new MatrixTransform(matrix2 * matrix1));
                            if (frameworkElement.GetLocalValue(Base2DElement.RenderTransformProperty) != null || !canonicalTransform.TransformGroup.Value.IsIdentity)
                            {
                                frameworkElement.SetValue(Base2DElement.RenderTransformProperty, canonicalTransform.GetPlatformTransform(frameworkElement.Platform.GeometryHelper));
                                if (frameworkElement.IsSet(Base2DElement.RenderTransformOriginProperty) == PropertyState.Unset)
                                {
                                    frameworkElement.SetValueAsWpf(Base2DElement.RenderTransformOriginProperty, (object)new Point(0.5, 0.5));
                                }
                            }
                        }
                    }
                    transaction.Update();
                    if (sceneElement != null)
                    {
                        this.SceneViewModel.SetLockedInsertionPoint(sceneElement);
                    }
                    bool[] flagArray = new bool[array.Length];
                    int    length    = 0;
                    for (int index2 = 0; index2 < array.Length; ++index2)
                    {
                        BaseFrameworkElement frameworkElement = array[index2] as BaseFrameworkElement;
                        if (frameworkElement != null && array[index2].Parent != null)
                        {
                            if (!flag)
                            {
                                LayoutCacheRecord layoutCacheRecord = layoutCacheRecordArray[index2];
                                Rect  rect1  = layoutCacheRecord.Rect;
                                Point point1 = new Point(rect1.X + rect1.Width * pointArray[index2].X, rect1.Y + rect1.Height * pointArray[index2].Y);
                                Point point2 = effectiveRenderTransform.Transform(point1);
                                Rect  rect2  = new Rect(rect1.TopLeft + point2 - point1 + (Vector)childRect.TopLeft, rect1.Size);
                                designerForParent1.ClearUnusedLayoutProperties(frameworkElement);
                                designerForParent1.SetChildRect(frameworkElement, rect2, layoutCacheRecord.Overrides, LayoutOverrides.Margin | LayoutOverrides.GridBox, LayoutOverrides.None);
                            }
                            flagArray[index2] = true;
                            ++length;
                        }
                    }
                    SceneNode[] sceneNodeArray = new SceneNode[length];
                    int         num2           = 0;
                    for (int index2 = 0; index2 < array.Length; ++index2)
                    {
                        if (flagArray[index2])
                        {
                            sceneNodeArray[num2++] = array[index2];
                        }
                    }
                    return(sceneNodeArray);
                }
            }
        }
Exemplo n.º 16
0
        protected override void EndEditingInternal(bool pathJustCreated)
        {
            Matrix identity = Matrix.Identity;

            if (!pathJustCreated)
            {
                Transform geometryTransform = this.pathElement.GeometryTransform;
                if (geometryTransform != null)
                {
                    identity = geometryTransform.Value;
                }
            }
            Rect extent1 = PathGeometryUtilities.TightExtent(this.PathGeometry, identity);
            Rect extent2 = extent1;
            bool flag1   = false;

            if (this.ViewModel.AnimationEditor.IsKeyFraming)
            {
                if ((Stretch)this.pathElement.GetLocalOrDefaultValueAsWpf(ShapeElement.StretchProperty) != Stretch.None)
                {
                    flag1 = true;
                    if (!pathJustCreated)
                    {
                        extent1 = PathGeometryUtilities.TightExtent(this.pathElement.PathGeometry, Matrix.Identity);
                    }
                    using (this.ViewModel.ForceBaseValue())
                    {
                        using (this.ViewModel.AnimationEditor.DeferKeyFraming())
                        {
                            this.pathElement.SetValueAsWpf(ShapeElement.StretchProperty, (object)Stretch.None);
                            this.ViewModel.Document.OnUpdatedEditTransaction();
                        }
                    }
                }
                if (this.pathElement.EnsureSingleSegmentsInPathGeometry())
                {
                    this.ViewModel.Document.OnUpdatedEditTransaction();
                }
            }
            Rect         extent3        = PathCommandHelper.InflateRectByStrokeWidth(extent1, this.pathElement, pathJustCreated);
            Rect         rect1          = PathCommandHelper.InflateRectByStrokeWidth(extent2, this.pathElement, pathJustCreated);
            Rect         computedBounds = this.pathElement.GetComputedBounds((Base2DElement)this.pathElement);
            PathGeometry pathGeometry1  = this.PathGeometry;

            if (flag1 && !pathJustCreated)
            {
                ScenePathEditorTarget.NormalizePathGeometry(pathGeometry1, extent3, computedBounds);
            }
            if (flag1)
            {
                this.OnMatrixChanged();
            }
            Vector    vector1     = new Vector(extent3.Left, extent3.Top);
            Transform transform   = (Transform)null;
            Point     centerPoint = new Point();
            bool      flag2       = (Stretch)this.pathElement.GetComputedValueAsWpf(ShapeElement.StretchProperty) == Stretch.None && (this.ViewModel.AnimationEditor.IsKeyFraming || this.pathElement.HasVertexAnimations) && !pathJustCreated;

            if (flag2 && !computedBounds.Contains(rect1))
            {
                ILayoutDesigner designerForChild = this.ViewModel.GetLayoutDesignerForChild((SceneElement)this.pathElement, true);
                Rect            childRect        = designerForChild.GetChildRect((BaseFrameworkElement)this.pathElement);
                double          x       = Math.Min(0.0, rect1.Left);
                double          y       = Math.Min(0.0, rect1.Top);
                Vector          vector2 = new Vector(x, y);
                centerPoint = this.pathElement.RenderTransformOrigin;
                transform   = this.pathElement.RenderTransform;
                if (transform != null && !transform.Value.IsIdentity)
                {
                    using (this.ViewModel.ForceBaseValue())
                    {
                        using (this.ViewModel.AnimationEditor.DeferKeyFraming())
                            this.UpdateCenterPoint(new Point(0.0, 0.0));
                    }
                    vector2 *= transform.Value;
                }
                double num1 = Math.Max(0.0, rect1.Right - computedBounds.Right);
                double num2 = Math.Max(0.0, rect1.Bottom - computedBounds.Bottom);
                childRect.X      += vector2.X;
                childRect.Y      += vector2.Y;
                childRect.Width  += -x + num1;
                childRect.Height += -y + num2;
                using (this.ViewModel.ForceBaseValue())
                {
                    using (this.ViewModel.AnimationEditor.DeferKeyFraming())
                        designerForChild.SetChildRect((BaseFrameworkElement)this.pathElement, childRect);
                }
                if (x != 0.0 || y != 0.0)
                {
                    this.AdjustKeyframes(new Vector(x, y));
                    ScenePathEditorTarget.UpdateAllPoints(pathGeometry1, new Vector(x, y), 1.0, 1.0);
                    PathGeometry pathGeometry2 = this.pathElement.PathGeometry;
                    ScenePathEditorTarget.UpdateAllPoints(pathGeometry2, new Vector(x, y), 1.0, 1.0);
                    this.pathElement.PathGeometry = pathGeometry2;
                }
                this.ViewModel.Document.OnUpdatedEditTransaction();
                if (transform != null && !transform.Value.IsIdentity)
                {
                    using (this.ViewModel.ForceBaseValue())
                    {
                        using (this.ViewModel.AnimationEditor.DeferKeyFraming())
                            this.UpdateCenterPoint(centerPoint);
                    }
                }
            }
            if (!flag2 && (Stretch)this.pathElement.GetComputedValueAsWpf(ShapeElement.StretchProperty) == Stretch.None)
            {
                ScenePathEditorTarget.UpdateAllPoints(pathGeometry1, vector1, 1.0, 1.0);
            }
            if (!flag2)
            {
                using (this.ViewModel.ForceBaseValue())
                {
                    using (this.ViewModel.AnimationEditor.DeferKeyFraming())
                    {
                        centerPoint = this.pathElement.RenderTransformOrigin;
                        transform   = this.pathElement.RenderTransform;
                        if (!extent3.IsEmpty)
                        {
                            if (transform != null && !transform.Value.IsIdentity)
                            {
                                this.UpdateCenterPoint(new Point(0.0, 0.0));
                                vector1 *= transform.Value;
                            }
                            ILayoutDesigner designerForChild = this.ViewModel.GetLayoutDesignerForChild((SceneElement)this.pathElement, false);
                            Rect            rect2            = designerForChild.GetChildRect((BaseFrameworkElement)this.pathElement);
                            if (pathJustCreated)
                            {
                                rect2 = new Rect(0.0, 0.0, 0.0, 0.0);
                            }
                            double width  = extent3.Width;
                            double height = extent3.Height;
                            rect2.Offset(vector1);
                            rect2.Width  = width;
                            rect2.Height = height;
                            designerForChild.SetChildRect((BaseFrameworkElement)this.pathElement, rect2);
                        }
                    }
                }
            }
            if (this.pathElement.IsAttached && (this.ViewModel.AnimationEditor.IsKeyFraming || this.pathElement.HasVertexAnimations) && !pathJustCreated)
            {
                new PathDiff((Base2DElement)this.pathElement, PathElement.DataProperty, this.PathDiffChangeList).SetPathUsingMinimalDiff(pathGeometry1);
            }
            else
            {
                this.pathElement.PathGeometry = pathGeometry1;
            }
            if (flag2)
            {
                return;
            }
            using (this.ViewModel.ForceBaseValue())
            {
                using (this.ViewModel.AnimationEditor.DeferKeyFraming())
                {
                    if (extent3.IsEmpty)
                    {
                        return;
                    }
                    this.ViewModel.Document.OnUpdatedEditTransaction();
                    if (transform == null || transform.Value.IsIdentity)
                    {
                        return;
                    }
                    this.UpdateCenterPoint(centerPoint);
                }
            }
        }