/** this list must match the one in mana/include/package.h, and equiv */
# define NGRAPHCOLORS 23
static char GRAPHCOLORS[NGRAPHCOLORS][2][15] = {
"black",    "0.00 0.00 0.00", 
"white",    "1.00 1.00 1.00", 
"red",      "1.00 0.00 0.00", 
"pink",     "1.00 0.75 0.80", 
"orange",   "1.00 0.65 0.00", 
"yellow",   "1.00 1.00 0.00", 
"wheat",    "0.96 0.87 0.70", 
"gold",     "1.00 0.84 0.00", 
"green",    "0.00 1.00 0.00", 
"darkgreen","0.00 0.40 0.00", 
"blue",     "0.00 0.00 1.00", 
"skyblue",  "0.53 0.81 0.92", 
"indigo",   "0.56 0.16 0.87", 
"violet",   "1.00 0.00 0.00",
"grey10",   "0.10 0.10 0.10",
"grey20",   "0.20 0.20 0.20",
"grey30",   "0.30 0.30 0.30",
"grey40",   "0.40 0.40 0.40",
"grey50",   "0.50 0.50 0.50",
"grey60",   "0.60 0.60 0.60",
"grey70",   "0.70 0.70 0.70",
"grey80",   "0.80 0.80 0.80",
"grey90",   "0.90 0.90 0.90"};

/**************** Graphic carries X info around ****************/
typedef struct {
  Display       *display;
  int            screen;
  int            depth;
  Window         window;
  GC             gc;
  XFontStruct   *font;
  Cursor         cursor;
  int            x,  y;
  int            dx, dy;
  Colormap       colormap;
  unsigned long  fore;
  unsigned long  back;
  unsigned long  color[NGRAPHCOLORS];
} Graphic;

/**************** X related "widget" structures ****************/
typedef struct {
  int      x, y, dx, dy;      /* position and size */
  int      text;              /* does this have a picture or text? */
  int      width, height;
  char    *bitmap;          /* picture on button */
  int    (*function_1) ();  /* mouse_button 1 function */
  int    (*function_2) ();  /* mouse_button 2 function */
  int    (*function_3) ();  /* mouse_button 3 function */
} Button;

typedef struct {
  int      x, y, dx, dy;   /* position and size */
  char    *label;          /* label on TextLine */
  char     text[1024];     /* words of TextLine */
  char     old_text[1024]; /* words of TextLine */
  int      outline;        /* draw an outline?  */ 
  int      cursor;         /* location of cursor (if selected) */
  int    (*function) ();   /* textline function */
} TextLine;

typedef char STRING[1024];

typedef struct {
  int      x, y, dx, dy;   /* position and size */
  STRING  *text;           /* words of TextLine */
  int      Nlines;
  int      outline;        /* draw an outline?  */ 
  int      cursor_line;    /* cursor line */
  int      cursor_x;       /* location of cursor (if selected) */
  int      cursor_y;       /* location of cursor (if selected) */
  int    (*function) ();   /* textline function */
} TextBox;

/**************** general structures ****************/
typedef struct {
  Pixmap pixmap;
  int    width;
  int    height;
  char  *bits;
} Icon;

typedef struct {
  int      dx, dy, x, y;
  XImage  *pix;
  char    *data;
} Picture;

typedef struct {
  char type[10];
  double x, y;
  double dx, dy;
  double angle;
  char  *text;
} Object;

typedef struct {
  int x, y;
  int dx, dy;
  double angle;
  int  size;
  char font[64]; 
  char text[128];
} Label;

typedef struct {
  int Nobjects;
  unsigned long color;
  Object *objects;
} Overlay;
  
typedef struct {
  char      ctype[16];
  double    crval1, crpix1, cdelt1;
  double    crval2, crpix2, cdelt2;
  double    pc1_1, pc1_2;
  double    pc2_1, pc2_2;
} Coords;

typedef struct {
  float *x, *y, *z, *dxp, *dxm, *dyp, *dym;
  int Npts;
  int style, ptype, ltype, color, etype, ebar;
  double lweight, size;
  double x0, x1, y0, y1;  /* limits for this object */
} Gobjects;

typedef struct {
  double min, max;
  char isaxis, areticks, islabel, islog;
  double fx, dfx, fy, dfy;  /* axis location on graphic */
  char label[64];
} Axis;


/******** Here we define the Layout struct specific to this program  *******/
typedef struct {
  Axis      axis[4];    /* coordinate axes */
  Label     label[8];   /* fixed axis labels */

  Gobjects *objects;    /* graphic objects */    
  int      Nobjects;    

  Label    *ptext;      /* placed text labels */
  int      Nptext;      

  double   x, dx;      /* location of plot on window ( 0 - 1, 0 - 1 ) */
  double   y, dy; 

  char     name[64];

} Layout;
