# include "Ximage.h"
# define FRAC(a) ((a) - (int)(a))

int UpdatePointer (Graphic *graphic, Layout *layout, XMotionEvent *event) {

  int textpad;
  double  x, y, z;
  char line[100];

  if (MOVE_POINTER && InPicture ((XButtonEvent *)event, &layout[0].picture)) {

    Screen_to_Image (&x, &y, (double)event[0].x, (double)event[0].y, layout);

    if ((x >= 0) && (x < layout[0].matrix.Naxis[0]) && (y >= 0) && (y < layout[0].matrix.Naxis[1])) {
      /*
      X = event[0].x - layout[0].picture.x;
      Y = event[0].y - layout[0].picture.y;
      pix = MIN (MAX (X + Y*layout[0].picture.dx, 0), layout[0].picture.dx*layout[0].picture.dy - 1);
      z = layout[0].range * layout[0].picture.data[pix] / layout[0].Npixels + layout[0].zero;
      */
      z = -1;
    }
    else
      z = -1;
    layout[0].x = x;
    layout[0].y = y;
    layout[0].z = z;
    
    UpdateStatusBox (graphic, layout, x, y, z, 0);
    XFlush (graphic[0].display);
      
    CreateZoom (layout, graphic, x, y);  
    XPutImage (graphic[0].display, graphic[0].window, graphic[0].gc,
	       layout[0].zoom.pix, 0, 0, 
	       layout[0].zoom.x, layout[0].zoom.y, 
	       layout[0].zoom.dx, layout[0].zoom.dy);
    CrossHairs (graphic, layout);
    XFlush (graphic[0].display);
    
  }
  
  if (InPicture ((XButtonEvent *)event, &layout[0].cmapbar)) {
    z = layout[0].zero  + layout[0].range * (event[0].x - layout[0].cmapbar.x) / layout[0].cmapbar.dx;
    textpad = graphic[0].font[0].ascent;
    XSetForeground (graphic[0].display, graphic[0].gc, graphic[0].white);
    XFillRectangle (graphic[0].display, graphic[0].window, graphic[0].gc,
                  layout[0].text_x + 1, layout[0].text_y + 1, ZOOM_X - 2, textpad + PAD1 + 1);
    XSetForeground (graphic[0].display, graphic[0].gc, graphic[0].black);
    bzero (line, 100);
    sprintf (line, "%25.2f", z);
    XDrawString (graphic[0].display, graphic[0].window, graphic[0].gc, 
                 layout[0].text_x + PAD1, layout[0].text_y + textpad + PAD1, 
		 line, strlen(line));
    
  }

  return (TRUE);
}
