Exemplo n.º 1
0
        Geometry GetTrapezoidGeometry(Size size, double borderThickness)
        {
            bool hasBorder = borderThickness != 0;
            Rect rect;

            if (hasBorder)
            {
                double margin = borderThickness / 2;
                if (IsBottom)
                {
                    rect = new Rect(margin, 0, size.Width - borderThickness, size.Height - margin);
                }
                else
                {
                    rect = new Rect(margin, margin, size.Width - borderThickness, size.Height - margin);
                }
            }
            else
            {
                rect = new Rect(size);
            }

            StreamGeometry geometry = new StreamGeometry();

            using (StreamGeometryContext context = geometry.Open())
            {
                Points points = new Points(rect, CornerRadius, LeftAngle, RightAngle, IsBottom);
                if (IsBottom)
                {
                    context.BeginFigure(points.Pt0, true, false);
                    context.ArcTo(points.Pt1, new Size(CornerRadius.TopLeft, CornerRadius.TopLeft), 0, false, SweepDirection.Clockwise, hasBorder, false);
                    context.LineTo(points.Pt2, hasBorder, false);
                    context.ArcTo(points.Pt3, new Size(CornerRadius.BottomLeft, CornerRadius.BottomLeft), 0, false, SweepDirection.Counterclockwise, hasBorder, false);
                    context.LineTo(points.Pt4, hasBorder, false);
                    context.ArcTo(points.Pt5, new Size(CornerRadius.BottomRight, CornerRadius.BottomRight), 0, false, SweepDirection.Counterclockwise, hasBorder, false);
                    context.LineTo(points.Pt6, hasBorder, false);
                    context.ArcTo(points.Pt7, new Size(CornerRadius.TopRight, CornerRadius.TopRight), 0, false, SweepDirection.Clockwise, hasBorder, false);
                    context.LineTo(points.Pt0, false, false);
                }
                else
                {
                    context.BeginFigure(points.Pt0, true, false);
                    context.ArcTo(points.Pt1, new Size(CornerRadius.BottomLeft, CornerRadius.BottomLeft), 0, false, SweepDirection.Counterclockwise, hasBorder, false);
                    context.LineTo(points.Pt2, hasBorder, false);
                    context.ArcTo(points.Pt3, new Size(CornerRadius.TopLeft, CornerRadius.TopLeft), 0, false, SweepDirection.Clockwise, hasBorder, false);
                    context.LineTo(points.Pt4, hasBorder, false);
                    context.ArcTo(points.Pt5, new Size(CornerRadius.TopRight, CornerRadius.TopRight), 0, false, SweepDirection.Clockwise, hasBorder, false);
                    context.LineTo(points.Pt6, hasBorder, false);
                    context.ArcTo(points.Pt7, new Size(CornerRadius.BottomRight, CornerRadius.BottomRight), 0, false, SweepDirection.Counterclockwise, hasBorder, false);
                    context.LineTo(points.Pt0, false, false);
                }
            }

            geometry.Freeze();
            return(geometry);
        }
Exemplo n.º 2
0
        public StreamGeometryPolyQuadraticBezierToExample()
        {
            // Create a path to draw a geometry with.
            Path myPath = new Path();

            myPath.Stroke          = Brushes.Black;
            myPath.StrokeThickness = 1;

            // Create a StreamGeometry to use to specify myPath.
            StreamGeometry geometry = new StreamGeometry();

            geometry.FillRule = FillRule.EvenOdd;

            // Open a StreamGeometryContext that can be used to describe this StreamGeometry object's contents.
            using (StreamGeometryContext ctx = geometry.Open())
            {
                // Set the begin point of the shape.
                ctx.BeginFigure(new Point(10, 100), true /* is filled */, false /* is closed */);

                // Create a collection of Point structures that will be used with the PolyQuadraticBezierTo
                // Method to create two quadratic Bezier curves.
                List <Point> pointList = new List <Point>();

                // First quadratic Bezier curve is specified with these two points.

                // Control point for first quadratic Bezier curve.
                pointList.Add(new Point(100, 0));

                // End point for first quadratic Bezier curve.
                pointList.Add(new Point(200, 200));

                // Second quadratic Bezier curve is specified with these two points.

                // Control point for second quadratic Bezier curve.
                pointList.Add(new Point(300, 300));

                // End point for second quadratic Bezier curve.
                pointList.Add(new Point(400, 100));

                // Create a Bezier curve using the collection of Point Structures.
                ctx.PolyQuadraticBezierTo(pointList, true /* is stroked */, false /* is smooth join */);
            }

            // Freeze the geometry (make it unmodifiable)
            // for additional performance benefits.
            geometry.Freeze();

            // specify the shape (quadratic Benzier curve) of the path using the StreamGeometry.
            myPath.Data = geometry;

            // Add path shape to the UI.
            StackPanel mainPanel = new StackPanel();

            mainPanel.Children.Add(myPath);
            this.Content = mainPanel;
        }
Exemplo n.º 3
0
        public static System.Windows.Media.Geometry GetTransformedRectangleGeometry(Rect rect, Matrix matrix, double thickness)
        {
            if (rect.IsEmpty)
            {
                return((System.Windows.Media.Geometry)null);
            }
            Vector vector1 = new Vector(1.0, 0.0) * matrix;
            Vector vector2 = new Vector(0.0, 1.0) * matrix;
            Vector v1      = new Vector(vector2.Y, -vector2.X);
            Vector v2      = new Vector(vector1.Y, -vector1.X);

            if (v1 * vector1 < 0.0)
            {
                v1 *= -1.0;
            }
            if (v2 * vector2 < 0.0)
            {
                v2 *= -1.0;
            }
            double length1 = v1.Length;

            if (length1 > 0.0)
            {
                v1 /= length1;
            }
            double length2 = v2.Length;

            if (length2 > 0.0)
            {
                v2 /= length2;
            }
            Vector                vector3               = (Vector)(rect.TopLeft * matrix);
            Vector                vector4               = (Vector)(rect.BottomRight * matrix);
            double                num                   = thickness / 2.0;
            double                c1_1                  = v1 * vector3 - num;
            double                c2_1                  = v2 * vector3 - num;
            double                c1_2                  = v1 * vector4 + num;
            double                c2_2                  = v2 * vector4 + num;
            Point                 intersection1         = Adorner.GetIntersection(v1, c1_1, v2, c2_1);
            Point                 intersection2         = Adorner.GetIntersection(v1, c1_2, v2, c2_1);
            Point                 intersection3         = Adorner.GetIntersection(v1, c1_1, v2, c2_2);
            Point                 intersection4         = Adorner.GetIntersection(v1, c1_2, v2, c2_2);
            StreamGeometry        streamGeometry        = new StreamGeometry();
            StreamGeometryContext streamGeometryContext = streamGeometry.Open();

            streamGeometryContext.BeginFigure(intersection1, true, true);
            streamGeometryContext.PolyLineTo((IList <Point>) new Point[3]
            {
                intersection2,
                intersection4,
                intersection3
            }, 1 != 0, 0 != 0);
            streamGeometryContext.Close();
            streamGeometry.Freeze();
            return((System.Windows.Media.Geometry)streamGeometry);
        }
Exemplo n.º 4
0
        internal StreamGeometry Close()
        {
            if (m_context != null)
            {
                m_context.Close();
                m_geometry.Freeze();
            }

            return(m_geometry);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Draws the frequency.
        /// </summary>
        /// <param name="event_">The event.</param>
        /// <exception cref="System.ArgumentException">The Amplitudes cannot be null and should include more than 1 frequencies</exception>
        public void DrawFrequency(EvaluationEvent event_)
        {
            if (!event_.HasFrequencies || event_.FrequencyAmplitudes.Length < 2)
            {
                throw new ArgumentException("The Amplitudes cannot be null and should include more than 1 frequencies");
            }
            this._children.Clear();
            double x0 = 0, x1 = Math.PI, y0 = 0, y1 = double.NegativeInfinity;

            for (int i = 0; i < event_.FrequencyAmplitudes.Length; i++)
            {
                if (event_.FrequencyAmplitudes[i] > y1)
                {
                    y1 = event_.FrequencyAmplitudes[i];
                }
            }
            DataStatVisualHost parent = (DataStatVisualHost)((Grid)this.Parent).Parent;
            double             h      = parent.Width - 10;
            double             yScale = -this.RenderSize.Height / (y1 - y0);
            double             xScale = this.RenderSize.Width / (x1 - x0);

            this._dataTransformMatrix.M11     = xScale;
            this._dataTransformMatrix.M22     = yScale;
            this._dataTransformMatrix.OffsetY = this.RenderSize.Height - y0 * yScale;
            this._dataTransformMatrix.OffsetX = -x0 * xScale;
            this._geometryTransform.Matrix    = this._dataTransformMatrix;
            double thickness = this._thickness / (2 * xScale);

            parent.YMAX = y1.ToString("0.0000");

            StreamGeometry geom = new StreamGeometry();

            using (var gc = geom.Open())
            {
                gc.BeginFigure(new Point(0, event_.FrequencyAmplitudes[0]), false, false);
                double dist = Math.PI / (event_.FrequencyAmplitudes.Length - 1);
                for (int i = 0; i <= event_.FrequencyAmplitudes.Length; i++)
                {
                    gc.LineTo(new Point(i * dist, event_.FrequencyAmplitudes[i]), true, true);
                }
            }
            geom.Transform = this._geometryTransform;
            if (geom.CanFreeze)
            {
                geom.Freeze();
            }
            DrawingVisual visual = new DrawingVisual();

            using (var vc = visual.RenderOpen())
            {
                vc.DrawGeometry(null, new Pen(this._trendlineBrush, 2.5 * this._thickness), geom);
            }

            this._children.Add(visual);
        }
Exemplo n.º 6
0
        public void DrawLine(double x1, double y1, double x2, double y2, SequenceLineType lineType, SequenceArrowType arrowHead)
        {
            Pen    pen          = lineType == SequenceLineType.Solid ? m_solidLinePen : m_dashedLinePen;
            double halfPenWidth = m_solidLinePen.Thickness / 2;

            GuidelineSet guidelines = new GuidelineSet();

            guidelines.GuidelinesX.Add(x1 + halfPenWidth);
            guidelines.GuidelinesX.Add(x2 + halfPenWidth);
            guidelines.GuidelinesY.Add(y1 + halfPenWidth);
            guidelines.GuidelinesY.Add(y2 + halfPenWidth);

            m_drawingContext.PushGuidelineSet(guidelines);

            // Draw the main line segment
            Point start = new Point(x1, y1);
            Point end   = new Point(x2, y2);

            DrawLine(m_drawingContext, pen, start, end);

            // Draw the arrowhead
            double direction = (x1 > x2) ? 1 : -1;
            Point  arrow0    = new Point(end.X + direction * LineThickness, end.Y);
            Point  arrow1    = new Point(x2 + direction * s_arrowHeadSize.Width, y2 - s_arrowHeadSize.Height);
            Point  arrow2    = new Point(x2 + direction * s_arrowHeadSize.Width, y2 + s_arrowHeadSize.Height);

            switch (arrowHead)
            {
            case SequenceArrowType.Filled:
            {
                var streamGeometry = new StreamGeometry();
                using (StreamGeometryContext geometryContext = streamGeometry.Open())
                {
                    geometryContext.BeginFigure(arrow0, true, true);
                    PointCollection points = new PointCollection {
                        arrow1, arrow2
                    };
                    geometryContext.PolyLineTo(points, true, true);
                }

                streamGeometry.Freeze();
                m_drawingContext.DrawGeometry(m_arrowBrush, m_solidLinePen, streamGeometry);
                break;
            }

            case SequenceArrowType.Open:
            {
                m_drawingContext.DrawLine(m_solidLinePen, arrow0, arrow1);
                m_drawingContext.DrawLine(m_solidLinePen, arrow0, arrow2);
                break;
            }
            }

            m_drawingContext.Pop();
        }
Exemplo n.º 7
0
        protected override void OnRender(DrawingContext drawingContext)
        {
            double width  = this.ActualWidth / 2.0;
            double height = this.ActualHeight / 2.0;
            Point  point  = new Point(width, height);
            Color  color  = this.ControlBrush.Color;
            Brush  brush  = new SolidColorBrush(color.AddColorDelta(-80));
            Brush  brush1 = color.CreateLinearTwoGradientsBrush(90.0, 80, -80);
            Brush  brush2 = new SolidColorBrush(color);
            Brush  brush3 = color.CreateLinearTwoGradientsBrush(90.0, -80, 80);
            Pen    pen    = new Pen(brush, StrokeThickness);

            drawingContext.PushTransform(new RotateTransform(450 - this.StartAngle, width, height));
            StreamGeometry geometry;

            switch (Design)
            {
            case NeedleDesign.Standard:
                geometry = new StreamGeometry();
                using (StreamGeometryContext context = geometry.Open())
                {
                    context.BeginFigure(new Point(0.85 * width, 0), true, true);
                    context.PolyLineTo(new Point[] { new Point(1.15 * width, 0), new Point(1.45 * width, height), new Point(0.55 * width, height) }, false, false);
                }
                geometry.Freeze();
                drawingContext.DrawGeometry(Brushes.Red, pen, geometry);
                drawingContext.DrawEllipse(brush1, pen, point, width * 1.5, width * 1.5);
                drawingContext.DrawEllipse(brush2, null, point, width * 1.2, width * 1.2);
                break;

            case NeedleDesign.Classic:
                drawingContext.DrawLine(new Pen(Brushes.Blue, 5), new Point(width, 0), new Point(width, 1.3 * height));
                drawingContext.DrawEllipse(brush1, pen, point, width * 1.5, width * 1.5);
                drawingContext.DrawEllipse(brush2, null, point, width * 1.2, width * 1.2);
                break;

            case NeedleDesign.Shape:
                geometry = new StreamGeometry();
                using (StreamGeometryContext context = geometry.Open())
                {
                    context.BeginFigure(new Point(width, 0), true, true);
                    context.LineTo(new Point(1.5 * width, height), true, false);
                    context.ArcTo(new Point(0.5 * width, height), new Size(width * 1.2, width * 1.2), 0.0, true, SweepDirection.Clockwise, true, true);
                }
                geometry.Freeze();
                drawingContext.DrawGeometry(ControlBrush, pen, geometry);
                break;

            case NeedleDesign.Thin:
                drawingContext.DrawLine(pen, new Point(width, 0), new Point(width, height));
                break;
            }

            //base.OnRender(drawingContext);
        }
Exemplo n.º 8
0
        // test streamgeometry
        StreamGeometry CreateStreamGeometryFromMsaglCurve(ICurve iCurve)
        {
            var geometry   = new StreamGeometry();
            var pathFigure = new PathFigure
            {
                IsClosed   = true,
                IsFilled   = true,
                StartPoint = Common.WpfPoint(iCurve.Start)
            };

            var curve = iCurve as Curve;

            if (curve != null)
            {
                AddCurve(pathFigure, curve);
            }
            else
            {
                var rect = iCurve as RoundedRect;
                if (rect != null)
                {
                    AddCurve(pathFigure, rect.Curve);
                }
                else
                {
                    var ellipse = iCurve as Ellipse;
                    if (ellipse != null)
                    {
                        var ellGeom = new EllipseGeometry(Common.WpfPoint(ellipse.Center), ellipse.AxisA.Length,
                                                          ellipse.AxisB.Length);
                        pathFigure = PathGeometry.CreateFromGeometry(ellGeom).Figures[0];
                    }
                    var poly = iCurve as Polyline;
                    if (poly != null)
                    {
                        var p = poly.StartPoint.Next;
                        do
                        {
                            pathFigure.Segments.Add(new System.Windows.Media.LineSegment(Common.WpfPoint(p.Point),
                                                                                         true));

                            p = p.NextOnPolyline;
                        } while (p != poly.StartPoint);
                    }
                }
            }

            using (var ctx = geometry.Open())
            {
                DrawFigure(ctx, pathFigure);
            }
            geometry.Freeze();
            return(geometry);
        }
Exemplo n.º 9
0
        static internal Geometry GetICurveWpfGeometry(ICurve curve)
        {
            var streamGeometry = new StreamGeometry();

            using (StreamGeometryContext context = streamGeometry.Open()) {
                FillStreamGeometryContext(context, curve);

                //test freeze for performace
                streamGeometry.Freeze();
                return(streamGeometry);
            }
        }
Exemplo n.º 10
0
        StreamGeometry GetNodeDotEllipseStreamGeometry(double nodeDotWidth)
        {
            var geometry = new StreamGeometry();

            using (var ctx = geometry.Open()) {
                var ellipse = GetNodeDotEllipseGeometry(nodeDotWidth);
                var figure  = PathGeometry.CreateFromGeometry(ellipse).Figures[0];
                DrawFigure(ctx, figure);
            }
            geometry.Freeze();
            return(geometry);
        }
Exemplo n.º 11
0
        void DrawTriangle(DrawingContext drawingContext, Point point1, Point point2, Point point3)
        {
            StreamGeometry geometry = new StreamGeometry();

            using (StreamGeometryContext context = geometry.Open()) {
                context.BeginFigure(point1, true, true);
                context.LineTo(point2, false, false);
                context.LineTo(point3, false, false);
            }
            geometry.Freeze();
            drawingContext.DrawGeometry(Fill, null, geometry);
        }
Exemplo n.º 12
0
        public override void Draw(DrawingContext drawingContext)
        {
            var geometry = new StreamGeometry();

            using (StreamGeometryContext ctx = geometry.Open())
            {
                ctx.BeginFigure(new Point(coordinates[0].X, coordinates[0].Y), true /* is filled */, false /* is closed */);
                ctx.PolyLineTo(coordinates, true /* is stroked */, false /* is smooth join */);
            }
            geometry.Freeze();
            drawingContext.DrawGeometry(Brushes.Transparent, Pen, geometry);
        }
Exemplo n.º 13
0
        internal static object DeserializeStreamGeometry(BinaryReader reader)
        {
            StreamGeometry geometry = new StreamGeometry();

            using (StreamGeometryContext context = geometry.Open())
            {
                ParserStreamGeometryContext.Deserialize(reader, context, geometry);
            }
            geometry.Freeze();

            return(geometry);
        }
Exemplo n.º 14
0
        public override void Draw(DrawingContext ctx, Matrix matrix)
        {
            if (!this.IsValid)
            {
                return;
            }
            PathFigureEditor      pathFigureEditor      = new PathFigureEditor(this.PathGeometry.Figures[this.FigureIndex]);
            StreamGeometry        streamGeometry        = new StreamGeometry();
            StreamGeometryContext streamGeometryContext = streamGeometry.Open();

            switch (this.PathPointKind)
            {
            case PathPointKind.Start:
                throw new InvalidOperationException(ExceptionStringTable.PathSegmentAdornerIsolatedPointSegment);

            case PathPointKind.Arc:
                ArcSegment arcSegment = (ArcSegment)pathFigureEditor.PathFigure.Segments[this.SegmentIndex];
                streamGeometryContext.BeginFigure(this.GetPoint(pathFigureEditor, -1), false, false);
                streamGeometryContext.ArcTo(arcSegment.Point, arcSegment.Size, arcSegment.RotationAngle, arcSegment.IsLargeArc, arcSegment.SweepDirection, true, false);
                break;

            case PathPointKind.Line:
                streamGeometryContext.BeginFigure(this.GetPoint(pathFigureEditor, -1), false, false);
                streamGeometryContext.LineTo(this.GetPoint(pathFigureEditor, 0), true, false);
                break;

            case PathPointKind.Quadratic:
                streamGeometryContext.BeginFigure(this.GetPoint(pathFigureEditor, -2), false, false);
                streamGeometryContext.QuadraticBezierTo(this.GetPoint(pathFigureEditor, -1), this.GetPoint(pathFigureEditor, 0), true, false);
                break;

            case PathPointKind.Cubic:
                streamGeometryContext.BeginFigure(this.GetPoint(pathFigureEditor, -3), false, false);
                streamGeometryContext.BezierTo(this.GetPoint(pathFigureEditor, -2), this.GetPoint(pathFigureEditor, -1), this.GetPoint(pathFigureEditor, 0), true, false);
                break;

            case PathPointKind.BezierHandle:
                throw new InvalidOperationException(ExceptionStringTable.PathSegmentAdornerLastPointIsBezier);

            default:
                throw new NotImplementedException(ExceptionStringTable.PathSegmentAdornerUnknownPathPoint);
            }
            streamGeometryContext.Close();
            MatrixTransform matrixTransform = new MatrixTransform(matrix);

            matrixTransform.Freeze();
            streamGeometry.Transform = (Transform)matrixTransform;
            streamGeometry.Freeze();
            Pen pen = this.IsActive ? this.ThickPathSegmentPen : this.ThinPathSegmentPen;

            ctx.DrawGeometry((Brush)null, pen, (System.Windows.Media.Geometry)streamGeometry);
            ctx.DrawGeometry((Brush)null, PathSegmentAdorner.HitTestPen, (System.Windows.Media.Geometry)streamGeometry);
        }
Exemplo n.º 15
0
    public void Draw(TextView textView, DrawingContext drawingContext)
    {
        if (markers == null || !textView.VisualLinesValid)
        {
            return;
        }
        var visualLines = textView.VisualLines;

        if (visualLines.Count == 0)
        {
            return;
        }
        int viewStart = visualLines.First().FirstDocumentLine.Offset;
        int viewEnd   = visualLines.Last().LastDocumentLine.EndOffset;

        foreach (TextMarker marker in markers.FindOverlappingSegments(viewStart, viewEnd - viewStart))
        {
            if (marker.BackgroundColor != null)
            {
                var geoBuilder = new BackgroundGeometryBuilder {
                    AlignToWholePixels = true, CornerRadius = 3
                };
                geoBuilder.AddSegment(textView, marker);
                Geometry geometry = geoBuilder.CreateGeometry();
                if (geometry != null)
                {
                    Color color = marker.BackgroundColor.Value;
                    var   brush = new SolidColorBrush(color);
                    brush.Freeze();
                    drawingContext.DrawGeometry(brush, null, geometry);
                }
            }
            foreach (Rect r in BackgroundGeometryBuilder.GetRectsForSegment(textView, marker))
            {
                Point startPoint = r.BottomLeft;
                Point endPoint   = r.BottomRight;
                var   usedPen    = new Pen(new SolidColorBrush(marker.MarkerColor), 1);
                usedPen.Freeze();
                const double offset   = 2.5;
                int          count    = Math.Max((int)((endPoint.X - startPoint.X) / offset) + 1, 4);
                var          geometry = new StreamGeometry();
                using (StreamGeometryContext ctx = geometry.Open())
                {
                    ctx.BeginFigure(startPoint, false, false);
                    ctx.PolyLineTo(CreatePoints(startPoint, endPoint, offset, count).ToArray(), true, false);
                }
                geometry.Freeze();
                drawingContext.DrawGeometry(Brushes.Transparent, usedPen, geometry);
                break;
            }
        }
    }
Exemplo n.º 16
0
        private Path CreateArcPath(System.Windows.Point centre, double radians, double radius)
        {
            // Create a path to draw a geometry with.
            Path path = new Path();

            path.Stroke          = saccadeAngleBrush;
            path.Fill            = saccadeAngleBrush;
            path.StrokeThickness = 1;

            // Create a StreamGeometry to use to specify myPath.
            StreamGeometry geometry = new StreamGeometry();

            geometry.FillRule = FillRule.EvenOdd;

            // Open a StreamGeometryContext that can be used to describe this StreamGeometry object's contents.
            using (StreamGeometryContext ctx = geometry.Open())
            {
                // start point is the centre
                // end point is the radius times (radius * cos(radians), radius* sin(radians))

                double endX = centre.X + (radius * Math.Cos(radians));
                double endY = centre.Y - (radius * Math.Sin(radians));
                System.Windows.Point endPoint = new System.Windows.Point(endX, endY);

                SweepDirection direction  = radians < 0 ? SweepDirection.Clockwise : SweepDirection.Counterclockwise;
                bool           isLargeArc = radians > Math.PI ? true : false;


                // Set the begin point of the shape.
                ctx.BeginFigure(centre, true /* is filled */, true /* is closed */);

                ctx.LineTo(new System.Windows.Point(centre.X + radius, centre.Y), true, false);


                // Create an arc. Draw the arc from the begin point to 200,100 with the specified parameters.
                ctx.ArcTo(endPoint, new Size(radius, radius), 0 /* rotation angle */, isLargeArc /* is large arc */,
                          direction, true /* is stroked */, false /* is smooth join */);

                Console.WriteLine(radians);

                ctx.LineTo(centre, true, false);
            }

            // Freeze the geometry (make it unmodifiable)
            // for additional performance benefits.
            geometry.Freeze();

            // specify the shape (arc) of the path using the StreamGeometry.
            path.Data = geometry;

            return(path);
        }
Exemplo n.º 17
0
        /// <summary>
        /// обработчик ТЕСТ кнопки
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        //private void Button_Click_2(object sender, RoutedEventArgs e)
        //{

        // pic.Children.Clear();
        //    FillerX8 obj = new    FillerX8(10);
        //// obj.addNewVector(4);
        // obj.addPointToVectorMainList2();
        // showinConsoleDebug("Vector Start", false);
        // //showinConsoleDebug(obj.showAllLength(obj.mainList2),false);

        // showinConsoleDebug(obj.test(), false);

        // var po = Math.Pow(12, 6);
        // var maxval = long.MaxValue;

        // for (UInt64 i = 0; i < po; i++)
        // {
        //     var res = obj.alif4(0);
        // }

        //           for (long i = 0; i < po; i++)
        //           {
        //Thread tr = new Thread(obj.startThread);
        //tr.Start();
        ////tr.Join();

        //           }



        //    #region ДЛя рисования разкоментировать
        ////         curentList=   obj.draw2();
        //// curentindex = 0;
        //// if (curentList.Count <= 0) { return; }
        ////var temp2 = curentList[curentindex];
        //// myMatrixTransformScale(ref temp2);


        //// List<System.Windows.Point> arrpoint = new List<System.Windows.Point>();
        //// ////////////////////////
        //// foreach (var item in temp2.path)
        //// {
        ////     LineGeometry blackLineGeometry = new LineGeometry();


        ////     Line l = moveLine(item);
        ////     arrpoint.Add(new System.Windows.Point(l.X1, l.Y1));
        ////     arrpoint.Add(new System.Windows.Point(l.X2, l.Y2));

        //// }
        //// StreamGeometryTriangleExample(arrpoint);
        //// showinConsoleDebug("Vector Finish", false);
        ////}
        //    #endregion

        #endregion



        //}

        /// <summary>
        ///  рисовалка для фигуры
        /// </summary>
        /// <param name="arrPoints"></param>
        public Canvas StreamGeometryTriangleLitle(List <System.Windows.Point> arrPoints)
        {
            // Create a path to draw a geometry with.
            Path myPath = new Path();

            myPath.Stroke          = System.Windows.Media.Brushes.Black;
            myPath.StrokeThickness = 1;

            byte[] arr = new byte[4];
            rand.NextBytes(arr);
            //cl.A =
            System.Windows.Media.Brush br = new SolidColorBrush(System.Windows.Media.Color.FromArgb(arr[0], arr[1], arr[2], arr[3]));
            myPath.Fill = br;
            // Create a StreamGeometry to use to specify myPath.
            StreamGeometry geometry = new StreamGeometry();

            geometry.FillRule = FillRule.EvenOdd;

            // Open a StreamGeometryContext that can be used to describe this StreamGeometry
            // object's contents.

            using (StreamGeometryContext ctx = geometry.Open())
            {
                // Begin the triangle at the point specified. Notice that the shape is set to
                // be closed so only two lines need to be specified below to make the triangle.
                ctx.BeginFigure(arrPoints[0], true /* is filled */, true /* is closed */);
                for (int i = 1; i < arrPoints.Count; i++)
                {
                    ctx.LineTo(arrPoints[i], true /* is stroked */, true /* is smooth join */);
                }
                // Draw a line to the next specified point.
                //   ctx.LineTo(new System.Windows.Point(100, 100), true /* is stroked */, false /* is smooth join */);

                // Draw another line to the next specified point.
                //  ctx.LineTo(new System.Windows.Point(100, 50), true /* is stroked */, false /* is smooth join */);
            }

            // Freeze the geometry (make it unmodifiable)
            // for additional performance benefits.
            geometry.Freeze();

            // Specify the shape (triangle) of the Path using the StreamGeometry.
            myPath.Data = geometry;

            // Add path shape to the UI.
            //  StackPanel mainPanel = new StackPanel();
            Canvas c = new Canvas();

            //    myPath.RenderTransform
            c.Children.Add(myPath);
            return(c);
        }
Exemplo n.º 18
0
        /// <summary>
        /// Parse a PathGeometry string.
        /// The PathGeometry syntax is the same as the PathFigureCollection syntax except that it
        /// may start with a "wsp*Fwsp*(0|1)" which indicate the winding mode (F0 is EvenOdd while
        /// F1 is NonZero).
        /// </summary>
        public static Geometry ParseGeometry(string pathString, IFormatProvider formatProvider, bool isFilled = true)
        {
            FillRule              fillRule = FillRule.EvenOdd;
            StreamGeometry        geometry = new StreamGeometry();
            StreamGeometryContext context  = geometry.Open();

            ParseStringToStreamGeometryContext(context, pathString, formatProvider, ref fillRule, isFilled);

            geometry.FillRule = fillRule;
            geometry.Freeze();

            return(geometry);
        }
Exemplo n.º 19
0
        private Geometry CreateCurve(Point startPoint, List <Point> linePoints)
        {
            // Curve figure geometry
            StreamGeometry geometry = new StreamGeometry();

            using (StreamGeometryContext ctx = geometry.Open())
            {
                ctx.BeginFigure(startPoint, false /* is filled */, false /* is closed */);
                ctx.PolyLineTo(linePoints, true /* is stroked */, true /* is smooth join */);
            }
            geometry.Freeze();
            return(geometry);
        }
Exemplo n.º 20
0
        public static Geometry SingleBondGeometry(Point startPoint, Point endPoint)
        {
            StreamGeometry sg = new StreamGeometry();

            using (StreamGeometryContext sgc = sg.Open())
            {
                sgc.BeginFigure(startPoint, false, false);
                sgc.LineTo(endPoint, true, false);
                sgc.Close();
            }
            sg.Freeze();
            return(sg);
        }
Exemplo n.º 21
0
        private static StreamGeometry GenerateRoundedGeometry(Point startPoint, Point endPoint, Size size)
        {
            var streamGeometry = new StreamGeometry();

            using (StreamGeometryContext sc = streamGeometry.Open())
            {
                sc.BeginFigure(startPoint, true, false);
                sc.ArcTo(endPoint, size, 0, false, SweepDirection.Clockwise, true, false);
            }

            streamGeometry.Freeze();
            return(streamGeometry);
        }
Exemplo n.º 22
0
        private void DrawMap(Point [] points)
        {
            Path myPath = new Path();

            myPath.Stroke          = Brushes.Black;
            myPath.StrokeThickness = 0.5;
            StreamGeometry streamGeometry = BuildRegularPolygon(points, false, false);

            streamGeometry.FillRule = FillRule.EvenOdd;
            streamGeometry.Freeze();
            myPath.Data = streamGeometry;
            canvasOs.Children.Add(myPath);
        }
Exemplo n.º 23
0
        protected override void OnRender(DrawingContext drawingContext)
        {
            Stopwatch sw = new Stopwatch();

            sw.Start();

            if (timedValues.Count == 0)
            {
                return;
            }

            var minimumShownTime = timedValues.Last().Item1.Subtract(DisplayPeriod);

            var ticksPerUnit     = (DisplayPeriod.Ticks / ActualWidth);
            var maximumShownTime = timedValues.Last().Item1.Ticks / ticksPerUnit;
            // Reduce the collected points into one data point per pixel
            var times = timedValues
                        .Where(value => value.Item1 > minimumShownTime)
                        .Select(t => new Point(ActualWidth - (((t.Item1.Ticks) / ticksPerUnit) - maximumShownTime), ActualHeight - ((ActualHeight / 100) * t.Item2)))
                        .GroupBy(point => point.X)
                        .Select(points => new Point(points.Key, points.Select(point => point.Y).Average()))
                        .ToList();

            if (times.Count == 0)
            {
                return;
            }
            sw.Stop();

            Debug.WriteLine("Reducing - " + sw.ElapsedMilliseconds);
            sw.Restart();
            //var smoothedItems = new MovingAverageSmoothing(5).Smooth(times.Select(point => (int)point.Y));
            //var smoothedTimeItems = times.Select(point => point.X).Zip(smoothedItems, (d, i) => new Point(d, i)).ToList();

            var smoothedTimeItems = times;

            for (var i = 1; i < times.Count; i++)
            {
                var geometry = new StreamGeometry();
                using (var context = geometry.Open())
                {
                    context.BeginFigure(smoothedTimeItems[i - 1], false, false);
                    context.LineTo(smoothedTimeItems[i], true, false);
                }

                geometry.Freeze();
                drawingContext.DrawGeometry(null, rawPen, geometry);
            }
            sw.Stop();
            Debug.WriteLine("Drawing - " + sw.ElapsedMilliseconds);
        }
Exemplo n.º 24
0
        /// <summary>
        /// creates path from list of points, for performance set addBlurEffect to false
        /// </summary>
        /// <param name="pl"></param>
        /// <returns></returns>
        public virtual Path CreatePolygonPath(List <Point> localPath, bool addBlurEffect)
        {
            // Create a StreamGeometry to use to specify myPath.
            StreamGeometry geometry = new StreamGeometry();

            using (StreamGeometryContext ctx = geometry.Open())
            {
                ctx.BeginFigure(localPath[0], true, true);

                // Draw a line to the next specified point.
                ctx.PolyLineTo(localPath, true, true);
            }

            // Freeze the geometry (make it unmodifiable)
            // for additional performance benefits.
            geometry.Freeze();

            // Create a path to draw a geometry with.
            Path myPath = new Path();

            {
                // Specify the shape of the Path using the StreamGeometry.
                myPath.Data = geometry;

                if (addBlurEffect)
                {
                    BlurEffect ef = new BlurEffect();
                    {
                        ef.KernelType    = KernelType.Gaussian;
                        ef.Radius        = 3.0;
                        ef.RenderingBias = RenderingBias.Performance;
                    }

                    myPath.Effect = ef;
                }

                myPath.Stroke             = Stroke;
                myPath.StrokeThickness    = StrokeThickness;
                myPath.StrokeLineJoin     = StrokeLineJoin;
                myPath.StrokeStartLineCap = StrokeStartLineCap;
                myPath.StrokeEndLineCap   = StrokeEndLineCap;
                myPath.StrokeDashArray    = StrokeDashArray;
                myPath.Fill = Fill;

                myPath.Opacity          = Opacity;
                myPath.IsHitTestVisible = IsHitTestVisible;
                myPath.MouseEnter      += myPath_MouseEnter;
                myPath.MouseLeave      += myPath_MouseLeave;
            }
            return(myPath);
        }
Exemplo n.º 25
0
        private void DrawReference(System.Windows.Shapes.Path pathElement, int yOffset)
        {
            drawGeometry = new StreamGeometry {
                FillRule = FillRule.EvenOdd
            };

            using (drawContext = drawGeometry.Open()) {
                drawContext.BeginFigure(new Point(0, Utility.Clamp(yOffset, 0, cnvDrawing.ActualHeight)), true, false);
                drawContext.LineTo(new Point(cnvDrawing.ActualWidth, Utility.Clamp(yOffset, 0, cnvDrawing.ActualHeight)), true, true);
            }

            drawGeometry.Freeze();
            pathElement.Data = drawGeometry;
        }
Exemplo n.º 26
0
        private Geometry CreateGeometry(LevelLine lineData)
        {
            var transform = Plotter2D.Viewport.Transform;

            StreamGeometry geometry = new StreamGeometry();

            using (var context = geometry.Open())
            {
                context.BeginFigure(lineData.StartPoint.DataToScreen(transform), false, false);
                context.PolyLineTo(lineData.OtherPoints.DataToScreenAsList(transform), true, true);
            }
            geometry.Freeze();
            return(geometry);
        }
Exemplo n.º 27
0
        private void DrawOffsetReference()
        {
            drawGeometry = new StreamGeometry {
                FillRule = FillRule.EvenOdd
            };

            using (drawContext = drawGeometry.Open()) {
                drawContext.BeginFigure(new Point(Utility.Clamp((int)((IndexOffset * drawXMultiplier) + drawXOffset), 0, cnvDrawing.ActualWidth), 0), true, false);
                drawContext.LineTo(new Point(Utility.Clamp((int)((IndexOffset * drawXMultiplier) + drawXOffset), 0, cnvDrawing.ActualWidth), cnvDrawing.ActualHeight), true, true);
            }

            drawGeometry.Freeze();
            pathIndexOffset.Data = drawGeometry;
        }
Exemplo n.º 28
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.º 29
0
        public void DrawAndFillPolygon(Pen pen, Brush brush, TPointF[] points, TClippingStyle clippingStyle)
        {
            if (points == null || points.Length <= 1)
            {
                return;
            }
            if (!CheckPoints(points))
            {
                return;
            }

            StreamGeometry Line = new StreamGeometry();

            using (StreamGeometryContext sc = Line.Open())
            {
                sc.BeginFigure(new Point(points[0].X, points[0].Y), brush != null, true);
                for (int i = 1; i < points.Length; i++)
                {
                    sc.LineTo(new Point(points[i].X, points[i].Y), true, true);
                }
            }

            if (Line.CanFreeze)
            {
                Line.Freeze();
            }

            if (brush != null)
            {
                switch (clippingStyle)
                {
                case TClippingStyle.Exclude:
                    IntersectClip(Reverse(Line));
                    break;

                case TClippingStyle.Include:
                    IntersectClip(Line);
                    break;

                default:
                    //Will be handled below.
                    break;
                }
            }

            if (clippingStyle == TClippingStyle.None)
            {
                FCanvas.DrawGeometry(brush, pen, Line);
            }
        }
Exemplo n.º 30
0
        /// <inheritdoc />
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            if (values[1] is List <ILayoutElement> elements)
            {
                // Create a StreamGeometry to draw element
                StreamGeometry geometry = new StreamGeometry();
                using (StreamGeometryContext ctx = geometry.Open())
                {
                    if (elements.FirstOrDefault() is Obstacle)
                    {
                        foreach (var obstacle in elements)
                        {
                            var position = obstacle.Position;
                            var pointNW  = new Point(position.X, position.Y);
                            var pointNE  = new Point(position.X + obstacle.Area.Width, position.Y);
                            var pointSW  = new Point(position.X, position.Y + obstacle.Area.Height);
                            var pointSE  = new Point(position.X + obstacle.Area.Width, position.Y + obstacle.Area.Height);
                            ctx.BeginFigure(pointNW, false, true);
                            ctx.LineTo(pointNE, true, false);
                            ctx.LineTo(pointSE, true, false);
                            ctx.LineTo(pointSW, true, false);
                            ctx.LineTo(pointNW, true, false);
                            ctx.LineTo(pointSE, true, false);
                            ctx.LineTo(pointNE, true, false);
                            ctx.LineTo(pointSW, true, false);
                        }
                        geometry.FillRule = FillRule.EvenOdd;
                    }
                    else if (elements.FirstOrDefault() is PickingSlot)
                    {
                        foreach (var pickingSlot in elements)
                        {
                            ctx.DrawGeometry(new EllipseGeometry(new Point(pickingSlot.Position.X, pickingSlot.Position.Y), 1.5, 1.5));
                        }
                    }
                    else if (elements.FirstOrDefault() is CoordLayoutElement)
                    {
                        foreach (var travelStep in elements)
                        {
                            ctx.DrawGeometry(new RectangleGeometry(new Rect(travelStep.Position.X, travelStep.Position.Y, 1, 1)));
                        }
                    }

                    geometry.Freeze();
                    return(geometry);
                }
            }

            return(Binding.DoNothing);
        }