Re: Expose events -- normal behavior or code error?
- From: Owen Taylor <otaylor redhat com>
- To: "Jim Scott" <jdscott execpc com>
- Cc: <gtk-list redhat com>
- Subject: Re: Expose events -- normal behavior or code error?
- Date: 15 Nov 1999 13:08:13 -0500
"Jim Scott" <firstname.lastname@example.org> writes:
> Hi all,
> I am new to GTK and have written a program that animates a circle moving
> across a drawing area. I based my program on scribble-simple.c. I clear
> the backing pixmap, draw a circle in the new location on the backing pixmap,
> cause an expose event, and then sleep(1).
> The circle moves across the screen, but without a pause. I inserted a
> g_print into my expose event callback to see what was happening. Expose
> event is being called every second, but it doesn't seem like the drawing
> area is being exposed until after the last expose event is called.
> Is this part of Gtk's natural behavior, or is there likely an error in the
sleep() tells the operating system to suspend the process for a second,
so GTK+ can't do anything while your program is sleeping.
What you want to use is a timeout. The tutorial has some information
about using timeouts.
When you do this, things should work properly.
(Actually, if you are calling gtk_widget_draw() as in the tutorial,
then the only reason that things aren't being displayed is that
the queue of events being sent to X isn't being flushed;
Simpy calling gdk_flush() before the sleep() would probably
fix things. But in general, sleep() should be avoided any time
you are using a GUI toolkit.)
] [Thread Prev