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é
on 18.06.2008 18:21
on 19.06.2008 15:10
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é
on 19.06.2008 16:19
I dont even know whether this is possible
on 19.06.2008 16:21
> 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é
on 19.06.2008 16:53
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
on 19.06.2008 17:57
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 Hallendal
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
> ruby-gnome2-devel-en@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/ruby-gnome2-devel-en
--
Mikael Hallendal
Imendio AB - Expert solutions in GTK+
http://www.imendio.com
on 19.06.2008 18:23
Am Donnerstag, den 19.06.2008, 17:55 +0200 schrieb Mikael Hallendal: > 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
on 19.06.2008 18:49
> 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é
on 18.07.2008 17:03
on 18.07.2008 17:03
Egoist Egoist555 wrote: > > <a href="http://obaldel.ru/index.html">эротика секс порно видео</a><br>