/// <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, OxyPlot.LineJoin lineJoin, bool aliased) { var path = new PathGeometry(this.d2dFactory); var sink = path.Open(); foreach (var points in polygons) { sink.BeginFigure(points[0].ToVector2(aliased), new FigureBegin()); sink.AddLines(points.Skip(1).Select(pt => (dx.Mathematics.Interop.RawVector2)pt.ToVector2(aliased)).ToArray()); sink.EndFigure(new FigureEnd()); } sink.Close(); sink.Dispose(); var strokeStyle = this.GetStroke(dashArray, lineJoin); this.renderUnits.Add(new GeometryRenderUnit(path, this.GetBrush(stroke), this.GetBrush(fill), (float)thickness, strokeStyle)); }
/// <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, OxyPlot.LineJoin lineJoin, bool aliased) { if (stroke.IsVisible() && thickness > 0 && points.Count >= 2) { // g.SmoothingMode = aliased ? SmoothingMode.None : SmoothingMode.HighQuality; // TODO: Smoothing modes this.g.Save(); this.g.SetSourceColor(stroke); this.g.LineJoin = lineJoin.ToLineJoin(); this.g.LineWidth = thickness; if (dashArray != null) { this.g.SetDash(dashArray, 0); } this.g.MoveTo(points[0].ToPointD(aliased)); foreach (var point in points.Skip(1)) { this.g.LineTo(point.ToPointD(aliased)); } this.g.Stroke(); this.g.Restore(); } }
/// <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, OxyPlot.LineJoin lineJoin, bool aliased) { var path = new PathGeometry(this.d2dFactory); var sink = path.Open(); for (int i = 0; i + 1 < points.Count; i += 2) { sink.BeginFigure(points[i].ToVector2(aliased), new FigureBegin()); sink.AddLine(points[i + 1].ToVector2(aliased)); sink.EndFigure(new FigureEnd()); } sink.Close(); sink.Dispose(); var strokeStyle = this.GetStroke(dashArray, lineJoin); this.renderUnits.Add(new GeometryRenderUnit(path, this.GetBrush(stroke), null, (float)thickness, strokeStyle)); }
/// <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, OxyPlot.LineJoin lineJoin, bool aliased) { if (points.Count <= 1) { return; } var path = new PathGeometry(this.d2dFactory); var sink = path.Open(); sink.BeginFigure(points[0].ToVector2(aliased), FigureBegin.Hollow); sink.AddLines(points.Skip(1).Select(pt => (dx.Mathematics.Interop.RawVector2)pt.ToVector2(aliased)).ToArray()); sink.EndFigure(FigureEnd.Open); sink.Close(); sink.Dispose(); var strokeStyle = this.GetStroke(dashArray, lineJoin); this.renderUnits.Add(new GeometryRenderUnit(path, this.GetBrush(stroke), null, (float)thickness, strokeStyle)); }
/// <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="renderingMode">The edge rendering mode.</param> /// <param name="dashArray">The dash array.</param> /// <param name="lineJoin">The line join.</param> public override void DrawPolygon( IList <ScreenPoint> points, OxyColor fill, OxyColor stroke, double thickness, EdgeRenderingMode renderingMode, double[] dashArray, OxyPlot.LineJoin lineJoin) { bool aliased = !ShouldUseAntiAliasingForEllipse(renderingMode); if (fill.IsVisible() && points.Count >= 2) { // g.SmoothingMode = aliased ? SmoothingMode.None : SmoothingMode.HighQuality; // TODO: Smoothing modes this.g.Save(); this.g.SetSourceColor(fill); this.g.LineJoin = lineJoin.ToLineJoin(); this.g.LineWidth = thickness; if (dashArray != null) { this.g.SetDash(dashArray, 0); } this.g.MoveTo(points[0].ToPointD(aliased)); foreach (var point in points.Skip(1)) { this.g.LineTo(point.ToPointD(aliased)); } // g.LineTo(points[0].ToPointD(aliased)); this.g.ClosePath(); this.g.Fill(); this.g.Restore(); } if (stroke.IsVisible() && thickness > 0 && points.Count >= 2) { // g.SmoothingMode = aliased ? SmoothingMode.None : SmoothingMode.HighQuality; // TODO: Smoothing modes this.g.Save(); this.g.SetSourceColor(stroke); this.g.LineJoin = lineJoin.ToLineJoin(); this.g.LineWidth = thickness; if (dashArray != null) { this.g.SetDash(dashArray, 0); } this.g.MoveTo(points[0].ToPointD(aliased)); foreach (var point in points.Skip(1)) { this.g.LineTo(point.ToPointD(aliased)); } this.g.ClosePath(); this.g.Stroke(); this.g.Restore(); } }
/// <summary> /// Initializes a new instance of the <see cref="GraphicsPenDescription" /> class. /// </summary> /// <param name="color">The color.</param> /// <param name="thickness">The thickness.</param> /// <param name="dashArray">The dash array.</param> /// <param name="lineJoin">The line join.</param> public GraphicsPenDescription(OxyColor color, double thickness, double[] dashArray = null, OxyPlot.LineJoin lineJoin = OxyPlot.LineJoin.Miter) { Color = color; Thickness = thickness; DashArray = dashArray; LineJoin = lineJoin; cachedHashCode = ComputeHashCode(); }
/// <summary> /// Gets the stroke. /// </summary> /// <param name="dashArray">The dashes array.</param> /// <param name="lineJoin">The line join type.</param> /// <returns>Returns stroke stroke style.</returns> private StrokeStyle GetStroke(double[] dashArray, OxyPlot.LineJoin lineJoin) { if (dashArray == null) { return(new StrokeStyle(this.d2dFactory, new StrokeStyleProperties { LineJoin = lineJoin.ToDXLineJoin() })); } return(new StrokeStyle(this.d2dFactory, new StrokeStyleProperties { LineJoin = lineJoin.ToDXLineJoin(), DashStyle = DashStyle.Custom }, dashArray.Select(x => (float)x).ToArray())); }
/// <summary> /// Converts an <see cref="OxyPlot.LineJoin" /> to a <see cref="LineJoin" />. /// </summary> /// <param name="lineJoin">The <see cref="OxyPlot.LineJoin" /> to convert.</param> /// <returns>The converted value.</returns> public static LineJoin ToLineJoin(this OxyPlot.LineJoin lineJoin) { switch (lineJoin) { case OxyPlot.LineJoin.Round: return(LineJoin.Round); case OxyPlot.LineJoin.Bevel: return(LineJoin.Bevel); default: return(LineJoin.Miter); } }
/// <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, OxyPlot.LineJoin lineJoin, bool aliased) { if (points.Count < 2) { return; } this.g.SmoothingMode = aliased ? SmoothingMode.None : SmoothingMode.HighQuality; var pts = this.ToPoints(points); if (fill != null) { this.g.FillPolygon(fill.ToBrush(), pts); } if (stroke != null && thickness > 0) { using (var pen = new Pen(stroke.ToColor(), (float)thickness)) { if (dashArray != null) { pen.DashPattern = this.ToFloatArray(dashArray); } switch (lineJoin) { case OxyPlot.LineJoin.Round: pen.LineJoin = System.Drawing.Drawing2D.LineJoin.Round; break; case OxyPlot.LineJoin.Bevel: pen.LineJoin = System.Drawing.Drawing2D.LineJoin.Bevel; break; // The default LineJoin is Miter } this.g.DrawPolygon(pen, pts); } } }
/// <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, OxyPlot.LineJoin 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(stroke.ToColor(), (float)thickness)) { if (dashArray != null) { pen.DashPattern = this.ToFloatArray(dashArray); } switch (lineJoin) { case OxyPlot.LineJoin.Round: pen.LineJoin = System.Drawing.Drawing2D.LineJoin.Round; break; case OxyPlot.LineJoin.Bevel: pen.LineJoin = System.Drawing.Drawing2D.LineJoin.Bevel; break; // The default LineJoin is Miter } this.g.DrawLines(pen, this.ToPoints(points)); } }