PixbufSimpleAnim - looping animation

Hello,

I’m trying to use the PixbufSimpleAnim, to show a animation generated by
multiple image files. The problem is that the animation runs once, and
then stops.

I saw in the samples that a gif file loaded using PixbufAnimation gives
me a looping animation. How can I accomplish the same result using a
PixbufSimpleAnim?

Thank you in advance,

André

Anyone?

André

André Wagner wrote:

Hello,

I’m trying to use the PixbufSimpleAnim, to show a animation generated by
multiple image files. The problem is that the animation runs once, and
then stops.

I saw in the samples that a gif file loaded using PixbufAnimation gives
me a looping animation. How can I accomplish the same result using a
PixbufSimpleAnim?

Thank you in advance,

André

I dont even know whether this is possible

I dont even know whether this is possible

Ok, thank you. I think I’ll write my own class to do that. I can share
it later.

André

Ok, I wrote a little class that does the animation. You can use it as a
simple image, just pass the frames as a array of pixbufs in the
initialization:

class ImageAnimation < Gtk::Image

attr_reader :fps, :frame_time

def initialize(frames=[], fps=60, frame_time=1)
super()
@frames, @fps, @frame_time = frames, fps, frame_time
start_animation
end

def restart(frames=[], fps=60, frame_time=1)
@frames, @fps, @frame_time = frames, fps, frame_time
@running = false
@t.join if @t
start_animation
end

def fps=(i)
@fps = i
start_animation
end

def frame_time=(i)
@frame_time = i
start_animation
end

private

def start_animation
return if not @frames or @fps == 0 or @frame_time < 1
return if @frames.length == 0

@running = true
i = 0
@t = Thread.new do
  while @running and not self.destroyed?
    self.pixbuf = @frames[i]
    i += 1
    i = 0 if i == @frames.length
    sleep 1.0 / @fps.to_f * @frame_time.to_f
  end
end

end

end

Hi,

I would rather implement this without the use of threads. If you use
threads and touch GTK+ from several threads you need to run

Gdk::Threads.init

And run the code that updates GTK+ like:

Gdk::Threads.synchronize { self.pixbuf = @frames[i] }

The usual way of doing this with GTK+ is to use the Mainloop.

Ie. instead of starting a new thread you add a GTimeout
(GLib::Timeout.add) that is called in certain intervals to swap the
image.

Best Regards,
Mikael H.

19 jun 2008 kl. 16.53 skrev André Wagner:

def initialize(frames=[], fps=60, frame_time=1)
end

   self.pixbuf = @frames[i]

Check out the new SourceForge.net Marketplace.
It’s the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php


ruby-gnome2-devel-en mailing list
[email protected]
ruby-gnome2-devel-en List Signup and Options


Mikael H.
Imendio AB - Expert solutions in GTK+

Am Donnerstag, den 19.06.2008, 17:55 +0200 schrieb Mikael H.:

Ie. instead of starting a new thread you add a GTimeout
(GLib::Timeout.add) that is called in certain intervals to swap the
image.

That works not so well specialy for bigger images. The animation will
not get smooth. Better you can do it in a loop like this:

Gtk.idle_add_priority(GLib::PRIORITY_LOW) do
now = Time.new
tdiff = now - @last_update
@last_update = now

do the work

sleep for at least 0.01 second to keep the app responsive

if @time_per_frame - tdiff < 0.01
sleep 0.01
else
sleep @time_per_frame - tdiff
end

I would rather implement this without the use of threads. If you use
threads and touch GTK+ from several threads you need to run

Gdk::Threads.init

And run the code that updates GTK+ like:

Gdk::Threads.synchronize { self.pixbuf = @frames[i] }

The usual way of doing this with GTK+ is to use the Mainloop.

Ie. instead of starting a new thread you add a GTimeout
(GLib::Timeout.add) that is called in certain intervals to swap the
image.

Thank you for this info!

But: why should I prefer using the mainloop instead of sychronized
threads?

André