/// <summary> /// Creates a copy of the BitmapBuilder. /// </summary> public BitmapBuilder Clone() { BitmapBuilder b = new BitmapBuilder(); b.CopyFrom(this); return(b); }
/// <summary> /// Copies a BitmapBuilder from another BitmapBuilder. /// </summary> /// <param name="b"></param> public void CopyFrom(BitmapBuilder b) { bitmap = b.bitmap; data = b.data; g = b.g; Bounds = b.Bounds; }
/// <summary> /// Starts recalculation of the painter. /// </summary> public override void Start(Plot plot) { base.Start(plot); if (Recalc) { cache = new BitmapBuilder(plot.Bounds); cache.Graphics.Clear(Color.Transparent); plot.MaxProgress += plot.Bounds.Width * plot.Bounds.Height; } }
/// <summary> /// Recalculates the Painter. /// </summary> public override void Calc(Plot plot) { int X, Y; Plot2D plot2D = (Plot2D)plot; BitmapBuilder bmp = cache; Rectangle r = plot2D.Bounds; if (Recalc) { unsafe { lock (this) { int * pixel; Color c; bmp.Lock(); pixel = bmp.Pixel(r.X, r.Y); for (Y = r.Y; Y < r.Y + r.Height; Y++) { if (plot2D.DrawStop) { break; } for (X = r.X; X < r.X + r.Width; X++) { if (plot2D.DrawStop) { break; } try { c = F.f(plot2D.WorldCoordinateX(X), plot2D.WorldCoordinateY(Y)); } catch (ThreadAbortException ex) { throw ex; } catch (Exception e) { if (F.ThrowOnErrors) { throw e; } else { c = Color.Transparent; } } *pixel = c.ToArgb(); pixel++; } plot2D.Progress += r.Width; } bmp.Unlock(); } } Recalc = plot.DrawStop; } }
/// <summary> /// Fills a rectangle with the gradient. /// </summary> /// <param name="g">The <see cref="Graphics"/> object to draw to.</param> /// <param name="gradient">The gradient to use.</param> /// <param name="frame">The rectangle to fill with the gradient.</param> /// <param name="direction">The direction of the gradient.</param> public static void FillRectangle(Graphics g, IGradient gradient, Rectangle frame, Direction direction) { BitmapBuilder bmp = null; int N = 0; bool reverse = false; switch (direction) { case Direction.Down: N = frame.Height; bmp = new BitmapBuilder(new Rectangle(0, 0, 1, N)); reverse = false; break; case Direction.Up: N = frame.Height; bmp = new BitmapBuilder(new Rectangle(0, 0, 1, N)); reverse = true; break; case Direction.Left: N = frame.Width; bmp = new BitmapBuilder(new Rectangle(0, 0, N, 1)); reverse = true; break; case Direction.Right: N = frame.Width; bmp = new BitmapBuilder(new Rectangle(0, 0, N, 1)); reverse = false; break; } bmp.Lock(); unsafe { int *pixel = bmp.Pixel(0, 0); for (double x = 0; x < N; x++) { try { if (reverse) { *pixel = gradient.Color((N - x - 1) / N).ToArgb(); } else { *pixel = gradient.Color(x / N).ToArgb(); } } catch { *pixel = Color.Transparent.ToArgb(); } pixel++; } } bmp.Unlock(); TextureBrush t = new TextureBrush(bmp.Bitmap); Matrix T0 = g.Transform.Clone(); Matrix T = g.Transform.Clone(); T.Translate(frame.X, frame.Y); g.Transform = T; g.FillRectangle(t, new Rectangle(0, 0, frame.Width, frame.Height)); g.Transform = T0; }