andrei_c wrote:
> Hello everyone, I was trying to make some simple program
> that involves animation, and I came up whit the idea of
> making a program that draws a rectangle at a different position
> each half a second.That seems pretty simple.I managed to do that,
> but until I exit the aplication, the animation never stops.
I tried your app, but had to make these changes
for it to compile on my linux box:
> #include <FL/fl_draw.h>
Had to change the ".h" -> ".H".
> int main()
> {
> srand(time(0))
Had to put a ';' at the end of that line.
Doing this, the app ran fine and stopped by itself.
I think a possible problem here is the timeout shouldn't be
set to repeat if you're going to also remove the timeout
immediately after.
Why it's not stopping for you, but is stopping for us
might be a platform issue; many of us use linux, whereas
you might be using windows or osx. Which?
I would say, change this part of your code around:
---- snip
Fl::repeat_timeout(0.5,timer_cb,c); // 0.5 s delay
n_frames++;
if(n_frames > 10) // this should stop the animation but it doesn't
Fl::remove_timeout(timer_cb);
---- snip
I'd suggest changing that to read:
---- snip
n_frames++;
if(n_frames > 10) { // this should stop the animation but it doesn't
Fl::remove_timeout(timer_cb);
} else {
// REPEAT ONLY IF NOT BEYOND MAX
Fl::repeat_timeout(0.5,timer_cb,c); // 0.5 s delay
}
---- snip
..so that the timer doesn't set to repeat on the last iter.
Since the timer code is implemented internally to FLTK
on a platform specific basis, it's possible that on
one of the platforms, FLTK's remove_timeout() doesn't
actually stop pending timeouts, which is maybe why the
time keeps retriggering.
What platform are you on?
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk