public void PatternsAndImages (Context ctx, double x, double y) { ctx.Save (); ctx.Translate (x, y); ctx.SetColor (Colors.Black); // Dashed lines ctx.SetLineWidth (2); ctx.SetLineDash (15, 10, 10, 5, 5); ctx.Rectangle (10, 10, 100, 100); ctx.Stroke (); ctx.SetLineDash (0); // Image var arcColor = new Color (1, 0, 1); ImageBuilder ib = new ImageBuilder (30, 30); ib.Context.Arc (15, 15, 15, 0, 360); ib.Context.SetColor (arcColor); ib.Context.Fill (); ib.Context.SetColor (Colors.DarkKhaki); ib.Context.Rectangle (0, 0, 5, 5); ib.Context.Fill (); var img = ib.ToVectorImage (); ctx.DrawImage (img, 0, 0); ctx.DrawImage (img, 0, 50, 50, 10); ctx.Arc (100, 100, 15, 0, 360); arcColor.Alpha = 0.4; ctx.SetColor (arcColor); ctx.Fill (); // ImagePattern ctx.Save (); ctx.Translate (x + 130, y); ctx.Pattern = new ImagePattern (img); ctx.Rectangle (0, 0, 100, 100); ctx.Fill (); ctx.Restore (); ctx.Restore (); // Setting pixels ctx.SetLineWidth (1); for (int i=0; i<50;i++) { for (var j=0; j<50;j++) { Color c = Color.FromHsl (0.5, (double)i / 50d, (double)j / 50d); ctx.Rectangle (i, j, 1, 1); ctx.SetColor (c); ctx.Fill (); } } }
public void Path (Context ctx, double px, double py) { ctx.Save (); ctx.Translate (px, py); var path = new DrawingPath (); path.MoveTo (0.44, 18); path.LineTo (-1, 18); path.LineTo (-1, 26); path.LineTo (0.44, 26); path.LineTo (0, 42); path.LineTo (29, 21.98); path.LineTo (29, 21.98); path.LineTo (0, 2); path.LineTo (0.44, 18); ctx.AppendPath (path); ctx.SetColor (Colors.Black); ctx.SetLineWidth (2); ctx.Stroke (); var path2 = path.CopyPath (); path2.LineTo (15, 8); path2.ClosePath (); ctx.Rotate (180); ctx.AppendPath (path2); ctx.SetColor (Colors.Red); ctx.SetLineDash (0, 5); ctx.Stroke (); ctx.Restore (); }
/// <summary> /// Draws the line plot using the Context and Physical Axes provided /// </summary> /// <param name="ctx">The Drawing Context with which to draw.</param> /// <param name="xAxis">The X-Axis to draw against.</param> /// <param name="yAxis">The Y-Axis to draw against.</param> /// <param name="drawShadow">If true draw the shadow for the line. If false, draw line.</param> public void DrawLineOrShadow(Context ctx, PhysicalAxis xAxis, PhysicalAxis yAxis, bool drawShadow) { SequenceAdapter data = new SequenceAdapter (DataSource, DataMember, OrdinateData, AbscissaData); ITransform2D t = Transform2D.GetTransformer (xAxis, yAxis); int numberPoints = data.Count; if (data.Count == 0) { return; } ctx.Save (); ctx.SetLineWidth (lineWidth); if (lineDash != null) { ctx.SetLineDash (0, lineDash); } if (numberPoints == 1) { Point physical = t.Transform (data[0]); if (drawShadow) { ctx.SetColor (shadowColor); ctx.MoveTo (physical.X - 0.5 + ShadowOffset.X, physical.Y + ShadowOffset.Y); ctx.LineTo (physical.X + 0.5 + ShadowOffset.X, physical.Y + ShadowOffset.Y); ctx.Stroke (); } else { ctx.SetColor (lineColor); ctx.MoveTo (physical.X-0.5, physical.Y); ctx.LineTo (physical.X+0.5, physical.Y); ctx.Stroke (); } } else { // prepare for clipping double leftCutoff = xAxis.PhysicalToWorld (xAxis.PhysicalMin, false); double rightCutoff = xAxis.PhysicalToWorld (xAxis.PhysicalMax, false); if (leftCutoff > rightCutoff) { Utils.Swap (ref leftCutoff, ref rightCutoff); } if (drawShadow) { // correct cut-offs double shadowCorrection = xAxis.PhysicalToWorld (ShadowOffset, false) - xAxis.PhysicalToWorld (new Point(0,0), false); leftCutoff -= shadowCorrection; rightCutoff -= shadowCorrection; } for (int i = 1; i < numberPoints; ++i) { // check to see if any values null. If so, then continue. double dx1 = data[i-1].X; double dx2 = data[i].X; double dy1 = data[i-1].Y; double dy2 = data[i].Y; if (Double.IsNaN(dx1) || Double.IsNaN(dy1) || Double.IsNaN(dx2) || Double.IsNaN(dy2)) { continue; } // do horizontal clipping here, to speed up if ((dx1 < leftCutoff && dx2 < leftCutoff) || (rightCutoff < dx1 && rightCutoff < dx2)) { continue; } // else draw line. Point p1 = t.Transform (data[i-1]); Point p2 = t.Transform (data[i]); // when very far zoomed in, points can fall ontop of each other, // and g.DrawLine throws an overflow exception if (p1.Equals(p2)) { continue; } if (drawShadow) { ctx.SetColor (shadowColor); ctx.MoveTo (p1.X + ShadowOffset.X, p1.Y + ShadowOffset.Y); ctx.LineTo (p2.X + ShadowOffset.X, p2.Y + ShadowOffset.Y); ctx.Stroke (); } else { ctx.SetColor (lineColor); ctx.MoveTo (p1.X, p1.Y); ctx.LineTo (p2.X, p2.Y); ctx.Stroke (); } } } ctx.Restore (); }
protected override void OnDraw(Xwt.Drawing.Context ctx) { base.OnDraw(ctx); // Simple rectangles ctx.SetLineWidth(1); ctx.Rectangle(100, 5, 10, 10); ctx.SetColor(Color.Black); ctx.Fill(); ctx.Rectangle(115, 5, 10, 10); ctx.SetColor(Color.Black); ctx.Stroke(); // ctx.SetLineWidth(3); ctx.Rectangle(100, 20, 10, 10); ctx.SetColor(Color.Black); ctx.Fill(); ctx.Rectangle(115, 20, 10, 10); ctx.SetColor(Color.Black); ctx.Stroke(); // Rectangle with hole ctx.Rectangle(10, 100, 40, 40); ctx.MoveTo(45, 135); ctx.RelLineTo(0, -20); ctx.RelLineTo(-20, 0); ctx.RelLineTo(0, 20); ctx.ClosePath(); ctx.SetColor(Color.Black); ctx.Fill(); // Dashed lines ctx.SetLineDash(15, 10, 10, 5, 5); ctx.Rectangle(100, 100, 100, 100); ctx.Stroke(); ctx.SetLineDash(0); ImageBuilder ib = new ImageBuilder(30, 30, ImageFormat.ARGB32); ib.Context.Arc(15, 15, 15, 0, 360); ib.Context.SetColor(new Color(1, 0, 1)); ib.Context.Rectangle(0, 0, 5, 5); ib.Context.Fill(); var img = ib.ToImage(); ctx.DrawImage(img, 90, 90); ctx.DrawImage(img, 90, 140, 50, 10); ctx.Arc(190, 190, 15, 0, 360); ctx.SetColor(new Color(1, 0, 1, 0.4)); ctx.Fill(); ctx.Save(); ctx.Translate(90, 220); ctx.Pattern = new ImagePattern(img); ctx.Rectangle(0, 0, 100, 70); ctx.Fill(); ctx.Restore(); ctx.Translate(30, 30); double end = 270; for (double n = 0; n <= end; n += 5) { ctx.Save(); ctx.Rotate(n); ctx.MoveTo(0, 0); ctx.RelLineTo(30, 0); double c = n / end; ctx.SetColor(new Color(c, c, c)); ctx.Stroke(); ctx.Restore(); } ctx.ResetTransform(); }
/// <summary> /// Does all the work in drawing grid lines. /// </summary> /// <param name="ctx">The graphics context with which to draw</param> /// <param name="axis">TODO</param> /// <param name="orthogonalAxis">TODO</param> /// <param name="a">the list of world values to draw grid lines at.</param> /// <param name="horizontal">true if want horizontal lines, false otherwise.</param> /// <param name="color">the color to draw the grid lines.</param> private void DrawGridLines(Context ctx, PhysicalAxis axis, PhysicalAxis orthogonalAxis, System.Collections.ArrayList a, bool horizontal) { for (int i=0; i<a.Count; ++i) { Point p1 = axis.WorldToPhysical ((double)a[i], true); Point p2 = p1; Point p3 = orthogonalAxis.PhysicalMax; Point p4 = orthogonalAxis.PhysicalMin; if (horizontal) { p1.Y = p4.Y; p2.Y = p3.Y; } else { p1.X = p4.X; p2.X = p3.X; } ctx.MoveTo (p1); ctx.LineTo (p2); } ctx.SetLineWidth (1); ctx.SetColor (gridColor); ctx.SetLineDash (0, gridDash); ctx.Stroke (); }