> >
> > You should never draw anything in an enter/leave callback, but only in an
> > expose event. Also note that creating/destroying a GC each time you draw
> > it is very slow, so you should do something like this instead:
>
> Ok, I have questions here and they are because I really want to know why
> and not start anything.
>
> 1. Why is drawing in the enter in leave callback not something you
> should do? Is it because if you do to much it can cause a backlog of
> events?

Merely a 'good design' question, but also because some prepare/release stuff 
is required before and after drawing on a GdkWindow (basicaly to set the 
clipping region and to setup the double buffer and copy its contents after 
the drawing operations). This is done by gdk_window_begin_paint_rect() and 
gdk_window_end_paint() which are automatically called by gtk when an expose 
event is processed. I think you can also call these yourself if you really 
want to keep your drawing within the leave/enter events, but a 
more 'conventional' way is to invalidate the window and then call 
gdk_window_process_updates() to process the expose event immediately.
You'll find a lot of interesting things about that in the GdkWindow doc.

>
> 2. Actually while creating and destroying a GC may be slow (and I don't
> think it is actually that slow) it seems that in this case I should have
> just looked them up off the widget (which I didn't know there were
> several GCs off of the widget style).

Not sure it is that slow, but using an existing one is obviously faster than 
creating it. It's also better (but of course not mandatory) to use the ones 
provided by the widget style, first because that's why they are here, and 
because it'll keep your app consistent if the user modify some style/resource 
settings (but I don't know much about that).
For info, manys GCs are created by the style, see gtkstyle.h for a list of 
them.

>
> 3. I did try what you recommended and basically I found this. The expose
> event was not fired enough. I _think_ what happens is that GTK optimizes
> calls to event handlers and so if you send it 5 requests to expose on
> the same object and they stack up in the dispatcher, you only get one
> expose event called (this is actually the right thing to do) and so when
> I was testing this, I would get only one call to expose and so the box
> would never be drawn. (my guess could be totally wrong here).

I don't understand what you mean here. It's true that gtk optimizes the 
invalidate calls, not by stacking them but by keeping an 'update_area' for 
each window and thus only redrawing the dirty part of it when nothing else 
has to be done (this is managed by an idle event). But even if you get only 
one call to expose, shouldn't it be enough to redraw it ?

Finally, note that I'm definitely not a gtk wizard, so maybe am I only saying 
stupid things here ;)

-- 
Cédric Lucantis
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Reply via email to