Re: drawing graphics



On Thu, 19 Sep 2002 12:00:10 +0300
Olexiy Avramchenko <ath beast stu cn ua> wrote:

> >My app uses a GtkDrawingArea to display some data (lines & texts)  drawn
> >with gdk drawing primitives.
> >the main drawing function is linked with the expose_event of my drawing area
> >
> >  gtk_signal_connect (GTK_OBJECT (drawingarea1), "expose_event",
> >  		GTK_SIGNAL_FUNC(DrawData),this);
> >
> >thus my system is not very effective and my function is called for each
> >refresh request...
> >what would be the most effective solution ?
> > or where could i put the draw code so that it could be called only once ?
> >maybe i should use something else rather than drawing area???
> >(btw: my drawing function reads a hard drive file that s why i would avoid
> >to call it so much)
> >
> Hmm, in that case you have to use back buffer (usual GdkPixmap). You 
> have to paint all
> graphics to that pixmap and draw pixmap on expose event. Look at 
> scribble-simple example,
> coming with gtk.

In addition to using a background pixmap (as suggested), I also 'attach'
the pixmap to the window (using gdk_window_set_back_pixmap()).
This way, you never have to deal with expose events (unless you are
drawing stuff that isn't in your background pixmap).

All in all, this give a very fast and pleasing application.  No flicker,
no waiting for expose events to be processed, the data is always visible
(Even when stepping through the debugger! :-) etc, etc.
(As you've discovered, trying to draw all your data within every expose
event is really inefficient, and grinds your app to a standstill if you
have much data to draw....)

Ian



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]