[Gtk-sharp-list] Gnome.Canvas slows down

Michael Hutchinson m.j.hutchinson at gmail.com
Sun Apr 26 15:14:16 EDT 2009

On Sat, Apr 25, 2009 at 3:56 AM, SKeaLoT <skealot at gmail.com> wrote:
> searched for this around the internet but found nothing...
> well.
> i made a little application to test some cylindrical coordinate rendering
> using a Gnome.Canvas . this is the first time i use this class, so i'm
> probably missing something, but anyway the problem is that the more i play
> with a slider, the slower the rendering gets. (each slider controls a point
> of view property... and redraws the scene)

I'm not familiar with GnomeCanvas, but I'm pretty sure it's a retained
mode canvas, i.e. you add a collection of shapes to it, and it handles
rendering them. Then you can manipulate the shapes (e.g. using affine
transformations) and add/remove them. It retains the shapes because it
handles repainting for you, e.g. when the window is invalidated by
another window moving over it.

>From a quick look at your code, I suspect you're re-adding the
transformed shapes every time the scene changes, covering up the old
ones without removing them. Hence your canvas is filling up with
unused, hidden items. So, if I'm correct, you should have you sliders
rotate the existing group instead of re-adding it.

However, AFAIK GnomeCanvas is deprecated. There are a few alternatives
for retained mode canvases (such as the Moonlight GTK widget), but it
looks to me like your drawing model is more suited to immediate mode.
If you want to do immediate mode graphics, I suggest creating a custom
widget that subclasses Gtk.DrawingArea, then override OnExposeEvent to
do the drawing directly:

You can also use Gdk.CairoHelper to get a Cairo context from the
GdkWindow, then use Cairo to draw on the GdkWindow.

Michael Hutchinson

More information about the Gtk-sharp-list mailing list