protected override bool OnDrag(Point dragStartPosition, Point dragCurrentPosition, bool scrollNow)
        {
            SceneView activeView = this.ActiveView;

            this.EnsureEditTransaction();
            dragCurrentPosition = this.ToolBehaviorContext.SnappingEngine.SnapPoint(dragCurrentPosition);
            Point point = dragCurrentPosition * activeView.GetComputedTransformFromRoot(this.EditingElement.Visual);

            if (this.ActiveAdorner.IsX)
            {
                double num = RoundingHelper.RoundLength(Math.Max(0.0, Math.Min(point.X, this.ActiveView.GetRenderSize(this.EditingElement.Visual).Width / 2.0) - this.ActiveAdorner.HalfStrokeThickness));
                this.EditingElement.SetValue(RectangleElement.RadiusXProperty, (object)num);
                if (!this.IsShiftDown)
                {
                    this.EditingElement.SetValue(RectangleElement.RadiusYProperty, (object)num);
                }
            }
            else
            {
                double num = RoundingHelper.RoundLength(Math.Max(0.0, Math.Min(point.Y, this.ActiveView.GetRenderSize(this.EditingElement.Visual).Height / 2.0) - this.ActiveAdorner.HalfStrokeThickness));
                this.EditingElement.SetValue(RectangleElement.RadiusYProperty, (object)num);
                if (!this.IsShiftDown)
                {
                    this.EditingElement.SetValue(RectangleElement.RadiusXProperty, (object)num);
                }
            }
            this.UpdateEditTransaction();
            activeView.EnsureVisible((IAdorner)this.ActiveAdorner, scrollNow);
            return(true);
        }
示例#2
0
        protected virtual void UpdateCenterPoint(Point centerPoint)
        {
            CanonicalTransform canonicalTransform = new CanonicalTransform((Transform)this.EditingElement.GetComputedValueAsWpf(Base2DElement.RenderTransformProperty));
            Point  elementCoordinates             = this.BaseEditingElement.RenderTransformOriginInElementCoordinates;
            Vector translation           = canonicalTransform.Translation;
            Rect   computedTightBounds   = ((Base2DElement)this.EditingElement).GetComputedTightBounds();
            Point  renderTransformOrigin = this.BaseEditingElement.RenderTransformOrigin;
            Point  point2 = new Point((centerPoint.X - computedTightBounds.Left) / (computedTightBounds.Width == 0.0 ? 1.0 : computedTightBounds.Width), (centerPoint.Y - computedTightBounds.Top) / (computedTightBounds.Height == 0.0 ? 1.0 : computedTightBounds.Height));

            point2 = RoundingHelper.RoundPosition(point2);
            Point newOrigin = new Point(computedTightBounds.Left + point2.X * computedTightBounds.Width, computedTightBounds.Top + point2.Y * computedTightBounds.Height);

            canonicalTransform.UpdateForNewOrigin(elementCoordinates, newOrigin);
            canonicalTransform.TranslationX = RoundingHelper.RoundLength(canonicalTransform.TranslationX);
            canonicalTransform.TranslationY = RoundingHelper.RoundLength(canonicalTransform.TranslationY);
            if (!Point.Equals(renderTransformOrigin, point2))
            {
                this.BaseEditingElement.RenderTransformOrigin = point2;
            }
            if (!object.Equals((object)translation.X, (object)canonicalTransform.TranslationX))
            {
                this.EditingElement.SetValue(this.EditingElement.Platform.Metadata.CommonProperties.RenderTransformTranslationX, (object)canonicalTransform.TranslationX);
            }
            if (object.Equals((object)translation.Y, (object)canonicalTransform.TranslationY))
            {
                return;
            }
            this.EditingElement.SetValue(this.EditingElement.Platform.Metadata.CommonProperties.RenderTransformTranslationY, (object)canonicalTransform.TranslationY);
        }
        protected override void ApplyScale(Vector scale, Point center)
        {
            Rect   elementBounds = this.EditingElementSet.ElementBounds;
            Matrix m             = this.startSharedTransform;
            Matrix inverseMatrix = ElementUtilities.GetInverseMatrix(m);
            Matrix matrix1       = new Matrix();

            matrix1.Translate(-center.X, -center.Y);
            foreach (SceneElement element in this.EditingElementSet.Elements)
            {
                Matrix matrix2 = this.elementToElementsTransformDictionary[element] * matrix1;
                Point  point1  = this.startCentersDictionary[element];
                Matrix matrix3 = this.startTransformsDictionary[element];
                Rect   rect    = this.startBoundsDictionary[element];
                Point  point2  = new Point(rect.X + rect.Width * point1.X, rect.Y + rect.Height * point1.Y);
                Point  point3  = matrix2.Transform(point2);
                Vector vector  = new Point(scale.X * point3.X, scale.Y * point3.Y) - point3;
                Matrix matrix4 = matrix3 * inverseMatrix;
                matrix4.ScaleAt(scale.X, scale.Y, matrix4.OffsetX, matrix4.OffsetY);
                matrix4.Translate(vector.X, vector.Y);
                CanonicalDecomposition newTransform = new CanonicalDecomposition(matrix4 * m);
                newTransform.ScaleX        = RoundingHelper.RoundScale(newTransform.ScaleX);
                newTransform.ScaleY        = RoundingHelper.RoundScale(newTransform.ScaleY);
                newTransform.SkewX         = RoundingHelper.RoundAngle(newTransform.SkewX);
                newTransform.SkewY         = RoundingHelper.RoundAngle(newTransform.SkewY);
                newTransform.RotationAngle = RoundingHelper.RoundAngle(newTransform.RotationAngle);
                newTransform.TranslationX  = RoundingHelper.RoundLength(newTransform.TranslationX);
                newTransform.TranslationY  = RoundingHelper.RoundLength(newTransform.TranslationY);
                AdornedToolBehavior.UpdateElementTransform(element, newTransform, AdornedToolBehavior.TransformPropertyFlags.All);
            }
        }
示例#4
0
        protected virtual void ComputeIdealMargin()
        {
            bool flag1 = (this.WidthConstraintMode & LayoutConstraintMode.CanvasLike) == LayoutConstraintMode.NonOverlappingGridlike;
            bool flag2 = (this.HeightConstraintMode & LayoutConstraintMode.CanvasLike) == LayoutConstraintMode.NonOverlappingGridlike;

            this.Settings.Margin = new Thickness(RoundingHelper.RoundLength(!flag1 || this.Settings.HorizontalAlignment != HorizontalAlignment.Left && this.Settings.HorizontalAlignment != HorizontalAlignment.Stretch ? 0.0 : this.ChildRect.Left - this.SlotRect.Left), RoundingHelper.RoundLength(!flag2 || this.Settings.VerticalAlignment != VerticalAlignment.Top && this.Settings.VerticalAlignment != VerticalAlignment.Stretch ? 0.0 : this.ChildRect.Top - this.SlotRect.Top), RoundingHelper.RoundLength(!flag1 || this.Settings.HorizontalAlignment != HorizontalAlignment.Right && this.Settings.HorizontalAlignment != HorizontalAlignment.Stretch ? 0.0 : this.SlotRect.Right - this.ChildRect.Right), RoundingHelper.RoundLength(!flag2 || this.Settings.VerticalAlignment != VerticalAlignment.Bottom && this.Settings.VerticalAlignment != VerticalAlignment.Stretch ? 0.0 : this.SlotRect.Bottom - this.ChildRect.Bottom));
        }
        public void TranslateBrushPosition(Vector elementDelta, SceneElement element)
        {
            PropertyReference propertyReference = this.GetBrushPropertyReference((SceneNode)element);

            if (propertyReference == null)
            {
                return;
            }
            object computedValue = element.GetComputedValue(propertyReference);

            if (computedValue == null || PlatformTypes.IsInstance(computedValue, PlatformTypes.SolidColorBrush, (ITypeResolver)element.ProjectContext))
            {
                return;
            }
            ReferenceStep      referenceStep      = (ReferenceStep)element.Platform.Metadata.ResolveProperty(BrushNode.RelativeTransformProperty);
            object             obj                = element.ViewModel.DefaultView.ConvertToWpfValue(referenceStep.GetCurrentValue(computedValue));
            CanonicalTransform canonicalTransform = !(obj is Transform) ? new CanonicalTransform(Matrix.Identity) : new CanonicalTransform((Transform)obj);

            elementDelta *= canonicalTransform.TransformGroup.Value;
            double valueToSet1 = RoundingHelper.RoundLength(canonicalTransform.TranslationX + elementDelta.X);
            double valueToSet2 = RoundingHelper.RoundLength(canonicalTransform.TranslationY + elementDelta.Y);

            this.SetBrushTransformValue(element.Platform.Metadata.CommonProperties.BrushTranslationXReference, valueToSet1);
            this.SetBrushTransformValue(element.Platform.Metadata.CommonProperties.BrushTranslationYReference, valueToSet2);
        }
示例#6
0
        protected override void UpdateModelFromMouse(Base3DElement selected3DElement, Vector mousePositionDelta)
        {
            Camera   camera    = (Camera)selected3DElement.Viewport.Camera.ViewObject.PlatformSpecificObject;
            Matrix3D matrix3D1 = Helper3D.CameraRotationMatrix(camera);
            Matrix3D matrix3D2 = camera.Transform.Value;

            if (matrix3D2.HasInverse)
            {
                matrix3D2.Invert();
                matrix3D1 *= matrix3D2;
            }
            Vector3D      vector1       = new Vector3D(matrix3D1.M11, matrix3D1.M21, matrix3D1.M31);
            Vector3D      vector2_1     = new Vector3D(matrix3D1.M12, matrix3D1.M22, matrix3D1.M32);
            Vector3D      vector2_2     = new Vector3D(matrix3D1.M13, matrix3D1.M23, matrix3D1.M33);
            Base3DElement base3Delement = selected3DElement.Parent as Base3DElement;
            Matrix3D      matrix3D3     = Matrix3D.Identity;

            if (base3Delement != null)
            {
                matrix3D3 = base3Delement.GetComputedTransformFromRoot3DElementToElement();
                matrix3D3.Invert();
            }
            if (this.mouseMovementMode == ObjectRotateTranslateBehavior.MovementMode.Rotate)
            {
                mousePositionDelta /= 2.0;
                Vector3D axisOfRotation = Vector3D.CrossProduct(new Vector3D(-mousePositionDelta.X, mousePositionDelta.Y, 0.0), vector2_2);
                double   length         = axisOfRotation.Length;
                if (length <= 0.0)
                {
                    return;
                }
                Vector3D vector3D = Helper3D.EulerAnglesFromQuaternion(new Quaternion(axisOfRotation, length) * Helper3D.QuaternionFromEulerAngles(selected3DElement.CanonicalRotationAngles));
                vector3D = new Vector3D(RoundingHelper.RoundAngle(vector3D.X), RoundingHelper.RoundAngle(vector3D.Y), RoundingHelper.RoundAngle(vector3D.Z));
                selected3DElement.CanonicalRotationAngles = vector3D;
            }
            else
            {
                Vector3D vector3D1         = new Vector3D(selected3DElement.CanonicalTranslationX, selected3DElement.CanonicalTranslationY, selected3DElement.CanonicalTranslationZ);
                Point    lastMousePosition = this.LastMousePosition;
                Point    endPoint          = lastMousePosition + mousePositionDelta;
                Vector3D vector3D2;
                if (this.mouseMovementMode == ObjectRotateTranslateBehavior.MovementMode.TranslateXY)
                {
                    Plane3D  plane     = new Plane3D(Vector3D.CrossProduct(vector1, vector2_1), this.hitPoint);
                    Vector3D vector    = Helper3D.VectorBetweenPointsOnPlane((Viewport3D)selected3DElement.Viewport.ViewObject.PlatformSpecificObject, plane, lastMousePosition, endPoint);
                    Vector3D vector3D3 = matrix3D3.Transform(vector);
                    vector3D2 = vector3D1 + vector3D3;
                }
                else
                {
                    double scale = this.Scale;
                    vector3D2 = vector3D1 + scale * -mousePositionDelta.Y * vector2_2;
                }
                selected3DElement.CanonicalTranslationX = RoundingHelper.RoundLength(vector3D2.X);
                selected3DElement.CanonicalTranslationY = RoundingHelper.RoundLength(vector3D2.Y);
                selected3DElement.CanonicalTranslationZ = RoundingHelper.RoundLength(vector3D2.Z);
            }
        }
示例#7
0
        protected override void UpdateModelFromMouse(Base3DElement selected3DElement, Vector mousePositionDelta)
        {
            double   num      = this.mouseMovementAxis * mousePositionDelta;
            Vector3D vector3D = new Vector3D(selected3DElement.CanonicalTranslationX, selected3DElement.CanonicalTranslationY, selected3DElement.CanonicalTranslationZ) + this.Scale * num * this.translationAxis;

            selected3DElement.CanonicalTranslationX = RoundingHelper.RoundLength(vector3D.X);
            selected3DElement.CanonicalTranslationY = RoundingHelper.RoundLength(vector3D.Y);
            selected3DElement.CanonicalTranslationZ = RoundingHelper.RoundLength(vector3D.Z);
        }
        private System.Windows.Media.Geometry GetTransformedClippingGeometry(SceneElement clipper, Transform transform)
        {
            RectangleElement rectangleElement = clipper as RectangleElement;

            if (rectangleElement == null || !this.DesignerContext.ActiveDocument.ProjectContext.IsCapabilitySet(PlatformCapability.PrefersRectangularClippingPath))
            {
                PathGeometry pathGeometry = PathGeometryUtilities.TransformGeometry(this.ApplyCurrentClippingToGeometry((System.Windows.Media.Geometry)PathConversionHelper.ConvertToPathGeometry(clipper), clipper), transform);
                if (pathGeometry.Bounds == Rect.Empty)
                {
                    pathGeometry = new PathGeometry();
                }
                return((System.Windows.Media.Geometry)pathGeometry);
            }
            RectangleGeometry rectangleGeometry = rectangleElement.ViewModel.DefaultView.GetRenderedGeometryAsWpf((SceneElement)rectangleElement) as RectangleGeometry;

            if (rectangleGeometry == null)
            {
                return((System.Windows.Media.Geometry) new RectangleGeometry());
            }
            CanonicalDecomposition canonicalDecomposition = new CanonicalDecomposition(transform.Value);
            Matrix matrix = new Matrix();

            matrix.Scale(canonicalDecomposition.ScaleX, canonicalDecomposition.ScaleY);
            matrix.Translate(canonicalDecomposition.TranslationX, canonicalDecomposition.TranslationY);
            Rect rect = rectangleGeometry.Rect;

            rect.Transform(matrix);
            rectangleGeometry.Rect = RoundingHelper.RoundRect(rect);
            CanonicalTransform canonicalTransform = new CanonicalTransform();
            bool flag = false;

            canonicalTransform.CenterX = canonicalDecomposition.TranslationX;
            canonicalTransform.CenterY = canonicalDecomposition.TranslationY;
            if (canonicalDecomposition.RotationAngle != 0.0)
            {
                canonicalTransform.RotationAngle = canonicalDecomposition.RotationAngle;
                flag = true;
            }
            if (canonicalDecomposition.SkewX != 0.0 || canonicalDecomposition.SkewY != 0.0)
            {
                canonicalTransform.SkewX = RoundingHelper.RoundLength(canonicalDecomposition.SkewX);
                canonicalTransform.SkewY = RoundingHelper.RoundLength(canonicalDecomposition.SkewY);
                flag = true;
            }
            if (flag)
            {
                rectangleGeometry.Transform = (Transform)canonicalTransform.TransformGroup;
            }
            if ((double)rectangleElement.GetComputedValue(RectangleElement.RadiusXProperty) != 0.0 || (double)rectangleElement.GetComputedValue(RectangleElement.RadiusYProperty) != 0.0)
            {
                rectangleGeometry.ClearValue(RectangleGeometry.RadiusXProperty);
                rectangleGeometry.ClearValue(RectangleGeometry.RadiusYProperty);
                this.SceneView.ShowBubble(StringTable.ClippingRectanglePropertiesLostWarning, MessageBubbleType.Warning);
            }
            return((System.Windows.Media.Geometry)rectangleGeometry);
        }
示例#9
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();
        }
示例#10
0
 protected override bool OnClickEnd(Point pointerPosition, int clickCount)
 {
     if (clickCount > 1)
     {
         this.actionString = StringTable.UndoUnitResetRadialGradient;
         Point  point = new Point(0.5, 0.5);
         double num1  = 1.0;
         double num2  = 1.0;
         if (this.ActiveAdorner.IsStretchedToFitBoundingBox)
         {
             point = new Point(0.5, 0.5);
             num1  = num2 = 0.5;
         }
         else
         {
             BaseFrameworkElement frameworkElement = this.EditingElement as BaseFrameworkElement;
             if (frameworkElement == null)
             {
                 StyleNode styleNode = this.EditingElement as StyleNode;
                 if (styleNode != null)
                 {
                     frameworkElement = styleNode.TargetElement;
                 }
             }
             if (frameworkElement != null)
             {
                 Rect computedTightBounds = frameworkElement.GetComputedTightBounds();
                 num1  = RoundingHelper.RoundLength(computedTightBounds.Width / 2.0);
                 num2  = RoundingHelper.RoundLength(computedTightBounds.Height / 2.0);
                 point = RoundingHelper.RoundPosition(new Point(computedTightBounds.X + num1, computedTightBounds.Y + num2));
             }
         }
         this.CopyPrimaryBrushToSelection();
         this.ClearBrushTransform();
         if ((Point)this.GetBrushValue(RadialGradientBrushNode.GradientOriginProperty) != point)
         {
             this.SetBrushValue(RadialGradientBrushNode.GradientOriginProperty, (object)point);
         }
         if ((Point)this.GetBrushValue(RadialGradientBrushNode.CenterProperty) != point)
         {
             this.SetBrushValue(RadialGradientBrushNode.CenterProperty, (object)point);
         }
         if ((double)this.GetBrushValue(RadialGradientBrushNode.RadiusXProperty) != num1)
         {
             this.SetBrushValue(RadialGradientBrushNode.RadiusXProperty, (object)num1);
         }
         if ((double)this.GetBrushValue(RadialGradientBrushNode.RadiusYProperty) != num2)
         {
             this.SetBrushValue(RadialGradientBrushNode.RadiusYProperty, (object)num2);
         }
     }
     this.CommitEditTransaction();
     return(base.OnClickEnd(pointerPosition, clickCount));
 }
示例#11
0
        protected virtual void ApplyScale(Vector scale, Point center)
        {
            CanonicalTransform newTransform = new CanonicalTransform(this.startTransform);

            newTransform.ApplyScale(scale, this.BaseEditingElement.RenderTransformOriginInElementCoordinates, center);
            newTransform.ScaleX       = RoundingHelper.RoundScale(newTransform.ScaleX);
            newTransform.ScaleY       = RoundingHelper.RoundScale(newTransform.ScaleY);
            newTransform.TranslationX = RoundingHelper.RoundLength(newTransform.TranslationX);
            newTransform.TranslationY = RoundingHelper.RoundLength(newTransform.TranslationY);
            AdornedToolBehavior.UpdateElementTransform(this.EditingElement, newTransform, AdornedToolBehavior.TransformPropertyFlags.Scale | AdornedToolBehavior.TransformPropertyFlags.Translation);
        }
示例#12
0
        protected override bool OnDrag(Point dragStartPosition, Point dragCurrentPosition, bool scrollNow)
        {
            switch (this.ActiveAdorner.Kind)
            {
            case RadialGradientAdornerKind.GradientOriginPoint:
                this.actionString = StringTable.UndoUnitRadialGradientOrigin;
                if (!this.HasMouseMovedAfterDown)
                {
                    this.CopyPrimaryBrushToSelection();
                }
                Point point = this.initialCenterInBrush;
                if (Tolerances.HaveMoved(dragCurrentPosition, this.initialCenterInDocument, this.ActiveView.Zoom))
                {
                    Point positionInBrush = this.ActiveAdorner.InverseTransformPoint(dragCurrentPosition * this.initialContextToElementMatrix, true) * this.brushToRootMatrix;
                    BrushTransformBehavior.OffsetDragPoint(ref positionInBrush, this.initialCenterInBrush * this.brushToRootMatrix, this.dragOffset, 0.0);
                    point = RoundingHelper.RoundPosition(positionInBrush * this.rootToBrushMatrix);
                }
                if (this.ActiveAdorner.GradientOriginPoint != point)
                {
                    this.SetBrushValue(RadialGradientBrushNode.GradientOriginProperty, (object)point);
                    this.UpdateEditTransaction();
                    break;
                }
                break;

            case RadialGradientAdornerKind.RadiusPoint:
                this.actionString = StringTable.UndoUnitScaleRadialGradient;
                if (!this.HasMouseMovedAfterDown)
                {
                    this.CopyPrimaryBrushToSelection();
                    this.radiusX = (double)this.GetBrushValue(RadialGradientBrushNode.RadiusXProperty);
                    this.radiusY = (double)this.GetBrushValue(RadialGradientBrushNode.RadiusYProperty);
                    if (Math.Abs(this.radiusX) < 0.01)
                    {
                        this.radiusX = 0.01;
                    }
                    if (Math.Abs(this.radiusY) < 0.01)
                    {
                        this.radiusY = 0.01;
                    }
                }
                Vector perpendicular;
                double num1 = GradientStopBehavior.VectorProjection(this.ActiveAdorner.BrushCenter * this.brushToRootMatrix, this.initialPointerPosition, dragCurrentPosition, 0.0, out perpendicular);
                double num2 = RoundingHelper.RoundLength(this.radiusX * num1);
                double num3 = RoundingHelper.RoundLength(this.radiusY * num1);
                this.SetBrushValue(RadialGradientBrushNode.RadiusXProperty, (object)num2);
                this.SetBrushValue(RadialGradientBrushNode.RadiusYProperty, (object)num3);
                this.UpdateEditTransaction();
                break;
            }
            this.ActiveView.EnsureVisible((IAdorner)this.ActiveAdorner, scrollNow);
            return(true);
        }
        protected void SetBrushTransform(CanonicalTransform transform)
        {
            this.EnsureEditTransaction();
            transform.CenterX       = RoundingHelper.RoundLength(transform.CenterX);
            transform.CenterY       = RoundingHelper.RoundLength(transform.CenterY);
            transform.ScaleX        = RoundingHelper.RoundScale(transform.ScaleX);
            transform.ScaleY        = RoundingHelper.RoundScale(transform.ScaleY);
            transform.SkewX         = RoundingHelper.RoundAngle(transform.SkewX);
            transform.SkewY         = RoundingHelper.RoundAngle(transform.SkewY);
            transform.RotationAngle = RoundingHelper.RoundAngle(transform.RotationAngle);
            transform.TranslationX  = RoundingHelper.RoundLength(transform.TranslationX);
            transform.TranslationY  = RoundingHelper.RoundLength(transform.TranslationY);
            IProjectContext    projectContext     = this.ActiveDocument.ProjectContext;
            CanonicalTransform canonicalTransform = new CanonicalTransform((Transform)this.GetBrushValue(BrushNode.RelativeTransformProperty));

            if (JoltHelper.CompareDoubles(projectContext, canonicalTransform.CenterX, transform.CenterX) != 0 || JoltHelper.CompareDoubles(projectContext, canonicalTransform.CenterY, transform.CenterY) != 0)
            {
                this.SetBrushValue(BrushNode.RelativeTransformProperty, transform.GetPlatformTransform(this.RootNode.Platform.GeometryHelper));
            }
            else
            {
                if (JoltHelper.CompareDoubles(projectContext, canonicalTransform.ScaleX, transform.ScaleX) != 0)
                {
                    this.SetBrushTransformValue(this.EditingElement.Platform.Metadata.CommonProperties.BrushScaleXReference, transform.ScaleX);
                }
                if (JoltHelper.CompareDoubles(projectContext, canonicalTransform.ScaleY, transform.ScaleY) != 0)
                {
                    this.SetBrushTransformValue(this.EditingElement.Platform.Metadata.CommonProperties.BrushScaleYReference, transform.ScaleY);
                }
                if (JoltHelper.CompareDoubles(projectContext, canonicalTransform.SkewX, transform.SkewX) != 0)
                {
                    this.SetBrushTransformValue(this.EditingElement.Platform.Metadata.CommonProperties.BrushSkewXReference, transform.SkewX);
                }
                if (JoltHelper.CompareDoubles(projectContext, canonicalTransform.SkewY, transform.SkewY) != 0)
                {
                    this.SetBrushTransformValue(this.EditingElement.Platform.Metadata.CommonProperties.BrushSkewYReference, transform.SkewY);
                }
                if (JoltHelper.CompareDoubles(projectContext, canonicalTransform.RotationAngle, transform.RotationAngle) != 0)
                {
                    this.SetBrushTransformValue(this.EditingElement.Platform.Metadata.CommonProperties.BrushRotationAngleReference, transform.RotationAngle);
                }
                if (JoltHelper.CompareDoubles(projectContext, canonicalTransform.TranslationX, transform.TranslationX) != 0)
                {
                    this.SetBrushTransformValue(this.EditingElement.Platform.Metadata.CommonProperties.BrushTranslationXReference, transform.TranslationX);
                }
                if (JoltHelper.CompareDoubles(projectContext, canonicalTransform.TranslationY, transform.TranslationY) != 0)
                {
                    this.SetBrushTransformValue(this.EditingElement.Platform.Metadata.CommonProperties.BrushTranslationYReference, transform.TranslationY);
                }
            }
            this.UpdateEditTransaction();
        }
示例#14
0
 protected virtual void ComputeSizeOverrides()
 {
     if (!object.Equals((object)RoundingHelper.RoundLength(this.SettingsFromElement.Width), (object)RoundingHelper.RoundLength(this.Settings.Width)))
     {
         this.Settings.LayoutOverrides |= LayoutOverrides.Width;
         this.Settings.Width            = this.SettingsFromElement.Width;
     }
     if (object.Equals((object)RoundingHelper.RoundLength(this.SettingsFromElement.Height), (object)RoundingHelper.RoundLength(this.Settings.Height)))
     {
         return;
     }
     this.Settings.LayoutOverrides |= LayoutOverrides.Height;
     this.Settings.Height           = this.SettingsFromElement.Height;
 }
示例#15
0
        private void NormalizeWidthStars(GridElement grid, List <int> widthStarIndices)
        {
            double num1 = 0.0;

            foreach (int column in widthStarIndices)
            {
                num1 += grid.GetComputedColumnWidth(column);
            }
            foreach (int column in widthStarIndices)
            {
                double num2 = RoundingHelper.RoundLength(num1 == 0.0 ? 1.0 : grid.GetComputedColumnWidth(column) / num1);
                grid.ColumnDefinitions[column].Width = new GridLength(num2, GridUnitType.Star);
            }
        }
示例#16
0
        private void NormalizeHeightStars(GridElement grid, List <int> heightStarIndices)
        {
            double num1 = 0.0;

            foreach (int row in heightStarIndices)
            {
                num1 += grid.GetComputedRowHeight(row);
            }
            foreach (int row in heightStarIndices)
            {
                double num2 = RoundingHelper.RoundLength(num1 == 0.0 ? 1.0 : grid.GetComputedRowHeight(row) / num1);
                grid.RowDefinitions[row].Height = new GridLength(num2, GridUnitType.Star);
            }
        }
示例#17
0
        private void SetColumnWidthCore(GridElement grid, int col, double width)
        {
            width = RoundingHelper.RoundLength(width);
            ColumnDefinitionNode columnDefinitionNode = grid.ColumnDefinitions[col];

            if (columnDefinitionNode.Width.IsAuto)
            {
                columnDefinitionNode.MinWidth = width;
            }
            else
            {
                columnDefinitionNode.Width = new GridLength(width);
            }
            grid.ComputedColumnWidthCache[col] = width;
        }
示例#18
0
        private void SetRowHeightCore(GridElement grid, int row, double height)
        {
            height = RoundingHelper.RoundLength(height);
            RowDefinitionNode rowDefinitionNode = grid.RowDefinitions[row];

            if (rowDefinitionNode.Height.IsAuto)
            {
                rowDefinitionNode.MinHeight = height;
            }
            else
            {
                rowDefinitionNode.Height = new GridLength(height);
            }
            grid.ComputedRowHeightCache[row] = height;
        }
示例#19
0
        protected static void UpdateElementTransform(SceneElement element, CanonicalDecomposition newTransform, AdornedToolBehavior.TransformPropertyFlags properties)
        {
            Transform transform = element.GetComputedValueAsWpf(Base2DElement.RenderTransformProperty) as Transform;
            CanonicalDecomposition canonicalDecomposition = new CanonicalDecomposition();

            if (transform != null)
            {
                canonicalDecomposition = new CanonicalTransform(transform).Decomposition;
            }
            double num1 = RoundingHelper.RoundScale(newTransform.ScaleX);
            double num2 = RoundingHelper.RoundScale(newTransform.ScaleY);
            double num3 = RoundingHelper.RoundLength(newTransform.TranslationX);
            double num4 = RoundingHelper.RoundLength(newTransform.TranslationY);
            double num5 = RoundingHelper.RoundLength(newTransform.SkewX);
            double num6 = RoundingHelper.RoundLength(newTransform.SkewY);
            double num7 = RoundingHelper.RoundAngle(newTransform.RotationAngle);

            if ((properties & AdornedToolBehavior.TransformPropertyFlags.ScaleX) != AdornedToolBehavior.TransformPropertyFlags.None && !Tolerances.AreClose(canonicalDecomposition.ScaleX, num1))
            {
                element.SetValue(element.Platform.Metadata.CommonProperties.RenderTransformScaleX, (object)num1);
            }
            if ((properties & AdornedToolBehavior.TransformPropertyFlags.ScaleY) != AdornedToolBehavior.TransformPropertyFlags.None && !Tolerances.AreClose(canonicalDecomposition.ScaleY, num2))
            {
                element.SetValue(element.Platform.Metadata.CommonProperties.RenderTransformScaleY, (object)num2);
            }
            if ((properties & AdornedToolBehavior.TransformPropertyFlags.TranslationX) != AdornedToolBehavior.TransformPropertyFlags.None && !Tolerances.AreClose(canonicalDecomposition.TranslationX, num3))
            {
                element.SetValue(element.Platform.Metadata.CommonProperties.RenderTransformTranslationX, (object)num3);
            }
            if ((properties & AdornedToolBehavior.TransformPropertyFlags.TranslationY) != AdornedToolBehavior.TransformPropertyFlags.None && !Tolerances.AreClose(canonicalDecomposition.TranslationY, num4))
            {
                element.SetValue(element.Platform.Metadata.CommonProperties.RenderTransformTranslationY, (object)num4);
            }
            if ((properties & AdornedToolBehavior.TransformPropertyFlags.SkewX) != AdornedToolBehavior.TransformPropertyFlags.None && !Tolerances.AreClose(canonicalDecomposition.SkewX, num5))
            {
                element.SetValue(element.Platform.Metadata.CommonProperties.RenderTransformSkewX, (object)num5);
            }
            if ((properties & AdornedToolBehavior.TransformPropertyFlags.SkewY) != AdornedToolBehavior.TransformPropertyFlags.None && !Tolerances.AreClose(canonicalDecomposition.SkewY, num6))
            {
                element.SetValue(element.Platform.Metadata.CommonProperties.RenderTransformSkewY, (object)num6);
            }
            if ((properties & AdornedToolBehavior.TransformPropertyFlags.RotatationAngle) == AdornedToolBehavior.TransformPropertyFlags.None || Tolerances.AreClose(canonicalDecomposition.RotationAngle, num7))
            {
                return;
            }
            element.SetValue(element.Platform.Metadata.CommonProperties.RenderTransformRotationAngle, (object)num7);
        }
        public override void SetChildRect(BaseFrameworkElement child, Rect rect, LayoutOverrides layoutOverrides, LayoutOverrides overridesToIgnore, LayoutOverrides nonExplicitOverrides, SetRectMode setRectMode)
        {
            if (child == null)
            {
                throw new ArgumentNullException("child");
            }
            CanonicalTransform canonicalTransform = new CanonicalTransform((Transform)child.GetComputedValueAsWpf(Base2DElement.RenderTransformProperty));
            Vector             translation        = canonicalTransform.Translation;

            canonicalTransform.TranslationX  = 0.0;
            canonicalTransform.TranslationY  = 0.0;
            canonicalTransform.SkewX         = 0.0;
            canonicalTransform.SkewY         = 0.0;
            canonicalTransform.RotationAngle = 0.0;
            Rect   computedTightBounds = child.GetComputedTightBounds();
            double num1 = computedTightBounds.Width == 0.0 ? 0.0 : rect.Width / computedTightBounds.Width;
            double num2 = computedTightBounds.Height == 0.0 ? 0.0 : rect.Height / computedTightBounds.Height;
            double num3 = RoundingHelper.RoundScale(num1);
            double num4 = RoundingHelper.RoundScale(num2);

            if ((overridesToIgnore & LayoutOverrides.Width) != LayoutOverrides.None && !object.Equals((object)canonicalTransform.ScaleX, (object)num3))
            {
                child.SetValueAsWpf(child.Platform.Metadata.CommonProperties.RenderTransformScaleX, (object)num3);
            }
            if ((overridesToIgnore & LayoutOverrides.Height) != LayoutOverrides.None && !object.Equals((object)canonicalTransform.ScaleY, (object)num4))
            {
                child.SetValueAsWpf(child.Platform.Metadata.CommonProperties.RenderTransformScaleY, (object)num4);
            }
            canonicalTransform.ScaleX = num3;
            canonicalTransform.ScaleY = num4;
            canonicalTransform.Center = child.RenderTransformOriginInElementCoordinates;
            computedTightBounds.Transform(canonicalTransform.TransformGroup.Value);
            double num5 = rect.Left - computedTightBounds.Left + translation.X;
            double num6 = rect.Top - computedTightBounds.Top + translation.Y;
            double num7 = RoundingHelper.RoundLength(num5);
            double num8 = RoundingHelper.RoundLength(num6);

            if (!object.Equals((object)translation.X, (object)num7))
            {
                child.SetValueAsWpf(child.Platform.Metadata.CommonProperties.RenderTransformTranslationX, (object)num7);
            }
            if (object.Equals((object)translation.Y, (object)num8))
            {
                return;
            }
            child.SetValueAsWpf(child.Platform.Metadata.CommonProperties.RenderTransformTranslationY, (object)num8);
        }
示例#21
0
        private void UpdateArcThicknessToPixel()
        {
            if (this.IsSet(ArcShapeElement.ArcThicknessProperty) != PropertyState.Set || this.IsValueExpression(ArcShapeElement.ArcThicknessProperty))
            {
                return;
            }
            Rect computedTightBounds = this.GetComputedTightBounds();

            if (computedTightBounds.Width <= 0.0 || computedTightBounds.Height <= 0.0)
            {
                return;
            }
            double num1 = (double)this.GetLocalValueAsWpf(ArcShapeElement.ArcThicknessProperty);
            double num2 = Math.Min(computedTightBounds.Width, computedTightBounds.Height) / 2.0;

            this.SetLocalValue(ArcShapeElement.ArcThicknessProperty, (object)RoundingHelper.RoundLength(num2 * num1));
        }
示例#22
0
        private void UpdateSkew()
        {
            if (!this.behaviorEnabled)
            {
                return;
            }
            Vector vector1 = this.MouseDevice.GetPosition((IInputElement)this.ActiveView.ViewRootContainer) - this.startPointerPosition;
            double num1    = vector1.X * this.transformedDisplacementVector.X + vector1.Y * this.transformedDisplacementVector.Y;

            vector1.X = this.transformedDisplacementVector.X * num1;
            vector1.Y = this.transformedDisplacementVector.Y * num1;
            Vector             vector2      = vector1 * this.documentToObjectTransform;
            double             num2         = vector2.X * this.displacementVector.X + vector2.Y * this.displacementVector.Y;
            CanonicalTransform newTransform = new CanonicalTransform(this.canonicalTransform);
            Point  fixedPoint = !this.skewAroundCenter ? this.oppositeAdornerPosition : this.BaseEditingElement.RenderTransformOriginInElementCoordinates;
            Vector vector3    = fixedPoint - this.adornerPosition;

            if (vector3.LengthSquared < FloatingPointArithmetic.DistanceTolerance)
            {
                return;
            }
            Vector vector4 = vector3 / vector3.Length;
            double num3    = vector4.X * this.displacementVector.X + vector4.Y * this.displacementVector.Y;

            if ((this.displacementVector - vector4 * num3).LengthSquared < FloatingPointArithmetic.DistanceTolerance)
            {
                return;
            }
            newTransform.ApplySkewScale(this.displacementVector, this.adornerPosition - fixedPoint, this.BaseEditingElement.RenderTransformOriginInElementCoordinates, fixedPoint, this.displacementVector, this.adornerPosition - fixedPoint + this.displacementVector * num2);
            newTransform.ScaleX       = RoundingHelper.RoundScale(newTransform.ScaleX);
            newTransform.ScaleY       = RoundingHelper.RoundScale(newTransform.ScaleY);
            newTransform.SkewX        = RoundingHelper.RoundAngle(newTransform.SkewX);
            newTransform.SkewY        = RoundingHelper.RoundAngle(newTransform.SkewY);
            newTransform.TranslationX = RoundingHelper.RoundLength(newTransform.TranslationX);
            newTransform.TranslationY = RoundingHelper.RoundLength(newTransform.TranslationY);
            if ((Math.Abs(newTransform.Skew.X) - 90.0) * (Math.Abs(newTransform.Skew.X) - 90.0) < FloatingPointArithmetic.DistanceTolerance || (Math.Abs(newTransform.Skew.Y) - 90.0) * (Math.Abs(newTransform.Skew.Y) - 90.0) < FloatingPointArithmetic.DistanceTolerance)
            {
                return;
            }
            AdornedToolBehavior.UpdateElementTransform(this.EditingElement, newTransform, AdornedToolBehavior.TransformPropertyFlags.Scale | AdornedToolBehavior.TransformPropertyFlags.Skew | AdornedToolBehavior.TransformPropertyFlags.Translation);
        }
示例#23
0
        public void SetRect(Rect rect, LayoutOverrides layoutOverrides, LayoutOverrides overridesToIgnore, LayoutOverrides nonExplicitOverrides, SetRectMode setRectMode)
        {
            if (this.Child.Visual == null)
            {
                return;
            }
            this.LayoutOverrides      = layoutOverrides;
            this.OverridesToIgnore    = overridesToIgnore;
            this.NonExplicitOverrides = nonExplicitOverrides;
            this.SetRectMode          = setRectMode;
            LayoutOverrides explicitOverrides = this.ExplicitOverrides;

            if (this.RoundBeforeSettingChildRect)
            {
                double num1 = (this.LayoutOverrides & LayoutOverrides.Width) == LayoutOverrides.None || (this.OverridesToIgnore & LayoutOverrides.Width) != LayoutOverrides.None ? 0.0 : 0.00045;
                double num2 = (this.LayoutOverrides & LayoutOverrides.Height) == LayoutOverrides.None || (this.OverridesToIgnore & LayoutOverrides.Height) != LayoutOverrides.None ? 0.0 : 0.00045;
                double x    = RoundingHelper.RoundLength(rect.Left - num1);
                double y    = RoundingHelper.RoundLength(rect.Top - num2);
                double num3 = RoundingHelper.RoundLength(rect.Right + num1);
                double num4 = RoundingHelper.RoundLength(rect.Bottom + num2);
                rect = new Rect(x, y, RoundingHelper.RoundLength(num3 - x), RoundingHelper.RoundLength(num4 - y));
            }
            this.ChildRect = rect;
            this.ComputeIdealSlotRect();
            this.SetSlotRectChanges();
            this.UpdateChildRectWithinSlot();
            this.ComputeIdealAlignment();
            this.SetAlignmentChanges();
            this.ComputeIdealSize();
            this.SetSizeChanges();
            this.ComputeIdealMargin();
            this.SetMarginChanges();
            this.ExplicitOverrides &= ~this.NonExplicitOverrides;
            if (this.ExplicitOverrides == explicitOverrides)
            {
                return;
            }
            LayoutUtilities.SetLayoutOverrides((SceneElement)this.Child, this.ExplicitOverrides);
        }
示例#24
0
 public void SetRowHeight(GridElement grid, int index, GridLength height, double minHeight)
 {
     using (this.DeferTokenForGridDesignMode(grid))
     {
         List <int> heightStarIndices = this.GetHeightStarIndices(grid);
         bool       isStar            = grid.RowDefinitions[index].Height.IsStar;
         height = new GridLength(RoundingHelper.RoundLength(height.Value), height.GridUnitType);
         grid.RowDefinitions[index].Height = height;
         if (double.IsNaN(minHeight))
         {
             grid.RowDefinitions[index].ClearValue(RowDefinitionNode.MinHeightProperty);
         }
         else
         {
             grid.RowDefinitions[index].MinHeight = minHeight;
         }
         if (!isStar || height.IsStar)
         {
             return;
         }
         heightStarIndices.Remove(index);
         this.NormalizeHeightStars(grid, heightStarIndices);
     }
 }
示例#25
0
 public void SetColumnWidth(GridElement grid, int index, GridLength width, double minWidth)
 {
     using (this.DeferTokenForGridDesignMode(grid))
     {
         List <int> widthStarIndices = this.GetWidthStarIndices(grid);
         bool       isStar           = grid.ColumnDefinitions[index].Width.IsStar;
         width = new GridLength(RoundingHelper.RoundLength(width.Value), width.GridUnitType);
         grid.ColumnDefinitions[index].Width = width;
         if (double.IsNaN(minWidth))
         {
             grid.ColumnDefinitions[index].ClearValue(ColumnDefinitionNode.MinWidthProperty);
         }
         else
         {
             grid.ColumnDefinitions[index].MinWidth = minWidth;
         }
         if (!isStar || width.IsStar)
         {
             return;
         }
         widthStarIndices.Remove(index);
         this.NormalizeWidthStars(grid, widthStarIndices);
     }
 }
 protected override bool OnClickEnd(Point pointerPosition, int clickCount)
 {
     if (clickCount == 1 && this.ActiveAdorner != null && this.Tool is GradientBrushTool)
     {
         PropertyReference      propertyReference1     = this.GetBrushPropertyReference((SceneNode)this.EditingElement);
         GradientStopCollection gradientStopCollection = (GradientStopCollection)this.ActiveAdorner.GetBrushPropertyAsWpf(GradientBrushNode.GradientStopsProperty);
         Matrix matrix = this.ActiveAdorner.GetCompleteBrushTransformMatrix(true) * this.ActiveView.GetComputedTransformToRoot(this.EditingElement);
         Point  startPoint;
         Point  endPoint;
         if (gradientStopCollection == null || !this.ActiveAdorner.GetBrushEndpoints(out startPoint, out endPoint))
         {
             return(true);
         }
         Vector perpendicular;
         double offset = RoundingHelper.RoundLength(GradientStopBehavior.VectorProjection(startPoint * matrix, endPoint * matrix, this.dragStartPosition, 0.0, out perpendicular));
         int    index1 = 0;
         int    index2 = 0;
         for (int index3 = 0; index3 < gradientStopCollection.Count; ++index3)
         {
             if (gradientStopCollection[index1].Offset > offset || gradientStopCollection[index3].Offset > gradientStopCollection[index1].Offset && gradientStopCollection[index3].Offset <= offset)
             {
                 index1 = index3;
             }
             if (gradientStopCollection[index2].Offset < offset || gradientStopCollection[index3].Offset < gradientStopCollection[index2].Offset && gradientStopCollection[index3].Offset >= offset)
             {
                 index2 = index3;
             }
         }
         GradientStop gradientStop;
         if (gradientStopCollection.Count == 0)
         {
             gradientStop = new GradientStop(Colors.White, offset);
         }
         else
         {
             double num = (offset - gradientStopCollection[index1].Offset) / (gradientStopCollection[index2].Offset - gradientStopCollection[index1].Offset);
             if (num > 1.0)
             {
                 num = 1.0;
             }
             if (num < 0.0)
             {
                 num = 0.0;
             }
             gradientStop = new GradientStop(Color.FromArgb((byte)((double)gradientStopCollection[index1].Color.A * (1.0 - num) + (double)gradientStopCollection[index2].Color.A * num), (byte)((double)gradientStopCollection[index1].Color.R * (1.0 - num) + (double)gradientStopCollection[index2].Color.R * num), (byte)((double)gradientStopCollection[index1].Color.G * (1.0 - num) + (double)gradientStopCollection[index2].Color.G * num), (byte)((double)gradientStopCollection[index1].Color.B * (1.0 - num) + (double)gradientStopCollection[index2].Color.B * num)), offset);
         }
         this.CopyPrimaryBrushToSelection();
         PropertyReference propertyReference2 = propertyReference1.Append(GradientBrushNode.GradientStopsProperty);
         PropertyReference propertyReference3 = propertyReference2.Append(GradientStopCollectionNode.CountProperty);
         foreach (SceneElement sceneElement in this.ActiveView.ElementSelectionSet.Selection)
         {
             PropertyReference propertyReference4 = this.ActiveView.DesignerContext.PropertyManager.FilterProperty((SceneNode)sceneElement, propertyReference3);
             PropertyReference propertyReference5 = this.ActiveView.DesignerContext.PropertyManager.FilterProperty((SceneNode)sceneElement, propertyReference2);
             if (propertyReference4 != null && propertyReference5 != null)
             {
                 int index3 = (int)sceneElement.GetComputedValue(propertyReference4);
                 sceneElement.InsertValueAsWpf(propertyReference5, index3, (object)gradientStop);
             }
         }
         this.SetSelectedStopIndex(gradientStopCollection.Count);
         this.CommitEditTransaction();
     }
     return(base.OnClickEnd(pointerPosition, clickCount));
 }
示例#27
0
        private void UpdateTranslation()
        {
            SceneViewModel    viewModel          = this.ActiveView.ViewModel;
            PropertyReference propertyReference1 = this.GetBrushPropertyReference((SceneNode)this.EditingElement);

            if (propertyReference1 == null)
            {
                return;
            }
            Matrix matrixToAdornerLayer = this.ActiveAdorner.AdornerSet.GetTransformMatrixToAdornerLayer();

            this.EnsureEditTransaction();
            Point startPoint;
            Point endPoint;

            if (PlatformTypes.IsInstance(this.ActiveAdorner.PlatformBrush, PlatformTypes.GradientBrush, (ITypeResolver)this.EditingElement.ProjectContext) && this.ActiveAdorner.GetBrushEndpoints(out startPoint, out endPoint))
            {
                if (!this.HasMouseMovedAfterDown)
                {
                    this.CopyPrimaryBrushToSelection();
                }
                PropertyReference      propertyReference2     = propertyReference1.Append(GradientBrushNode.GradientStopsProperty);
                PropertyReference      propertyReference3     = propertyReference2.Append((ReferenceStep)IndexedClrPropertyReferenceStep.GetReferenceStep((IPlatformMetadata)viewModel.ProjectContext.Platform.Metadata, PlatformTypes.GradientStopCollection, this.ActiveAdorner.Index));
                PropertyReference      propertyReference4     = propertyReference3.Append(GradientStopNode.OffsetProperty);
                PropertyReference      propertyReference5     = propertyReference3.Append(GradientStopNode.ColorProperty);
                Matrix                 matrix                 = this.ActiveAdorner.GetCompleteBrushTransformMatrix(true) * this.ActiveView.GetComputedTransformToRoot(this.EditingElement);
                GradientStopCollection gradientStopCollection = (GradientStopCollection)this.EditingElement.GetComputedValueAsWpf(propertyReference2);
                GradientStop           gradientStop           = gradientStopCollection[this.ActiveAdorner.Index];
                Vector                 perpendicular;
                double                 num1   = GradientStopBehavior.VectorProjection(startPoint * matrix, endPoint * matrix, this.dragCurrentPosition, gradientStop.Offset, out perpendicular);
                double                 length = (perpendicular * matrixToAdornerLayer).Length;
                int index = this.ActiveAdorner.Index + 1;
                if (index >= gradientStopCollection.Count)
                {
                    index = this.ActiveAdorner.Index - 1;
                }
                if (length > 30.0 && !this.isDraggedOff && gradientStopCollection.Count > 2)
                {
                    this.isDraggedOff         = true;
                    this.ActiveAdorner.Hidden = true;
                    this.saveDraggedOffColor  = gradientStop.Color;
                    this.SetBrushValue(propertyReference5, (object)gradientStopCollection[index].Color);
                    this.SetBrushValue(propertyReference4, (object)gradientStopCollection[index].Offset);
                    this.Cursor = ToolCursors.MinusArrowCursor;
                }
                if (length <= 30.0 && this.isDraggedOff)
                {
                    this.isDraggedOff         = false;
                    this.ActiveAdorner.Hidden = false;
                    this.SetBrushValue(propertyReference5, (object)this.saveDraggedOffColor);
                    this.Cursor = this.ActiveAdorner.AdornerSet.GetCursor((IAdorner)this.ActiveAdorner);
                }
                if (!this.isDraggedOff)
                {
                    double num2 = RoundingHelper.RoundLength(gradientStop.Offset + num1);
                    if (num2 > 1.0)
                    {
                        num2 = 1.0;
                    }
                    else if (num2 < 0.0)
                    {
                        num2 = 0.0;
                    }
                    this.SetBrushValue(propertyReference4, (object)num2);
                }
                else
                {
                    this.SetBrushValue(propertyReference4, (object)gradientStopCollection[index].Offset);
                }
            }
            if (!this.HasMouseMovedAfterDown)
            {
                this.SetSelectedStopIndex(this.ActiveAdorner.Index);
            }
            this.UpdateEditTransaction();
        }
示例#28
0
        private object ApplyRelativeTransform(object relativeTransform, object currentTransform)
        {
            object instance1 = Activator.CreateInstance(this.ComponentType);
            object instance2 = Activator.CreateInstance(this.ComponentType);
            object target    = instance2;

            if (currentTransform != null)
            {
                if (this.PropertyLookup.TransformType == TransformType.PlaneProjection || this.PropertyLookup.IsCompositeSupported)
                {
                    target = currentTransform;
                }
                else
                {
                    target = Activator.CreateInstance(this.ComponentType, new object[1]
                    {
                        currentTransform
                    });
                }
            }
            foreach (PropertyReferenceProperty property in this.PropertyLookup.ActiveProperties)
            {
                if (property != null && property.Reference.FirstStep.TargetType == this.ComponentType)
                {
                    if (((PropertyEntry)property).get_PropertyType() == typeof(double) && !(property.Reference.ShortPath == "RotationAngleX") && (!(property.Reference.ShortPath == "RotationAngleY") && !(property.Reference.ShortPath == "RotationAngleZ")))
                    {
                        double num1 = (double)property.Reference.GetValue(relativeTransform);
                        double num2 = (double)property.Reference.GetValue(target);
                        double num3 = (double)property.Reference.GetValue(instance2);
                        double num4 = !this.ComposesByMultiplication(property, instance2) ? num2 + (num1 - num3) : num2 * num1;
                        double num5 = !((PropertyEntry)property).get_PropertyName().Contains("Angle") ? (!((PropertyEntry)property).get_PropertyName().Contains("Scale") ? RoundingHelper.RoundLength(num4) : RoundingHelper.RoundScale(num4)) : RoundingHelper.RoundAngle(num4);
                        if (num5 != num3)
                        {
                            property.Reference.SetValue(instance1, (object)num5);
                        }
                    }
                    else if (property.Reference.ShortPath == "RotationAngles")
                    {
                        Quaternion orientation = Helper3D.QuaternionFromEulerAngles((Vector3D)property.Reference.GetValue(relativeTransform)) * Helper3D.QuaternionFromEulerAngles((Vector3D)property.Reference.GetCurrentValue(target));
                        property.Reference.SetValue(instance1, (object)Helper3D.EulerAnglesFromQuaternion(orientation));
                    }
                }
            }
            return(instance1);
        }
        protected override void ApplyScale(Vector scale, Point center)
        {
            Size newSize = this.ComputeNewSize(scale);

            if (!object.Equals((object)newSize.Width, (object)this.StartSize.Width) && DesignTimeSizeBehavior.IsWidthEnabled(this.BaseEditingElement))
            {
                this.BaseEditingElement.SetValue(DesignTimeProperties.DesignWidthProperty, (object)RoundingHelper.RoundLength(newSize.Width));
            }
            if (object.Equals((object)newSize.Height, (object)this.StartSize.Height) || !DesignTimeSizeBehavior.IsHeightEnabled(this.BaseEditingElement))
            {
                return;
            }
            this.BaseEditingElement.SetValue(DesignTimeProperties.DesignHeightProperty, (object)RoundingHelper.RoundLength(newSize.Height));
        }
示例#30
0
        private void UpdateBrushForMappingModeChange(PropertyReference brushPropertyReference, BrushMappingMode mappingMode)
        {
            GradientBrush gradientBrush = this.GetComputedValueAsWpf(brushPropertyReference) as GradientBrush;

            if (gradientBrush == null || gradientBrush.MappingMode == mappingMode)
            {
                return;
            }
            Rect computedTightBounds = this.GetComputedTightBounds();

            if (computedTightBounds.IsEmpty)
            {
                return;
            }
            Matrix identity = Matrix.Identity;
            Matrix matrix   = Matrix.Identity;

            if (BrushAdorner.IsAdorningFillProperty((SceneElement)this))
            {
                matrix = BrushAdorner.GetStrokeTransform((SceneElement)this);
            }
            if (mappingMode == BrushMappingMode.Absolute)
            {
                identity *= matrix;
                identity.Scale(computedTightBounds.Width, computedTightBounds.Height);
                identity.Translate(computedTightBounds.X, computedTightBounds.Y);
            }
            else if (mappingMode == BrushMappingMode.RelativeToBoundingBox)
            {
                identity.Translate(-computedTightBounds.X, -computedTightBounds.Y);
                identity.Scale(computedTightBounds.Width == 0.0 ? 1.0 : 1.0 / computedTightBounds.Width, computedTightBounds.Height == 0.0 ? 1.0 : 1.0 / computedTightBounds.Height);
                matrix.Invert();
                identity *= matrix;
            }
            if (identity.IsIdentity)
            {
                return;
            }
            LinearGradientBrush linearGradientBrush;

            if ((linearGradientBrush = gradientBrush as LinearGradientBrush) != null)
            {
                Point point1 = RoundingHelper.RoundPosition(linearGradientBrush.StartPoint * identity);
                Point point2 = RoundingHelper.RoundPosition(linearGradientBrush.EndPoint * identity);
                this.SetValueAsWpf(brushPropertyReference.Append(LinearGradientBrushNode.StartPointProperty), (object)point1);
                this.SetValueAsWpf(brushPropertyReference.Append(LinearGradientBrushNode.EndPointProperty), (object)point2);
            }
            else
            {
                RadialGradientBrush radialGradientBrush;
                if ((radialGradientBrush = gradientBrush as RadialGradientBrush) == null)
                {
                    return;
                }
                Point  point1 = RoundingHelper.RoundPosition(radialGradientBrush.Center * identity);
                Point  point2 = RoundingHelper.RoundPosition(radialGradientBrush.GradientOrigin * identity);
                double num1   = RoundingHelper.RoundLength(radialGradientBrush.RadiusX * identity.M11);
                double num2   = RoundingHelper.RoundLength(radialGradientBrush.RadiusY * identity.M22);
                this.SetValueAsWpf(brushPropertyReference.Append(RadialGradientBrushNode.CenterProperty), (object)point1);
                this.SetValueAsWpf(brushPropertyReference.Append(RadialGradientBrushNode.GradientOriginProperty), (object)point2);
                this.SetValue(brushPropertyReference.Append(RadialGradientBrushNode.RadiusXProperty), (object)num1);
                this.SetValue(brushPropertyReference.Append(RadialGradientBrushNode.RadiusYProperty), (object)num2);
            }
        }