Exemplo n.º 1
0
        void AddArrow(Edge drawingEdge, StreamGeometryContext context, Point start, Point end, double lineWidthOfAttachedNode)
        {
            Point  dir = end - start;
            double dl  = dir.Length;

            double scaling   = (dl < 12? 1 : 12 / dl) / _scale;
            Point  new_start = end - (end - start) * scaling;

            //take into account the widths
            double delta = Math.Min(dl / 2, drawingEdge.Attr.LineWidth + lineWidthOfAttachedNode / 2);

            //dir *= (dl - delta) / dl;
            end = start + dir;
            dir = dir.Rotate(Math.PI / 2);
            Point s = dir * HalfArrowAngleTan * scaling;

            context.BeginFigure(CommonX.WpfPoint(start), true, true);
            context.LineTo(CommonX.WpfPoint(new_start), true, true);

            if (_category == "References")
            {
                double r = dl * scaling / 2;
                context.ArcTo(CommonX.WpfPoint(end), new Size(r, r), 0, true, SweepDirection.Clockwise, true, true);
                context.ArcTo(CommonX.WpfPoint(new_start), new Size(r, r), 0, true, SweepDirection.Clockwise, true, true);
            }
            else
            {
                context.LineTo(CommonX.WpfPoint(new_start + s), true, true);
                context.LineTo(CommonX.WpfPoint(end), true, true);
                context.LineTo(CommonX.WpfPoint(new_start - s), true, true);
                context.LineTo(CommonX.WpfPoint(new_start), true, true);
            }
        }
Exemplo n.º 2
0
        UIElement createCoil(float vx1, float vy1, float vx2, float vy2, float vw, bool dirDown, Brush stroke, float vthick, Brush fill)
        {
            Path  path  = new Path();
            float thick = vthick * (float)Math.Sqrt(w * h);
            float rad   = (float)convVSizeX(vw / 2);
            float y1    = (float)convVY(vy1) + rad;
            float y2    = (float)convVY(vy2) - rad;

            if (stroke != null)
            {
                path.Stroke = stroke;
            }
            path.Fill            = fill;
            path.StrokeThickness = thick;

            StreamGeometry geometry = new StreamGeometry();

            using (StreamGeometryContext ctx = geometry.Open())
            {
                ctx.BeginFigure(new Point(convVX(vx1), y1), true, false);
                ctx.LineTo(new Point(convVX(vx2), y2), true, true);
                ctx.ArcTo(new Point(convVX(vx2 + vw), y2), new Size(rad, rad), 0, true, SweepDirection.Counterclockwise, true, true);
                ctx.LineTo(new Point(convVX(vx1 + vw), y1), true, true);
                ctx.ArcTo(new Point(convVX(vx1), y1), new Size(rad, rad), 0, true, SweepDirection.Counterclockwise, true, true);
            }
            geometry.Freeze();
            path.Data = geometry;
            return(path);
        }
Exemplo n.º 3
0
        private Geometry GenerateInnerSpeechBubble()
        {
            StreamGeometry geom = new StreamGeometry();

            using (StreamGeometryContext gc = geom.Open())
            {
                Size  cornerSize = new Size(5, 5);
                Point start      = new Point(20, 15);
                gc.BeginFigure(start, true, true);
                gc.LineTo(new Point(415, 15), true, true);
                gc.ArcTo(new Point(420, 20), cornerSize, 0.0, false, SweepDirection.Clockwise, true, true);
                gc.LineTo(new Point(420, 60), true, true);
                gc.ArcTo(new Point(415, 65), cornerSize, 0.0, false, SweepDirection.Clockwise, true, true);
                gc.LineTo(new Point(20, 65), true, true);
                gc.ArcTo(new Point(15, 60), cornerSize, 0.0, false, SweepDirection.Clockwise, true, true);
                gc.LineTo(new Point(15, 48), true, true);
                gc.LineTo(new Point(2, 40), true, true);
                gc.LineTo(new Point(15, 32), true, true);

                gc.LineTo(new Point(15, 20), true, true);
                gc.ArcTo(start, cornerSize, 0.0, false, SweepDirection.Clockwise, true, true);
            }

            return(geom);
        }
Exemplo n.º 4
0
        private void method18(StreamGeometryContext streamGeometryContext)
        {
            Point point  = new Point(method10(), method12());
            Point point2 = Utils.ComputeCartesianCoordinate(method8(), method4());

            point2.Offset(method10(), method12());
            Point point3 = Utils.ComputeCartesianCoordinate(method8() + method6(), method4());

            point3.Offset(method10(), method12());
            Point point4 = Utils.ComputeCartesianCoordinate(method8(), method0());

            point4.Offset(method10(), method12());
            Point point5 = Utils.ComputeCartesianCoordinate(method8() + method6(), method0());

            point5.Offset(method10(), method12());
            bool isLargeArc = method6() > 180.0;

            if (method2() > 0.0)
            {
                Point point6 = Utils.ComputeCartesianCoordinate(method8() + method6() / 2.0, method2());
                point2.Offset(point6.X, point6.Y);
                point3.Offset(point6.X, point6.Y);
                point4.Offset(point6.X, point6.Y);
                point5.Offset(point6.X, point6.Y);
            }

            Size size  = new Size(method0(), method0());
            Size size2 = new Size(method4(), method4());

            streamGeometryContext.BeginFigure(point2, true, true);
            streamGeometryContext.LineTo(point4, true, true);
            streamGeometryContext.ArcTo(point5, size, 0.0, isLargeArc, SweepDirection.Clockwise, true, true);
            streamGeometryContext.LineTo(point3, true, true);
            streamGeometryContext.ArcTo(point2, size2, 0.0, isLargeArc, SweepDirection.Counterclockwise, true, true);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Draws the pie piece
        /// </summary>
        private void DrawGeometry(StreamGeometryContext context)
        {
            Point innerArcStartPoint = ComputeCartesianCoordinate(this.RotationAngle, this.InnerRadius);

            innerArcStartPoint.Offset(this.CentreX, this.CentreY);

            Point innerArcEndPoint = ComputeCartesianCoordinate(this.RotationAngle + this.WedgeAngle, this.InnerRadius);

            innerArcEndPoint.Offset(this.CentreX, this.CentreY);

            Point outerArcStartPoint = ComputeCartesianCoordinate(this.RotationAngle, this.Radius);

            outerArcStartPoint.Offset(this.CentreX, this.CentreY);

            Point outerArcEndPoint = ComputeCartesianCoordinate(this.RotationAngle + this.WedgeAngle, this.Radius);

            outerArcEndPoint.Offset(this.CentreX, this.CentreY);

            bool largeArc = this.WedgeAngle > 180.0;

            var outerArcSize = new Size(this.Radius, this.Radius);
            var innerArcSize = new Size(this.InnerRadius, this.InnerRadius);

            context.BeginFigure(innerArcStartPoint, true, true);
            context.LineTo(outerArcStartPoint, true, true);
            context.ArcTo(outerArcEndPoint, outerArcSize, 0, largeArc, SweepDirection.Clockwise, true, true);
            context.LineTo(innerArcEndPoint, true, true);
            context.ArcTo(innerArcStartPoint, innerArcSize, 0, largeArc, SweepDirection.Counterclockwise, true, true);
        }
        private void DrawGeometry(StreamGeometryContext context)
        {
            bool large = Math.Abs(EndAngle - StartAngle) > 180.0;

            Point innerArcStartPoint  = ToPoint(Center, InnerRadius, StartAngle);
            Point innerArcMiddlePoint = ToPoint(Center, InnerRadius, (StartAngle + EndAngle) / 2);
            Point innerArcEndPoint    = ToPoint(Center, InnerRadius, EndAngle);

            Point outerArcStartPoint  = ToPoint(Center, OuterRadius, StartAngle);
            Point outerArcMiddlePoint = ToPoint(Center, OuterRadius, (StartAngle + EndAngle) / 2);
            Point outerArcEndPoint    = ToPoint(Center, OuterRadius, EndAngle);

            var outerArcSize = new Size(OuterRadius, OuterRadius);
            var innerArcSize = new Size(InnerRadius, InnerRadius);

            context.BeginFigure(innerArcStartPoint, true, true);
            context.LineTo(outerArcStartPoint, true, true);
            if (large)
            {
                context.ArcTo(outerArcMiddlePoint, outerArcSize, 0, false, SweepDirection.Clockwise, true, true);
            }
            context.ArcTo(outerArcEndPoint, outerArcSize, 0, false, SweepDirection.Clockwise, true, true);
            context.LineTo(innerArcEndPoint, true, true);
            if (large)
            {
                context.ArcTo(innerArcMiddlePoint, innerArcSize, 0, false, SweepDirection.Counterclockwise, true, true);
            }
            context.ArcTo(innerArcStartPoint, innerArcSize, 0, false, SweepDirection.Counterclockwise, true, true);
        }
        public override void Draw(StreamGeometryContext context, Connection connection)
        {
            if (connection.SourceConnectionPoint == null || connection.TargetConnectionPoint == null)
            {
                context.BeginFigure(connection.StartPoint, true, false);
                context.LineTo(connection.EndPoint, true, true);
            }
            else if (connection.Source == connection.Target)
            {
                Point startPoint = connection.SourceEndPoint.EndPoint;
                Point midPoint   = connection.SourceConnectionPoint.LineAwayFromThisTo(startPoint, 50);

                context.BeginFigure(startPoint, true, true);
                context.ArcTo(midPoint, new Size(50, 50), 180, false, SweepDirection.Clockwise, true, true);
                context.ArcTo(startPoint, new Size(50, 50), 180, false, SweepDirection.Clockwise, true, true);
            }
            else
            {
                Point startPoint = connection.SourceEndPoint.EndPoint;
                Point endPoint   = connection.TargetEndPoint.EndPoint;

                context.BeginFigure(startPoint, true, false);
                context.LineTo(endPoint, true, true);
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Draws the pie piece
        /// </summary>
        private void DrawGeometry(StreamGeometryContext context)
        {
            double centreX = Radius;
            double centreY = Radius;

            Point startPoint = new Point(centreX, centreY);

            Point innerArcStartPoint = Utils.ComputeCartesianCoordinate(RotationAngle, InnerRadius);

            innerArcStartPoint.Offset(centreX, centreY);

            Point innerArcEndPoint = Utils.ComputeCartesianCoordinate(RotationAngle + WedgeAngle, InnerRadius);

            innerArcEndPoint.Offset(centreX, centreY);

            Point outerArcStartPoint = Utils.ComputeCartesianCoordinate(RotationAngle, Radius);

            outerArcStartPoint.Offset(centreX, centreY);

            Point outerArcEndPoint = Utils.ComputeCartesianCoordinate(RotationAngle + WedgeAngle, Radius);

            outerArcEndPoint.Offset(centreX, centreY);

            bool largeArc = WedgeAngle > 180.0;

            Size outerArcSize = new Size(Radius, Radius);
            Size innerArcSize = new Size(InnerRadius, InnerRadius);

            context.BeginFigure(innerArcStartPoint, true, true);
            context.LineTo(outerArcStartPoint, true, true);
            context.ArcTo(outerArcEndPoint, outerArcSize, 0, largeArc, SweepDirection.Clockwise, true, true);
            context.LineTo(innerArcEndPoint, true, true);
            context.ArcTo(innerArcStartPoint, innerArcSize, 0, largeArc, SweepDirection.Counterclockwise, true, true);
        }
Exemplo n.º 9
0
        private void DrawGeometry(StreamGeometryContext context)
        {
            Point startPoint = new Point(CentreX, CentreY);
            //this.
            Point outerArcStartPoint = ComputeCartesianCoordinate(Rotation, Radius);

            outerArcStartPoint.Offset(CentreX, CentreY);

            Point outerArcEndPoint = ComputeCartesianCoordinate(180 /*Angle*/, Radius);

            outerArcEndPoint.Offset(CentreX, CentreY);

            //bool largeArc = Angle > 180.0;
            Size outerArcSize = new Size(Radius, Radius);

            Fill = (SolidColorBrush)(new BrushConverter().ConvertFrom("black"));//"#4386D8"
            context.BeginFigure(startPoint, true, true);
            context.LineTo(outerArcStartPoint, true, true);
            context.ArcTo(outerArcEndPoint, outerArcSize, 0, false, SweepDirection.Clockwise, true, true);

            Fill = (SolidColorBrush)(new BrushConverter().ConvertFrom("white"));//"#4386D8"
            context.ArcTo(outerArcStartPoint, outerArcSize, 0, false, SweepDirection.Clockwise, true, true);

            //outerArcStartPoint = outerArcEndPoint;
        }
Exemplo n.º 10
0
        private void Render(StreamGeometryContext context)
        {
            var bounds = Bounds;

            var  direction = Angle < 0 ? SweepDirection.Counterclockwise : SweepDirection.Clockwise;
            var  reverse   = Angle >= 0 ? SweepDirection.Counterclockwise : SweepDirection.Clockwise;
            bool isLarge   = Math.Abs(Angle) > Math.PI;

            var rx = bounds.Width / 2;
            var ry = bounds.Height / 2;

            var cx = rx + bounds.X;
            var cy = ry + bounds.Y;

            var x1 = cx + Math.Cos(Start) * rx;
            var y1 = cy + Math.Sin(Start) * ry;

            var x2 = cx + Math.Cos(Start + Angle) * rx;
            var y2 = cy + Math.Sin(Start + Angle) * ry;

            var ix1 = cx + Math.Cos(Start) * rx * InnerRatio;
            var iy1 = cy + Math.Sin(Start) * ry * InnerRatio;

            var ix2 = cx + Math.Cos(Start + Angle) * rx * InnerRatio;
            var iy2 = cy + Math.Sin(Start + Angle) * ry * InnerRatio;

            context.BeginFigure(new Point(x1, y1), true, true);

            context.ArcTo(new Point(x2, y2), new Size(rx, ry), 0, isLarge, direction, true, false);

            context.LineTo(new Point(ix2, iy2), false, false);

            context.ArcTo(new Point(ix1, iy1), new Size(InnerRatio * rx, InnerRatio * ry), 0, isLarge, reverse, true, false);
        }
Exemplo n.º 11
0
        private void method_18(StreamGeometryContext streamGeometryContext_0)
        {
            Point point  = new Point(this.method_10(), this.method_12());
            Point point2 = Utils.ComputeCartesianCoordinate(this.method_8(), this.method_4());

            point2.Offset(this.method_10(), this.method_12());
            Point point3 = Utils.ComputeCartesianCoordinate(this.method_8() + this.method_6(), this.method_4());

            point3.Offset(this.method_10(), this.method_12());
            Point point4 = Utils.ComputeCartesianCoordinate(this.method_8(), this.method_0());

            point4.Offset(this.method_10(), this.method_12());
            Point point5 = Utils.ComputeCartesianCoordinate(this.method_8() + this.method_6(), this.method_0());

            point5.Offset(this.method_10(), this.method_12());
            bool isLargeArc = this.method_6() > 180.0;

            if (this.method_2() > 0.0)
            {
                Point point6 = Utils.ComputeCartesianCoordinate(this.method_8() + this.method_6() / 2.0, this.method_2());
                point2.Offset(point6.X, point6.Y);
                point3.Offset(point6.X, point6.Y);
                point4.Offset(point6.X, point6.Y);
                point5.Offset(point6.X, point6.Y);
            }
            Size size  = new Size(this.method_0(), this.method_0());
            Size size2 = new Size(this.method_4(), this.method_4());

            streamGeometryContext_0.BeginFigure(point2, true, true);
            streamGeometryContext_0.LineTo(point4, true, true);
            streamGeometryContext_0.ArcTo(point5, size, 0.0, isLargeArc, SweepDirection.Clockwise, true, true);
            streamGeometryContext_0.LineTo(point3, true, true);
            streamGeometryContext_0.ArcTo(point2, size2, 0.0, isLargeArc, SweepDirection.Counterclockwise, true, true);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Draws the pie piece
        /// </summary>
        private void DrawGeometry(StreamGeometryContext context)
        {
            double originalWedgeAngle = this.WedgeAngle;
            double modifiedWedgeAngle = originalWedgeAngle;

            double modWedgeAngle = originalWedgeAngle % 360.0D;

            if (modifiedWedgeAngle > 360.0D)
            {
                modifiedWedgeAngle = modWedgeAngle;
            }

            bool isWedgeAngleNotZero          = originalWedgeAngle != 0.0D;
            bool isWedgeAngleNotMultipleOf360 = modWedgeAngle != 0.0D;


            // for some reason, the arcs collapsed when 360 degrees.
            if (isWedgeAngleNotZero && !isWedgeAngleNotMultipleOf360)
            {
                modifiedWedgeAngle = 359.9D;
            }

            Point startPoint = new Point(CentreX, CentreY);

            Point innerArcStartPoint = Utils.ComputeCartesianCoordinate(RotationAngle, InnerRadius);

            innerArcStartPoint.Offset(CentreX, CentreY);

            Point innerArcEndPoint = Utils.ComputeCartesianCoordinate(RotationAngle + modifiedWedgeAngle, InnerRadius);

            innerArcEndPoint.Offset(CentreX, CentreY);

            Point outerArcStartPoint = Utils.ComputeCartesianCoordinate(RotationAngle, Radius);

            outerArcStartPoint.Offset(CentreX, CentreY);

            Point outerArcEndPoint = Utils.ComputeCartesianCoordinate(RotationAngle + modifiedWedgeAngle, Radius);

            outerArcEndPoint.Offset(CentreX, CentreY);

            bool largeArc = modifiedWedgeAngle > 180.0;

            if (PushOut > 0)
            {
                Point offset = Utils.ComputeCartesianCoordinate(RotationAngle + modifiedWedgeAngle / 2, PushOut);
                innerArcStartPoint.Offset(offset.X, offset.Y);
                innerArcEndPoint.Offset(offset.X, offset.Y);
                outerArcStartPoint.Offset(offset.X, offset.Y);
                outerArcEndPoint.Offset(offset.X, offset.Y);
            }

            Size outerArcSize = new Size(Radius, Radius);
            Size innerArcSize = new Size(InnerRadius, InnerRadius);

            context.BeginFigure(innerArcStartPoint, true, true);
            context.LineTo(outerArcStartPoint, true, true);
            context.ArcTo(outerArcEndPoint, outerArcSize, 0, largeArc, SweepDirection.Clockwise, true, true);
            context.LineTo(innerArcEndPoint, true, true);
            context.ArcTo(innerArcStartPoint, innerArcSize, 0, largeArc, SweepDirection.Counterclockwise, true, true);
        }
Exemplo n.º 13
0
        private Geometry GenerateSpeechBubble()
        {
            StreamGeometry geom = new StreamGeometry();

            using (StreamGeometryContext gc = geom.Open())
            {
                Size  cornerSize = new Size(10, 10);
                Point start      = new Point(20, 0);
                gc.BeginFigure(start, true, true);
                gc.LineTo(new Point(440, 0), true, true);
                gc.ArcTo(new Point(450, 10), cornerSize, 0.0, false, SweepDirection.Clockwise, true, true);
                gc.LineTo(new Point(450, 70), true, true);
                gc.ArcTo(new Point(440, 80), cornerSize, 0.0, false, SweepDirection.Clockwise, true, true);
                gc.LineTo(new Point(20, 80), true, true);
                gc.ArcTo(new Point(10, 70), cornerSize, 0.0, false, SweepDirection.Clockwise, true, true);
                gc.LineTo(new Point(10, 55), true, true);
                gc.LineTo(new Point(-10, 40), true, true);
                gc.LineTo(new Point(10, 25), true, true);

                gc.LineTo(new Point(10, 10), true, true);
                gc.ArcTo(start, cornerSize, 0.0, false, SweepDirection.Clockwise, true, true);
            }

            return(geom);
        }
        internal override Geometry DefineSegment()
        {
            double radius = BufferRadius;

            if (displayArc.NodeCenters.Count <= 1)
            {
                if (displayArc.NodeCenters.Count == 1)
                {
                    displayArc.Center = new Point(displayArc.NodeCenters[0].X, displayArc.NodeCenters[0].Y);
                    radius           += Math.Max(((hyperarc)displayArc.icon.GraphElement).nodes[0].DisplayShape.Width,
                                                 ((hyperarc)displayArc.icon.GraphElement).nodes[0].DisplayShape.Height) / 2;
                }
                return(new EllipseGeometry
                {
                    Center = displayArc.Center,
                    RadiusX = radius + BufferRadius,
                    RadiusY = radius + BufferRadius
                });
            }
            var rawPoints = MIConvexHull.Find(displayArc.NodeCenters);

            displayArc.Center = new Point(displayArc.NodeCenters.Average(n => n.X),
                                          displayArc.NodeCenters.Average(n => n.Y));

            var geometry = new StreamGeometry();

            if (BufferRadius <= 0)
            {
                using (var ctx = geometry.Open())
                {
                    ctx.BeginFigure(rawPoints[0], true, true);
                    for (int i = 1; i < rawPoints.Count; i++)
                    {
                        ctx.LineTo(rawPoints[i], true, true);
                    }
                }
            }
            else
            {
                var size = new Size(BufferRadius, BufferRadius);
                using (StreamGeometryContext ctx = geometry.Open())
                {
                    ctx.BeginFigure(findNextPoint(rawPoints[rawPoints.Count - 1], rawPoints[0]), true, true);
                    for (int i = 0; i < rawPoints.Count - 1; i++)
                    {
                        ctx.ArcTo(findThisPoint(rawPoints[i], rawPoints[i + 1]), size, 0.0, false,
                                  SweepDirection.Clockwise,
                                  true, true);
                        ctx.LineTo(findNextPoint(rawPoints[i], rawPoints[i + 1]), true, true);
                    }
                    ctx.ArcTo(findThisPoint(rawPoints[rawPoints.Count - 1], rawPoints[0]), size, 0.0, false,
                              SweepDirection.Clockwise,
                              true, true);
                }
            }
            return(geometry);
        }
Exemplo n.º 15
0
        // a simple circle
        protected override void DrawToStream(StreamGeometryContext stream, double radius, Point offset)
        {
            Point startPoint = new Point(offset.X, offset.Y - radius);
            Point midPoint   = new Point(offset.X, offset.Y + radius);
            Size  size       = new Size(radius, radius);

            stream.BeginFigure(startPoint, true, false);
            stream.ArcTo(midPoint, size, 0.0, true, SweepDirection.Clockwise, true, false);
            stream.ArcTo(startPoint, size, 0.0, true, SweepDirection.Clockwise, true, false);
        }
Exemplo n.º 16
0
        internal static void DrawEllipseGeometry(this StreamGeometryContext ctx, double X, double Y, double Width, double Height)
        {
            X      = X * 2;
            Y      = Y * 2;
            Height = Height * 2;
            Width  = Width * 2;

            ctx.BeginFigure(new Point(X, Y + Height / 2), true, true);
            ctx.ArcTo(new Point(X + Width, Y + Height / 2), new Size(Width / 2, Height / 2), 90, false, SweepDirection.Clockwise, true, true);
            ctx.ArcTo(new Point(X, Y + Height / 2), new Size(Width / 2, Height / 2), 90, false, SweepDirection.Clockwise, true, true);
        }
Exemplo n.º 17
0
        private static void CreateGeometry(StreamGeometryContext context, Rect boundRect,
                                           BorderGeometryKeypoints keypoints)
        {
            context.BeginFigure(keypoints.TopLeft, true);

            // Top
            context.LineTo(keypoints.TopRight);

            // TopRight corner
            var radiusX = boundRect.TopRight.X - keypoints.TopRight.X;
            var radiusY = keypoints.RightTop.Y - boundRect.TopRight.Y;

            if (radiusX != 0 || radiusY != 0)
            {
                context.ArcTo(keypoints.RightTop, new Size(radiusX, radiusY), 0, false, SweepDirection.Clockwise);
            }

            // Right
            context.LineTo(keypoints.RightBottom);

            // BottomRight corner
            radiusX = boundRect.BottomRight.X - keypoints.BottomRight.X;
            radiusY = boundRect.BottomRight.Y - keypoints.RightBottom.Y;
            if (radiusX != 0 || radiusY != 0)
            {
                context.ArcTo(keypoints.BottomRight, new Size(radiusX, radiusY), 0, false, SweepDirection.Clockwise);
            }

            // Bottom
            context.LineTo(keypoints.BottomLeft);

            // BottomLeft corner
            radiusX = keypoints.BottomLeft.X - boundRect.BottomLeft.X;
            radiusY = boundRect.BottomLeft.Y - keypoints.LeftBottom.Y;
            if (radiusX != 0 || radiusY != 0)
            {
                context.ArcTo(keypoints.LeftBottom, new Size(radiusX, radiusY), 0, false, SweepDirection.Clockwise);
            }

            // Left
            context.LineTo(keypoints.LeftTop);

            // TopLeft corner
            radiusX = keypoints.TopLeft.X - boundRect.TopLeft.X;
            radiusY = keypoints.LeftTop.Y - boundRect.TopLeft.Y;

            if (radiusX != 0 || radiusY != 0)
            {
                context.ArcTo(keypoints.TopLeft, new Size(radiusX, radiusY), 0, false, SweepDirection.Clockwise);
            }

            context.EndFigure(true);
        }
Exemplo n.º 18
0
        private void InternalDrawArrowGeometry(StreamGeometryContext context)
        {
            //因为线宽的不同会导致区域显示不全,因此在计算时需考虑线宽
            double w = this.Width - this.StrokeThickness * 2;
            double h = this.Height - this.StrokeThickness * 2;

            if (w > 0 && h > 0)
            {
                Point pt = new Point(w / 2 + this.StrokeThickness, this.StrokeThickness);
                context.BeginFigure(pt, true, true);
                context.ArcTo(new Point(w / 2 + this.StrokeThickness, h + this.StrokeThickness), new Size(w / 2, h / 2), 0, true, SweepDirection.Counterclockwise, true, true);
                context.ArcTo(pt, new Size(w / 2, h / 2), 0, true, SweepDirection.Counterclockwise, true, true);
            }
        }
Exemplo n.º 19
0
        private Path CreateMenuItemTip(int index)
        {
            // menu item info
            double MenuItemStartAngle = MenuItemAngle * index;
            double MenuItemRotation   = MenuItemStartAngle + MenuItemAngle / 2;
            double OuterRingRadius    = MenuSize / 2;
            double InnerRingRadius    = (MenuSize - MenuTipSize) / 2;
            double OuterAngleDiff     = (180 * (MenuItemPadding / OuterRingRadius)) / Math.PI;
            double InnerAngleDiff     = (180 * (MenuItemPadding / InnerRingRadius)) / Math.PI;
            double OuterRingAngle     = MenuItemStartAngle + OuterAngleDiff;
            double OuterAngleDelta    = MenuItemAngle - (OuterAngleDiff * 2);
            double InnerRingAngle     = MenuItemStartAngle + InnerAngleDiff;
            double InnerAngleDelta    = MenuItemAngle - (InnerAngleDiff * 2);

            Point OuterArcStart = ComputeCartesianCoordinate(MenuCenter, OuterRingAngle, OuterRingRadius + MenuCenterSection);
            Point OuterArcEnd   = ComputeCartesianCoordinate(MenuCenter, OuterRingAngle + OuterAngleDelta, OuterRingRadius + MenuCenterSection);
            Point InnerArcStart = ComputeCartesianCoordinate(MenuCenter, InnerRingAngle, InnerRingRadius + MenuCenterSection);
            Point InnerArcEnd   = ComputeCartesianCoordinate(MenuCenter, InnerRingAngle + InnerAngleDelta, InnerRingRadius + MenuCenterSection);

            bool LargeOuterArc = OuterAngleDelta > 180.0;
            bool LargeInnerArc = InnerAngleDelta > 180.0;

            // Create path
            Path TempPath = new Path();

            TempPath.Fill            = MenuOuterColor;
            TempPath.Opacity         = 0.7;
            TempPath.StrokeThickness = 0;

            // create streamgeometry for path
            StreamGeometry geom = new StreamGeometry();

            geom.FillRule = FillRule.EvenOdd;
            using (StreamGeometryContext ctx = geom.Open())
            {
                if (MenuItemCount > 1)
                {
                    ctx.BeginFigure(InnerArcStart, true, true);
                    ctx.LineTo(OuterArcStart, true, true);
                    ctx.ArcTo(OuterArcEnd, new Size(OuterRingRadius, OuterRingRadius), 0, LargeOuterArc, SweepDirection.Clockwise, true, true);
                    ctx.LineTo(InnerArcEnd, true, true);
                    ctx.ArcTo(InnerArcStart, new Size(InnerRingRadius, InnerRingRadius), 0, LargeInnerArc, SweepDirection.Counterclockwise, true, true);
                }
            }

            geom.Freeze();
            TempPath.Data = geom;

            return(TempPath);
        }
Exemplo n.º 20
0
        private void InternalDrawArrowGeometry(StreamGeometryContext context)
        {
            double radiu = 1.5;

            this.Height = radiu * 2 + 2;
            this.Width  = radiu * 2 + 2;
            Point pt1  = new Point(0 + 1, radiu + 1);
            Point pt2  = new Point(2 * radiu + 1, radiu + 1);
            Size  size = new Size(radiu, radiu);

            context.BeginFigure(pt1, true, true);

            context.ArcTo(pt2, size, 180, false, SweepDirection.Clockwise, true, true);
            context.ArcTo(pt1, size, 180, false, SweepDirection.Clockwise, true, true);
        }
Exemplo n.º 21
0
        /// <summary>
        /// Draws the pie piece
        /// </summary>
        private void DrawGeometry(StreamGeometryContext context)
        {
            if (WedgeAngle == 0)
            {
                return;
            }
            if (WedgeAngle == 360)
            {
                context.DrawGeometry(new EllipseGeometry(new Point(CentreX, CentreY), Radius, Radius));
                return;
            }

            Point innerArcStartPoint = ComputeCartesianCoordinate(RotationAngle, InnerRadius);

            innerArcStartPoint.Offset(CentreX, CentreY);

            Point innerArcEndPoint = ComputeCartesianCoordinate(RotationAngle + WedgeAngle, InnerRadius);

            innerArcEndPoint.Offset(CentreX, CentreY);

            Point outerArcStartPoint = ComputeCartesianCoordinate(RotationAngle, Radius);

            outerArcStartPoint.Offset(CentreX, CentreY);

            Point outerArcEndPoint = ComputeCartesianCoordinate(RotationAngle + WedgeAngle, Radius);

            outerArcEndPoint.Offset(CentreX, CentreY);

            bool largeArc = WedgeAngle > 180.0;

            if (PushOut > 0)
            {
                Point offset = ComputeCartesianCoordinate(RotationAngle + WedgeAngle / 2, PushOut);
                innerArcStartPoint.Offset(offset.X, offset.Y);
                innerArcEndPoint.Offset(offset.X, offset.Y);
                outerArcStartPoint.Offset(offset.X, offset.Y);
                outerArcEndPoint.Offset(offset.X, offset.Y);
            }

            Size outerArcSize = new Size(Radius, Radius);
            Size innerArcSize = new Size(InnerRadius, InnerRadius);

            context.BeginFigure(innerArcStartPoint, true, true);
            context.LineTo(outerArcStartPoint, true, true);
            context.ArcTo(outerArcEndPoint, outerArcSize, 0, largeArc, SweepDirection.Clockwise, true, true);
            context.LineTo(innerArcEndPoint, true, true);
            context.ArcTo(innerArcStartPoint, innerArcSize, 0, largeArc, SweepDirection.Counterclockwise, true, true);
        }
Exemplo n.º 22
0
        private static GeometryDrawing CreateArcDrawing(Point point, int radius, int degree_start, int degree_sweep)
        {
            var startRadians = degree_start * Math.PI / 180.0;
            var sweepRadians = degree_sweep * Math.PI / 180.0;

            var xs = point.X + (Math.Cos(startRadians) * radius);
            var ys = point.Y + (Math.Sin(startRadians) * radius);

            var xe = point.X + (Math.Cos(startRadians + sweepRadians) * radius);
            var ye = point.Y + (Math.Sin(startRadians + sweepRadians) * radius);


            StreamGeometry streamGeometry = new StreamGeometry();

            using (StreamGeometryContext ctx = streamGeometry.Open())
            {
                bool           isLargeArc     = Math.Abs(degree_sweep) > 180;
                SweepDirection sweepDirection = SweepDirection.Clockwise;

                ctx.BeginFigure(new Point(xs, ys), false, false);
                ctx.ArcTo(new Point(xe, ye), new Size(radius, radius),
                          0, isLargeArc, sweepDirection, true, false);
            }

            GeometryDrawing drawing = new GeometryDrawing();

            drawing.Geometry = streamGeometry;
            return(drawing);
        }
Exemplo n.º 23
0
        private Geometry CreateGeometry(Point p, double radius, double startDegrees, double deltaDegrees)
        {
            // Create a StreamGeometry for describing the shape
            StreamGeometry geometry = new StreamGeometry();

            using (StreamGeometryContext context = geometry.Open())
            {
                var rad1 = Deg2Rad(startDegrees);
                var drad = Deg2Rad(deltaDegrees);
                var rad2 = rad1 + drad;
                var p1   = new Point((Math.Cos(rad1) + 1) * radius + p.X, -(Math.Sin(rad1) - 1) * radius + p.Y);
                var p2   = new Point((Math.Cos(rad2) + 1) * radius + p.X, -(Math.Sin(rad2) - 1) * radius + p.Y);

                context.BeginFigure(p, true, true);
                if (deltaDegrees >= 360)
                {
                    context.DrawGeometry(new EllipseGeometry(new Rect(p.X - radius, p.Y - radius, radius * 2, radius * 2)));
                }
                else if (deltaDegrees >= 0)
                {
                    context.LineTo(p1, true, true);
                    context.ArcTo(p2, new Size(radius, radius), drad, deltaDegrees > 180, SweepDirection.Counterclockwise, true, true);
                    context.Close();
                }
            }

            // Freeze the geometry for performance benefits
            geometry.Freeze();

            return(geometry);
        }
Exemplo n.º 24
0
        private const double ArrowAngle = 30.0; //degrees

        private static void CreateWideEdgeArrow(StreamGeometryContext context, GeometryPoint start, GeometryPoint end, double pathStrokeThickness)

        {
            GeometryPoint dir = end - start;
            GeometryPoint h   = dir;
            double        dl  = dir.Length;

            if (dl < 0.001)
            {
                return;
            }
            dir /= dl;

            var           s  = new GeometryPoint(-dir.Y, dir.X);
            double        w  = 0.5 * pathStrokeThickness;
            GeometryPoint s0 = w * s;

            s *= h.Length * HalfArrowAngleTan;
            s += s0;

            double rad = w / HalfArrowAngleCos;

            context.BeginFigure((start + s).ToWpf(), true, true);
            context.LineTo((start - s).ToWpf(), true, false);
            context.LineTo((end - s0).ToWpf(), true, false);
            context.ArcTo((end + s0).ToWpf(), new Size(rad, rad), Math.PI - ArrowAngle, false, SweepDirection.Clockwise, true, false);
        }
Exemplo n.º 25
0
        private static void DeserializeArcTo(BinaryReader br, byte firstByte, StreamGeometryContext sc)
        {
            Point          point;
            Size           size = new Size();
            double         rotationAngle;
            bool           isStroked;
            bool           isSmoothJoin;
            bool           isLargeArc;
            SweepDirection sweepDirection;

            DeserializePointAndTwoBools(br, firstByte, out point, out isStroked, out isSmoothJoin);

            // Read the packed byte for isLargeArd & sweepDirection.

            //
            // Pack isLargeArc & sweepDirection into a signle byte.
            //
            byte packedByte = br.ReadByte();

            isLargeArc = ((packedByte & LowNibble) != 0);

            sweepDirection = BoolToSweep(((packedByte & HighNibble) != 0));


            size.Width    = XamlSerializationHelper.ReadDouble(br);
            size.Height   = XamlSerializationHelper.ReadDouble(br);
            rotationAngle = XamlSerializationHelper.ReadDouble(br);

            sc.ArcTo(point, size, rotationAngle, isLargeArc, sweepDirection, isStroked, isSmoothJoin);
        }
        private Geometry GetArcGeometry()
        {
            Point startPoint = PointAtAngle(Math.Min(StartAngle, EndAngle), Direction);
            Point endPoint   = PointAtAngle(Math.Max(StartAngle, EndAngle), Direction);

            Size arcSize = new Size(Math.Max(0, (RenderSize.Width - StrokeThickness) / 2),
                                    Math.Max(0, (RenderSize.Height - StrokeThickness) / 2));
            bool isLargeArc = Math.Abs(EndAngle - StartAngle) > 180;

            StreamGeometry geom = new StreamGeometry();// BuildRegularPolygon(new Point(0, 9), 2, 4, 30);

            using (StreamGeometryContext context = geom.Open())
            {
                context.BeginFigure(startPoint, false, false);
                context.ArcTo(endPoint, arcSize, 0, isLargeArc, Direction, true, false);

                var c = new EllipseGeometry(startPoint, 0, 0);

                var c2 = new EllipseGeometry(endPoint, 0, 0);

                GeometryGroup combined = new GeometryGroup();
                combined.Children.Add(c);
                combined.Children.Add(c2);
                combined.Children.Add(geom);

                combined.Transform = new TranslateTransform(StrokeThickness / 2, StrokeThickness / 2);

                return(combined);
            }
        }
Exemplo n.º 27
0
        private Geometry GetArcGeometry()
        {
            StreamGeometry geom = new StreamGeometry();

            try
            {
                Point startPoint = PointAtAngle(Math.Min(StartAngle, EndAngle), Direction);
                Point endPoint   = PointAtAngle(Math.Max(StartAngle, EndAngle), Direction);
                Size  arcSize    = new Size(Math.Max(0, (RenderSize.Width - StrokeThickness) / 2), Math.Max(0, (RenderSize.Height - StrokeThickness) / 2));
                bool  isLargeArc = Math.Abs(EndAngle - StartAngle) > 180;

                using (StreamGeometryContext context = geom.Open())
                {
                    context.BeginFigure(startPoint, false, false);
                    context.ArcTo(endPoint, arcSize, 0, isLargeArc, Direction, true, false);
                }

                geom.Transform = new TranslateTransform(StrokeThickness / 2, StrokeThickness / 2);
            }
            catch (Exception ex)
            {
                StaticCode.Logger?.Here().Error(ex.Message);
            }

            return(geom);
        }
Exemplo n.º 28
0
        public SectorVisual()
        {
            StreamGeometry geometry = new StreamGeometry();

            using (StreamGeometryContext c = geometry.Open())
            {
                c.BeginFigure(new Point(200, 200),
                              true /* isFilled */, true /* isClosed */);

                // First line
                c.LineTo(new Point(175, 50), true /* isFilled */, true /* isClosed */);

                // Bottom arc
                c.ArcTo(new Point(50, 150), new Size(1, 1), 0, true,
                        SweepDirection.Counterclockwise, true /* isFilled */, true /* isClosed */);

                // Second line
                c.LineTo(new Point(200, 200),
                         true /* isFilled */, true /* isClosed */);
            }

            // Draw the geometry
            using (DrawingContext context = RenderOpen())
            {
                Pen pen = new Pen(Brushes.Black, 1);
                context.DrawGeometry(Brushes.CornflowerBlue, pen, geometry);
            }
        }
Exemplo n.º 29
0
        /// <summary>
        /// Create an Arc geometry drawing of an ellipse or circle
        /// </summary>
        /// <param name="rect">Box to hold the whole ellipse described by the arc</param>
        /// <param name="startDegrees">Start angle of the arc degrees within the ellipse. 0 degrees is a line to the right.</param>
        /// <param name="sweepDegrees">Sweep angle, -ve = Counterclockwise, +ve = Clockwise</param>
        /// <returns>GeometryDrawing object</returns>
        private Geometry CreateArcGeometry(Rect rect, double startRadians, double sweepRadians)
        {
            // x and y radius
            double dx = rect.Width / 2;
            double dy = rect.Height / 2;

            // determine the start point
            double xs = rect.X + dx + (Math.Cos(startRadians) * dx);
            double ys = rect.Y + dy + (Math.Sin(startRadians) * dy);

            // determine the end point
            double xe = rect.X + dx + (Math.Cos(startRadians + sweepRadians) * dx);
            double ye = rect.Y + dy + (Math.Sin(startRadians + sweepRadians) * dy);

            // draw the arc into a stream geometry
            StreamGeometry streamGeom = new StreamGeometry();

            using (StreamGeometryContext ctx = streamGeom.Open())
            {
                bool           isLargeArc     = Math.Abs(sweepRadians) > Math.PI;
                SweepDirection sweepDirection = sweepRadians < 0 ? SweepDirection.Counterclockwise : SweepDirection.Clockwise;

                ctx.BeginFigure(new Point(dx + rect.Left, dy + rect.Top), true, true);
                ctx.LineTo(new Point(xs, ys), false, true);
                ctx.ArcTo(new Point(xe, ye), new Size(dx, dy), 0, isLargeArc, sweepDirection, true, true);
                ctx.LineTo(new Point(dx + rect.Left, dy + rect.Top), false, true);
            }

            return(streamGeom);
        }
Exemplo n.º 30
0
    private void DrawSemiCircle(StreamGeometryContext context)
    {
        double tOff    = StrokeThickness / 2.0;                 // an offset to account for stroke thickness
        Point  startPt = new Point(tOff, tOff);                 // upper left corner

        if (Alignment == SemiCircleAlignment.Bottom || Alignment == SemiCircleAlignment.Right)
        {
            startPt = new Point(ActualWidth - tOff, ActualHeight - tOff);            // or lower right corner
        }
        Point endPt = new Point(ActualWidth - tOff, tOff);                           // upper right corner

        if (Alignment == SemiCircleAlignment.Left || Alignment == SemiCircleAlignment.Bottom)
        {
            endPt = new Point(tOff, ActualHeight - tOff);                             // or lower left corner
        }
        Size s = new Size(Math.Max(0.0, (ActualWidth / 2) - tOff),
                          Math.Max(0, ActualHeight - StrokeThickness)); // half width is radius
        SweepDirection sweep = SweepDirection.Counterclockwise;

        if (Alignment == SemiCircleAlignment.Left || Alignment == SemiCircleAlignment.Right)
        {
            s = new Size(Math.Max(0, ActualWidth - StrokeThickness),
                         Math.Max(0.0, (ActualHeight / 2) - tOff)); // or half height is radius
            sweep = SweepDirection.Clockwise;
        }

        context.BeginFigure(startPt, true, true);
        context.ArcTo(endPt, s, 0, false, sweep, true, false);
    }
Exemplo n.º 31
0
 protected internal override void ApplyTo(StreamGeometryContext ctx)
 {
     ctx.ArcTo(Point, Size, RotationAngle, IsLargeArc, SweepDirection);
 }
Exemplo n.º 32
0
        private static void DeserializeArcTo(BinaryReader br, byte firstByte, StreamGeometryContext sc)
        {
            Point point;
            Size size = new Size();
            double rotationAngle;
            bool isStroked;
            bool isSmoothJoin;
            bool isLargeArc;
            SweepDirection sweepDirection;

            DeserializePointAndTwoBools(br, firstByte, out point, out isStroked, out isSmoothJoin);

            // Read the packed byte for isLargeArd & sweepDirection.

            //
            // Pack isLargeArc & sweepDirection into a signle byte.
            //
            byte packedByte = br.ReadByte();

            isLargeArc = ((packedByte & LowNibble) != 0);

            sweepDirection = BoolToSweep(((packedByte & HighNibble) != 0));


            size.Width = XamlSerializationHelper.ReadDouble(br);
            size.Height = XamlSerializationHelper.ReadDouble(br);
            rotationAngle = XamlSerializationHelper.ReadDouble(br);

            sc.ArcTo(point, size, rotationAngle, isLargeArc, sweepDirection, isStroked, isSmoothJoin);
        }