[Top][All Lists]

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

[XForms] How to use an idle_callback to run an animation?

From: Peter Rowat
Subject: [XForms] How to use an idle_callback to run an animation?
Date: Tue, 20 Dec 2016 15:32:05 -0800

Dear Jens,

   I have tried to follow the instructions for using an idle_callback but so far have been unable to make the program work.

The callback is registered in my “create_form_canvasform”, and the callback is declared, as per p.47 in the Library manual. 
As I understand it, the callback should be getting called continually when otherwise there’s nothing happening. But it is never called. My test idle_callback merely prints a number, no graphics at all.

I can’t see anything I’m doing wrong.

My program is derived from the demo “canvas.c”, and I’ll append a file with the relevant parts of the program. 
The main addition to “canvas.c” was to draw the path of the mouse in the canvas. 

I apologize for asking this sort of question so close to Christmas, but it’s been a major aim for me to have this (and much more) running by now.  Any suggestions greatly appreciated.  I’ll proceed to look at the xforms source-code.


On Jul 3, 2015, at 7:05 AM, Jens Thoms Toerring <address@hidden> wrote:

Hi Peter,

On Thu, Jul 02, 2015 at 07:12:55PM -0700, Peter Rowat wrote:
Is there a function that will repeatedly call a draw routine forever, at a
particular rate so the animation speed can be changed? Something like the
XView function “notify_set_itimer_func” I used long ago.

I’ve looked at the manual section, 21.1 Timer Object and I’m not sure.

A timer would be one way to go - in the callback function you
do your drawing and restart the timer. Another possibility
would be an idle callback. But all depends on how regular your
redraws have to be done. Idle calbacks are called when there's
time to spare - so they are're not too reliable. Timers are
more precise since they have a much higher priority.

But neither will work when you use up all the CPU time and
never call a function like do_forms() which invokes the
event loop. So, if you expect something that does work in
parallel to doing lots of computations than this won't do
too well - XForms (as I think, most GUI libraries) requires
that you regularly give the event loop a chance to run. But
if you don't do that the whole GUI becomes unresponsive and,
of course, also timer callbacks aren't getting invoked. A
way around that would be to use a "worker| thread for your
computations and passing results back to the main thread,
mostly running the event loop. Then, in a callback you can
display whatever new results you received from the "worker"
thread. Mind though that XForms is not thread-safe in the
sense that you could call XForms functions from such a se-
cond thread - they can only be invoked from the thread that
initialized XForms (via fl_initialize()), having two threads
call them uncoordinatedly is a sure recipe for disaster;-)

I hope this explains your options. Don't hesitate to ask if
my attempt at an explanation is unintelligble or you need
more information.
                           Best regards, Jens
 \   Jens Thoms Toerring  ________      address@hidden
  \_______________________________      http://toerring.de

reply via email to

[Prev in Thread] Current Thread [Next in Thread]