public static Gdk.Pixbuf GetAsPixbuf(this IDrawingCell aCell, bool aFramed) { int fw = (aFramed == true) ? 1 : 0; Cairo.ImageSurface surface = new Cairo.ImageSurface(Cairo.Format.RGB24, System.Convert.ToInt32(aCell.Area.Width + 2), System.Convert.ToInt32(aCell.Area.Height + 2)); Cairo.Context context = new Cairo.Context(surface); CellRectangle rect = new CellRectangle(0, 0, aCell.Area.Width + (fw * 2), aCell.Area.Height + (fw * 2)); context.Color = new Cairo.Color(1, 1, 1); rect.DrawPath(context); // context.Rectangle (rect); context.FillPreserve(); context.Color = new Cairo.Color(0, 0, 0); if (aFramed == true) { context.Stroke(); rect = new CellRectangle(1, 1, aCell.Area.Width + 1, aCell.Area.Height + 1); } CellRectangle fake = new CellRectangle(0, 0, 9999999, 9999999); CellExposeEventArgs args = new CellExposeEventArgs(null, context, null, fake, rect); args.NeedsRecalculation = true; aCell.Paint(args); Gdk.Pixbuf px = surface.GetAsPixbuf(); ((IDisposable)context.Target).Dispose(); ((IDisposable)context).Dispose(); ((IDisposable)surface).Dispose(); return(px); }
/// <summary> /// Paints border on cairo context /// </summary> /// <param name="aArgs"> /// A <see cref="CellExposeEventArgs"/> /// </param> public virtual void PaintBorder(CellExposeEventArgs aArgs) { CellRectangle r = aArgs.CellArea.Copy(); if (PaintFrame == true) { r.Grow(-1); } r.DrawPath(aArgs.Context); // aArgs.Context.Rectangle (r); aArgs.Context.Color = FrameColor; aArgs.Context.LineWidth = BorderWidth; if (PaintFrame == true) { if (PaintBackground == true) { aArgs.Context.StrokePreserve(); } else { aArgs.Context.Stroke(); } } aArgs.Context.Color = BackgroundColor; if (PaintBackground == true) { aArgs.Context.Fill(); } }
/// <summary> /// Expose event handler, calls PaintBackground and then PaintCells /// </summary> /// <param name="evnt"> /// Arguments <see cref="Gdk.EventExpose"/> /// </param> /// <returns> /// true if successful, false if not <see cref="System.Boolean"/> /// </returns> protected override bool OnExposeEvent(Gdk.EventExpose evnt) { base.OnExposeEvent(evnt); int x, y, w, h, d = 0; GdkWindow.GetGeometry(out x, out y, out w, out h, out d); CellRectangle r = new CellRectangle(0, 0, w, h); System.Console.WriteLine("Using cellrendererwindow=" + (IsCellRenderer == true)); Gdk.Window masterDrawable = (IsCellRenderer == true) ? cellRendererWindow : evnt.Window; Gdk.Drawable buffer = null; Cairo.Context context = null; if (IsDoubleBuffered == true) { System.Console.WriteLine("DoubleBuffered"); buffer = new Gdk.Pixmap(masterDrawable, Allocation.Width, Allocation.Height, 24); context = Gdk.CairoHelper.Create(buffer); } else { masterDrawable.BeginPaintRect(evnt.Area); context = Gdk.CairoHelper.Create(masterDrawable); } Gdk.Color clr = Style.Backgrounds[(int)StateType.Normal]; // context.Color = new Cairo.Color (0, 0, 1); context.Color = clr.GetCairoColor(); r.DrawPath(context); context.Fill(); // if ((BackgroundPainted == true) && (Sensitive == true)) // PaintBackground (evnt, g, rect); // Cairo.Rectangle r = rect.CopyAndShrink (Padding); r.Shrink(Padding); CalculateCellAreas(r); if (IsDoubleBuffered == true) { PaintCells(evnt, buffer, context, r); evnt.Window.DrawDrawable(Style.BlackGC, buffer, evnt.Area.X, evnt.Area.Y, evnt.Area.X, evnt.Area.Y, evnt.Area.Width, evnt.Area.Height); buffer.Dispose(); } else { PaintCells(evnt, masterDrawable, context, r); masterDrawable.EndPaint(); } ((IDisposable)context.Target).Dispose(); ((IDisposable)context).Dispose(); context = null; return(true); }