Exemple #1
0
        public static Rect InflateRectByStrokeWidth(Rect extent, PathElement pathElement, bool justCreated)
        {
            double halfStrokeWidth = PathCommandHelper.GetHalfStrokeWidth(pathElement);

            if (halfStrokeWidth != 0.0 && !extent.IsEmpty)
            {
                if (justCreated)
                {
                    double num1 = Math.Truncate(halfStrokeWidth);
                    double num2 = halfStrokeWidth - num1;
                    extent.Inflate(num1, num1);
                    extent.Width  += num2 * 2.0;
                    extent.Height += num2 * 2.0;
                }
                else
                {
                    extent.Inflate(halfStrokeWidth, halfStrokeWidth);
                }
            }
            return(extent);
        }
Exemple #2
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);
        }