From: beilby@latcs1.lat.oz.au (Scorpius)
Newsgroups: fj.mail-lists.x-window
Subject: Need help with Pixmaps and Athena Widgets.
Date: 11 Apr 92 12:43:03 GMT
Distribution: fj
Organization: Comp Sci, La Trobe Uni, Australia

Date: 11 Apr 92 07:37:50 GMT
Message-Id: <1992Apr11.073750.5883@latcs1.lat.oz.au>
Newsgroups: comp.windows.x


	I'm trying to produce a pixmap from a raster file to display in
a athena label widget.  The program compiles, but instead of the image
showing up in the label widget, it apears transparent (ie can see the window
below through the label widget.)  Moving the window reveals that it is not
actualy transparent, but instead copied what was under the widget when it
was created.  (resizing the form widget causes the label widget to fill
with the background colour of the form widget.)

	Any help, solutions, or sugestions will be much apreciated.


Here's the code.
-----------------------------------------------------------------------------

#include <stdio.h>
#include <rasterfile.h>
#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>
#include <X11/Xlib.h>
#include <X11/Xaw/Command.h>
#include <X11/Xaw/Form.h>
#include <X11/Xaw/Label.h>

#define HEIGHT 200
#define WIDTH 256
#define DEPTH 8 

/************************************************************************/
/*	X Function Defs.						*/
/************************************************************************/


/* quit button callback function */
/*ARGSUSED*/
void Quit(w, client_data, call_data)
Widget w;
XtPointer client_data, call_data;
{ 
   exit(0); 
}


/************************************************************************/
/*	Globel Variable Declarations.					*/
/************************************************************************/

struct rasterfile *ras_head;
unsigned char *image_data, *rgb;


/************************************************************************/
/*	Main.								*/
/************************************************************************/

main(argc, argv)
int argc;
char **argv;
{
   XtAppContext app_context;
   Widget label, form, quit, button1, topLevel;
   XImage *image;
   Pixmap *pixmap;
   Display *theDisplay;
   GC theGC;
   int theDepth, theScreen;
   Visual *theVisual;

   int e_val;   /* Error value retured by functions. */


/************************************************************************/
/*	Image data storage mallocs.					*/
/************************************************************************/

   ras_head = (struct rasterfile *)malloc(sizeof(struct rasterfile));
   image_data = (unsigned char *)malloc(WIDTH*HEIGHT*sizeof(char));
   rgb = (unsigned char *)malloc(768*sizeof(unsigned char));

   e_val = load_raster("reptile.ras"); 
   if (e_val != 0)
   {
      printf("Error in raster file read.\n");
      exit(1);
   }


/************************************************************************/
/*	Widget setup.							*/
/************************************************************************/

    topLevel = XtVaAppInitialize(
        &app_context,       /* Application context */
	"Test1",            /* application class name */
        NULL, 0,            /* command line option list */
        &argc, argv,        /* command line args */
        NULL,               /* for missing app-defaults file */
        NULL);              /* terminate varargs list */


   form = XtVaCreateManagedWidget(
		"form", 		/* widget name */
		formWidgetClass,	/* widget class */
		topLevel,		/* parent widget*/
		/* Varargs argumant list (name/value pairs) */
                XtNwidth,100,		/* Set Height (doesn't work) */ 
                XtNheight,100,		/*              ditto        */
		XtVaTypedArg,		/* Indicates next 4 need convertion
					   into a name/value pair. */
                XtNbackground,XtRString,"blue",strlen("blue")+1,
		NULL);			/* End of argument list. */

   quit = XtVaCreateManagedWidget(
		"Quit",			/* widget name */
		commandWidgetClass,	/* widget class */
		form,			/* parent widget*/
		NULL);			/* argument list*/

   label = XtVaCreateManagedWidget(
		"Picture",		/* widget name.	 */
		labelWidgetClass,	/* widget class. */
		form,			/* parent widget. */
		XtNfromVert,quit,
                XtNbackgroundPixmap,pixmap,
		NULL);			/* End of args list. */

/************************************************************************/
/*	Setup Pixmap to be used to display image.			*/
/************************************************************************/

   theDisplay = XtDisplay(topLevel);
   theGC      = DefaultGC(theDisplay,theScreen);
   theScreen  = DefaultScreen(theDisplay);
   theVisual  = DefaultVisual(theDisplay,theScreen);
   theDepth   = DefaultDepth(theDisplay,theScreen);


   pixmap = XCreatePixmap(theDisplay, RootWindowOfScreen(XtScreen(topLevel)),
		WIDTH, HEIGHT, theDepth);

   image = XCreateImage(theDisplay, theVisual, theDepth,
		ZPixmap, 0, image_data, WIDTH, HEIGHT, 8,0 );
   image->byte_order = MSBFirst;

   XPutImage(theDisplay,pixmap,theGC,
	image,0,0,0,0,image->width,image->height);

   XtAddCallback(quit, XtNcallback, Quit, 0);
   XtRealizeWidget(topLevel);
   XtAppMainLoop(app_context);
}


/************************************************************************/
/*	Image Manipulation and suport code functions defs. 		*/
/************************************************************************/

/* Function to load raster image data into mem */
load_raster(filename)
char *filename;
{
   FILE *fp;
   int read_chk;

   fp = fopen(filename,"rb");
   if (!fp)
   {
      fprintf(stderr,"Could not open input file, %s\n",filename);
      exit(1);
   }

   read_chk = fread(ras_head,sizeof(struct rasterfile),1,fp);
   if (read_chk != 1) 
      return(2);   /* Bad file header */

   read_chk = fread(rgb,sizeof(unsigned char),768,fp);
   if (read_chk != 768) 
      return(3);   /* Bad LUT */

   read_chk = fread(image_data,sizeof(unsigned char),WIDTH*HEIGHT,fp);
   if (read_chk != WIDTH*HEIGHT) 
      return(4);   /* Bad image data */

   fclose(fp);
   return(0);   /* Succesfull load */
}

----------------------------------------------------------------------------
End of Code.

                                     / / / /     __
                                )--/+-+-+-+---  '  \
                                  (8| Scorpius>\___/
                                )--\+-+-+-+---
                                     \ \ \ \
					
					beilby@latcs1.lat.oz.au