public void PatternsAndImages(Context ctx, double x, double y) { ctx.Save (); ctx.Translate (x, y); ctx.SetColor (Colors.Black); // Dashed lines 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, ImageFormat.ARGB32); 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.ToImage (); 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 (); } } }
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 (); } }
protected override void OnDraw(Context ctx, Rectangle dirtyRect) { if (colorBox == null) { using (var ib = new ImageBuilder (size, size)) { for (int i=0; i<size; i++) { for (int j=0; j<size; j++) { ib.Context.Rectangle (i, j, 1, 1); ib.Context.SetColor (GetColor (i,j)); ib.Context.Fill (); } } colorBox = ib.ToImage (); } } ctx.DrawImage (colorBox, padding, padding); ctx.SetLineWidth (1); ctx.SetColor (Colors.Black); ctx.Rectangle (selection.X + padding - 2 + 0.5, selection.Y + padding - 2 + 0.5, 4, 4); ctx.Stroke (); }
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 (); }
protected override void OnBoundsChanged() { bounds = this.Bounds; if (plotCache != null ) { plotCache.Dispose (); } plotCache = new ImageBuilder ((int)bounds.Width, (int)bounds.Height, ImageFormat.ARGB32); cacheContext = plotCache.Context; UpdateCache (cacheContext); plotImage = plotCache.ToImage (); base.OnBoundsChanged (); }