Re: Expose events -- normal behavior or code error?

"Jim Scott" <> 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
> code?

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.)


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