RE: XForms: Problem displaying images

Michael Glickman (michaelg@linx.com.au)
Thu, 16 Sep 1999 11:30:09 +1000

# To subscribers of the xforms list from Michael Glickman <michaelg@linx.com.au> :

Dear neighbour!
Our time goes 4 hours in front, let it be your morning surprise.

Consider two different ways of using pixmaps in your application:

1. A simple way

Instead of having troubles with a canvas, you can just declare a pixmap
object.
In order to do that, use fdesign, or add the following line to your
code

pixmap_object = fl_add_pixmap(FL_NORMAL_PIXMAP, .... );

Can you guess what goes next ? Exactly. You need to associate an XPM
file with your pixmap. Probably it can be provided by fdesign as well,
but here
is an instruction to do that:

fl_set_pixmap_file(pixmap_object, "filename.xpm");

Oops, again the name may be wrong. Consult a section in the manual
related
to the pixmaps, or just scan /usr/include/forms.h for 'pixmap' word.
It looks logical, that the file has to be associated before the form is
shown.

Once the form appears, you can manipulate with your pixmap object,
using already familiar fl_set_object_position. This is simple, and I
don't know why it shouldn't work. I didn't use it in my application,
simply
because I had a slightly different scenario.

2. Deeper into the jungles.

Back to the canvas object and the callback routine.
I assume the following names for the form and the canvas:

FL_OBJECT *canvas_object;
FL_FORM *MainForm;

You wil also need the following declarations on the top:

Pixmap pixmap_handle;
GC default_gc;
Window MainWnd;

This is a part of initialization routine:

unsigned w, h, hx, hy;

/* Creates a hidden window. */
MainWnd = fl_prepare_form_window(MainForm, FL_PLACE_MOUSE, 2,
"AppClass");

/* Get canvas window id */
canvas_wnd = fl_get_canvas_id(canvas_object);

/* Check the name and specification for the following call !
It reads the XPM file, creates a pixmap in memory and returns a
handle
to it as Pixmap variable */
pixmap_handle = fl_read_pixmap_file(MainWnd, "filename.xpm",
&w, &h, &hx, &hy);

/* This associates a callback routine to your canvas */
fl_add_canvas_handler(canvas_object, Expose, canvas_callback,
NULL);

/* The XForms default graphic context should be OK */
default_gc = fl_state[(int) fl_get_vclass()].gc[0];

/* Show the form */
fl_show_form_window(MainForm);

........................................................................
...........................................
A callback routine

static int canvas_callback(FL_OBJECT *obj, Window win,
int win_width, int win_height,
XEvent *xev, void *user_data)
{

if (xev->xexpose.count <= 0 ) /* This filters out redundant
exposures */
{
XCopyArea(fl_display, pixmap_handle, cnvas_wnd,
default_gc, 0, 0, win_width, win_height, 0, 0)
}

return 0;
}

Cheers, Michael

> -----Original Message-----
> From: Ravi Mehrotra [SMTP:ravi@csnpl.ren.nic.in]
> Sent: Wednesday, 15 September 1999 13:01 EST
> To: xforms@bob.usuhs.mil
> Subject: Re: XForms: Problem displaying images
>
> # To subscribers of the xforms list from Ravi Mehrotra
> <ravi@csnpl.ren.nic.in> :
>
> Dear Michael,
>
> Thanks for replying. As indicated the section of the code I included,
> the canvas is moved programmatically (fl_set_object_position) and I
> also
> execute a pic->display and XFlush(fl_display) after the move.
> Actually,
> how one moves the canvas does not seem to matter.I have also tried
> moving the canvas by traping a mouse event with the same results. The
> only way it works is to free the pic and reload it into the canvas.
> But
> that is very inconvenient.
>
> I will try out the xpm format. However, it would be nice to get the
> ppm
> also working wihtout glitches.
>
> Regards,
>
> Ravi Mehrotra
> National Physical Laboratory
> New Delhi 110012
> India
>
>
_________________________________________________
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://bragg.phys.uwm.edu/xforms
List Archive: http://bob.usuhs.mil/mailserv/list-archives/