Re: Simple draw question
- From: Kevin DeKorte <kdekorte gmail com>
- To: gtk-app-devel-list gnome org
- Subject: Re: Simple draw question
- Date: Sat, 05 May 2007 07:28:58 -0600
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Cédric Lucantis wrote:
Le samedi 5 mai 2007 00:48, Kevin DeKorte a écrit :
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?
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).
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).
enter_button_callback()
{
gtk_widget_set_state(widget, GTK_STATE_PRELIGHT);
/* not sure this is required, as it's maybe called by set_state? */
/* you may use gdk_window_invalidate_* instead for better performances,
* see the docs for more infos */
gtk_widget_queue_draw(widget);
}
leave_button_callback()
{
/* same with GTK_STATE_NORMAL */
}
expose_button_callback()
{
gdk_draw_rectangle(widget->window, widget->state->fg_gc[widget->state], ...)
}
Oh for others reading this the line should be
gdk_draw_rectangle(widget->window, widget->style->fg_gc[widget->state], ...)
Kevin
- --
Get my public GnuPG key from
http://pgp.mit.edu:11371/pks/lookup?op=get&search=0x7D0BD5D1
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)
Comment: Using GnuPG with Remi - http://enigmail.mozdev.org
iD8DBQFGPIaa6w2kMH0L1dERAnTrAJ9dP2jchOhrHVAGf8FBNjCm4lMtPQCdHjtT
516nI5zuTdUxRaXbRHpJ/Ew=
=/rw5
-----END PGP SIGNATURE-----
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]