protected override void OnDraw(Xwt.Drawing.Context ctx) { base.OnDraw (ctx); 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 (); } }
public virtual void Rotate(Xwt.Drawing.Context ctx, double x, double y) { // draws a line along the x-axis from (0,0) to (r,0) with a constant translation and an increasing // rotational component. This composite transform is then applied to a vertical line, with inverse // color, and an additional x-offset, to form a mirror image figure for easy visual comparison. // These transformed points must be drawn with the identity CTM, hence the Restore() each time. ctx.Save (); // save caller's context (assumed to be the Identity CTM) ctx.SetLineWidth (3); // should align exactly if drawn with half-pixel coordinates // Vector length (pixels) and rotation limit (degrees) double r = 30; double end = 270; for (double n = 0; n<=end; n += 5) { ctx.Save (); // save context and identity CTM for each line // Set up translation to centre point of first figure, ensuring pixel alignment ctx.Translate (x + 30.5, y + 30.5); ctx.Rotate (n); ctx.MoveTo (0, 0); ctx.RelLineTo (r, 0); double c = n / end; ctx.SetColor (new Color (c, c, c)); ctx.Stroke (); // stroke first figure with composite Translation and Rotation CTM // Generate mirror image figure as a visual test of TransformPoints Point p0 = new Point (0,0); Point p1 = new Point (0, -r); Point[] p = new Point[] {p0, p1}; ctx.TransformPoints (p); // using composite transformation ctx.Restore (); // restore identity CTM ctx.Save (); // save again (to restore after additional Translation) ctx.Translate (2 * r + 1, 0); // extra x-offset to clear first figure ctx.MoveTo (p[0]); ctx.LineTo (p[1]); c = 1-c; ctx.SetColor (new Color (c, c, c)); ctx.Stroke(); // stroke transformed points with offset in CTM ctx.Restore (); // restore identity CTM for next line } ctx.Restore (); // restore caller's context }
protected override void OnDraw(Xwt.Drawing.Context ctx) { base.OnDraw (ctx); 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 (); } }
public virtual void Rotate(Xwt.Drawing.Context ctx, double x, double y) { ctx.Save (); ctx.Translate (x + 30, y + 30); ctx.SetLineWidth (3); // Rotation double end = 270; double r = 30; for (double n = 0; n<=end; n += 5) { ctx.Save (); ctx.Rotate (n); ctx.MoveTo (0, 0); ctx.RelLineTo (r, 0); double c = n / end; ctx.SetColor (new Color (c, c, c)); ctx.Stroke (); // Visual test for TransformPoints Point p0 = new Point (0,0); Point p1 = new Point (0, -r); Point[] p = new Point[] {p0, p1}; ctx.TransformPoints (p); ctx.ResetTransform (); ctx.Translate (2 * r + 1, 0); ctx.MoveTo (p[0]); ctx.LineTo (p[1]); c = 1-c; ctx.SetColor (new Color (c, c, c)); ctx.Stroke(); ctx.Restore (); } 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 (); }