# To subscribers of the xforms list from Steve Lamont <spl@ncmir.ucsd.edu> :
> I have created a canvas as follows ...
>
> [...]
>
> on which I place an image:
>
> flimage_display(image, FL_ObjWin(canvas)) ;
>
> [...]
>
> Everything works fine, except that the image takes quite long (i.e a second
> or so) to be redrawn whenever an expose event occurs. ...
My guess, without looking at the innards of flimage_display() is that
some rather elaborate conversion may have to take place in
flimage_display() to match the characteristics of the X Window of the
Canvas object. You may wish to check whether the Visual of the Canvas
is appropriate to the image.
> ... As
> an experiment, I placed the image in a box rather than a canvas:
>
> box = fl_add_box(FL_UP_BOX,0,0,WIDTH,HEIGHT,"");
> flimage_display(image, FL_ObjWin(box)) ;
>
> The refresh here is instantaneous...
I'm guessing again, but I expect that XForms is doing some internal
buffering that speeds things up. The characteristics of the Window in
which the Box object resides may also be more appropriate to the
image.
My favorite trick in using a Canvas is to create a Pixmap and use the
Xlib function XSetBackgroundPixmap() to paste the Pixmap of the image
onto the background, then let the X server handle the refresh.
The code is roughly as follows:
Pixmap pixmap = flimage_to_pixmap( image, FL_ObjWin( canvas ) );
/* Now stuff the Pixmap onto the Window's background */
XSetBackgroundPixmap( fl_get_display(),
FL_ObjWin( canvas ),
pixmap );
/* Do this to make the image appear */
XClearWindow( fl_get_display(),
FL_ObjWin( canvas ) );
Now, in your Expose handler, all you have to do is another
XClearWindow( fl_get_display(),
FL_ObjWin( canvas ) );
to refresh the image. You can do any other drawing on the image after
this refresh operation. Obviously, if you do it after the drawing,
the drawing will disappear -- not what you intend.
An XFlush() may be necessary to completely cause the additional
graphics to be drawn completely.
If you are doing an animation, several Pixmaps could be created and
then all you need to do is change the Window's background Pixmap and
do an XClearWindow() to update the displayed image.
I'm not sure if flimage_to_pximap() is documented -- it's not in my
manual but I haven't printed out a new copy of the manual in a while.
spl
_________________________________________________
To unsubscribe, send the message "unsubscribe" to
xforms-request@bob.usuhs.mil or see
http://bob.usuhs.mil/mailserv/xforms.html
XForms Home Page: http://world.std.com/~xforms
List Archive: http://bob.usuhs.mil/mailserv/list-archives/
This archive was generated by hypermail 2b29 : Sat Feb 17 2001 - 08:41:25 EST