# include "Ximage.h"
# define NPOINTS 10

void Refresh (Graphic *graphic, Layout *layout, int mode) {

  int i;

  XSetForeground (graphic[0].display, graphic[0].gc, layout[0].black);
  XDrawRectangle (graphic[0].display, graphic[0].window, graphic[0].gc, 
		  layout[0].picture.x, layout[0].picture.y, 
		  layout[0].picture.dx + 1, layout[0].picture.dy + 1);
  
  XPutImage (graphic[0].display, graphic[0].window, graphic[0].gc,
	     layout[0].picture.pix, 0, 0, 
	     layout[0].picture.x + 1, layout[0].picture.y + 1, 
	     layout[0].picture.dx, layout[0].picture.dy);

  XPutImage (graphic[0].display, graphic[0].window, graphic[0].gc,
	     layout[0].cmapbar.pix, 0, 0, 
	     layout[0].cmapbar.x, layout[0].cmapbar.y, 
	     layout[0].cmapbar.dx, layout[0].cmapbar.dy);

  CrossHairs (graphic, layout);

  for (i = 0; i < NOVERLAYS; i++) {
    if (OVERLAY[i])
      PaintOverlay (graphic, layout, i);
  }
  PaintTickmarks (graphic, layout);

  if (mode == 1) {
    /* erase everything below zoom box, then draw */
    XSetForeground (graphic[0].display, graphic[0].gc, layout[0].white);
    XFillRectangle (graphic[0].display, graphic[0].window, graphic[0].gc, 
		    layout[0].text_x, layout[0].text_x, layout[0].zoom.dx, graphic[0].dy); 
    
    DrawButton (graphic, &layout[0].PS_button);
    DrawButton (graphic, &layout[0].recenter_button);
    DrawButton (graphic, &layout[0].grey_button);
    DrawButton (graphic, &layout[0].rainbow_button);
    DrawButton (graphic, &layout[0].puns_button);
    DrawButton (graphic, &layout[0].hms_button);

    for (i = 0; i < NOVERLAYS; i++) {
      DrawButton (graphic, &layout[0].overlay_button[i]);
    }
  }

  StatusBox (graphic, layout);

  FlushDisplay (graphic[0].display);
}

/* this routine is independent of the number of overlays */

