[Mono-list] Double-buffered graphics solutions in mono

Miguel de Icaza miguel@ximian.com
Thu, 12 Feb 2004 21:24:50 -0500


> If anyone could give me some tips, or better yet, suggest a sample 
> application which does vaguely what I'm looking for that I could look at 
> the sample code of, I'd really appreciate it. I'd like something that's 
> actually going to work with recent mono, despite the 
> libgdiplus/Cairo/System.Drawing/WinForms upheaval - or better yet, work 
> with the Jan 14th snapshots as packaged in Debian, which *do* include 
> GTK# :)

You can turn any widget in Gtk# into doing double buffering for you very
easily:

	Widget d = new DrawingArea ();
	d.DoubleBuffered = true;

If you want more control over this, you can create a Gdk.Pixmap where
you perform all of your drawing operations, keep in mind the following
hierarchy:

	Gdk.Drawable
	    + Gdk.Window
	    + Gdk.Pixmap

So you can create your Pixmap, do all your drawing there, and when you
want to transfer this into the screen, you do a DrawDrawable on the
window. 

Like this:

        void ExposeHandler (object obj, ExposeEventArgs args)
        {
                Gdk.Window win = args.Event.window;
		Pixmap buffer = new Pixmap (win, 100, 100, -1);

		buffer.DrawXXX ();

		// Once you are done, copy the pixmap to the window.
		win.DrawDrawable (Style.WhiteGC, buffer, 0, 0, 0, 0, 100, 100);
	}

But as I said, you get that for free with Gtk+ 

More details are on Monodoc.	

Miguel.