# include "Ximage.h"

static char default_colormap[] = "grayscale";

void DefineLayout (Layout *layout, Graphic *graphic, int argc, char **argv) {

  int i, N;
  char *colormap;

  /** initiate connection with mana **/
  if (!FOREGROUND) {
    if (argc < 2) {
      fprintf (stderr, "socket path not specified\n");
      exit (0);
    }
    layout[0].Ximage = KiiWait (argv[1]);
  }

  PositionPictures (layout, graphic);
  
  /* get the display colors */
  if (USE_XWINDOW) {
    MakeColormap (graphic, layout, argc, argv);
  } else {
    colormap = default_colormap;
    if ((N = get_argument (argc, argv, "-cm"))) {
      remove_argument (N, &argc, argv);
      colormap = argv[N];
    }
    layout[0].Npixels = 256;
    SetColormap (graphic, layout, colormap);
  }

  /** set up a bunch of default things **/
  layout[0].X = layout[0].Y = 0;
  layout[0].expand = 1;
  layout[0].zero = 0;
  layout[0].range = 1;
  layout[0].coords.Npolyterms = 0;
  for (i = 0; i < NOVERLAYS; i++) {
    layout[0].overlay[i].Nobjects = 0;
    ALLOCATE (layout[0].overlay[i].objects, Object, 1);  /* allocate so later free will not crash! */
    OVERLAY[i] = FALSE;
  }
  layout[0].matrix.size = 0; /* a flag to show there is no data in the matrix */

  MOVE_POINTER = TRUE;
  DECIMAL_DEG  = TRUE;
  ALLOCATE (layout[0].matrix.buffer, char, 1);  /* allocate so later free will not crash! */
  ALLOCATE (layout[0].picture.data, char, 1);   /* allocate so later free will not crash! */
  ALLOCATE (layout[0].cmapbar.data, char, 1);   /* allocate so later free will not crash! */
  ALLOCATE (layout[0].zoom.data, char, 1);      /* allocate so later free will not crash! */

  if (USE_XWINDOW) {
    CreatePicture (layout, graphic);
    CreateColorbar (layout, graphic);
    CreateZoom (layout, graphic, 0, 0); 
  }
}

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

  /* cmap = the mapping of value to color in kii
     colormap = the set of pixel -> color representation in X */
