Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[XForms] Can Xforms be used to run an animation?

0 views
Skip to first unread message

Peter Rowat

unread,
Jul 3, 2015, 9:30:57 AM7/3/15
to xforms-de...@nongnu.org


Xforms looks like an excellent system for me but before I spend time learning it I want to be sure I can run an animation:

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.

Thanks in advance for any help,

— Peter Rowat



Jens Thoms Toerring

unread,
Jul 3, 2015, 10:06:05 AM7/3/15
to Development with and of XForms, Peter Rowat
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 ________ j...@toerring.de
\_______________________________ http://toerring.de

Peter Rowat

unread,
Dec 16, 2015, 8:17:30 PM12/16/15
to j...@toerring.de, Development with and of XForms
Hello All,

If I XUnmapWindow (ref p.199 in the manual) a canvas with various items drawn on it, (e.g. XDrawLines) the following XMapWindow doesn’t restore the previous contents. XMapWindow requires a window as 2nd argument but, supposedly, that was destroyed by the XUnmap ??
What functions are there to Save/Restore the contents. Presumably some save/restore pixrect function ??

Any ideas?

Thanks,

Peter





Jens Thoms Toerring

unread,
Dec 17, 2015, 6:13:01 PM12/17/15
to Peter Rowat, xforms-de...@nongnu.org
Hi Peter,

On Wed, Dec 16, 2015 at 05:16:51PM -0800, Peter Rowat wrote:
> If I XUnmapWindow (ref p.199 in the manual) a canvas with various items
> drawn on it, (e.g. XDrawLines) the following XMapWindow doesn’t restore the
> previous contents. XMapWindow requires a window as 2nd argument but,
> supposedly, that was destroyed by the XUnmap ??

A window doesn't have amy "content", it's just an area you're
allowed to draw into (and receive events for). Even if another
window is moved over your window and then again removed, the
previous content of your windiw isn't restored all by itself.
Instead, you get XEvents for thar window that tell you which
parts of it need restoring. And if you unmap a window its con-
tent is gone for good. All that unmapping it does is to tell
the Window manager to withdraw the borders and issue redraw
XEvent so all windows that had been obscured by your window
you just unmapped.

> What functions are there to Save/Restore the contents. Presumably some
> save/restore pixrect function ??

There are none that I know of. In my experience, one typically has
an off-screen pixmap into which all drawing requests go (instead
of directly to the window) and then that is XCopy'ed the on-screen
window (already to avoid flicker). With such a pixmap as a kind of
"back-up" it's easy to restore the window contents. If you don't
have one I'd think you'll have to do a complete redraw of every-
thing from scratch.

Of course, you can implement some function for saving the window
contents before you unmap it by simply copyimg its content into
an off-screen pixmap with XCopy (though that alaways assumes that
your window isn't partially obscured by another window). But there
is none in XForms for that (and to get that right all of the time
would be extremely difficult!). With canvases, which are a very
thin layer on top of an X window, you're mostly on your own;-)

Of course, I could completely misunderstand your question (and
at the moment, I'm not too deeply into the details of Xlib due
to other work...), so the answer you're looking for might be
something completely different...

Jens Thoms Toerring

unread,
Dec 17, 2015, 7:51:55 PM12/17/15
to Peter Rowat, xforms-de...@nongnu.org
Hi Peter,

On Thu, Dec 17, 2015 at 03:55:10PM -0800, Peter Rowat wrote:
> My quick reply is that I’ve been trying to use the functions
> “fl_redraw_form" and "fl_redraw_object” functions but neither work..

No, they just draw the background of the canvas (if there's
one). They don't know anything about the contents of the can-
vas. How should they if you use a lower level function like
XDrawLine() or similar, which completely by-passes XForms?

> But perhaps I misunderstood what “redraw” means. I was thinking it meant
> re-draw everything previously drawn into the canvas window, whereas maybe it
> merely means redraw the border of the canvas/window with blank “contents”.

A canvas is just an X window (you're basically telling XForms
that you want some area that you will control by yourself in
all aspects) - all suppport you get that makes it a tiny bit
easier is getting at the XEvents directed at that window. But
whatever you do with the canvas becomes your responsibility.
You do that using Xlib functions and all the support you get
is what Xlib does. So a "redraw" of a canvas involves re-
questing the corresponding Xlib events to figure out when it
needs to be done and then to really redraw everything in there
(unless you have some off-screen pixmap you can copy the con-
tents from - but that also requires the Xlib XCopy function).

A canvas is definitely not an XForm-managed drawing area,
which the XForms library takes care of. Otherwise it could
only be used with XForms-specific drawing routines. It's
mostly just a raw X window you can ask Xforms to give you,
with a bit of help in circumventing the worst raw edges of
Xlib.

This is rather different to more "modern" toolkits like e.g.
Qt, that have much higher level "drawing areas". They have all
their own functions for drawing and zooming, maybe even having
sliders around them etc., making a lot of things easier and some
harder. None of that exists in this form in Forms.
0 new messages