[Gtk-sharp-list] Gtk DrawingArea & Double-Buffering with Cairo

philippe.monteil philippe.monteil at dolce-vista.com
Tue Aug 23 02:10:37 EDT 2011


How about:
- render your charts in an ImageSurface, eventually in a background thread,
save it in a class member
- use it to paint the background of the DrawingArea, perform any additional
drawing on top of it

something like:

static ImageSurface build_Surface(int Width, int Height, Color Color)
{
	Context _context = null;
	try
	{
		ImageSurface _surface = new ImageSurface(Format.Argb32, Width, Height);
			
		_context = new Context(_surface);
			
                _context.Rectangle(0, 0, Width, Height);
                _context.Color = Color;
                _context.Fill();
			
		return _surface;
	}
	finally
	{
		if (_context != null) ((IDisposable)_context).Dispose();
	}
}

ImageSurface m_surface = build_Surface(512, 512, new Color(1,0,0,1));

private void onExposeEvent (object o, ExposeEventArgs args)
{
	DateTime _ti = DateTime.Now;
	Context _pContext = null;
	try
	{
		_pContext = Gdk.CairoHelper.Create(this.GdkWindow);
			
		_pContext.Rectangle(0, 0, this.Allocation.Width, this.Allocation.Height);
		_pContext.SetSource(m_surface);
		_pContext.Fill();
			
		// Any additional rendering here

	}
	finally
	{
		if (_pContext != null) ((IDisposable)_pContext).Dispose();
	}
}


--
View this message in context: http://mono.1490590.n4.nabble.com/Gtk-DrawingArea-Double-Buffering-with-Cairo-tp3738337p3761932.html
Sent from the Mono - Gtk# mailing list archive at Nabble.com.


More information about the Gtk-sharp-list mailing list