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);
            }
        }
示例#2
0
        private void AddGradientStop(object sender, ExecutedRoutedEventArgs eventArgs)
        {
            GradientBrushEditor gradientBrushEditor = (GradientBrushEditor)this.DataContext;

            if (gradientBrushEditor == null)
            {
                return;
            }
            gradientBrushEditor.AddGradientStop((IInputElement)this, RoundingHelper.RoundScale((double)eventArgs.Parameter));
        }
示例#3
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);
        }
        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();
        }
示例#5
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);
        }
示例#7
0
        private void ReverseGradientStopsHandler()
        {
            PropertyValueEditorCommands.get_BeginTransaction().Execute((object)null, (IInputElement)this.BrushEditor);
            if (!this.BasisProperty.IsValueLocal)
            {
                this.BasisProperty.DoSetLocalValue();
            }
            Dictionary <double, List <GradientStopEditor> > dictionary = new Dictionary <double, List <GradientStopEditor> >();

            foreach (GradientStopEditor gradientStopEditor in (IEnumerable)this.GradientStops)
            {
                if (!dictionary.ContainsKey(gradientStopEditor.Offset))
                {
                    dictionary.Add(gradientStopEditor.Offset, new List <GradientStopEditor>());
                }
                dictionary[gradientStopEditor.Offset].Add(gradientStopEditor);
            }
            SceneNodeObjectSet sceneNodeObjectSet = this.BasisProperty.SceneNodeObjectSet;

            foreach (KeyValuePair <double, List <GradientStopEditor> > keyValuePair in dictionary)
            {
                double key = keyValuePair.Key;
                List <GradientStopEditor> list = keyValuePair.Value;
                bool flag    = list.Count > 1;
                bool isMixed = false;
                for (int index = 0; index < list.Count; ++index)
                {
                    list[index].Offset = RoundingHelper.RoundScale(1.0 - key);
                    if (flag && index < list.Count / 2)
                    {
                        GradientStopEditor gradientStopEditor1  = list[index];
                        GradientStopEditor gradientStopEditor2  = list[list.Count - 1 - index];
                        DocumentNode       valueAsDocumentNode1 = gradientStopEditor1.ColorProperty.GetLocalValueAsDocumentNode(false, out isMixed);
                        DocumentNode       valueAsDocumentNode2 = gradientStopEditor2.ColorProperty.GetLocalValueAsDocumentNode(false, out isMixed);
                        gradientStopEditor1.ColorProperty.SetValue((object)valueAsDocumentNode2);
                        gradientStopEditor2.ColorProperty.SetValue((object)valueAsDocumentNode1);
                    }
                }
            }
            PropertyValueEditorCommands.get_CommitTransaction().Execute((object)null, (IInputElement)this.BrushEditor);
            this.RebuildModel(-1);
        }
示例#8
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);
        }
示例#9
0
        protected override void UpdateModelFromMouse(Base3DElement selected3DElement, Vector mousePositionDelta)
        {
            double           num = this.mouseMovementAxis * mousePositionDelta;
            ScaleTransform3D scaleTransform3D = selected3DElement.CanonicalScaleTransform3D;
            Vector3D         vector3D         = new Vector3D(scaleTransform3D.ScaleX, scaleTransform3D.ScaleY, scaleTransform3D.ScaleZ) + num * this.scaleAxis * 1.0 / 96.0;

            if (vector3D.X < 0.0)
            {
                vector3D.X = 0.0;
            }
            if (vector3D.Y < 0.0)
            {
                vector3D.Y = 0.0;
            }
            if (vector3D.Z < 0.0)
            {
                vector3D.Z = 0.0;
            }
            selected3DElement.CanonicalScaleX = RoundingHelper.RoundScale(vector3D.X);
            selected3DElement.CanonicalScaleY = RoundingHelper.RoundScale(vector3D.Y);
            selected3DElement.CanonicalScaleZ = RoundingHelper.RoundScale(vector3D.Z);
        }
 private void ChoiceEditorValueChanged(object sender, EventArgs e)
 {
     if (this.isUpdatingValue)
     {
         return;
     }
     this.isUpdatingValue = true;
     try
     {
         object obj = this.TextChoiceEditor.Value;
         if (obj == null)
         {
             this.WrappedValue = MixedProperty.Mixed;
         }
         else
         {
             UnitTypedSize unitTypedSize1 = obj as UnitTypedSize;
             if (unitTypedSize1 == null)
             {
                 return;
             }
             UnitTypedSize unitTypedSize2 = unitTypedSize1.ConvertTo(UnitType.Pixels);
             double        size           = unitTypedSize2.Size;
             unitTypedSize2.Size = this.EnforceHardMaximumAndMinimum(unitTypedSize2.Size);
             if (size != unitTypedSize2.Size)
             {
                 this.TextChoiceEditor.Value = (object)unitTypedSize2.ConvertTo(this.UnitType);
             }
             unitTypedSize2.Size = RoundingHelper.RoundScale(unitTypedSize2.Size);
             this.WrappedValue   = (object)unitTypedSize2.Size;
         }
     }
     finally
     {
         this.isUpdatingValue = false;
     }
 }
示例#11
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);
        }
示例#12
0
 private void AddGradientStop(LinearGradientBrush brush, List <Color> colors, int stopIndex, List <double> accumulatedDistances)
 {
     brush.GradientStops.Add(new GradientStop(colors[stopIndex], RoundingHelper.RoundScale(accumulatedDistances[stopIndex] / accumulatedDistances[accumulatedDistances.Count - 1])));
 }