예제 #1
0
        public static void DrawDimension(DrawingContext drawingContext, ElementLayoutAdornerType edge, Matrix matrix, Matrix rootMatrix, Pen pen, Rect bounds, double scale)
        {
            Point point1;
            Point point2;

            switch (edge)
            {
            case ElementLayoutAdornerType.Left:
                point1 = bounds.TopLeft;
                point2 = bounds.BottomLeft;
                break;

            case ElementLayoutAdornerType.Top:
                point1 = bounds.TopLeft;
                point2 = bounds.TopRight;
                break;

            case ElementLayoutAdornerType.Right:
                point1 = bounds.TopRight;
                point2 = bounds.BottomRight;
                break;

            case ElementLayoutAdornerType.Bottom:
                point1 = bounds.BottomLeft;
                point2 = bounds.BottomRight;
                break;

            default:
                throw new NotSupportedException();
            }
            double length  = ((point2 - point1) * rootMatrix).Length;
            Point  point3  = bounds.TopLeft + 0.5 * (bounds.BottomRight - bounds.TopLeft);
            Point  point4  = point1 * matrix;
            Point  point5  = point2 * matrix;
            Point  point6  = point3 * matrix;
            Vector vector1 = point4 + 0.5 * (point5 - point4) - point6;

            vector1.Normalize();
            Vector vector2 = point5 - point4;

            vector2.Normalize();
            Vector overflowDirection = new Vector(vector2.Y, -vector2.X);

            if (overflowDirection * vector1 < 0.0)
            {
                overflowDirection = -overflowDirection;
            }
            Point  point7  = point4 - 0.5 * pen.Thickness * vector2;
            Point  point8  = point5 + 0.5 * pen.Thickness * vector2;
            Vector vector3 = scale * 7.0 * overflowDirection;
            Vector vector4 = scale * 22.0 * overflowDirection;

            drawingContext.DrawLine(pen, point7 + vector3, point7 + vector4);
            drawingContext.DrawLine(pen, point8 + vector3, point8 + vector4);
            Point  a    = point4 + scale * 17.5 * overflowDirection;
            Point  b    = point5 + scale * 17.5 * overflowDirection;
            string text = length.ToString("0.###", (IFormatProvider)CultureInfo.CurrentCulture);

            SizeAdorner.DrawLineAndText(drawingContext, a, b, overflowDirection, pen, pen.Brush, text, scale);
        }
예제 #2
0
        private void DrawAnimate(DrawingContext ctx, Matrix matrix, IEnumerable <IAdornerAnimation> activeAdornerAnimations)
        {
            IAdornerAnimation adornerAnimation = activeAdornerAnimations != null?Enumerable.FirstOrDefault <IAdornerAnimation>(activeAdornerAnimations, (Func <IAdornerAnimation, bool>)(item => item.Name == "PreviewBox")) : (IAdornerAnimation)null;

            if (!this.ShouldDraw || this.Element.Visual == null)
            {
                return;
            }
            Rect elementBounds = this.ElementBounds;
            Pen  pen           = this.BorderPen;

            if (pen.IsFrozen && adornerAnimation != null)
            {
                pen = adornerAnimation.ClientData as Pen;
                if (pen == null)
                {
                    pen = this.BorderPen.Clone();
                    adornerAnimation.ClientData = (object)pen;
                }
            }
            if (adornerAnimation != null)
            {
                pen.Brush.Opacity = adornerAnimation.LerpValue;
            }
            this.DrawBounds(ctx, elementBounds, (Brush)null, pen);
            if (!this.AdornerSet.ToolContext.Tool.ShowDimensions || !this.Element.ViewModel.ElementSelectionSet.Selection.Contains(this.Element) || this.ElementSet.IsPrimaryTransformNonAffine)
            {
                return;
            }
            Matrix computedTransformToRoot = this.DesignerContext.ActiveView.GetComputedTransformToRoot(this.Element);

            SizeAdorner.DrawDimension(ctx, ElementLayoutAdornerType.Right, matrix, computedTransformToRoot, pen, elementBounds, 1.0);
            SizeAdorner.DrawDimension(ctx, ElementLayoutAdornerType.Bottom, matrix, computedTransformToRoot, pen, elementBounds, 1.0);
        }
예제 #3
0
        public override void Draw(DrawingContext ctx, Matrix matrix)
        {
            if (!this.shouldDraw)
            {
                return;
            }
            bool  flag        = this.AdornerSet is RectangleGeometryAdornerSetBase;
            Point anchorPoint = this.GetAnchorPoint(matrix);
            Brush brush       = this.IsActive ? (flag ? FeedbackHelper.GetActiveBrush(AdornerType.ClipPath) : this.ActiveBrush) : this.InactiveBrush;
            Pen   pen         = flag ? FeedbackHelper.GetThinPen(AdornerType.ClipPath) : this.ThinPen;
            Rect  targetRect  = this.TargetRect;
            AdornerRenderLocation location = AdornerRenderLocation.Outside;

            if (this.DesignerContext.SelectionManager.ElementSelectionSet != null && this.DesignerContext.SelectionManager.ElementSelectionSet.Selection.Count > 1 && !this.ElementSet.AdornsMultipleElements)
            {
                location = AdornerRenderLocation.Inside;
            }
            SizeAdorner.DrawSizeAdorner(ctx, anchorPoint, this.EdgeFlags, matrix, brush, pen, targetRect, location);
            if (!this.IsActive)
            {
                return;
            }
            Matrix transformMatrix = this.ElementSet.GetTransformMatrix(this.DesignerContext.ActiveView.ViewRoot);

            SizeAdorner.DrawDimensions(ctx, matrix, transformMatrix, pen, targetRect, this.EdgeFlags);
        }
예제 #4
0
        public override void Draw(DrawingContext ctx, Matrix matrix)
        {
            Point anchorPoint   = this.GetAnchorPoint(matrix);
            Brush brush         = this.IsActive ? this.ActiveBrush : this.InactiveBrush;
            Rect  elementBounds = this.ElementBounds;

            if (this.Type == DesignTimeAdornerType.Width || this.Type == DesignTimeAdornerType.Height)
            {
                if (!this.handlingDrag || this.IsActive || !this.IsEnabled)
                {
                    Pen thinPen = this.ThinPen;
                    this.DrawEdgeAdorner(ctx, anchorPoint, matrix, brush, thinPen, elementBounds);
                }
            }
            else
            {
                if (!this.TestFlags(EdgeFlags.BottomRight))
                {
                    throw new NotSupportedException();
                }
                Pen pen = this.IsEnabled ? this.MediumPen : this.ThinPen;
                this.DrawCornerAdorner(ctx, anchorPoint, matrix, brush, pen);
            }
            if (!this.IsActive || !this.IsEnabled)
            {
                return;
            }
            Matrix transformMatrix = this.ElementSet.GetTransformMatrix(this.DesignerContext.ActiveView.ViewRoot);

            SizeAdorner.DrawDimensions(ctx, matrix, transformMatrix, this.ThinPen, elementBounds, this.EdgeFlags);
        }
        public override void Draw(DrawingContext ctx, Matrix matrix)
        {
            if (this.Element.ParentElement == null || this.Element.Visual == null)
            {
                return;
            }
            Point pointBegin;
            Point pointEnd;

            this.GetPoints(out pointBegin, out pointEnd);
            string text = string.Empty;

            if (!this.IsAuto)
            {
                Matrix computedTransformToRoot = this.DesignerContext.ActiveView.GetComputedTransformToRoot((SceneElement)this.Element);
                text = ((pointEnd - pointBegin) * computedTransformToRoot).Length.ToString("0.###", (IFormatProvider)CultureInfo.CurrentCulture);
            }
            Point a    = pointBegin * matrix;
            Point b    = pointEnd * matrix;
            Pen   pen1 = this.ThinPen.Clone();

            pen1.Brush.Opacity = 0.5;
            if (this.IsAuto && VectorUtilities.SquaredDistance(a, b) < 10000000000.0)
            {
                pen1.DashStyle = ElementLayoutLineAdorner.LineDashStyle;
            }
            pen1.Freeze();
            Vector overflowDirection = b - a;

            overflowDirection.Normalize();
            SizeAdorner.DrawLineAndText(ctx, a, b, overflowDirection, pen1, this.ActiveBrush, text, 1.0);
            if (this.type != ElementLayoutAdornerType.Left)
            {
                return;
            }
            Transform   transform1  = (Transform)this.Element.GetComputedValueAsWpf(Base2DElement.RenderTransformProperty);
            Transform   transform2  = (Transform)null;
            IPropertyId propertyKey = (IPropertyId)this.Element.ProjectContext.ResolveProperty(BaseFrameworkElement.LayoutTransformProperty);

            if (propertyKey != null)
            {
                transform2 = (Transform)this.Element.GetComputedValueAsWpf(propertyKey);
            }
            if ((transform1 == null || transform1.Value.IsIdentity) && (transform2 == null || transform2.Value.IsIdentity))
            {
                return;
            }
            RectangleGeometry rectangleGeometry = new RectangleGeometry(this.DesignerContext.ActiveSceneViewModel.GetLayoutDesignerForChild((SceneElement)this.Element, true).GetChildRect(this.Element), 0.0, 0.0, (Transform) new MatrixTransform(this.Element.GetComputedTransformFromVisualParent() * matrix));

            rectangleGeometry.Freeze();
            Pen pen2 = this.ThinPen.Clone();

            pen2.Brush.Opacity = 0.5;
            pen2.Freeze();
            ctx.DrawGeometry((Brush)null, pen2, (System.Windows.Media.Geometry)rectangleGeometry);
        }
예제 #6
0
        public override void Draw(DrawingContext ctx, Matrix matrix)
        {
            if (!this.ShouldDraw)
            {
                return;
            }
            Point anchorPoint = this.GetAnchorPoint(matrix);

            matrix = this.GetCompleteBrushTransformMatrix(true) * matrix;
            Brush brush = this.IsActive ? this.ActiveBrush : this.InactiveBrush;

            SizeAdorner.DrawSizeAdorner(ctx, anchorPoint, this.EdgeFlags, matrix, brush, this.ThinPen, this.BrushBounds, AdornerRenderLocation.Outside);
        }
예제 #7
0
        public static void DrawDimensions(DrawingContext drawingContext, Matrix matrix, Matrix rootMatrix, Pen pen, Rect bounds, EdgeFlags edgeFlags)
        {
            if ((edgeFlags & EdgeFlags.LeftOrRight) != EdgeFlags.None)
            {
                ElementLayoutAdornerType edge = (edgeFlags & EdgeFlags.Top) != EdgeFlags.None ? ElementLayoutAdornerType.Top : ElementLayoutAdornerType.Bottom;
                SizeAdorner.DrawDimension(drawingContext, edge, matrix, rootMatrix, pen, bounds, 1.0);
            }
            if ((edgeFlags & EdgeFlags.TopOrBottom) == EdgeFlags.None)
            {
                return;
            }
            ElementLayoutAdornerType edge1 = (edgeFlags & EdgeFlags.Left) != EdgeFlags.None ? ElementLayoutAdornerType.Left : ElementLayoutAdornerType.Right;

            SizeAdorner.DrawDimension(drawingContext, edge1, matrix, rootMatrix, pen, bounds, 1.0);
        }
예제 #8
0
        public static void DrawSizeAdorner(DrawingContext drawingContext, Point anchorPoint, EdgeFlags edgeFlags, Matrix matrix, Brush brush, Pen pen, Rect bounds, AdornerRenderLocation location)
        {
            if (SizeAdorner.SkipAdorner(edgeFlags, matrix, bounds))
            {
                return;
            }
            Vector vector1 = new Vector(1.0, 0.0) * matrix;
            Vector vector2 = new Vector(0.0, 1.0) * matrix;

            vector1.Normalize();
            vector2.Normalize();
            double num1    = matrix.Determinant < 0.0 ? -1.0 : 1.0;
            Point  point   = anchorPoint;
            Matrix matrix1 = new Matrix(0.0, 1.0 * num1, -1.0 * num1, 0.0, 0.0, 0.0);
            Matrix matrix2 = new Matrix(0.0, -1.0 * num1, 1.0 * num1, 0.0, 0.0, 0.0);
            Vector vector3 = vector1 * matrix1;
            Vector vector4 = vector2 * matrix2;
            Vector vector5 = vector1 * 8.0;
            Vector vector6 = vector2 * 8.0;

            if (location == AdornerRenderLocation.Inside)
            {
                switch (edgeFlags & EdgeFlags.TopOrBottom)
                {
                case EdgeFlags.None:
                    vector1      = vector4;
                    anchorPoint -= 0.5 * (5.0 - pen.Thickness) * vector2;
                    point       += vector2 * 0.5 * 8.0;
                    break;

                case EdgeFlags.Top:
                    vector2      = vector3;
                    anchorPoint += 0.5 * pen.Thickness * vector2;
                    point       += vector2 * 8.0;
                    break;

                case EdgeFlags.Bottom:
                    vector2      = vector3;
                    anchorPoint -= (5.0 - 0.5 * pen.Thickness) * vector2;
                    break;
                }
                switch (edgeFlags & EdgeFlags.LeftOrRight)
                {
                case EdgeFlags.None:
                    anchorPoint -= 0.5 * (5.0 - pen.Thickness) * vector1;
                    point       += vector1 * 0.5 * 8.0;
                    break;

                case EdgeFlags.Left:
                    anchorPoint += 0.5 * pen.Thickness * vector1;
                    point       += vector1 * 8.0;
                    break;

                case EdgeFlags.Right:
                    anchorPoint -= (5.0 - 0.5 * pen.Thickness) * vector1;
                    break;
                }
            }
            else
            {
                switch (edgeFlags & EdgeFlags.TopOrBottom)
                {
                case EdgeFlags.None:
                    vector1      = vector4;
                    anchorPoint -= 0.5 * (5.0 - pen.Thickness) * vector2;
                    point       += vector2 * 0.5 * 8.0;
                    break;

                case EdgeFlags.Top:
                    vector2      = vector3;
                    anchorPoint -= (5.0 - 0.5 * pen.Thickness) * vector2;
                    break;

                case EdgeFlags.Bottom:
                    vector2      = vector3;
                    anchorPoint += 0.5 * pen.Thickness * vector2;
                    point       += vector2 * 8.0;
                    break;
                }
                switch (edgeFlags & EdgeFlags.LeftOrRight)
                {
                case EdgeFlags.None:
                    anchorPoint -= 0.5 * (5.0 - pen.Thickness) * vector1;
                    point       += vector1 * 0.5 * 8.0;
                    break;

                case EdgeFlags.Left:
                    anchorPoint -= (5.0 - 0.5 * pen.Thickness) * vector1;
                    break;

                case EdgeFlags.Right:
                    anchorPoint += 0.5 * pen.Thickness * vector1;
                    point       += vector1 * 8.0;
                    break;
                }
            }
            StreamGeometry        streamGeometry1        = new StreamGeometry();
            StreamGeometryContext streamGeometryContext1 = streamGeometry1.Open();

            streamGeometryContext1.BeginFigure(point - vector5, true, true);
            streamGeometryContext1.LineTo(point - vector5 - vector6, false, false);
            streamGeometryContext1.LineTo(point - vector6, false, false);
            streamGeometryContext1.LineTo(point, false, false);
            streamGeometryContext1.Close();
            streamGeometry1.Freeze();
            drawingContext.DrawGeometry((Brush)Brushes.Transparent, (Pen)null, (System.Windows.Media.Geometry)streamGeometry1);
            double                num2                   = 5.0 - pen.Thickness;
            Vector                vector7                = vector1 * num2;
            Vector                vector8                = vector2 * num2;
            StreamGeometry        streamGeometry2        = new StreamGeometry();
            StreamGeometryContext streamGeometryContext2 = streamGeometry2.Open();

            streamGeometryContext2.BeginFigure(anchorPoint, true, true);
            streamGeometryContext2.LineTo(anchorPoint + vector8, true, false);
            streamGeometryContext2.LineTo(anchorPoint + vector7 + vector8, true, false);
            streamGeometryContext2.LineTo(anchorPoint + vector7, true, false);
            streamGeometryContext2.Close();
            streamGeometry2.Freeze();
            drawingContext.DrawGeometry(brush, pen, (System.Windows.Media.Geometry)streamGeometry2);
        }
예제 #9
0
        private void DrawEdgeAdorner(DrawingContext drawingContext, Point anchorPoint, Matrix matrix, Brush brush, Pen pen, Rect bounds)
        {
            if (SizeAdorner.SkipAdorner(this.EdgeFlags, matrix, bounds))
            {
                return;
            }
            Vector vector1 = new Vector(1.0, 0.0) * matrix;
            Vector vector2 = new Vector(0.0, 1.0) * matrix;

            vector1.Normalize();
            vector2.Normalize();
            double num1 = this.TestFlags(EdgeFlags.Right) ? -1.0 : 1.0;
            double num2 = this.TestFlags(EdgeFlags.Bottom) ? -1.0 : 1.0;

            switch (this.EdgeFlags & EdgeFlags.TopOrBottom)
            {
            case EdgeFlags.None:
                anchorPoint -= 0.5 * (13.0 - pen.Thickness) * vector2;
                break;

            case EdgeFlags.Top:
            case EdgeFlags.Bottom:
                anchorPoint -= (15.0 - 0.5 * pen.Thickness) * vector2 * num2;
                break;
            }
            switch (this.EdgeFlags & EdgeFlags.LeftOrRight)
            {
            case EdgeFlags.None:
                anchorPoint -= 0.5 * (13.0 - pen.Thickness) * vector1;
                break;

            case EdgeFlags.Left:
            case EdgeFlags.Right:
                anchorPoint -= (15.0 - 0.5 * pen.Thickness) * vector1 * num1;
                break;
            }
            bool   flag = this.TestFlags(EdgeFlags.LeftOrRight);
            double num3 = (flag ? 4.0 : 13.0) - pen.Thickness;
            double num4 = (flag ? 13.0 : 4.0) - pen.Thickness;

            vector1 *= num3 * num1;
            Vector                vector3               = vector2 * (num4 * num2);
            StreamGeometry        streamGeometry        = new StreamGeometry();
            StreamGeometryContext streamGeometryContext = streamGeometry.Open();

            streamGeometryContext.BeginFigure(anchorPoint, true, true);
            streamGeometryContext.LineTo(anchorPoint + vector3, true, false);
            streamGeometryContext.LineTo(anchorPoint + vector1 + vector3, true, false);
            streamGeometryContext.LineTo(anchorPoint + vector1, true, false);
            streamGeometryContext.Close();
            streamGeometry.Freeze();
            if (this.IsEnabled)
            {
                drawingContext.DrawGeometry(brush, pen, (System.Windows.Media.Geometry)streamGeometry);
            }
            else
            {
                drawingContext.DrawGeometry((Brush)Brushes.Transparent, (Pen)null, (System.Windows.Media.Geometry)streamGeometry);
                Vector vector4 = flag ? vector3 : vector1;
                drawingContext.DrawLine(pen, anchorPoint, anchorPoint + vector4);
            }
        }