public void DrawLine(IList<ScreenPoint> points, OxyColor stroke, double thickness, double[] dashArray,
                             OxyPenLineJoin lineJoin, bool aliased)
        {
            var e = new Polyline();
            if (stroke != null && thickness > 0)
            {
                e.Stroke = GetCachedBrush(stroke);

                switch (lineJoin)
                {
                    case OxyPenLineJoin.Round:
                        e.StrokeLineJoin = PenLineJoin.Round;
                        break;
                    case OxyPenLineJoin.Bevel:
                        e.StrokeLineJoin = PenLineJoin.Bevel;
                        break;
                    //  The default StrokeLineJoin is Miter
                }

                if (thickness != 1) // default values is 1
                    e.StrokeThickness = thickness;
                if (dashArray != null)
                    e.StrokeDashArray = new DoubleCollection(dashArray);
            }
            // pl.Fill = null;
            if (aliased)
                e.SetValue(RenderOptions.EdgeModeProperty, EdgeMode.Aliased);

            var pc = new PointCollection(points.Count);
            foreach (var p in points)
                pc.Add(ToPoint(p));
            e.Points = pc;

            Add(e);
        }
Esempio n. 2
0
 /// <summary>
 /// Draws a polyline.
 /// </summary>
 /// <param name="points">The points.</param>
 /// <param name="stroke">The stroke color.</param>
 /// <param name="thickness">The stroke thickness.</param>
 /// <param name="dashArray">The dash array.</param>
 /// <param name="lineJoin">The line join type.</param>
 /// <param name="aliased">if set to <c>true</c> the shape will be aliased.</param>
 public abstract void DrawLine(
     IList<ScreenPoint> points,
     OxyColor stroke,
     double thickness,
     double[] dashArray,
     OxyPenLineJoin lineJoin,
     bool aliased);
Esempio n. 3
0
 /// <summary>
 /// Draws a polyline.
 /// </summary>
 /// <param name="points">The points.</param>
 /// <param name="stroke">The stroke color.</param>
 /// <param name="thickness">The stroke thickness (in device independent units, 1/96 inch).</param>
 /// <param name="dashArray">The dash array (in device independent units, 1/96 inch). Use <c>null</c> to get a solid line.</param>
 /// <param name="lineJoin">The line join type.</param>
 /// <param name="aliased">if set to <c>true</c> the shape will be aliased.</param>
 public void DrawLine(
     IList<ScreenPoint> points,
     OxyColor stroke,
     double thickness = 1,
     double[] dashArray = null,
     OxyPenLineJoin lineJoin = OxyPenLineJoin.Miter,
     bool aliased = false)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="OxyPen"/> class.
 /// </summary>
 /// <param name="color">
 /// The color.
 /// </param>
 /// <param name="thickness">
 /// The thickness.
 /// </param>
 /// <param name="lineStyle">
 /// The line style.
 /// </param>
 /// <param name="lineJoin">
 /// The line join.
 /// </param>
 public OxyPen(
     OxyColor color,
     double thickness = 1.0,
     LineStyle lineStyle = LineStyle.Solid,
     OxyPenLineJoin lineJoin = OxyPenLineJoin.Miter)
 {
     this.Color = color;
     this.Thickness = thickness;
     this.DashArray = LineStyleHelper.GetDashArray(lineStyle);
     this.LineStyle = lineStyle;
     this.LineJoin = lineJoin;
 }
Esempio n. 5
0
 /// <summary>
 /// Draws the multiple line segments defined by points (0,1) (2,3) (4,5) etc.
 /// This should have better performance than calling DrawLine for each segment.
 /// </summary>
 /// <param name="points">
 /// The points.
 /// </param>
 /// <param name="stroke">
 /// The stroke color.
 /// </param>
 /// <param name="thickness">
 /// The stroke thickness.
 /// </param>
 /// <param name="dashArray">
 /// The dash array.
 /// </param>
 /// <param name="lineJoin">
 /// The line join type.
 /// </param>
 /// <param name="aliased">
 /// if set to <c>true</c> the shape will be aliased.
 /// </param>
 public virtual void DrawLineSegments(
     IList <ScreenPoint> points,
     OxyColor stroke,
     double thickness,
     double[] dashArray,
     OxyPenLineJoin lineJoin,
     bool aliased)
 {
     for (int i = 0; i + 1 < points.Count; i += 2)
     {
         this.DrawLine(new[] { points[i], points[i + 1] }, stroke, thickness, dashArray, lineJoin, aliased);
     }
 }
        /// <summary>
        /// Draws the polygon from the specified points. The polygon can have stroke and/or fill.
        /// </summary>
        /// <param name="points">The points.</param>
        /// <param name="fill">The fill color.</param>
        /// <param name="stroke">The stroke color.</param>
        /// <param name="thickness">The stroke thickness.</param>
        /// <param name="dashArray">The dash array.</param>
        /// <param name="lineJoin">The line join type.</param>
        /// <param name="aliased">if set to <c>true</c> the shape will be aliased.</param>
        public override void DrawPolygon(
            IList <ScreenPoint> points,
            OxyColor fill,
            OxyColor stroke,
            double thickness,
            double[] dashArray,
            OxyPenLineJoin lineJoin,
            bool aliased)
        {
            if (points.Count < 2)
            {
                return;
            }

            this.g.SmoothingMode = aliased ? SmoothingMode.None : SmoothingMode.HighQuality;

            var pts = this.ToPoints(points);

            if (fill.IsVisible())
            {
                this.g.FillPolygon(fill.ToBrush(), pts);
            }

            if (stroke.IsInvisible() || thickness <= 0)
            {
                return;
            }

            using (var pen = this.CreatePen(stroke, thickness))
            {
                if (dashArray != null)
                {
                    pen.DashPattern = this.ToFloatArray(dashArray);
                }

                switch (lineJoin)
                {
                case OxyPenLineJoin.Round:
                    pen.LineJoin = System.Drawing.Drawing2D.LineJoin.Round;
                    break;

                case OxyPenLineJoin.Bevel:
                    pen.LineJoin = System.Drawing.Drawing2D.LineJoin.Bevel;
                    break;

                    // The default LineJoin is Miter
                }

                this.g.DrawPolygon(pen, pts);
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Converts an <see cref="OxyPenLineJoin" /> to a <see cref="LineJoin" />.
        /// </summary>
        /// <param name="lineJoin">The <see cref="OxyPenLineJoin" /> to convert.</param>
        /// <returns>The converted value.</returns>
        public static LineJoin ToLineJoin(this OxyPenLineJoin lineJoin)
        {
            switch (lineJoin)
            {
            case OxyPenLineJoin.Round:
                return(LineJoin.Round);

            case OxyPenLineJoin.Bevel:
                return(LineJoin.Bevel);

            default:
                return(LineJoin.Miter);
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Converts the specified <see cref="OxyPenLineJoin" /> to a <see cref="LineJoin" />.
        /// </summary>
        /// <param name="lineJoin">The value to convert.</param>
        /// <returns>The converted value.</returns>
        private static LineJoin Convert(OxyPenLineJoin lineJoin)
        {
            switch (lineJoin)
            {
            case OxyPenLineJoin.Bevel:
                return(LineJoin.Bevel);

            case OxyPenLineJoin.Miter:
                return(LineJoin.Miter);

            default:
                return(LineJoin.Round);
            }
        }
Esempio n. 9
0
 /// <summary>
 /// Draws a collection of polygons, where all polygons have the same stroke and fill.
 /// This performs better than calling DrawPolygon multiple times.
 /// </summary>
 /// <param name="polygons">The polygons.</param>
 /// <param name="fill">The fill color.</param>
 /// <param name="stroke">The stroke color.</param>
 /// <param name="thickness">The stroke thickness.</param>
 /// <param name="dashArray">The dash array.</param>
 /// <param name="lineJoin">The line join type.</param>
 /// <param name="aliased">if set to <c>true</c> the shape will be aliased.</param>
 public virtual void DrawPolygons(
     IList <IList <ScreenPoint> > polygons,
     OxyColor fill,
     OxyColor stroke,
     double thickness,
     double[] dashArray,
     OxyPenLineJoin lineJoin,
     bool aliased)
 {
     foreach (var polygon in polygons)
     {
         this.DrawPolygon(polygon, fill, stroke, thickness, dashArray, lineJoin, aliased);
     }
 }
Esempio n. 10
0
        public void DrawPolygon(IList <ScreenPoint> points, OxyColor fill, OxyColor stroke, double thickness,
                                double[] dashArray, OxyPenLineJoin lineJoin, bool aliased)
        {
            Brush brush = null;

            if (fill != null)
            {
                brush = fill.ToBrush();
            }

            var pen = CreatePen(stroke, thickness, dashArray, lineJoin);
            var g   = CreateGeometry(points, true);

            dc.DrawGeometry(brush, pen, g);
        }
        public void DrawPolygon(IEnumerable <ScreenPoint> points, OxyColor fill, OxyColor stroke, double thickness,
                                double[] dashArray, OxyPenLineJoin lineJoin, bool aliased)
        {
            var e = new Polygon();

            if (stroke != null && thickness > 0)
            {
                e.Stroke = GetCachedBrush(stroke);
                if (thickness != 1)
                {
                    e.StrokeThickness = thickness;
                }
                if (dashArray != null)
                {
                    e.StrokeDashArray = new DoubleCollection(dashArray);
                }
                switch (lineJoin)
                {
                case OxyPenLineJoin.Round:
                    e.StrokeLineJoin = PenLineJoin.Round;
                    break;

                case OxyPenLineJoin.Bevel:
                    e.StrokeLineJoin = PenLineJoin.Bevel;
                    break;
                    //  The default StrokeLineJoin is Miter
                }
            }
            if (aliased)
            {
                e.SetValue(RenderOptions.EdgeModeProperty, EdgeMode.Aliased);
            }

            if (fill != null)
            {
                e.Fill = GetCachedBrush(fill);
            }

            var pc = new PointCollection(points.Count);

            foreach (var p in points)
            {
                pc.Add(ToPoint(p));
            }
            e.Points = pc;

            Add(e);
        }
        /// <summary>
        /// Draws the polygon.
        /// </summary>
        /// <param name="points">The points.</param>
        /// <param name="fill">The fill.</param>
        /// <param name="stroke">The stroke.</param>
        /// <param name="thickness">The thickness.</param>
        /// <param name="dashArray">The dash array.</param>
        /// <param name="lineJoin">The line join.</param>
        /// <param name="aliased">if set to <c>true</c> [aliased].</param>
        public override void DrawPolygon(
            IList <ScreenPoint> points,
            OxyColor fill,
            OxyColor stroke,
            double thickness,
            double[] dashArray,
            OxyPenLineJoin lineJoin,
            bool aliased)
        {
            if (points.Count < 2)
            {
                return;
            }

            this.g.SmoothingMode = aliased ? SmoothingMode.None : SmoothingMode.HighQuality;

            PointF[] pts = this.ToPoints(points);
            if (fill != null)
            {
                this.g.FillPolygon(this.ToBrush(fill), pts);
            }

            if (stroke != null && thickness > 0)
            {
                using (var pen = new Pen(this.ToColor(stroke), (float)thickness))
                {
                    if (dashArray != null)
                    {
                        pen.DashPattern = this.ToFloatArray(dashArray);
                    }

                    switch (lineJoin)
                    {
                    case OxyPenLineJoin.Round:
                        pen.LineJoin = LineJoin.Round;
                        break;

                    case OxyPenLineJoin.Bevel:
                        pen.LineJoin = LineJoin.Bevel;
                        break;

                        // The default LineJoin is Miter
                    }

                    this.g.DrawPolygon(pen, pts);
                }
            }
        }
        /// <summary>
        /// Draws the line segments by stream geometry.
        /// </summary>
        /// <param name="points">
        /// The points.
        /// </param>
        /// <param name="stroke">
        /// The stroke.
        /// </param>
        /// <param name="thickness">
        /// The thickness.
        /// </param>
        /// <param name="dashArray">
        /// The dash array.
        /// </param>
        /// <param name="lineJoin">
        /// The line join.
        /// </param>
        /// <param name="aliased">
        /// Draw aliased line if set to <c>true</c> .
        /// </param>
        private void DrawLineSegmentsByStreamGeometry(
            IList <ScreenPoint> points,
            OxyColor stroke,
            double thickness,
            double[] dashArray,
            OxyPenLineJoin lineJoin,
            bool aliased)
        {
            StreamGeometry        streamGeometry        = null;
            StreamGeometryContext streamGeometryContext = null;

            int count = 0;

            for (int i = 0; i + 1 < points.Count; i += 2)
            {
                if (streamGeometry == null)
                {
                    streamGeometry        = new StreamGeometry();
                    streamGeometryContext = streamGeometry.Open();
                }

                streamGeometryContext.BeginFigure(points[i].ToPoint(aliased), false, false);
                streamGeometryContext.LineTo(points[i + 1].ToPoint(aliased), true, false);

                count++;

                // Must limit the number of figures, otherwise drawing errors...
                if (count > MaxFiguresPerGeometry || dashArray != null)
                {
                    streamGeometryContext.Close();
                    var path = new Path();
                    this.SetStroke(path, stroke, thickness, lineJoin, dashArray, aliased);
                    path.Data = streamGeometry;
                    this.Add(path);
                    streamGeometry = null;
                    count          = 0;
                }
            }

            if (streamGeometry != null)
            {
                streamGeometryContext.Close();
                var path = new Path();
                this.SetStroke(path, stroke, thickness, lineJoin, dashArray, aliased);
                path.Data = streamGeometry;
                this.Add(path);
            }
        }
Esempio n. 14
0
        /// <summary>
        /// Draws a collection of polygons, where all polygons have the same stroke and fill.
        /// This performs better than calling DrawPolygon multiple times.
        /// </summary>
        /// <param name="polygons">The polygons.</param>
        /// <param name="fill">The fill color.</param>
        /// <param name="stroke">The stroke color.</param>
        /// <param name="thickness">The stroke thickness.</param>
        /// <param name="dashArray">The dash array.</param>
        /// <param name="lineJoin">The line join type.</param>
        /// <param name="aliased">if set to <c>true</c> the shape will be aliased.</param>
        public void DrawPolygons(
            IList <IList <ScreenPoint> > polygons,
            OxyColor fill,
            OxyColor stroke,
            double thickness,
            double[] dashArray,
            OxyPenLineJoin lineJoin,
            bool aliased)
        {
            var path = new Path();

            this.SetStroke(path, stroke, thickness, lineJoin, dashArray, aliased);
            if (fill.IsVisible())
            {
                path.Fill = this.GetCachedBrush(fill);
            }

            var pg = new PathGeometry {
                FillRule = FillRule.Nonzero
            };

            foreach (var polygon in polygons)
            {
                var figure = new PathFigure {
                    IsClosed = true
                };
                bool first = true;
                foreach (var p in polygon)
                {
                    if (first)
                    {
                        figure.StartPoint = p.ToPoint(aliased);
                        first             = false;
                    }
                    else
                    {
                        figure.Segments.Add(new LineSegment {
                            Point = p.ToPoint(aliased)
                        });
                    }
                }

                pg.Figures.Add(figure);
            }

            path.Data = pg;
            this.Add(path);
        }
        private CGLineCap ToLine(OxyPenLineJoin lineJoin)
        {
            switch (lineJoin)
            {
            case OxyPenLineJoin.Bevel:
                return(CGLineCap.Butt);

            case OxyPenLineJoin.Miter:
                return(CGLineCap.Square);

            case OxyPenLineJoin.Round:
                return(CGLineCap.Round);
            }

            return(CGLineCap.Square);
        }
Esempio n. 16
0
        /// <summary>
        /// Converts an <see cref="OxyPenLineJoin" /> to a <see cref="Paint.Join" />.
        /// </summary>
        /// <param name="join">The join value to convert.</param>
        /// <returns>The converted join value.</returns>
        public static Paint.Join Convert(this OxyPenLineJoin join)
        {
            switch (join)
            {
            case OxyPenLineJoin.Bevel:
                return(Paint.Join.Bevel);

            case OxyPenLineJoin.Miter:
                return(Paint.Join.Miter);

            case OxyPenLineJoin.Round:
                return(Paint.Join.Round);

            default:
                throw new InvalidOperationException("Invalid join type.");
            }
        }
        /// <summary>
        /// Draws a polygon. The polygon can have stroke and/or fill.
        /// </summary>
        /// <param name="points">The points.</param>
        /// <param name="fill">The fill color.</param>
        /// <param name="stroke">The stroke color.</param>
        /// <param name="thickness">The stroke thickness.</param>
        /// <param name="dashArray">The dash array.</param>
        /// <param name="lineJoin">The line join type.</param>
        /// <param name="aliased">If set to <c>true</c> the shape will be aliased.</param>
        public override void DrawPolygon(
            IList <ScreenPoint> points,
            OxyColor fill,
            OxyColor stroke,
            double thickness,
            double[] dashArray,
            OxyPenLineJoin lineJoin,
            bool aliased)
        {
            var p = new List <ScreenPoint>(points);

            p.Add(p[0]);

            var xckdPoints = this.Distort(p);

            this.rc.DrawPolygon(xckdPoints, fill, stroke, thickness * this.ThicknessScale, dashArray, lineJoin);
        }
        /// <summary>
        /// The draw clipped polygon.
        /// </summary>
        /// <param name="rc">
        /// The render context.
        /// </param>
        /// <param name="points">
        /// The points.
        /// </param>
        /// <param name="clippingRectangle">
        /// The clipping rectangle.
        /// </param>
        /// <param name="minDistSquared">
        /// The min dist squared.
        /// </param>
        /// <param name="fill">
        /// The fill.
        /// </param>
        /// <param name="stroke">
        /// The stroke.
        /// </param>
        /// <param name="strokeThickness">
        /// The stroke thickness.
        /// </param>
        /// <param name="lineStyle">
        /// The line style.
        /// </param>
        /// <param name="lineJoin">
        /// The line join.
        /// </param>
        /// <param name="aliased">
        /// The aliased.
        /// </param>
        public static void DrawClippedPolygon(
            this IRenderContext rc,
            IList <ScreenPoint> points,
            OxyRect clippingRectangle,
            double minDistSquared,
            OxyColor fill,
            OxyColor stroke,
            double strokeThickness  = 1.0,
            LineStyle lineStyle     = LineStyle.Solid,
            OxyPenLineJoin lineJoin = OxyPenLineJoin.Miter,
            bool aliased            = false)
        {
            var clippedPoints = SutherlandHodgmanClipping.ClipPolygon(clippingRectangle, points);

            rc.DrawPolygon(
                clippedPoints, fill, stroke, strokeThickness, LineStyleHelper.GetDashArray(lineStyle), lineJoin, aliased);
        }
Esempio n. 19
0
        /// <summary>
        /// Sets the stroke properties of the specified shape object.
        /// </summary>
        /// <param name="shape">The shape.</param>
        /// <param name="stroke">The stroke color.</param>
        /// <param name="thickness">The thickness.</param>
        /// <param name="lineJoin">The line join.</param>
        /// <param name="dashArray">The dash array. Use <c>null</c> to get a solid line.</param>
        /// <param name="dashOffset">The dash offset.</param>
        /// <param name="aliased">The aliased.</param>
        private void SetStroke(
            Shape shape,
            OxyColor stroke,
            double thickness,
            OxyPenLineJoin lineJoin        = OxyPenLineJoin.Miter,
            IEnumerable <double> dashArray = null,
            double dashOffset = 0,
            bool aliased      = false)
        {
            if (!stroke.IsUndefined() && thickness > 0)
            {
                shape.Stroke = this.GetCachedBrush(stroke);

                switch (lineJoin)
                {
                case OxyPenLineJoin.Round:
                    shape.StrokeLineJoin = PenLineJoin.Round;
                    break;

                case OxyPenLineJoin.Bevel:
                    shape.StrokeLineJoin = PenLineJoin.Bevel;
                    break;

                    // The default StrokeLineJoin is Miter
                }

                if (Math.Abs(thickness - 1) > double.Epsilon)
                {
                    // only set if different from the default value (1)
                    shape.StrokeThickness = thickness;
                }

                if (dashArray != null)
                {
                    shape.StrokeDashArray  = new DoubleCollection(dashArray);
                    shape.StrokeDashOffset = dashOffset;
                }
            }

            if (aliased)
            {
                shape.SetValue(RenderOptions.EdgeModeProperty, EdgeMode.Aliased);
                shape.SnapsToDevicePixels = true;
            }
        }
 public void DrawLines(IEnumerable<ScreenPoint> points, OxyColor stroke, double thickness, double[] dashArray,
                      OxyPenLineJoin lineJoin, bool aliased)
 {
     var startPoint = new ScreenPoint();
     bool first = true;
     foreach (var p in points)
     {
         if (!first)
         {
             Add(new Line { X1 = startPoint.X, Y1 = startPoint.Y, X2 = p.X, Y2 = p.Y });
         }
         else
         {
             startPoint = p;
         }
         first = !first;
     }
 }
        /// <summary>
        /// Draws the polyline from the specified points.
        /// </summary>
        /// <param name="points">The points.</param>
        /// <param name="stroke">The stroke color.</param>
        /// <param name="thickness">The stroke thickness.</param>
        /// <param name="dashArray">The dash array.</param>
        /// <param name="lineJoin">The line join type.</param>
        /// <param name="aliased">if set to <c>true</c> the shape will be aliased.</param>
        public override void DrawLine(
            IList <ScreenPoint> points,
            OxyColor stroke,
            double thickness,
            double[] dashArray,
            OxyPenLineJoin lineJoin,
            bool aliased)
        {
            if (stroke.IsInvisible() || thickness <= 0 || points.Count < 2)
            {
                return;
            }

            this.g.SmoothingMode = aliased ? SmoothingMode.None : SmoothingMode.HighQuality;
            using (var pen = this.CreatePen(stroke, thickness, dashArray, lineJoin))
            {
                this.g.DrawLines(pen, this.ToPoints(points));
            }
        }
Esempio n. 22
0
        /// <summary>
        /// Draws the polygon from the specified points. The polygon can have stroke and/or fill.
        /// </summary>
        /// <param name="points">The points.</param>
        /// <param name="fill">The fill color.</param>
        /// <param name="stroke">The stroke color.</param>
        /// <param name="thickness">The stroke thickness.</param>
        /// <param name="dashArray">The dash array.</param>
        /// <param name="lineJoin">The line join type.</param>
        /// <param name="aliased">if set to <c>true</c> the shape will be aliased.</param>
        public override void DrawPolygon(
            IList <ScreenPoint> points,
            OxyColor fill,
            OxyColor stroke,
            double thickness,
            double[] dashArray,
            OxyPenLineJoin lineJoin,
            bool aliased)
        {
            this.g.SmoothingMode = aliased ? XSmoothingMode.None : XSmoothingMode.HighQuality;

            var pts = ToPoints(points);

            if (fill.IsVisible())
            {
                this.g.DrawPolygon(ToBrush(fill), pts, XFillMode.Alternate);
            }

            if (stroke.IsVisible() && thickness > 0)
            {
                var pen = new XPen(ToColor(stroke), (float)thickness);

                if (dashArray != null)
                {
                    pen.DashPattern = dashArray;
                }

                switch (lineJoin)
                {
                case OxyPenLineJoin.Round:
                    pen.LineJoin = XLineJoin.Round;
                    break;

                case OxyPenLineJoin.Bevel:
                    pen.LineJoin = XLineJoin.Bevel;
                    break;

                    // The default LineJoin is Miter
                }

                this.g.DrawPolygon(pen, pts);
            }
        }
Esempio n. 23
0
        /// <summary>
        /// Draws a polygon.
        /// </summary>
        /// <param name="points">The points.</param>
        /// <param name="fill">The fill color. If set to <c>OxyColors.Undefined</c>, the polygon will not be filled.</param>
        /// <param name="stroke">The stroke color. If set to <c>OxyColors.Undefined</c>, the polygon will not be stroked.</param>
        /// <param name="thickness">The stroke thickness (in device independent units, 1/96 inch).</param>
        /// <param name="dashArray">The dash array (in device independent units, 1/96 inch).</param>
        /// <param name="lineJoin">The line join type.</param>
        /// <param name="aliased">If set to <c>true</c> the polygon will be aliased.</param>
        public void DrawPolygon(
            IList <ScreenPoint> points,
            OxyColor fill,
            OxyColor stroke,
            double thickness,
            double[] dashArray,
            OxyPenLineJoin lineJoin,
            bool aliased)
        {
            var e = this.CreateAndAdd <Polygon>();

            this.SetStroke(e, stroke, thickness, lineJoin, dashArray, 0, aliased);

            if (!fill.IsUndefined())
            {
                e.Fill = this.GetCachedBrush(fill);
            }

            e.Points = this.ToPointCollection(points, aliased);
        }
Esempio n. 24
0
        /// <summary>
        /// Draws a polyline.
        /// </summary>
        /// <param name="points">The points.</param>
        /// <param name="stroke">The stroke color.</param>
        /// <param name="thickness">The stroke thickness (in device independent units, 1/96 inch).</param>
        /// <param name="dashArray">The dash array (in device independent units, 1/96 inch). Use <c>null</c> to get a solid line.</param>
        /// <param name="lineJoin">The line join type.</param>
        /// <param name="aliased">if set to <c>true</c> the shape will be aliased.</param>
        public void DrawLine(
            IList <ScreenPoint> points,
            OxyColor stroke,
            double thickness,
            double[] dashArray,
            OxyPenLineJoin lineJoin,
            bool aliased)
        {
            if (thickness < this.BalancedLineDrawingThicknessLimit)
            {
                this.DrawLineBalanced(points, stroke, thickness, dashArray, lineJoin, aliased);
                return;
            }

            var e = this.CreateAndAdd <Polyline>();

            this.SetStroke(e, stroke, thickness, lineJoin, dashArray, 0, aliased);

            e.Points = this.ToPointCollection(points, aliased);
        }
Esempio n. 25
0
        /// <summary>
        /// Sets the stroke properties of the specified shape.
        /// </summary>
        /// <param name="shape">The shape.</param>
        /// <param name="stroke">The stroke.</param>
        /// <param name="thickness">The thickness.</param>
        /// <param name="lineJoin">The line join.</param>
        /// <param name="dashArray">The dash array.</param>
        /// <param name="aliased">The aliased.</param>
        // ReSharper disable UnusedParameter.Local
        private void SetStroke(
            Shape shape,
            OxyColor stroke,
            double thickness,
            OxyPenLineJoin lineJoin = OxyPenLineJoin.Miter,
            double[] dashArray      = null,
            bool aliased            = false)
        {
            if (stroke.IsInvisible() || thickness <= 0)
            {
                return;
            }

            shape.Stroke = this.GetCachedBrush(stroke);

            switch (lineJoin)
            {
            case OxyPenLineJoin.Round:
                shape.StrokeLineJoin = PenLineJoin.Round;
                break;

            case OxyPenLineJoin.Bevel:
                shape.StrokeLineJoin = PenLineJoin.Bevel;
                break;

                // The default StrokeLineJoin is Miter
            }

            if (!thickness.Equals(1.0))
            {
                // default values is 1
                shape.StrokeThickness = thickness;
            }

            if (dashArray != null)
            {
                shape.StrokeDashArray = CreateDashArrayCollection(dashArray);
            }

            // shape.UseLayoutRounding = aliased;
        }
        public void DrawLines(IEnumerable <ScreenPoint> points, OxyColor stroke, double thickness, double[] dashArray,
                              OxyPenLineJoin lineJoin, bool aliased)
        {
            var  startPoint = new ScreenPoint();
            bool first      = true;

            foreach (var p in points)
            {
                if (!first)
                {
                    Add(new Line {
                        X1 = startPoint.X, Y1 = startPoint.Y, X2 = p.X, Y2 = p.Y
                    });
                }
                else
                {
                    startPoint = p;
                }
                first = !first;
            }
        }
Esempio n. 27
0
        /// <summary>
        /// Draws the multiple line segments defined by points (0,1) (2,3) (4,5) etc.
        /// This should have better performance than calling DrawLine for each segment.
        /// </summary>
        /// <param name="points">The points.</param>
        /// <param name="stroke">The stroke color.</param>
        /// <param name="thickness">The stroke thickness.</param>
        /// <param name="dashArray">The dash array.</param>
        /// <param name="lineJoin">The line join type.</param>
        /// <param name="aliased">if set to <c>true</c> the shape will be aliased.</param>
        public void DrawLineSegments(
            IList <ScreenPoint> points,
            OxyColor stroke,
            double thickness,
            double[] dashArray,
            OxyPenLineJoin lineJoin,
            bool aliased)
        {
            var path = new Path();

            this.SetStroke(path, stroke, thickness, lineJoin, dashArray, aliased);
            var pg = new PathGeometry();

            for (int i = 0; i + 1 < points.Count; i += 2)
            {
                // if (points[i].Y==points[i+1].Y)
                // {
                // var line = new Line();

                // line.X1 = 0.5+(int)points[i].X;
                // line.X2 = 0.5+(int)points[i+1].X;
                // line.Y1 = 0.5+(int)points[i].Y;
                // line.Y2 = 0.5+(int)points[i+1].Y;
                // SetStroke(line, OxyColors.DarkRed, thickness, lineJoin, dashArray, aliased);
                // Add(line);
                // continue;
                // }
                var figure = new PathFigure {
                    StartPoint = points[i].ToPoint(aliased), IsClosed = false
                };
                figure.Segments.Add(new LineSegment {
                    Point = points[i + 1].ToPoint(aliased)
                });
                pg.Figures.Add(figure);
            }

            path.Data = pg;
            this.Add(path);
        }
 private static Pen CreatePen(OxyColor stroke, double thickness, double[] dashArray,
                              OxyPenLineJoin lineJoin = OxyPenLineJoin.Miter)
 {
     if (stroke == null)
         return null;
     var pen = new Pen(stroke.ToBrush(), thickness);
     if (dashArray != null)
     {
         pen.DashStyle = new DashStyle(dashArray, 0);
     }
     switch (lineJoin)
     {
         case OxyPenLineJoin.Round:
             pen.LineJoin = PenLineJoin.Round;
             break;
         case OxyPenLineJoin.Bevel:
             pen.LineJoin = PenLineJoin.Bevel;
             break;
             //  The default LineJoin is Miter
     }
     return pen;
 }
        public void DrawLine(IList<ScreenPoint> points, OxyColor stroke, double thickness, double[] dashArray,
                             OxyPenLineJoin lineJoin, bool aliased)
        {
            var pen = CreatePen(stroke, thickness, dashArray, lineJoin);

            // todo: alias line
            //            if (aliased)
            //              .SetValue(RenderOptions.EdgeModeProperty, EdgeMode.Aliased);

            var lp = new Point();
            int i = 0;
            foreach (var point in points)
            {
                var p = point.ToPoint();
                if (i > 0)
                {
                    dc.DrawLine(pen, lp, p);
                }
                i++;
                lp = p;
            }
        }
Esempio n. 30
0
        /// <summary>
        /// Sets the stroke of the specified shape.
        /// </summary>
        /// <param name="shape">The shape.</param>
        /// <param name="stroke">The stroke.</param>
        /// <param name="thickness">The thickness.</param>
        /// <param name="lineJoin">The line join.</param>
        /// <param name="dashArray">The dash array.</param>
        /// <param name="aliased">aliased if set to <c>true</c>.</param>
        private void SetStroke(
            Shape shape,
            OxyColor stroke,
            double thickness,
            OxyPenLineJoin lineJoin        = OxyPenLineJoin.Miter,
            IEnumerable <double> dashArray = null,
            bool aliased = false)
        {
            if (stroke.IsVisible() && thickness > 0)
            {
                shape.Stroke = this.GetCachedBrush(stroke);

                switch (lineJoin)
                {
                case OxyPenLineJoin.Round:
                    shape.StrokeLineJoin = PenLineJoin.Round;
                    break;

                case OxyPenLineJoin.Bevel:
                    shape.StrokeLineJoin = PenLineJoin.Bevel;
                    break;

                    // The default StrokeLineJoin is Miter
                }

                shape.StrokeThickness = thickness;

                if (dashArray != null)
                {
                    shape.StrokeDashArray = CreateDashArrayCollection(dashArray);
                }

                if (aliased)
                {
                    // shape.UseLayoutRounding = aliased;
                }
            }
        }
Esempio n. 31
0
        /// <summary>
        /// Draws the polyline from the specified points.
        /// </summary>
        /// <param name="points">The points.</param>
        /// <param name="stroke">The stroke color.</param>
        /// <param name="thickness">The stroke thickness.</param>
        /// <param name="dashArray">The dash array.</param>
        /// <param name="lineJoin">The line join type.</param>
        /// <param name="aliased">if set to <c>true</c> the shape will be aliased.</param>
        public void DrawLine(
            IList <ScreenPoint> points,
            OxyColor stroke,
            double thickness,
            double[] dashArray,
            OxyPenLineJoin lineJoin,
            bool aliased)
        {
            var e = new Polyline();

            this.SetStroke(e, stroke, thickness, lineJoin, dashArray, aliased);

            var pc = new PointCollection();

            foreach (var p in points)
            {
                pc.Add(p.ToPoint(aliased));
            }

            e.Points = pc;

            this.Add(e);
        }
Esempio n. 32
0
        public void DrawLine(IList <ScreenPoint> points, OxyColor stroke, double thickness, double[] dashArray,
                             OxyPenLineJoin lineJoin, bool aliased)
        {
            var pen = CreatePen(stroke, thickness, dashArray, lineJoin);

            // todo: alias line
            //            if (aliased)
            //              .SetValue(RenderOptions.EdgeModeProperty, EdgeMode.Aliased);

            var lp = new Point();
            int i  = 0;

            foreach (var point in points)
            {
                var p = point.ToPoint();
                if (i > 0)
                {
                    dc.DrawLine(pen, lp, p);
                }
                i++;
                lp = p;
            }
        }
        /// <summary>
        /// Draws the line.
        /// </summary>
        /// <param name="points">The points.</param>
        /// <param name="stroke">The stroke.</param>
        /// <param name="thickness">The thickness.</param>
        /// <param name="dashArray">The dash array.</param>
        /// <param name="lineJoin">The line join.</param>
        /// <param name="aliased">if set to <c>true</c> [aliased].</param>
        public override void DrawLine(
            IList <ScreenPoint> points,
            OxyColor stroke,
            double thickness,
            double[] dashArray,
            OxyPenLineJoin lineJoin,
            bool aliased)
        {
            if (stroke == null || thickness <= 0 || points.Count < 2)
            {
                return;
            }

            this.g.SmoothingMode = aliased ? SmoothingMode.None : SmoothingMode.HighQuality;
            using (var pen = new Pen(this.ToColor(stroke), (float)thickness))
            {
                if (dashArray != null)
                {
                    pen.DashPattern = this.ToFloatArray(dashArray);
                }

                switch (lineJoin)
                {
                case OxyPenLineJoin.Round:
                    pen.LineJoin = LineJoin.Round;
                    break;

                case OxyPenLineJoin.Bevel:
                    pen.LineJoin = LineJoin.Bevel;
                    break;

                    // The default LineJoin is Miter
                }

                this.g.DrawLines(pen, this.ToPoints(points));
            }
        }
Esempio n. 34
0
        /// <summary>
        /// Draws the polyline from the specified points.
        /// </summary>
        /// <param name="points">The points.</param>
        /// <param name="stroke">The stroke color.</param>
        /// <param name="thickness">The stroke thickness.</param>
        /// <param name="dashArray">The dash array.</param>
        /// <param name="lineJoin">The line join type.</param>
        /// <param name="aliased">if set to <c>true</c> the shape will be aliased.</param>
        public override void DrawLine(
            IList <ScreenPoint> points,
            OxyColor stroke,
            double thickness,
            double[] dashArray,
            OxyPenLineJoin lineJoin,
            bool aliased)
        {
            if (stroke.IsInvisible() || thickness <= 0)
            {
                return;
            }

            this.g.SmoothingMode = aliased ? XSmoothingMode.None : XSmoothingMode.HighQuality;
            var pen = new XPen(ToColor(stroke), (float)thickness);

            if (dashArray != null)
            {
                pen.DashPattern = dashArray;
            }

            switch (lineJoin)
            {
            case OxyPenLineJoin.Round:
                pen.LineJoin = XLineJoin.Round;
                break;

            case OxyPenLineJoin.Bevel:
                pen.LineJoin = XLineJoin.Bevel;
                break;

                // The default LineJoin is Miter
            }

            this.g.DrawLines(pen, ToPoints(points));
        }
Esempio n. 35
0
        /// <summary>
        /// Draws the polygon within the specified clipping rectangle.
        /// </summary>
        /// <param name="rc">The render context.</param>
        /// <param name="clippingRectangle">The clipping rectangle.</param>
        /// <param name="points">The points.</param>
        /// <param name="minDistSquared">The squared minimum distance between points.</param>
        /// <param name="fill">The fill.</param>
        /// <param name="stroke">The stroke.</param>
        /// <param name="strokeThickness">The stroke thickness.</param>
        /// <param name="lineStyle">The line style.</param>
        /// <param name="lineJoin">The line join.</param>
        /// <param name="aliased">The aliased.</param>
        public static void DrawClippedPolygon(
            this IRenderContext rc,
            OxyRect clippingRectangle,
            IList <ScreenPoint> points,
            double minDistSquared,
            OxyColor fill,
            OxyColor stroke,
            double strokeThickness  = 1.0,
            LineStyle lineStyle     = LineStyle.Solid,
            OxyPenLineJoin lineJoin = OxyPenLineJoin.Miter,
            bool aliased            = false)
        {
            // TODO: minDistSquared should be implemented or removed
            if (rc.SetClip(clippingRectangle))
            {
                rc.DrawPolygon(points, fill, stroke, strokeThickness, lineStyle.GetDashArray(), lineJoin, aliased);
                rc.ResetClip();
                return;
            }

            var clippedPoints = SutherlandHodgmanClipping.ClipPolygon(clippingRectangle, points);

            rc.DrawPolygon(clippedPoints, fill, stroke, strokeThickness, lineStyle.GetDashArray(), lineJoin, aliased);
        }
        /// <summary>
        /// The draw line.
        /// </summary>
        /// <param name="points">
        /// The points.
        /// </param>
        /// <param name="stroke">
        /// The stroke.
        /// </param>
        /// <param name="thickness">
        /// The thickness.
        /// </param>
        /// <param name="dashArray">
        /// The dash array.
        /// </param>
        /// <param name="lineJoin">
        /// The line join.
        /// </param>
        /// <param name="aliased">
        /// The aliased.
        /// </param>
        public void DrawLine(
            IList<ScreenPoint> points,
            OxyColor stroke,
            double thickness,
            double[] dashArray,
            OxyPenLineJoin lineJoin,
            bool aliased)
        {
            var e = new Polyline();
            this.SetStroke(e, stroke, thickness, lineJoin, dashArray, aliased);

            var pc = new PointCollection();
            foreach (ScreenPoint p in points)
            {
                pc.Add(p.ToPoint(aliased));
            }

            e.Points = pc;

            this.Add(e);
        }
        /// <summary>
        /// Sets the stroke of the specified shape.
        /// </summary>
        /// <param name="shape">The shape.</param>
        /// <param name="stroke">The stroke.</param>
        /// <param name="thickness">The thickness.</param>
        /// <param name="lineJoin">The line join.</param>
        /// <param name="dashArray">The dash array.</param>
        /// <param name="aliased">aliased if set to <c>true</c>.</param>
        private void SetStroke(
            Shape shape,
            OxyColor stroke,
            double thickness,
            OxyPenLineJoin lineJoin = OxyPenLineJoin.Miter,
            IEnumerable<double> dashArray = null,
            bool aliased = false)
        {
            if (stroke.IsVisible() && thickness > 0)
            {
                shape.Stroke = this.GetCachedBrush(stroke);

                switch (lineJoin)
                {
                    case OxyPenLineJoin.Round:
                        shape.StrokeLineJoin = PenLineJoin.Round;
                        break;
                    case OxyPenLineJoin.Bevel:
                        shape.StrokeLineJoin = PenLineJoin.Bevel;
                        break;

                    // The default StrokeLineJoin is Miter
                }

                shape.StrokeThickness = thickness;

                if (dashArray != null)
                {
                    shape.StrokeDashArray = CreateDashArrayCollection(dashArray);
                }

                if (aliased)
                {
                    // shape.UseLayoutRounding = aliased;
                }
            }
        }
        public override void DrawPolygon(IList <ScreenPoint> points, OxyColor fill, OxyColor stroke, double thickness, double[] dashArray, OxyPenLineJoin lineJoin, bool aliased)
        {
//			gctx.SetAllowsAntialiasing(aliased);

            if (fill != null)
            {
                ToColor(fill).SetFill();
                var path = new CGPath();
                path.AddLines(points.Select(p => ToPoint(p)).ToArray());
                path.CloseSubpath();
                gctx.AddPath(path);
                gctx.DrawPath(CGPathDrawingMode.Fill);
            }

            if (stroke != null && thickness > 0)
            {
                SetAttributes(null, stroke, thickness);

                gctx.SetLineCap(ToLine(lineJoin));

                var path = new CGPath();


                path.AddLines(points.Select(p => ToPoint(p)).ToArray());
                path.CloseSubpath();
                gctx.AddPath(path);
                gctx.DrawPath(CGPathDrawingMode.Stroke);
            }
        }
        public void DrawPolygon(IList<ScreenPoint> points, OxyColor fill, OxyColor stroke, double thickness = 1, double[] dashArray = null, OxyPenLineJoin lineJoin = OxyPenLineJoin.Miter, bool aliased = false)
        {
            using (var paint = new Paint())
            {
                paint.AntiAlias = !aliased;
                paint.StrokeWidth = (float)thickness;
                using (var path = new Path())
                {
                    path.MoveTo((float)points[0].X, (float)points[0].Y);
                    for (int i = 1; i <= points.Count; i++)
                    {
                        path.LineTo((float)points[i % points.Count].X, (float)points[i % points.Count].Y);
                    }

                    if (fill != null)
                    {
                        paint.SetStyle(Paint.Style.Fill);
                        paint.Color = fill.ToColor();
                        canvas.DrawPath(path, paint);
                    }

                    if (stroke != null)
                    {
                        paint.SetStyle(Paint.Style.Stroke);
                        paint.Color = stroke.ToColor();
                        canvas.DrawPath(path, paint);
                    }
                }
            }
        }
		public override void DrawLine (IList<ScreenPoint> points, OxyColor stroke, double thickness, double[] dashArray, OxyPenLineJoin lineJoin, bool aliased)
		{
			if (stroke == null || thickness <= 0)
            {
                return;
            }

//			gctx.SetAllowsAntialiasing(aliased);

			gctx.SetLineCap(ToLine(lineJoin));

			SetAttributes (null, stroke, thickness);

            var path = new CGPath ();

            path.AddLines(points.Select(p => ToPoint(p)).ToArray());


            gctx.AddPath (path);
            gctx.DrawPath (CGPathDrawingMode.Stroke);
		}
        /// <summary>
        /// The draw clipped polygon.
        /// </summary>
        /// <param name="rc">
        /// The render context.
        /// </param>
        /// <param name="points">
        /// The points.
        /// </param>
        /// <param name="clippingRectangle">
        /// The clipping rectangle.
        /// </param>
        /// <param name="minDistSquared">
        /// The min dist squared.
        /// </param>
        /// <param name="fill">
        /// The fill.
        /// </param>
        /// <param name="stroke">
        /// The stroke.
        /// </param>
        /// <param name="strokeThickness">
        /// The stroke thickness.
        /// </param>
        /// <param name="lineStyle">
        /// The line style.
        /// </param>
        /// <param name="lineJoin">
        /// The line join.
        /// </param>
        /// <param name="aliased">
        /// The aliased.
        /// </param>
        public static void DrawClippedPolygon(
            this IRenderContext rc,
            IList<ScreenPoint> points,
            OxyRect clippingRectangle,
            double minDistSquared,
            OxyColor fill,
            OxyColor stroke,
            double strokeThickness = 1.0,
            LineStyle lineStyle = LineStyle.Solid,
            OxyPenLineJoin lineJoin = OxyPenLineJoin.Miter,
            bool aliased = false)
        {
            var clippedPoints = SutherlandHodgmanClipping.ClipPolygon(clippingRectangle, points);

            rc.DrawPolygon(
                clippedPoints, fill, stroke, strokeThickness, LineStyleHelper.GetDashArray(lineStyle), lineJoin, aliased);
        }
        /// <summary>
        /// The draw polygons.
        /// </summary>
        /// <param name="polygons">
        /// The polygons.
        /// </param>
        /// <param name="fill">
        /// The fill.
        /// </param>
        /// <param name="stroke">
        /// The stroke.
        /// </param>
        /// <param name="thickness">
        /// The thickness.
        /// </param>
        /// <param name="dashArray">
        /// The dash array.
        /// </param>
        /// <param name="lineJoin">
        /// The line join.
        /// </param>
        /// <param name="aliased">
        /// The aliased.
        /// </param>
        public void DrawPolygons(
            IList<IList<ScreenPoint>> polygons,
            OxyColor fill,
            OxyColor stroke,
            double thickness,
            double[] dashArray,
            OxyPenLineJoin lineJoin,
            bool aliased)
        {
            var path = new Path();
            this.SetStroke(path, stroke, thickness, lineJoin, dashArray, aliased);
            if (fill != null)
            {
                path.Fill = this.GetCachedBrush(fill);
            }

            var pg = new PathGeometry { FillRule = FillRule.Nonzero };
            foreach (var polygon in polygons)
            {
                var figure = new PathFigure { IsClosed = true };
                bool first = true;
                foreach (ScreenPoint p in polygon)
                {
                    if (first)
                    {
                        figure.StartPoint = p.ToPoint(aliased);
                        first = false;
                    }
                    else
                    {
                        figure.Segments.Add(new LineSegment { Point = p.ToPoint(aliased) });
                    }
                }

                pg.Figures.Add(figure);
            }

            path.Data = pg;
            this.Add(path);
        }
		public override void DrawPolygon (IList<ScreenPoint> points, OxyColor fill, OxyColor stroke, double thickness, double[] dashArray, OxyPenLineJoin lineJoin, bool aliased)
		{
//			gctx.SetAllowsAntialiasing(aliased);

            if (fill != null)
			{
				ToColor(fill).SetFill();
				var path = new CGPath ();
	            path.AddLines(points.Select(p => ToPoint(p)).ToArray());
				path.CloseSubpath();
				gctx.AddPath(path);
	            gctx.DrawPath (CGPathDrawingMode.Fill);
			}

            if (stroke != null && thickness > 0)
			{
				SetAttributes (null, stroke, thickness);

				gctx.SetLineCap(ToLine(lineJoin));

	            var path = new CGPath ();


	            path.AddLines(points.Select(p => ToPoint(p)).ToArray());
				path.CloseSubpath();
				gctx.AddPath(path);
	            gctx.DrawPath (CGPathDrawingMode.Stroke);
			}
		}
Esempio n. 44
0
        /// <summary>
        /// Draws multiple line segments defined by points (0,1) (2,3) (4,5) etc.
        /// This should have better performance than calling DrawLine for each segment.
        /// </summary>
        /// <param name="points">The points.</param>
        /// <param name="stroke">The stroke color.</param>
        /// <param name="thickness">The stroke thickness.</param>
        /// <param name="dashArray">The dash array.</param>
        /// <param name="lineJoin">The line join type.</param>
        /// <param name="aliased">If set to <c>true</c> the shape will be aliased.</param>
        public override void DrawLineSegments(IList<ScreenPoint> points, OxyColor stroke, double thickness, double[] dashArray, OxyPenLineJoin lineJoin, bool aliased)
        {
            this.paint.Reset();
            {
                this.SetStroke(stroke, thickness, dashArray, lineJoin, aliased);
                this.pts.Clear();
                if (aliased)
                {
                    foreach (var p in points)
                    {
                        this.pts.Add(this.ConvertAliased(p.X));
                        this.pts.Add(this.ConvertAliased(p.Y));
                    }
                }
                else
                {
                    foreach (var p in points)
                    {
                        this.pts.Add(this.Convert(p.X));
                        this.pts.Add(this.Convert(p.Y));
                    }
                }

                this.canvas.DrawLines(this.pts.ToArray(), this.paint);
            }
        }
 public void DrawPolygons(IList<IList<ScreenPoint>> polygons, OxyColor fill, OxyColor stroke, double thickness = 1, double[] dashArray = null, OxyPenLineJoin lineJoin = OxyPenLineJoin.Miter, bool aliased = false)
 {
     foreach (var p in polygons)
         this.DrawPolygon(p, fill, stroke, thickness, dashArray, lineJoin, aliased);
 }
        /// <summary>
        /// The draw polygon.
        /// </summary>
        /// <param name="points">
        /// The points.
        /// </param>
        /// <param name="fill">
        /// The fill.
        /// </param>
        /// <param name="stroke">
        /// The stroke.
        /// </param>
        /// <param name="thickness">
        /// The thickness.
        /// </param>
        /// <param name="dashArray">
        /// The dash array.
        /// </param>
        /// <param name="lineJoin">
        /// The line join.
        /// </param>
        /// <param name="aliased">
        /// The aliased.
        /// </param>
        public override void DrawPolygon(
            IList<ScreenPoint> points,
            OxyColor fill,
            OxyColor stroke,
            double thickness,
            double[] dashArray,
            OxyPenLineJoin lineJoin,
            bool aliased)
        {
            this.g.SmoothingMode = aliased ? SmoothingMode.None : SmoothingMode.HighQuality;

            PointF[] pts = this.ToPoints(points);
            if (fill != null)
            {
                this.g.FillPolygon(this.ToBrush(fill), pts);
            }

            if (stroke != null && thickness > 0)
            {
                var pen = new Pen(this.ToColor(stroke), (float)thickness);

                if (dashArray != null)
                {
                    pen.DashPattern = this.ToFloatArray(dashArray);
                }

                switch (lineJoin)
                {
                    case OxyPenLineJoin.Round:
                        pen.LineJoin = LineJoin.Round;
                        break;
                    case OxyPenLineJoin.Bevel:
                        pen.LineJoin = LineJoin.Bevel;
                        break;

                        // The default LineJoin is Miter
                }

                this.g.DrawPolygon(pen, pts);
            }
        }
        /// <summary>
        /// The draw line.
        /// </summary>
        /// <param name="points">
        /// The points.
        /// </param>
        /// <param name="stroke">
        /// The stroke.
        /// </param>
        /// <param name="thickness">
        /// The thickness.
        /// </param>
        /// <param name="dashArray">
        /// The dash array.
        /// </param>
        /// <param name="lineJoin">
        /// The line join.
        /// </param>
        /// <param name="aliased">
        /// The aliased.
        /// </param>
        public override void DrawLine(
            IList<ScreenPoint> points,
            OxyColor stroke,
            double thickness,
            double[] dashArray,
            OxyPenLineJoin lineJoin,
            bool aliased)
        {
            if (stroke == null || thickness <= 0)
            {
                return;
            }

            this.g.SmoothingMode = aliased ? SmoothingMode.None : SmoothingMode.HighQuality;
            var pen = new Pen(this.ToColor(stroke), (float)thickness);

            if (dashArray != null)
            {
                pen.DashPattern = this.ToFloatArray(dashArray);
            }

            switch (lineJoin)
            {
                case OxyPenLineJoin.Round:
                    pen.LineJoin = LineJoin.Round;
                    break;
                case OxyPenLineJoin.Bevel:
                    pen.LineJoin = LineJoin.Bevel;
                    break;

                    // The default LineJoin is Miter
            }

            this.g.DrawLines(pen, this.ToPoints(points));
        }
Esempio n. 48
0
        /// <summary>
        /// Draws a polygon. The polygon can have stroke and/or fill.
        /// </summary>
        /// <param name="points">The points.</param>
        /// <param name="fill">The fill color.</param>
        /// <param name="stroke">The stroke color.</param>
        /// <param name="thickness">The stroke thickness.</param>
        /// <param name="dashArray">The dash array.</param>
        /// <param name="lineJoin">The line join type.</param>
        /// <param name="aliased">If set to <c>true</c> the shape will be aliased.</param>
        public override void DrawPolygon(IList<ScreenPoint> points, OxyColor fill, OxyColor stroke, double thickness, double[] dashArray, OxyPenLineJoin lineJoin, bool aliased)
        {
            this.paint.Reset();
            {
                this.path.Reset();
                {
                    this.SetPath(points, aliased);
                    this.path.Close();

                    if (fill.IsVisible())
                    {
                        this.SetFill(fill);
                        this.canvas.DrawPath(this.path, this.paint);
                    }

                    if (stroke.IsVisible())
                    {
                        this.SetStroke(stroke, thickness, dashArray, lineJoin, aliased);
                        this.canvas.DrawPath(this.path, this.paint);
                    }
                }
            }
        }
        /// <summary>
        /// The draw line segments.
        /// </summary>
        /// <param name="points">
        /// The points.
        /// </param>
        /// <param name="stroke">
        /// The stroke.
        /// </param>
        /// <param name="thickness">
        /// The thickness.
        /// </param>
        /// <param name="dashArray">
        /// The dash array.
        /// </param>
        /// <param name="lineJoin">
        /// The line join.
        /// </param>
        /// <param name="aliased">
        /// The aliased.
        /// </param>
        public void DrawLineSegments(
            IList<ScreenPoint> points,
            OxyColor stroke,
            double thickness,
            double[] dashArray,
            OxyPenLineJoin lineJoin,
            bool aliased)
        {
            var path = new Path();
            this.SetStroke(path, stroke, thickness, lineJoin, dashArray, aliased);
            var pg = new PathGeometry();
            for (int i = 0; i + 1 < points.Count; i += 2)
            {
                // if (points[i].Y==points[i+1].Y)
                // {
                // var line = new Line();

                // line.X1 = 0.5+(int)points[i].X;
                // line.X2 = 0.5+(int)points[i+1].X;
                // line.Y1 = 0.5+(int)points[i].Y;
                // line.Y2 = 0.5+(int)points[i+1].Y;
                // SetStroke(line, OxyColors.DarkRed, thickness, lineJoin, dashArray, aliased);
                // Add(line);
                // continue;
                // }
                var figure = new PathFigure { StartPoint = points[i].ToPoint(aliased), IsClosed = false };
                figure.Segments.Add(new LineSegment { Point = points[i + 1].ToPoint(aliased) });
                pg.Figures.Add(figure);
            }

            path.Data = pg;
            this.Add(path);
        }
        /// <summary>
        /// Draws the clipped line segments.
        /// </summary>
        /// <param name="rc">The render context.</param>
        /// <param name="points">The points.</param>
        /// <param name="clippingRectangle">The clipping rectangle.</param>
        /// <param name="stroke">The stroke.</param>
        /// <param name="strokeThickness">The stroke thickness.</param>
        /// <param name="lineStyle">The line style.</param>
        /// <param name="lineJoin">The line join.</param>
        /// <param name="aliased">if set to <c>true</c> [aliased].</param>
        public static void DrawClippedLineSegments(
            this IRenderContext rc,
            IList<ScreenPoint> points,
            OxyRect clippingRectangle,
            OxyColor stroke,
            double strokeThickness,
            LineStyle lineStyle,
            OxyPenLineJoin lineJoin,
            bool aliased)
        {
            var clipping = new CohenSutherlandClipping(clippingRectangle.Left, clippingRectangle.Right, clippingRectangle.Top, clippingRectangle.Bottom);

            var clippedPoints = new List<ScreenPoint>(points.Count);
            for (int i = 0; i + 1 < points.Count; i += 2)
            {
                var s0 = points[i];
                var s1 = points[i + 1];
                if (clipping.ClipLine(ref s0, ref s1))
                {
                    clippedPoints.Add(s0);
                    clippedPoints.Add(s1);
                }
            }

            rc.DrawLineSegments(clippedPoints, stroke, strokeThickness, LineStyleHelper.GetDashArray(lineStyle), lineJoin, aliased);
        }
        /// <summary>
        /// The draw polygon.
        /// </summary>
        /// <param name="points">
        /// The points.
        /// </param>
        /// <param name="fill">
        /// The fill.
        /// </param>
        /// <param name="stroke">
        /// The stroke.
        /// </param>
        /// <param name="thickness">
        /// The thickness.
        /// </param>
        /// <param name="dashArray">
        /// The dash array.
        /// </param>
        /// <param name="lineJoin">
        /// The line join.
        /// </param>
        /// <param name="aliased">
        /// The aliased.
        /// </param>
        public void DrawPolygon(
            IList<ScreenPoint> points,
            OxyColor fill,
            OxyColor stroke,
            double thickness,
            double[] dashArray,
            OxyPenLineJoin lineJoin,
            bool aliased)
        {
            var po = new Polygon();
            this.SetStroke(po, stroke, thickness, lineJoin, dashArray, aliased);

            if (fill != null)
            {
                po.Fill = this.GetCachedBrush(fill);
            }

            var pc = new PointCollection();
            foreach (ScreenPoint p in points)
            {
                pc.Add(p.ToPoint(aliased));
            }

            po.Points = pc;

            this.Add(po);
        }
Esempio n. 52
0
 /// <summary>
 /// Draws the polygon from the specified points. The polygon can have stroke and/or fill.
 /// </summary>
 /// <param name="points">The points.</param>
 /// <param name="fill">The fill color.</param>
 /// <param name="stroke">The stroke color.</param>
 /// <param name="thickness">The stroke thickness.</param>
 /// <param name="dashArray">The dash array.</param>
 /// <param name="lineJoin">The line join type.</param>
 /// <param name="aliased">if set to <c>true</c> the shape will be aliased.</param>
 public override void DrawPolygon(
     IList<ScreenPoint> points,
     OxyColor fill,
     OxyColor stroke,
     double thickness,
     double[] dashArray,
     OxyPenLineJoin lineJoin,
     bool aliased)
 {
     this.w.WritePolygon(points, this.w.CreateStyle(fill, stroke, thickness, dashArray, lineJoin));
 }
        /// <summary>
        /// Sets the stroke properties of the specified shape.
        /// </summary>
        /// <param name="shape">
        /// The shape.
        /// </param>
        /// <param name="stroke">
        /// The stroke.
        /// </param>
        /// <param name="thickness">
        /// The thickness.
        /// </param>
        /// <param name="lineJoin">
        /// The line join.
        /// </param>
        /// <param name="dashArray">
        /// The dash array.
        /// </param>
        /// <param name="aliased">
        /// The aliased.
        /// </param>
        private void SetStroke(
            Shape shape,
            OxyColor stroke,
            double thickness,
            OxyPenLineJoin lineJoin = OxyPenLineJoin.Miter,
            double[] dashArray = null,
            bool aliased = false)
        {
            if (stroke != null && thickness > 0)
            {
                shape.Stroke = this.GetCachedBrush(stroke);

                switch (lineJoin)
                {
                    case OxyPenLineJoin.Round:
                        shape.StrokeLineJoin = PenLineJoin.Round;
                        break;
                    case OxyPenLineJoin.Bevel:
                        shape.StrokeLineJoin = PenLineJoin.Bevel;
                        break;

                    // The default StrokeLineJoin is Miter
                }

                if (!thickness.Equals(1.0))
                {
                    // default values is 1
                    shape.StrokeThickness = thickness;
                }

                if (dashArray != null)
                {
                    shape.StrokeDashArray = CreateDashArrayCollection(dashArray);
                }
            }

            // shape.UseLayoutRounding = aliased;
        }
        public override void DrawLine(IList <ScreenPoint> points, OxyColor stroke, double thickness, double[] dashArray, OxyPenLineJoin lineJoin, bool aliased)
        {
            if (stroke == null || thickness <= 0)
            {
                return;
            }

//			gctx.SetAllowsAntialiasing(aliased);

            gctx.SetLineCap(ToLine(lineJoin));

            SetAttributes(null, stroke, thickness);

            var path = new CGPath();

            path.AddLines(points.Select(p => ToPoint(p)).ToArray());


            gctx.AddPath(path);
            gctx.DrawPath(CGPathDrawingMode.Stroke);
        }
Esempio n. 55
0
        /// <summary>
        /// Creates a style.
        /// </summary>
        /// <param name="fill">The fill color.</param>
        /// <param name="stroke">The stroke color.</param>
        /// <param name="thickness">The stroke thickness (in user units).</param>
        /// <param name="dashArray">The line dash array.</param>
        /// <param name="lineJoin">The line join type.</param>
        /// <returns>A style string.</returns>
        public string CreateStyle(
            OxyColor fill,
            OxyColor stroke,
            double thickness,
            double[] dashArray = null,
            OxyPenLineJoin lineJoin = OxyPenLineJoin.Miter)
        {
            // http://oreilly.com/catalog/svgess/chapter/ch03.html
            var style = new StringBuilder();
            if (fill.IsInvisible())
            {
                style.AppendFormat("fill:none;");
            }
            else
            {
                style.AppendFormat("fill:{0};", this.ColorToString(fill));
                if (fill.A != 0xFF)
                {
                    style.AppendFormat(CultureInfo.InvariantCulture, "fill-opacity:{0};", fill.A / 255.0);
                }
            }

            if (stroke.IsInvisible())
            {
                style.AppendFormat("stroke:none;");
            }
            else
            {
                string formatString = "stroke:{0};stroke-width:{1:" + this.NumberFormat + "}";
                style.AppendFormat(CultureInfo.InvariantCulture, formatString, this.ColorToString(stroke), thickness);
                switch (lineJoin)
                {
                    case OxyPenLineJoin.Round:
                        style.AppendFormat(";stroke-linejoin:round");
                        break;
                    case OxyPenLineJoin.Bevel:
                        style.AppendFormat(";stroke-linejoin:bevel");
                        break;
                }

                if (stroke.A != 0xFF)
                {
                    style.AppendFormat(CultureInfo.InvariantCulture, ";stroke-opacity:{0}", stroke.A / 255.0);
                }

                if (dashArray != null && dashArray.Length > 0)
                {
                    style.Append(";stroke-dasharray:");
                    for (int i = 0; i < dashArray.Length; i++)
                    {
                        style.AppendFormat(
                            CultureInfo.InvariantCulture, "{0}{1}", i > 0 ? "," : string.Empty, dashArray[i]);
                    }
                }
            }

            return style.ToString();
        }
Esempio n. 56
0
 /// <summary>
 /// Draws a polyline.
 /// </summary>
 /// <param name="points">The points.</param>
 /// <param name="stroke">The stroke color.</param>
 /// <param name="thickness">The stroke thickness.</param>
 /// <param name="dashArray">The dash array.</param>
 /// <param name="lineJoin">The line join type.</param>
 /// <param name="aliased">if set to <c>true</c> the shape will be aliased.</param>
 public override void DrawLine(IList<ScreenPoint> points, OxyColor stroke, double thickness, double[] dashArray, OxyPenLineJoin lineJoin, bool aliased)
 {
     this.paint.Reset();
     {
         this.path.Reset();
         {
             this.SetPath(points, aliased);
             this.SetStroke(stroke, thickness, dashArray, lineJoin, aliased);
             this.canvas.DrawPath(this.path, this.paint);
         }
     }
 }
		private CGLineCap ToLine (OxyPenLineJoin lineJoin)
		{
			switch(lineJoin)
			{
			case OxyPenLineJoin.Bevel:
				return CGLineCap.Butt;
			case OxyPenLineJoin.Miter:
				return CGLineCap.Square;
			case OxyPenLineJoin.Round:
				return CGLineCap.Round;
			}

			return CGLineCap.Square;
		}
Esempio n. 58
0
        /// <summary>
        /// Sets the stroke style.
        /// </summary>
        /// <param name="stroke">The stroke color.</param>
        /// <param name="thickness">The stroke thickness.</param>
        /// <param name="dashArray">The dash array.</param>
        /// <param name="lineJoin">The line join.</param>
        /// <param name="aliased">Use aliased strokes if set to <c>true</c>.</param>
        private void SetStroke(OxyColor stroke, double thickness, double[] dashArray = null, OxyPenLineJoin lineJoin = OxyPenLineJoin.Miter, bool aliased = false)
        {
            this.paint.SetStyle(Paint.Style.Stroke);
            this.paint.Color = stroke.ToColor();
            this.paint.StrokeWidth = this.Convert(thickness);
            this.paint.StrokeJoin = lineJoin.Convert();
            if (dashArray != null)
            {
                var dashArrayF = dashArray.Select(this.Convert).ToArray();
                this.paint.SetPathEffect(new DashPathEffect(dashArrayF, 0f));
            }

            this.paint.AntiAlias = !aliased;
        }
        /// <summary>
        /// Draws the clipped line.
        /// </summary>
        /// <param name="rc">The render context.</param>
        /// <param name="points">The points.</param>
        /// <param name="clippingRectangle">The clipping rectangle.</param>
        /// <param name="minDistSquared">The min dist squared.</param>
        /// <param name="stroke">The stroke.</param>
        /// <param name="strokeThickness">The stroke thickness.</param>
        /// <param name="lineStyle">The line style.</param>
        /// <param name="lineJoin">The line join.</param>
        /// <param name="aliased">if set to <c>true</c> [aliased].</param>
        /// <param name="pointsRendered">The points rendered callback.</param>
        public static void DrawClippedLine(
            this IRenderContext rc,
            IList<ScreenPoint> points,
            OxyRect clippingRectangle,
            double minDistSquared,
            OxyColor stroke,
            double strokeThickness,
            LineStyle lineStyle,
            OxyPenLineJoin lineJoin,
            bool aliased,
            Action<IList<ScreenPoint>> pointsRendered = null)
        {
            var clipping = new CohenSutherlandClipping(
                clippingRectangle.Left, clippingRectangle.Right, clippingRectangle.Top, clippingRectangle.Bottom);

            var pts = new List<ScreenPoint>();
            int n = points.Count;
            if (n > 0)
            {

                if (n == 1)
                {
                    pts.Add(points[0]);
                }

                var last = points[0];
                for (int i = 1; i < n; i++)
                {
                    var s0 = points[i - 1];
                    var s1 = points[i];

                    // Clipped version of this and next point.
                    var s0c = s0;
                    var s1c = s1;
                    bool isInside = clipping.ClipLine(ref s0c, ref s1c);
                    s0 = s1;

                    if (!isInside)
                    {
                        // keep the previous coordinate
                        continue;
                    }

                    // render from s0c-s1c
                    double dx = s1c.x - last.x;
                    double dy = s1c.y - last.y;

                    if (dx * dx + dy * dy > minDistSquared || i == 1 || i == n - 1)
                    {
                        if (!s0c.Equals(last) || i == 1)
                        {
                            pts.Add(s0c);
                        }

                        pts.Add(s1c);
                        last = s1c;
                    }

                    // render the line if we are leaving the clipping region););
                    if (!clipping.IsInside(s1))
                    {
                        if (pts.Count > 0)
                        {
                            rc.DrawLine(
                                pts, stroke, strokeThickness, LineStyleHelper.GetDashArray(lineStyle), lineJoin, aliased);
                            if (pointsRendered != null)
                            {
                                pointsRendered(pts);
                            }
                            pts = new List<ScreenPoint>();
                        }
                    }
                }

                // Check if the line contains two points and they are at the same point
                if (pts.Count == 2)
                {
                    if (pts[0].DistanceTo(pts[1]) < 1)
                    {
                        // Modify to a small horizontal line to make sure it is being rendered
                        pts[1] = new ScreenPoint(pts[0].X + 1, pts[0].Y);
                        pts[0] = new ScreenPoint(pts[0].X - 1, pts[0].Y);
                    }
                }

                // Check if the line contains a single point
                if (pts.Count == 1)
                {
                    // Add a second point to make sure the line is being rendered as a small dot
                    pts.Add(new ScreenPoint(pts[0].X + 1, pts[0].Y));
                    pts[0] = new ScreenPoint(pts[0].X - 1, pts[0].Y);
                }

                if (pts.Count > 0)
                {
                    rc.DrawLine(pts, stroke, strokeThickness, LineStyleHelper.GetDashArray(lineStyle), lineJoin, aliased);

                    // Execute the 'callback'.
                    if (pointsRendered != null)
                    {
                        pointsRendered(pts);
                    }
                }
            }
        }
        /// <summary>
        /// Creates the specified pen.
        /// </summary>
        /// <param name="color">The color.</param>
        /// <param name="thickness">The thickness.</param>
        /// <param name="lineStyle">The line style.</param>
        /// <param name="lineJoin">The line join.</param>
        /// <returns>A pen.</returns>
        public static OxyPen Create(
            OxyColor color,
            double thickness,
            LineStyle lineStyle = LineStyle.Solid,
            OxyPenLineJoin lineJoin = OxyPenLineJoin.Miter)
        {
            if (color == null || lineStyle == LineStyle.None || Math.Abs(thickness) < double.Epsilon)
            {
                return null;
            }

            return new OxyPen(color, thickness, lineStyle, lineJoin);
        }