示例#1
0
        public override Rect GetActualBoundsInParent(IViewObject element)
        {
            FrameworkElement element1 = element == null ? (FrameworkElement)null : element.PlatformSpecificObject as FrameworkElement;

            if (element1 == null)
            {
                return(new Rect());
            }
            return(ElementUtilities.GetActualBoundsInParent(element1));
        }
示例#2
0
        public override void Draw(DrawingContext drawingContext, Matrix matrix)
        {
            if (this.snapLines == null)
            {
                return;
            }
            FrameworkElement element = this.targetElement == null || !this.targetElement.IsViewObjectValid ? (FrameworkElement)null : this.targetElement.ViewObject.PlatformSpecificObject as FrameworkElement;

            if (element != null)
            {
                this.targetBounds = ElementUtilities.GetActualBoundsInParent(element);
            }
            foreach (SnapLine snapLine in this.snapLines)
            {
                if (this.BoundsMatchSnapLine(this.targetBounds, snapLine))
                {
                    Point p1 = snapLine.P1;
                    Point p2 = snapLine.P2;
                    if (snapLine.IsContainerLine || snapLine.Location != snapLine.LocationRelativeToTarget)
                    {
                        Point cornerPoint1;
                        Point cornerPoint2;
                        this.GetTargetCorners(this.targetBounds, snapLine.Orientation, snapLine.LocationRelativeToTarget, out cornerPoint1, out cornerPoint2);
                        Rect rect = new Rect(p1, p2);
                        rect.Union(cornerPoint1);
                        rect.Union(cornerPoint2);
                        if (Math.Abs(snapLine.OffsetRelativeToTarget) < 0.001)
                        {
                            p1 = rect.TopLeft * matrix;
                            Point point1 = rect.BottomRight * matrix;
                            drawingContext.DrawLine(SnapLineAdorner.SolidSnapLinePen, p1, point1);
                            drawingContext.DrawLine(SnapLineAdorner.DottedSnapLinePen, p1, point1);
                        }
                        else
                        {
                            StreamGeometry        streamGeometry        = new StreamGeometry();
                            StreamGeometryContext streamGeometryContext = streamGeometry.Open();
                            streamGeometryContext.BeginFigure(rect.TopLeft * matrix, true, true);
                            streamGeometryContext.PolyLineTo((IList <Point>) new Point[3]
                            {
                                rect.TopRight *matrix,
                                rect.BottomRight *matrix,
                                rect.BottomLeft *matrix
                            }, 0 != 0, 0 != 0);
                            streamGeometryContext.Close();
                            streamGeometry.Freeze();
                            drawingContext.DrawGeometry(SnapLineAdorner.MarginBrush, (Pen)null, (System.Windows.Media.Geometry)streamGeometry);
                        }
                    }
                    else
                    {
                        this.ExtendLine(this.targetBounds, snapLine.Orientation, ref p1, ref p2);
                        p1 *= matrix;
                        Point  point1 = p2 * matrix;
                        Vector vector = (snapLine.Orientation == SnapLineOrientation.Horizontal ? new Vector(0.0, 1.0) : new Vector(1.0, 0.0)) * matrix;
                        if (vector.X != 0.0 || vector.Y != 0.0)
                        {
                            vector.Normalize();
                            double num = (snapLine.LocationRelativeToTarget == SnapLineLocation.Minimum ? -1.0 : 1.0) * SnapLineAdorner.SolidSnapLinePen.Thickness / 2.0;
                            p1     += num * vector;
                            point1 += num * vector;
                        }
                        drawingContext.DrawLine(SnapLineAdorner.SolidSnapLinePen, p1, point1);
                        drawingContext.DrawLine(SnapLineAdorner.DottedSnapLinePen, p1, point1);
                    }
                }
            }
        }