Re: gdk-pixbuf-animation

"Ben K" <> writes: 
> this gives me trouble because i end up rendering the pixbuf before the 
> drawing area exists (seg), or i create an expose event on a drawing area 
> with NULL data (seg).
> please, if anyone could spare a minute do help drag this through my brain, 
> i'd truly appreciate it.

A drawing area becomes drawable when you get your first expose
event. So you don't want to draw before then. Also, you want to stop
drawing when the area is unmapped.

I would say:
 - keep a concept of "current frame" on the area
 - on the first expose, current_frame will be NULL, so set it to the
   first frame, and install a timeout of delay_time
 - in subsequent exposes, just redraw the current frame
 - in your timeout, change the current frame, call
   gtk_widget_draw() on the drawing area, and either return 
   TRUE to leave the timeout installed or install a new 
   timeout if the delay to the next frame is different.

   Before you draw in the timeout, check that the drawing 
   area is GTK_WIDGET_DRAWABLE(), and if not remove all timeouts.
   If you draw while it isn't drawable you'll get errors.

You could also do sophisticated stuff such as drop frames if the
machine isn't fast enough to keep up with the frame rate. To do that,
you could compute which frame you should be on (divide time per frame
into time since you started animating) and display the one you should
be on, instead of religiously going through them sequentially. You
need to record a timestamp on that first expose event for that. Or you
could record a timestamp each time you display a frame, and if you get
to the next frame and more than a single delay has elapsed, you could
skip a frame. I'm sure there are generic docs on the web somewhere
comparing the pros/cons of various ways to do this.



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