                                        /*-------------------------------
                                         |    anim2.c template          |
                                         -------------------------------*/
#include <Xm/DrawingA.h>
#include <X11/xpm.h>


Pixmap pixmaps[6], mask[6];
int pixmap_width, pixmap_height;

static char *file[] ={
 "animation/eye8.xpm",
 "animation/eye9.xpm",
 "animation/eye15.xpm",
 "animation/eye23.xpm",
 "animation/eye6.xpm",
 "animation/eye7.xpm"
  };           


void update_animation(w, client_data, call_data)
Widget w;
XtPointer  client_data;
XtPointer  call_data;
{
XmDrawingAreaCallbackStruct *calld = (XmDrawingAreaCallbackStruct *)call_data;
static int count = 0;


 if(!XtIsRealized(w) || calld->event->type != ButtonRelease)return;

   XCopyArea(XtDisplay(w), pixmaps[count], 
		XtWindow(w), DefaultGC(XtDisplay(w),0),
                0, 0, pixmap_width, pixmap_height, 20, 20 );

   count++;
   if( count == 5) count = 0;

}
		                                /*-------------------------------------
                                         |              MAIN                  |
                                         ------------------------------------*/
int main(argc, argv)
  unsigned int argc;
  char **argv;
{
   Widget toplevel, draw;
   XtAppContext context;
   Display *dpy;
   int ac = 0;
     
					   	    /* Initialize the toolkit */
   toplevel = XtAppInitialize(&context, "Anim1", NULL, 0, &argc, argv,
                              NULL, NULL, 0);
   dpy = XtDisplay(toplevel);


   draw = XtVaCreateManagedWidget("draw", xmDrawingAreaWidgetClass, toplevel,
				NULL);

   createPixmap(draw);

   XtVaSetValues(draw, XmNwidth, pixmap_width + 40,
			XmNheight, pixmap_height + 40,
			XmNbackground, WhitePixel(dpy, 0),
			NULL);
   XtAddCallback(draw, XmNinputCallback, 
			(XtCallbackProc)update_animation, (XtPointer)NULL);
		
   XtRealizeWidget(toplevel);
   XtAppMainLoop(context);

}/*------------------------------------------------------------ End of MAIN --*/

createPixmap(w)
Widget w;
{
	int i;
	XpmAttributes xpmatts;

	xpmatts.closeness = 40000;
	xpmatts.valuemask = XpmSize | XpmCloseness;

	for(i = 0; i < 5; i++)
	{
		if( XpmReadFileToPixmap(XtDisplay(w), DefaultRootWindow(XtDisplay(w)),
				 file[i], &pixmaps[i], &mask[i], &xpmatts) == XpmSuccess)
		{
				pixmap_width = xpmatts.width;
				pixmap_height = xpmatts.height;
   				if(mask[i] )
   	    			XFreePixmap(XtDisplay(w), mask[i]);
		}
		else
		{
			printf("Pixmap creation error\n");
			exit(0);
		}
   }


}
