Exemplo n.º 1
0
        public override void Draw(DrawingContext context, Matrix matrix)
        {
            if (!PlatformTypes.IsInstance(this.PlatformBrush, PlatformTypes.LinearGradientBrush, (ITypeResolver)this.Element.ProjectContext))
            {
                return;
            }
            switch (this.kind)
            {
            case LinearGradientAdornerKind.StartPoint:
                this.DrawArrowTail(context, matrix, this.StartPoint, this.EndPoint);
                break;

            case LinearGradientAdornerKind.EndPoint:
                this.DrawArrowHead(context, matrix, this.StartPoint, this.EndPoint);
                break;

            case LinearGradientAdornerKind.StartRotation:
                context.DrawEllipse((Brush)Brushes.Transparent, (Pen)null, this.GetOffsetStartPoint(matrix, RotateAdornerHelper.Radius), RotateAdornerHelper.Radius, RotateAdornerHelper.Radius);
                break;

            case LinearGradientAdornerKind.EndRotation:
                context.DrawEllipse((Brush)Brushes.Transparent, (Pen)null, this.GetOffsetEndPoint(matrix, RotateAdornerHelper.Radius), RotateAdornerHelper.Radius, RotateAdornerHelper.Radius);
                break;

            default:
                throw new NotImplementedException(ExceptionStringTable.UnknownLinearGradientAdorner);
            }
        }
Exemplo n.º 2
0
        private void UpdateTranslation(bool scrollNow)
        {
            SceneView      activeView = this.ActiveView;
            SceneViewModel viewModel  = activeView.ViewModel;
            Vector         delta      = this.dragCurrentPosition - this.dragStartPosition;

            if (this.isConstraining)
            {
                delta = this.ConstrainDeltaToAxis(delta);
            }
            if (delta == this.lastMove || this.IsAltDown)
            {
                return;
            }
            this.EnsureEditTransaction();
            Vector       vector1          = delta - this.lastMove;
            SceneElement primarySelection = viewModel.ElementSelectionSet.PrimarySelection;

            if (primarySelection == null)
            {
                return;
            }
            PropertyReference propertyReference = this.GetBrushPropertyReference((SceneNode)primarySelection);

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

            if (computedValue != null && !PlatformTypes.IsInstance(computedValue, PlatformTypes.SolidColorBrush, (ITypeResolver)primarySelection.ProjectContext))
            {
                Vector vector2 = vector1 * activeView.GetComputedTransformFromRoot(primarySelection) * BrushAdorner.GetCompleteInverseBrushTransformMatrix((Base2DElement)primarySelection, computedValue, true);
                if (PlatformTypes.IsInstance(computedValue, PlatformTypes.LinearGradientBrush, (ITypeResolver)primarySelection.ProjectContext) && this.Tool is GradientBrushTool)
                {
                    ReferenceStep referenceStep1 = (ReferenceStep)viewModel.ProjectContext.ResolveProperty(LinearGradientBrushNode.StartPointProperty);
                    ReferenceStep referenceStep2 = (ReferenceStep)viewModel.ProjectContext.ResolveProperty(LinearGradientBrushNode.EndPointProperty);
                    Point         point1         = RoundingHelper.RoundPosition((Point)viewModel.DefaultView.ConvertToWpfValue(referenceStep1.GetCurrentValue(computedValue)) + vector2);
                    Point         point2         = RoundingHelper.RoundPosition((Point)viewModel.DefaultView.ConvertToWpfValue(referenceStep2.GetCurrentValue(computedValue)) + vector2);
                    this.SetBrushValue(LinearGradientBrushNode.StartPointProperty, (object)point1);
                    this.SetBrushValue(LinearGradientBrushNode.EndPointProperty, (object)point2);
                }
                else if (PlatformTypes.IsInstance(computedValue, PlatformTypes.RadialGradientBrush, (ITypeResolver)primarySelection.ProjectContext) && this.Tool is GradientBrushTool)
                {
                    ReferenceStep referenceStep1 = (ReferenceStep)viewModel.ProjectContext.ResolveProperty(RadialGradientBrushNode.CenterProperty);
                    ReferenceStep referenceStep2 = (ReferenceStep)viewModel.ProjectContext.ResolveProperty(RadialGradientBrushNode.GradientOriginProperty);
                    Point         point1         = RoundingHelper.RoundPosition((Point)viewModel.DefaultView.ConvertToWpfValue(referenceStep1.GetCurrentValue(computedValue)) + vector2);
                    Point         point2         = RoundingHelper.RoundPosition((Point)viewModel.DefaultView.ConvertToWpfValue(referenceStep2.GetCurrentValue(computedValue)) + vector2);
                    this.SetBrushValue(RadialGradientBrushNode.CenterProperty, (object)point1);
                    this.SetBrushValue(RadialGradientBrushNode.GradientOriginProperty, (object)point2);
                }
                else
                {
                    this.TranslateBrushPosition(vector1 * activeView.GetComputedTransformFromRoot(primarySelection) * BrushAdorner.GetCompleteInverseBrushTransformMatrix((Base2DElement)primarySelection, computedValue, false), primarySelection);
                }
            }
            activeView.EnsureVisible(this.dragStartPosition + delta, scrollNow);
            this.lastMove = delta;
            this.UpdateEditTransaction();
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        public override void Draw(DrawingContext context, Matrix matrix)
        {
            if (!this.ShouldDraw)
            {
                return;
            }
            bool   flag    = this.AdornerSet.Behavior.Tool is BrushTransformTool;
            Matrix matrix1 = this.GetCompleteBrushTransformMatrix(true) * matrix;

            if (flag)
            {
                Rect brushBounds = this.BrushBounds;
                if (brushBounds.Width <= 0.0 || brushBounds.Height <= 0.0)
                {
                    return;
                }
                Pen thinPen = this.ThinPen;
                System.Windows.Media.Geometry rectangleGeometry = Adorner.GetTransformedRectangleGeometry(brushBounds, matrix1, thinPen.Thickness);
                context.DrawGeometry((Brush)Brushes.Transparent, thinPen, rectangleGeometry);
            }
            else
            {
                Pen pen = new Pen((Brush)Brushes.Transparent, 15.0);
                pen.Freeze();
                if (!PlatformTypes.IsInstance(this.PlatformBrush, PlatformTypes.GradientBrush, (ITypeResolver)this.Element.ProjectContext))
                {
                    return;
                }
                Point startPoint;
                Point endPoint;
                this.GetBrushOffsetEndpoints(out startPoint, out endPoint, 13.0, 11.0, matrix);
                context.DrawLine(pen, startPoint, endPoint);
                context.DrawLine(this.ThinPen, startPoint, endPoint);
            }
        }
        private static int GetFigureCount(PathElement pathElement)
        {
            if (pathElement == null || !pathElement.IsViewObjectValid)
            {
                return(0);
            }
            IPlatformTypes metadata = pathElement.Platform.Metadata;

            if (!PlatformTypes.IsInstance(pathElement.GetLocalValue(PathElement.DataProperty), PlatformTypes.PathGeometry, metadata.DefaultTypeResolver))
            {
                return(pathElement.PathGeometry.Figures.Count);
            }
            object obj = new PropertyReference(new List <ReferenceStep>()
            {
                metadata.ResolveProperty(PathElement.DataProperty) as ReferenceStep,
                metadata.ResolveProperty(PathElement.FiguresProperty) as ReferenceStep,
                metadata.ResolveProperty(PathElement.PathFigureCollectionCountProperty) as ReferenceStep
            }).GetValue(pathElement.ViewObject.PlatformSpecificObject);

            if (obj is int)
            {
                return((int)obj);
            }
            return(0);
        }
Exemplo n.º 6
0
 public override void Draw(DrawingContext ctx, Matrix matrix)
 {
     if (!PlatformTypes.IsInstance(this.PlatformBrush, PlatformTypes.RadialGradientBrush, (ITypeResolver)this.Element.ProjectContext) || !(this.AdornerSet.Behavior.Tool is GradientBrushTool))
     {
         return;
     }
     base.Draw(ctx, matrix);
 }
Exemplo n.º 7
0
            protected override void CreateAdorners()
            {
                BrushTranslateAdorner translateAdorner = new BrushTranslateAdorner((BrushTransformAdornerSet)this);

                if (this.Behavior.Tool is GradientBrushTool && PlatformTypes.IsInstance(translateAdorner.PlatformBrush, PlatformTypes.RadialGradientBrush, (ITypeResolver)this.Element.ProjectContext))
                {
                    this.AddAdorner((Adorner) new RadialGradientBrushTranslateAdorner((BrushTransformAdornerSet)this));
                }
                this.AddAdorner((Adorner)translateAdorner);
            }
Exemplo n.º 8
0
        private object ConvertImageBrush(object value, object result, ITypeResolver sourceTypeResolver, ITypeResolver targetTypeResolver)
        {
            ReferenceStep referenceStep1 = (ReferenceStep)sourceTypeResolver.ResolveProperty(TileBrushNode.StretchProperty);
            ReferenceStep referenceStep2 = (ReferenceStep)targetTypeResolver.ResolveProperty(TileBrushNode.StretchProperty);
            object        valueToSet1    = this.ConvertInternalFast(referenceStep1.GetValue(value), sourceTypeResolver, targetTypeResolver);

            referenceStep2.SetValue(result, valueToSet1);
            object objToInspect = ((ReferenceStep)sourceTypeResolver.ResolveProperty(ImageBrushNode.ImageSourceProperty)).GetValue(value);

            if (!PlatformTypes.IsInstance(objToInspect, PlatformTypes.BitmapImage, sourceTypeResolver))
            {
                return(result);
            }
            object obj1 = ((ReferenceStep)sourceTypeResolver.ResolveProperty(BitmapImageNode.UriSourceProperty)).GetValue(objToInspect);

            if (obj1 == null)
            {
                return(result);
            }
            Type   type1 = obj1.GetType();
            IType  type2 = targetTypeResolver.ResolveType(PlatformTypes.Uri);
            string text  = Microsoft.Expression.DesignModel.Metadata.MetadataStore.GetTypeConverter(type1).ConvertToInvariantString(obj1);

            if (string.IsNullOrEmpty(text))
            {
                return(result);
            }
            object        valueToSet2    = Microsoft.Expression.DesignModel.Metadata.MetadataStore.GetTypeConverter(type2.RuntimeType).ConvertFromInvariantString(text);
            ReferenceStep referenceStep3 = (ReferenceStep)targetTypeResolver.ResolveProperty(ImageBrushNode.ImageSourceProperty);
            object        obj2           = InstanceBuilderOperations.InstantiateType(targetTypeResolver.ResolveType(PlatformTypes.BitmapImage).RuntimeType, true);

            referenceStep3.SetValue(result, obj2);
            try
            {
                BitmapImage bitmapImage = obj2 as BitmapImage;
                if (bitmapImage != null)
                {
                    bitmapImage.BeginInit();
                    bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
                }
                ((ReferenceStep)targetTypeResolver.ResolveProperty(BitmapImageNode.UriSourceProperty)).SetValue(obj2, valueToSet2);
                if (bitmapImage != null)
                {
                    bitmapImage.EndInit();
                }
            }
            catch (Exception ex)
            {
                result = (object)null;
            }
            return(result);
        }
Exemplo n.º 9
0
        protected Point GetRadialGradientEndPoint()
        {
            Point point = new Point();

            if (PlatformTypes.IsInstance(this.PlatformBrush, PlatformTypes.RadialGradientBrush, (ITypeResolver)this.Element.ProjectContext))
            {
                Vector direction = (Point)this.GetBrushPropertyAsWpf(RadialGradientBrushNode.CenterProperty) - (Point)this.GetBrushPropertyAsWpf(RadialGradientBrushNode.GradientOriginProperty);
                if (direction.X == 0.0 && direction.Y == 0.0)
                {
                    direction = new Vector(1.0, -1.0);
                }
                point = (Point)this.GetBrushPropertyAsWpf(RadialGradientBrushNode.CenterProperty) + BrushAdorner.IntersectRayAndEllipse(direction, (double)this.GetBrushPropertyAsWpf(RadialGradientBrushNode.RadiusXProperty), (double)this.GetBrushPropertyAsWpf(RadialGradientBrushNode.RadiusYProperty));
            }
            return(point);
        }
        public override void Draw(DrawingContext context, Matrix matrix)
        {
            if (!this.ShouldDraw || !PlatformTypes.IsInstance(this.PlatformBrush, PlatformTypes.RadialGradientBrush, (ITypeResolver)this.Element.ProjectContext))
            {
                return;
            }
            Pen pen = new Pen((Brush)Brushes.Transparent, 15.0);

            pen.Freeze();
            Matrix          matrix1         = this.GetCompleteBrushTransformMatrix(true) * matrix;
            EllipseGeometry ellipseGeometry = new EllipseGeometry((Point)this.GetBrushPropertyAsWpf(RadialGradientBrushNode.CenterProperty), (double)this.GetBrushPropertyAsWpf(RadialGradientBrushNode.RadiusXProperty), (double)this.GetBrushPropertyAsWpf(RadialGradientBrushNode.RadiusYProperty));

            ellipseGeometry.Transform = (Transform) new MatrixTransform(matrix1);
            ellipseGeometry.Freeze();
            context.DrawGeometry((Brush)null, pen, (System.Windows.Media.Geometry)ellipseGeometry);
            context.DrawGeometry((Brush)null, this.ThinPen, (System.Windows.Media.Geometry)ellipseGeometry);
        }
Exemplo n.º 11
0
 public bool GetBrushEndpoints(out Point startPoint, out Point endPoint)
 {
     startPoint = new Point();
     endPoint   = new Point();
     if (PlatformTypes.IsInstance(this.PlatformBrush, PlatformTypes.LinearGradientBrush, (ITypeResolver)this.Element.ProjectContext))
     {
         startPoint = (Point)this.GetBrushPropertyAsWpf(LinearGradientBrushNode.StartPointProperty);
         endPoint   = (Point)this.GetBrushPropertyAsWpf(LinearGradientBrushNode.EndPointProperty);
         return(true);
     }
     if (!PlatformTypes.IsInstance(this.PlatformBrush, PlatformTypes.RadialGradientBrush, (ITypeResolver)this.Element.ProjectContext))
     {
         return(false);
     }
     startPoint = (Point)this.GetBrushPropertyAsWpf(RadialGradientBrushNode.GradientOriginProperty);
     endPoint   = this.GetRadialGradientEndPoint();
     return(true);
 }
Exemplo n.º 12
0
 private void Rebuild()
 {
     if (!this.editingProperty.IsMixedValue)
     {
         object obj = this.editingProperty.GetValue();
         if (PlatformTypes.IsInstance(obj, PlatformTypes.GridLength, (ITypeResolver)((SceneNodeProperty)this.editingProperty).SceneNodeObjectSet.ProjectContext))
         {
             SceneNodeObjectSet sceneNodeObjectSet = ((SceneNodeProperty)this.editingProperty).SceneNodeObjectSet;
             GridLength         gridLength         = (GridLength)sceneNodeObjectSet.DesignerContext.PlatformConverter.ConvertToWpf(((SceneNodeProperty)this.editingProperty).SceneNodeObjectSet.DocumentContext, obj);
             this.value        = JoltHelper.RoundDouble(sceneNodeObjectSet.ProjectContext, gridLength.Value);
             this.gridUnitType = gridLength.GridUnitType;
             this.OnPropertyChanged("Value");
         }
     }
     else
     {
         this.gridUnitType = GridUnitType.Star;
     }
     this.OnPropertyChanged("GridUnitType");
 }
Exemplo n.º 13
0
        public override void Draw(DrawingContext context, Matrix matrix)
        {
            if (!PlatformTypes.IsInstance(this.PlatformBrush, PlatformTypes.RadialGradientBrush, (ITypeResolver)this.Element.ProjectContext))
            {
                return;
            }
            switch (this.kind)
            {
            case RadialGradientAdornerKind.GradientOriginPoint:
                this.DrawArrowTail(context, matrix, this.GradientOriginPoint, this.RadiusPoint);
                break;

            case RadialGradientAdornerKind.RadiusPoint:
                this.DrawArrowHead(context, matrix, this.GradientOriginPoint, this.RadiusPoint);
                break;

            default:
                throw new NotImplementedException(ExceptionStringTable.UnknownRadialGradientAdorner);
            }
        }
Exemplo n.º 14
0
 public override Point GetClickablePoint(Matrix matrix)
 {
     if (PlatformTypes.IsInstance(this.PlatformBrush, PlatformTypes.GradientBrush, (ITypeResolver)this.Element.ProjectContext))
     {
         GradientStopCollection gradientStopCollection = (GradientStopCollection)this.GetBrushPropertyAsWpf(GradientBrushNode.GradientStopsProperty);
         Point startPoint;
         Point endPoint;
         if (this.GetBrushEndpoints(out startPoint, out endPoint) && this.Index >= 0 && this.Index < gradientStopCollection.Count)
         {
             GradientStop gradientStop = gradientStopCollection[this.Index];
             if (gradientStop != null)
             {
                 Matrix matrix1 = this.GetCompleteBrushTransformMatrix(true) * matrix;
                 Point  point   = startPoint * matrix1;
                 endPoint *= matrix1;
                 return((endPoint - point) * gradientStop.Offset + point);
             }
         }
     }
     return(new Point(0.0, 0.0));
 }
Exemplo n.º 15
0
        public override void Draw(DrawingContext context, Matrix matrix)
        {
            if (this.Hidden || !this.ShouldDraw || !PlatformTypes.IsInstance(this.PlatformBrush, PlatformTypes.GradientBrush, (ITypeResolver)this.Element.ProjectContext))
            {
                return;
            }
            Matrix            matrix1            = this.GetCompleteBrushTransformMatrix(true) * matrix;
            PropertyReference propertyReference1 = this.AdornerSet.BrushPropertyReference.Append(GradientBrushNode.GradientStopsProperty);
            int   num1 = (int)this.Element.GetComputedValue(propertyReference1.Append(GradientStopCollectionNode.CountProperty));
            Point startPoint;
            Point endPoint;

            if (!this.GetBrushEndpoints(out startPoint, out endPoint) || this.Index < 0 || this.Index >= num1)
            {
                return;
            }
            PropertyReference propertyReference2 = propertyReference1.Append((ReferenceStep)IndexedClrPropertyReferenceStep.GetReferenceStep((IPlatformMetadata)this.Element.ViewModel.ProjectContext.Platform.Metadata, PlatformTypes.GradientStopCollection, this.Index));
            PropertyReference propertyReference3 = propertyReference2.Append(GradientStopNode.OffsetProperty);
            PropertyReference propertyReference4 = propertyReference2.Append(GradientStopNode.ColorProperty);
            double            num2 = (double)this.Element.GetComputedValue(propertyReference3);
            int    index           = this.DesignerContext.GradientToolSelectionService.Index;
            Point  point           = (endPoint - startPoint) * num2 + startPoint;
            double num3            = 3.5;
            Color  color           = (Color)this.Element.GetComputedValueAsWpf(propertyReference4);

            color.A = byte.MaxValue;
            SolidColorBrush solidColorBrush = new SolidColorBrush(color);
            Pen             pen             = this.ThinPen;

            if (index == this.Index)
            {
                pen  = this.ThickPen;
                num3 = 4.5;
            }
            context.DrawEllipse((Brush)Brushes.Transparent, (Pen)null, point * matrix1, num3 + 4.0, num3 + 4.0);
            context.DrawEllipse((Brush)solidColorBrush, pen, point * matrix1, num3, num3);
        }
Exemplo n.º 16
0
        public override void Draw(DrawingContext ctx, Matrix matrix)
        {
            if (!this.ShouldDraw || PlatformTypes.IsInstance(this.PlatformBrush, PlatformTypes.LinearGradientBrush, (ITypeResolver)this.Element.ProjectContext) && this.AdornerSet.Behavior.Tool is GradientBrushTool)
            {
                return;
            }
            Rect brushBounds = this.BrushBounds;

            if (brushBounds.Width > 0.0 && brushBounds.Height > 0.0)
            {
                Point  anchorPoint = this.GetAnchorPoint(matrix);
                Matrix matrix1     = this.GetCompleteBrushTransformMatrix(true) * matrix;
                RotateAdornerHelper.DrawAdorner(ctx, anchorPoint, this.EdgeFlags, matrix1, (Brush)Brushes.Transparent);
            }
            else
            {
                if (brushBounds.Width <= 0.0 && brushBounds.Height <= 0.0 || this.EdgeFlags != EdgeFlags.TopLeft && this.EdgeFlags != EdgeFlags.BottomRight)
                {
                    return;
                }
                Point anchorPoint = this.GetAnchorPoint(matrix);
                ctx.DrawEllipse((Brush)Brushes.Transparent, (Pen)null, anchorPoint, RotateAdornerHelper.Radius, RotateAdornerHelper.Radius);
            }
        }
Exemplo n.º 17
0
        public static Matrix GetCompleteBrushTransformMatrix(Base2DElement element, object brush, bool includeTransformFromElementToBrushCoordinates)
        {
            Matrix matrix1 = Matrix.Identity;

            if (brush != null && element != null)
            {
                Rect   computedTightBounds = element.GetComputedTightBounds();
                Matrix matrix2             = BrushAdorner.GetBrushMatrix(element, brush, BrushNode.RelativeTransformProperty);
                if (PlatformTypes.IsInstance(brush, PlatformTypes.GradientBrush, (ITypeResolver)element.ProjectContext))
                {
                    if ((BrushMappingMode)BrushAdorner.GetBrushPropertyAsWpf(element, brush, GradientBrushNode.MappingModeProperty) == BrushMappingMode.Absolute)
                    {
                        if (includeTransformFromElementToBrushCoordinates)
                        {
                            Matrix identity = Matrix.Identity;
                            identity.Translate(-computedTightBounds.X, -computedTightBounds.Y);
                            double scaleX = computedTightBounds.Width == 0.0 ? 1.0 : 1.0 / computedTightBounds.Width;
                            double scaleY = computedTightBounds.Height == 0.0 ? 1.0 : 1.0 / computedTightBounds.Height;
                            identity.Scale(scaleX, scaleY);
                            matrix2 = identity * matrix2;
                        }
                    }
                    else if (BrushAdorner.IsAdorningFillProperty((SceneElement)element))
                    {
                        matrix2 *= BrushAdorner.GetStrokeTransform((SceneElement)element);
                    }
                }
                if (PlatformTypes.IsInstance(brush, PlatformTypes.TileBrush, (ITypeResolver)element.ProjectContext) && BrushAdorner.IsAdorningFillProperty((SceneElement)element))
                {
                    matrix2 *= BrushAdorner.GetStrokeTransform((SceneElement)element);
                }
                Matrix matrix3 = new Matrix(computedTightBounds.Width, 0.0, 0.0, computedTightBounds.Height, computedTightBounds.X, computedTightBounds.Y);
                matrix1 = matrix2 * matrix3 * BrushAdorner.GetBrushMatrix(element, brush, BrushNode.TransformProperty);
            }
            return(matrix1);
        }
Exemplo n.º 18
0
        private void UpdateTranslation(bool scrollNow)
        {
            SceneView      activeView = this.ActiveView;
            SceneViewModel viewModel  = activeView.ViewModel;

            if (!this.HasMouseMovedAfterDown)
            {
                this.hasInitializedBrush = false;
            }
            SceneElement primarySelection = this.ActiveView.ElementSelectionSet.PrimarySelection;

            if (primarySelection == null)
            {
                return;
            }
            PropertyReference propertyReference = this.GetBrushPropertyReference((SceneNode)primarySelection);

            if (propertyReference == null || Adorner.NonAffineTransformInParentStack(primarySelection))
            {
                return;
            }
            this.EnsureEditTransaction();
            if (!this.hasInitializedBrush)
            {
                if (!PlatformTypes.IsInstance(this.ActiveView.ElementSelectionSet.PrimarySelection.GetComputedValue(propertyReference), PlatformTypes.GradientBrush, (ITypeResolver)primarySelection.ProjectContext))
                {
                    object lastUsed = BrushCategory.GetLastUsed(this.ActiveView.DesignerContext, this.ActiveView.Document.DocumentContext, BrushCategory.Gradient);
                    this.ActiveView.ElementSelectionSet.PrimarySelection.SetValueAsWpf(propertyReference, lastUsed);
                    this.UpdateEditTransaction();
                }
                this.CopyPrimaryBrushToSelection();
                this.hasInitializedBrush = true;
            }
            object computedValue = primarySelection.GetComputedValue(propertyReference);
            Matrix matrix        = activeView.GetComputedTransformFromRoot(primarySelection) * BrushAdorner.GetCompleteInverseBrushTransformMatrix((Base2DElement)primarySelection, computedValue, true);
            Point  point1        = this.dragStartPosition * matrix;
            Point  point2        = this.dragCurrentPosition * matrix;
            Point  point3        = RoundingHelper.RoundPosition(point1);
            Point  point4        = RoundingHelper.RoundPosition(point2);

            if (PlatformTypes.IsInstance(computedValue, PlatformTypes.LinearGradientBrush, (ITypeResolver)primarySelection.ProjectContext))
            {
                this.SetBrushValue(LinearGradientBrushNode.StartPointProperty, (object)point3);
                this.SetBrushValue(LinearGradientBrushNode.EndPointProperty, (object)point4);
            }
            else if (PlatformTypes.IsInstance(computedValue, PlatformTypes.RadialGradientBrush, (ITypeResolver)primarySelection.ProjectContext))
            {
                this.SetBrushValue(RadialGradientBrushNode.CenterProperty, (object)point3);
                this.SetBrushValue(RadialGradientBrushNode.GradientOriginProperty, (object)point3);
                if (this.IsShiftDown)
                {
                    Vector vector = point4 - point3;
                    this.SetBrushValue(RadialGradientBrushNode.RadiusXProperty, (object)vector.Length);
                    this.SetBrushValue(RadialGradientBrushNode.RadiusYProperty, (object)vector.Length);
                }
                else
                {
                    Point point5 = RoundingHelper.RoundPosition(new Point(Math.Abs(point3.X - point4.X), Math.Abs(point3.Y - point4.Y)));
                    this.SetBrushValue(RadialGradientBrushNode.RadiusXProperty, (object)point5.X);
                    this.SetBrushValue(RadialGradientBrushNode.RadiusYProperty, (object)point5.Y);
                }
            }
            activeView.EnsureVisible(this.dragStartPosition + this.dragCurrentPosition - this.dragStartPosition, scrollNow);
            this.UpdateEditTransaction();
        }
Exemplo n.º 19
0
        private LayoutConstraintMode GetHeightConstraintModeCore(IViewVisual parent, IViewVisual child, SceneView view, bool allowGridAutoChecks)
        {
            if (parent == null)
            {
                return(LayoutConstraintMode.CanvasLike);
            }
            LayoutConstraintMode layoutConstraintMode = LayoutConstraintMode.NonOverlappingGridlike;
            IType itype = parent.GetIType((ITypeResolver)view.ProjectContext);

            if (PlatformTypes.Grid.IsAssignableFrom((ITypeId)itype) || PlatformTypes.Canvas.IsAssignableFrom((ITypeId)itype))
            {
                layoutConstraintMode |= LayoutConstraintMode.Overlapping;
            }
            IViewVisual viewVisual = parent.VisualParent as IViewVisual;

            if (viewVisual != null && PlatformTypes.IsInstance(viewVisual.PlatformSpecificObject, ProjectNeutralTypes.Viewbox, (ITypeResolver)view.ProjectContext))
            {
                layoutConstraintMode |= LayoutConstraintMode.CanvasLike;
            }
            if (PlatformTypes.Canvas.IsAssignableFrom((ITypeId)itype) || PlatformTypes.TextBlock.IsAssignableFrom((ITypeId)itype) || (PlatformTypes.RichTextBox.IsAssignableFrom((ITypeId)itype) || PlatformTypes.FlowDocumentScrollViewer.IsAssignableFrom((ITypeId)itype)) || (PlatformTypes.ScrollContentPresenter.IsAssignableFrom((ITypeId)itype) || ProjectNeutralTypes.Viewbox.IsAssignableFrom((ITypeId)itype) || (PlatformTypes.Popup.IsAssignableFrom((ITypeId)itype) || ProjectNeutralTypes.PathPanel.IsAssignableFrom((ITypeId)itype))))
            {
                layoutConstraintMode |= LayoutConstraintMode.CanvasLike;
            }
            if (PlatformTypes.StackPanel.IsAssignableFrom((ITypeId)itype) && ((IViewPanel)parent).Orientation == Orientation.Vertical)
            {
                layoutConstraintMode |= LayoutConstraintMode.CanvasLike;
            }
            if (ProjectNeutralTypes.DockPanel.IsAssignableFrom((ITypeId)itype) && child != null)
            {
                switch ((Dock)view.ConvertToWpfValue(child.GetCurrentValue(view.ProjectContext.ResolveProperty(DockPanelElement.DockProperty))))
                {
                case Dock.Top:
                case Dock.Bottom:
                    layoutConstraintMode |= LayoutConstraintMode.CanvasLike;
                    break;
                }
            }
            if (ProjectNeutralTypes.WrapPanel.IsAssignableFrom((ITypeId)itype) && double.IsNaN((double)parent.GetCurrentValue(view.ProjectContext.ResolveProperty(WrapPanelElement.ItemHeightProperty))))
            {
                layoutConstraintMode |= LayoutConstraintMode.CanvasLike;
            }
            if ((layoutConstraintMode & LayoutConstraintMode.CanvasLike) == LayoutConstraintMode.NonOverlappingGridlike && double.IsNaN((double)parent.GetCurrentValue(view.ProjectContext.ResolveProperty(BaseFrameworkElement.HeightProperty))) && double.IsNaN((double)parent.GetCurrentValue(view.ProjectContext.ResolveProperty(DesignTimeProperties.DesignHeightProperty))))
            {
                IViewGrid viewGrid = parent as IViewGrid;
                if (viewGrid != null)
                {
                    if (!allowGridAutoChecks)
                    {
                        return(layoutConstraintMode);
                    }
                    IType type = child == null ? (IType)null : child.GetIType((ITypeResolver)view.ProjectContext);
                    if (child != null && (!PlatformTypes.Path.IsAssignableFrom((ITypeId)type) || !double.IsNaN((double)child.GetCurrentValue(view.ProjectContext.ResolveProperty(BaseFrameworkElement.HeightProperty)))))
                    {
                        int    val2_1 = (int)child.GetCurrentValue(view.ProjectContext.ResolveProperty(GridElement.RowProperty));
                        int    val2_2 = val2_1 + (int)child.GetCurrentValue(view.ProjectContext.ResolveProperty(GridElement.RowSpanProperty));
                        int    num1   = Math.Max(0, Math.Min(viewGrid.RowDefinitionsCount - 1, val2_1));
                        int    num2   = Math.Max(0, Math.Min(viewGrid.RowDefinitionsCount, val2_2));
                        double num3   = 0.0;
                        bool   flag1  = true;
                        bool   flag2  = true;
                        if (num2 == 0)
                        {
                            flag1 = false;
                            flag2 = false;
                            num3  = viewGrid.RenderSize.Height;
                        }
                        else
                        {
                            for (int index = num1; index < num2; ++index)
                            {
                                IViewRowDefinition rowDefinition = viewGrid.GetRowDefinition(index);
                                flag1 &= rowDefinition.Height.IsAuto;
                                flag2 &= rowDefinition.Height.IsAbsolute;
                                num3  += rowDefinition.ActualHeight;
                            }
                        }
                        double    height      = child.DesiredSize.Height;
                        IProperty propertyKey = view.Platform.Metadata.ResolveProperty(Base2DElement.UseLayoutRoundingProperty);
                        if (propertyKey != null && child.GetCurrentValue(propertyKey) != parent.GetCurrentValue(propertyKey))
                        {
                            height += 0.999;
                        }
                        if (Tolerances.LessThan(height, num3) || flag2)
                        {
                            return(layoutConstraintMode);
                        }
                        if (flag1)
                        {
                            layoutConstraintMode |= LayoutConstraintMode.CanvasLike;
                        }
                    }
                }
                if ((VerticalAlignment)view.ConvertToWpfValue(parent.GetCurrentValue(view.ProjectContext.ResolveProperty(BaseFrameworkElement.VerticalAlignmentProperty))) != VerticalAlignment.Stretch)
                {
                    layoutConstraintMode |= LayoutConstraintMode.CanvasLike;
                }
                else
                {
                    if (PlatformTypes.Control.IsAssignableFrom((ITypeId)itype) || PlatformTypes.ContentPresenter.IsAssignableFrom((ITypeId)itype))
                    {
                        allowGridAutoChecks = true;
                    }
                    if ((this.GetHeightConstraintModeCore(parent.VisualParent as IViewVisual, parent, view, allowGridAutoChecks) & LayoutConstraintMode.CanvasLike) != LayoutConstraintMode.NonOverlappingGridlike)
                    {
                        layoutConstraintMode |= LayoutConstraintMode.CanvasLike;
                    }
                }
            }
            return(layoutConstraintMode);
        }
Exemplo n.º 20
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();
        }