protected override void DrawInternal(IRenderContext2D context, IEnumerable<Point> centers, IPen2D pen, IBrush2D brush) { double halfWidth = Width / 2; double halfHeight = Height / 2; foreach (var center in centers) { double top = center.Y - halfHeight; double bottom = center.Y + halfHeight; double left = center.X - halfWidth; double right = center.X + halfWidth; // x0 // //x1 x2 var points = new[] { new Point(right,top), new Point(right,bottom), new Point(left,bottom), new Point(right,top) }; context.FillPolygon(brush, points); context.DrawLines(pen, points); } }
private void DrawDiamond(IRenderContext2D context, Point center, double width, double height, IPen2D stroke, IBrush2D fill) { double top = center.Y - height; double bottom = center.Y + height; double left = center.X - width; double right = center.X + width; var diamondPoints = new[] { // Points drawn like this: // // x0 (x4 in same location as x0) // // x3 x1 // // x2 new Point(center.X, top), new Point(right, center.Y), new Point(center.X, bottom), new Point(left, center.Y), new Point(center.X, top), }; context.FillPolygon(fill, diamondPoints); context.DrawLines(stroke, diamondPoints); }
private void CustomDraw(IRenderContext2D renderContext) { foreach (var p in polygonList) { Polygon polygon = p.Value.polygon; if (polygon.Points.Count > 0) { Point initialPoint = GetRenderingPoint(polygon.Points[0]); System.Windows.Media.Color backgroundColor = System.Windows.Media.Color.FromArgb(p.Value.backgroundColor.A, p.Value.backgroundColor.R, p.Value.backgroundColor.G, p.Value.backgroundColor.B); using (var brush = renderContext.CreateBrush(backgroundColor)) { //IEnumerable<Point> points; // define your points renderContext.FillPolygon(brush, GetRenderingPoints(polygon.Points)); } //// Create a pen to draw. Make sure you dispose it! System.Windows.Media.Color borderColor = System.Windows.Media.Color.FromArgb(p.Value.borderColor.A, p.Value.borderColor.R, p.Value.borderColor.G, p.Value.borderColor.B); using (var linePen = renderContext.CreatePen(borderColor, this.AntiAliasing, p.Value.borderWidth, p.Value.borderOpacity, p.Value.borderDashPattern)) { using (var lineDrawingContext = renderContext.BeginLine(linePen, initialPoint.X, initialPoint.Y)) { for (int i = 1; i < polygon.Points.Count; i++) { lineDrawingContext.MoveTo(GetRenderingPoint(polygon.Points[i]).X, GetRenderingPoint(polygon.Points[i]).Y); } lineDrawingContext.End(); } } } } }
protected override void DrawInternal(IRenderContext2D context, IEnumerable<Point> centers, IPen2D pen, IBrush2D brush) { float width2 = (float)(Width * 0.5); float height2 = (float)(Height * 0.5); foreach (var center in centers) { double top = center.Y - height2; double bottom = center.Y + height2; double left = center.X - width2; double right = center.X + width2; var diamondPoints = new[] { // Points drawn like this: // // x0 (x4 in same location as x0) // // x3 x1 // // x2 new Point(center.X, top), // x0 new Point(right, center.Y), // x1 new Point(center.X, bottom), // x2 new Point(left, center.Y), // x3 new Point(center.X, top), // x4 == x0 }; context.FillPolygon(brush, diamondPoints); context.DrawLines(pen, diamondPoints); } }
protected override void RenderToCache(IRenderContext2D context, IPen2D strokePen, IBrush2D fillBrush) { var offset = 2d; var polygon = new Point[] { new Point(Width / 2, 0), new Point(Width / 2 + offset, Height / 2 - offset), new Point(Width, Height / 2), new Point(Width / 2 + offset, Height / 2 + offset), new Point(Width / 2, Height), new Point(Width / 2 - offset, Height / 2 + offset), new Point(0, Height / 2), new Point(Width / 2 - offset, Height / 2 - offset), new Point(Width / 2, 0) }; context.FillPolygon(fillBrush, polygon); context.DrawLines(strokePen, polygon); }
protected override void Draw(IRenderContext2D renderContext, IRenderPassData renderPassData) { base.Draw(renderContext, renderPassData); // Create a line drawing context. Make sure you dispose it! // NOTE: You can create mutliple line drawing contexts to draw segments if you want // You can also call renderContext.DrawLine() and renderContext.DrawLines(), but the lineDrawingContext is higher performance foreach (var p in polygonList) { Polygon polygon = p.Value.polygon; if (polygon.Points.Count > 0) { Point initialPoint = GetRenderingPoint(polygon.Points[0]); System.Windows.Media.Color backgroundColor = System.Windows.Media.Color.FromArgb(p.Value.backgroundColor.A, p.Value.backgroundColor.R, p.Value.backgroundColor.G, p.Value.backgroundColor.B); using (var brush = renderContext.CreateBrush(backgroundColor)) { //IEnumerable<Point> points; // define your points renderContext.FillPolygon(brush, GetRenderingPoints(polygon.Points)); } //// Create a pen to draw. Make sure you dispose it! System.Windows.Media.Color borderColor = System.Windows.Media.Color.FromArgb(p.Value.borderColor.A, p.Value.borderColor.R, p.Value.borderColor.G, p.Value.borderColor.B); using (var linePen = renderContext.CreatePen(borderColor, this.AntiAliasing, p.Value.borderWidth, p.Value.borderOpacity, p.Value.borderDashPattern)) { using (var lineDrawingContext = renderContext.BeginLine(linePen, initialPoint.X, initialPoint.Y)) { for (int i = 1; i < polygon.Points.Count; i++) { lineDrawingContext.MoveTo(GetRenderingPoint(polygon.Points[i]).X, GetRenderingPoint(polygon.Points[i]).Y); } lineDrawingContext.End(); } } } } }
public override void Draw(IRenderContext2D context, IEnumerable <Point> centers) { var fill = context.CreateBrush(Fill); var stroke = context.CreatePen(Stroke, AntiAliasing, (float)StrokeThickness); float width2 = (float)(Width * 0.5); float height2 = (float)(Height * 0.5); foreach (var center in centers) { double top = center.Y - height2; double bottom = center.Y + height2; double left = center.X - width2; double right = center.X + width2; var diamondPoints = new[] { // Points drawn like this: // // x0 (x4 in same location as x0) // // x3 x1 // // x2 new Point(center.X, top), // x0 new Point(right, center.Y), // x1 new Point(center.X, bottom), // x2 new Point(left, center.Y), // x3 new Point(center.X, top), // x4 == x0 }; context.FillPolygon(fill, diamondPoints); context.DrawLines(stroke, diamondPoints); } }