Index: /tags/kii-1-4/Ohana/src/kii/Makefile
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/Makefile	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/Makefile	(revision 11911)
@@ -0,0 +1,128 @@
+include ../../Configure
+HOME 	=	$(ROOT)/src/kii
+PROGRAM =       kii
+
+default: $(PROGRAM)
+
+INC	=	$(HOME)/include
+BIN	=	$(HOME)/bin
+BDIR	=	$(HOME)/button
+CDIR	=	$(HOME)/colorbar
+EDIR	=	$(HOME)/event
+MDIR	=	$(HOME)/misc
+ODIR	=	$(HOME)/overlay
+PDIR	=	$(HOME)/picture
+SDIR	=	$(HOME)/setup
+ZDIR	=	$(HOME)/zoom
+DESTBIN	=	$(LBIN)
+DESTLIB	=	$(LLIB)
+DESTINC	=	$(LINC)
+DESTMAN	=	$(LMAN)
+#
+INCS	= 	-I$(INC) -I$(LINC) -I$(XINC)
+LIBS	= 	-L$(LLIB) $(XLIB) -ldvo -lFITS -lkapa -lohana -ljpeg -lX11 -lsocket -lnsl -lm
+# LIBS	= 	-L$(LLIB) $(XLIB) -lohana -lFITS -ljpeg -lX11 -lsocket -lnsl -lm -static
+CFLAGS  =	-o $*.$(ARCH).o $(INCS) 
+CCFLAGS	=	$(INCS) $(LIBS) 
+
+# local source / object files ########################
+BOBJ = \
+$(BDIR)/ButtonFunctions.$(ARCH).o         $(BDIR)/InButton.$(ARCH).o           \
+$(BDIR)/CheckButtons.$(ARCH).o     	  $(BDIR)/InPicture.$(ARCH).o          \
+$(BDIR)/DrawButton.$(ARCH).o       	  $(BDIR)/InvertButton.$(ARCH).o       \
+$(BDIR)/FlashButton.$(ARCH).o      	  $(BDIR)/PSit.$(ARCH).o		\
+$(BDIR)/JPEGit.$(ARCH).o
+
+COBJ = \
+$(CDIR)/CreateColorbar.$(ARCH).o          $(CDIR)/SetColormap.$(ARCH).o        \
+$(CDIR)/DragColorbar.$(ARCH).o
+
+EOBJ = \
+$(EDIR)/CheckPipe.$(ARCH).o               $(EDIR)/Stop.$(ARCH).o               \
+$(EDIR)/EventLoop.$(ARCH).o         	  $(EDIR)/Reconfig.$(ARCH).o           \
+$(EDIR)/InterpretKeys.$(ARCH).o     	  $(EDIR)/Refresh.$(ARCH).o            \
+$(EDIR)/InterpretPresses.$(ARCH).o  	  $(EDIR)/FlushDisplay.$(ARCH).o
+
+MOBJ = \
+$(MDIR)/hh_hms.$(ARCH).o		  
+
+OOBJ = \
+$(ODIR)/EraseOverlay.$(ARCH).o            $(ODIR)/PaintOverlay.$(ARCH).o       \
+$(ODIR)/LoadOverlay.$(ARCH).o   	  $(ODIR)/SaveOverlay.$(ARCH).o        \
+$(ODIR)/DrawOverlay.$(ARCH).o		  $(ODIR)/CSaveOverlay.$(ARCH).o       \
+$(ODIR)/PaintTickmarks.$(ARCH).o          $(ODIR)/LoadTickmarks.$(ARCH).o      \
+$(ODIR)/bDrawOverlay.$(ARCH).o
+
+POBJ = \
+$(PDIR)/CreatePicture.$(ARCH).o           $(PDIR)/Reorient.$(ARCH).o           \
+$(PDIR)/NewPicture.$(ARCH).o        	  $(PDIR)/Center.$(ARCH).o             \
+$(PDIR)/PositionPictures.$(ARCH).o  	  $(PDIR)/StatusBox.$(ARCH).o          \
+$(PDIR)/CursorOps.$(ARCH).o 		  $(PDIR)/Resize.$(ARCH).o 		\
+$(PDIR)/Remap8.$(ARCH).o 		  $(PDIR)/Remap24.$(ARCH).o 		\
+$(PDIR)/Remap.$(ARCH).o             	  $(PDIR)/Remap32.$(ARCH).o		\
+$(PDIR)/Remap16.$(ARCH).o		  $(PDIR)/JPEGit24.$(ARCH).o            \
+$(PDIR)/cursor.$(ARCH).o
+
+SOBJ = \
+$(SDIR)/CheckColors.$(ARCH).o             $(SDIR)/MakeGC.$(ARCH).o             \
+$(SDIR)/CheckDisplayName.$(ARCH).o  	  $(SDIR)/MapWindow.$(ARCH).o          \
+$(SDIR)/CheckFontName.$(ARCH).o     	  $(SDIR)/NameWindow.$(ARCH).o         \
+$(SDIR)/CheckGeometry.$(ARCH).o     	  $(SDIR)/OpenDisplay.$(ARCH).o        \
+$(SDIR)/CloseDisplay.$(ARCH).o      	  $(SDIR)/QuitX.$(ARCH).o              \
+$(SDIR)/CreateWindow.$(ARCH).o      	  $(SDIR)/SetNormalHints.$(ARCH).o     \
+$(SDIR)/DefineLayout.$(ARCH).o      	  $(SDIR)/SetUpDisplay.$(ARCH).o       \
+$(SDIR)/DrawBitmap.$(ARCH).o        	  $(SDIR)/SetUpWindow.$(ARCH).o        \
+$(SDIR)/GetColor.$(ARCH).o          	  $(SDIR)/SetWMHints.$(ARCH).o         \
+$(SDIR)/LoadFont.$(ARCH).o          	  $(SDIR)/TopWindow.$(ARCH).o          \
+$(SDIR)/MakeColormap.$(ARCH).o      	  $(SDIR)/Ximage.$(ARCH).o             \
+$(SDIR)/MakeCursor.$(ARCH).o              $(SDIR)/CheckVisual.$(ARCH).o	       \
+$(SDIR)/args.$(ARCH).o
+
+ZOBJ = \
+$(ZDIR)/UpdatePointer.$(ARCH).o      \
+$(ZDIR)/CrossHairs.$(ARCH).o		  $(ZDIR)/UpdateStatusBox.$(ARCH).o	\
+$(ZDIR)/CreateZoom.$(ARCH).o              $(ZDIR)/CreateZoom32.$(ARCH).o        \
+$(ZDIR)/CreateZoom8.$(ARCH).o             $(ZDIR)/CreateZoom24.$(ARCH).o	\
+$(ZDIR)/CreateZoom16.$(ARCH).o
+
+
+OBJ  =  $(BOBJ) $(COBJ) $(EOBJ) $(MOBJ) $(OOBJ) $(POBJ) $(SOBJ) $(ZOBJ)
+
+# dependancy rules for include files ########################
+$(OBJ): $(INC)/Ximage.h \
+	$(INC)/constants.h \
+	$(INC)/structures.h \
+	$(INC)/prototypes.h
+
+#### nothing program-dependant below ####
+# dependancy rules for binary code ##########################
+$(PROGRAM): $(BIN)/$(PROGRAM).$(ARCH)
+
+$(BIN)/$(PROGRAM).$(ARCH): $(OBJ)
+	@if [ ! -d $(BIN) ]; then mkdir -p $(BIN); fi
+	$(CC) $(OBJ) -o $(BIN)/$(PROGRAM).$(ARCH) $(CCFLAGS)
+
+install: $(DESTBIN)/$(PROGRAM)
+
+$(DESTBIN)/$(PROGRAM): $(BIN)/$(PROGRAM).$(ARCH)
+	@if [ ! -d $(DESTBIN) ]; then mkdir -p $(DESTBIN); fi
+	rm -f $(DESTBIN)/$(PROGRAM)
+	cp $(BIN)/$(PROGRAM).$(ARCH) $(DESTBIN)/$(PROGRAM)
+
+# utilities #################################################
+clean:
+	rm -f $(BIN)/*.$(ARCH)
+	rm -f `find . -name "*.o"`
+	rm -f `find . -name "*~"`
+	rm -f `find . -name "#*"`
+
+dist: clean
+	rm -f */*.*.o
+	rm -f $(BIN)/$(PROGRAM).*
+
+.SUFFIXES: .$(ARCH).o
+
+.c.$(ARCH).o:
+	$(CC) $(CFLAGS) -c $<
+
+
Index: /tags/kii-1-4/Ohana/src/kii/bin/.cvsignore
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/bin/.cvsignore	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/bin/.cvsignore	(revision 11911)
@@ -0,0 +1,1 @@
+*.linux *.lin64 *.sol *.sun *.sid *.hp *.irix
Index: /tags/kii-1-4/Ohana/src/kii/button/ButtonFunctions.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/button/ButtonFunctions.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/button/ButtonFunctions.c	(revision 11911)
@@ -0,0 +1,126 @@
+# include "Ximage.h"
+
+static char *GREY = "greyscale";
+static char *PUNS = "Puns";
+static char *RAINBOW = "Rainbow";
+
+int greycolors (Graphic *graphic, Layout *layout) {
+  char *name;
+  name = GREY;
+  SetColormap (graphic, layout, name);
+  CreateColorbar (layout, graphic);
+  Remap (graphic, layout, &layout[0].matrix);
+  CreateZoom (layout, graphic, 0, 0); 
+  Refresh (graphic, layout, 0);
+  XFlush (graphic[0].display);
+  return (TRUE);
+}
+
+int puns (Graphic *graphic, Layout *layout) {
+  char *name;
+  name = PUNS;
+  SetColormap (graphic, layout, name);
+  CreateColorbar (layout, graphic);
+  Remap (graphic, layout, &layout[0].matrix);
+  CreateZoom (layout, graphic, 0, 0); 
+  Refresh (graphic, layout, 0);
+  XFlush (graphic[0].display);
+  return (TRUE);
+}
+
+int rainbow (Graphic *graphic, Layout *layout) {
+  char *name;
+  name = RAINBOW;
+  SetColormap (graphic, layout, name);
+  CreateColorbar (layout, graphic);
+  Remap (graphic, layout, &layout[0].matrix);
+  CreateZoom (layout, graphic, 0, 0); 
+  Refresh (graphic, layout, 0);
+  XFlush (graphic[0].display);
+  return (TRUE);
+}
+
+int Recenter (Graphic *graphic, Layout *layout) {
+
+  layout[0].X = 0;
+  layout[0].Y = 0;
+ 
+  Remap (graphic, layout, &layout[0].matrix);
+  Refresh (graphic, layout, 0);
+  FlushDisplay (graphic[0].display);
+  return (TRUE);
+
+}
+
+int Rescale (Graphic *graphic, Layout *layout) {
+
+  layout[0].expand = 1;
+  Remap (graphic, layout, &layout[0].matrix);
+  Refresh (graphic, layout, 0);
+  FlushDisplay (graphic[0].display);
+  return (TRUE);
+
+}
+
+int RecenterRescale (Graphic *graphic, Layout *layout) {
+
+  layout[0].X = 0;
+  layout[0].Y = 0;
+  layout[0].expand = 1;
+ 
+  Remap (graphic, layout, &layout[0].matrix);
+  Refresh (graphic, layout, 0);
+  FlushDisplay (graphic[0].display);
+  return (TRUE);
+
+}
+
+int ToggleDEG (Graphic *graphic, Layout *layout) {
+
+  DECIMAL_DEG = DECIMAL_DEG ^ TRUE;
+  StatusBox (graphic, layout);
+  FlushDisplay (graphic[0].display);
+  return (TRUE);
+
+}
+
+/*********** overlay_button functions ************/
+int Overlay0 (Graphic *graphic, Layout *layout) {
+
+  OVERLAY[0] = OVERLAY[0] ^ TRUE;
+  Refresh (graphic, layout, 0);
+  FlushDisplay (graphic[0].display);
+  return (TRUE);
+
+}
+
+int Overlay1 (Graphic *graphic, Layout *layout) {
+
+  OVERLAY[1] = OVERLAY[1] ^ TRUE;
+  Refresh (graphic, layout, 0);
+  FlushDisplay (graphic[0].display);
+  return (TRUE);
+
+}
+
+int Overlay2 (Graphic *graphic, Layout *layout) {
+
+  OVERLAY[2] = OVERLAY[2] ^ TRUE;
+  Refresh (graphic, layout, 0);
+  FlushDisplay (graphic[0].display);
+  return (TRUE);
+
+}
+
+int Overlay3 (Graphic *graphic, Layout *layout) {
+
+  OVERLAY[3] = OVERLAY[3] ^ TRUE;
+  Refresh (graphic, layout, 0);
+  FlushDisplay (graphic[0].display);
+  return (TRUE);
+
+}
+
+/* this routine is NOT independent of the number of overlays */
+
+
Index: /tags/kii-1-4/Ohana/src/kii/button/CheckButtons.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/button/CheckButtons.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/button/CheckButtons.c	(revision 11911)
@@ -0,0 +1,57 @@
+# include "Ximage.h"
+# define PAD_X 10
+# define PAD_Y 10
+# define NPLANES 1
+# define NPIXELS 255
+
+/******** Here we test the Buttons specific to this program  *******/
+Button *
+CheckButtons (event, layout)
+XButtonEvent  event[];
+Layout        layout[];
+{
+
+  int i;
+  Button *button;
+  button = (Button *) NULL;
+
+  if (InButton (event, &layout[0].recenter_button)) 
+    button = &layout[0].recenter_button;
+
+  if (InButton (event, &layout[0].grey_button)) 
+    button = &layout[0].grey_button;
+
+  if (InButton (event, &layout[0].rainbow_button)) 
+    button = &layout[0].rainbow_button;
+
+  if (InButton (event, &layout[0].puns_button)) 
+    button = &layout[0].puns_button;
+
+  if (InButton (event, &layout[0].PS_button)) 
+    button = &layout[0].PS_button;
+
+  if (InButton (event, &layout[0].hms_button)) 
+    button = &layout[0].hms_button;
+
+  for (i = 0; i < NOVERLAYS; i++) {
+    if (InButton (event, &layout[0].overlay_button[i])) 
+      button = &layout[0].overlay_button[i];
+  }
+
+  return (button);
+
+}
+
+
+/* To define a button, you must:
+
+   0) add the button to the Layout structure in structures.h
+   1) place the info about the button in PositionPicture.c
+   2) (make any bitmaps needed and put them in buttons.h
+   3) place an entry in CheckButtons.c
+   4) Add the button to Refresh.c
+   5) create the button's function
+   6) add it to the Makefile
+   7) add it to the prototypes
+
+*/
Index: /tags/kii-1-4/Ohana/src/kii/button/DrawButton.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/button/DrawButton.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/button/DrawButton.c	(revision 11911)
@@ -0,0 +1,44 @@
+# include "Ximage.h"
+
+void
+DrawButton (graphic, button)
+Graphic graphic[];
+Button button[];
+{
+  
+  int y, dX;
+  
+  XSetForeground (graphic[0].display, graphic[0].gc, graphic[0].white);
+  XFillRectangle (graphic[0].display, 
+		  graphic[0].window,
+		  graphic[0].gc,
+		  button[0].x,  button[0].y,
+		  button[0].dx, button[0].dy);
+  XSetForeground (graphic[0].display, graphic[0].gc, graphic[0].black);
+  XDrawRectangle (graphic[0].display, 
+		  graphic[0].window,
+		  graphic[0].gc,
+		  button[0].x,  button[0].y,
+		  button[0].dx, button[0].dy);
+
+  if (button[0].text) {
+    dX = XTextWidth (graphic[0].font, button[0].bitmap, strlen(button[0].bitmap));
+    y = button[0].y + (button[0].dy + graphic[0].font[0].ascent)/2;
+    XDrawString (graphic[0].display, 
+		 graphic[0].window, 
+		 graphic[0].gc, 
+		 button[0].x + (button[0].dx - dX) / 2, y,
+		 button[0].bitmap, strlen(button[0].bitmap));
+  }
+  else {
+    DrawBitmap (graphic, 
+		button[0].x + (button[0].dx - button[0].width) / 2 + 1, 
+		button[0].y + (button[0].dy - button[0].height) / 2 + 1, 
+		button[0].width, button[0].height, 
+		button[0].bitmap, 1);
+  }
+
+  XSetForeground (graphic[0].display, graphic[0].gc, graphic[0].black);
+
+}
+
Index: /tags/kii-1-4/Ohana/src/kii/button/FlashButton.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/button/FlashButton.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/button/FlashButton.c	(revision 11911)
@@ -0,0 +1,22 @@
+# include "Ximage.h"
+
+void FlashButton (Graphic *graphic, Button *button) {
+
+  unsigned long black, white;
+
+  black =  graphic[0].black;
+  white =  graphic[0].white;
+  graphic[0].black = white;
+  graphic[0].white = black;
+
+  DrawButton (graphic, button);
+  XFlush (graphic[0].display);
+/*  usleep (20000);  removed - not a standard C sleep command, apparently! */
+  
+  graphic[0].black = black;
+  graphic[0].white = white;
+  DrawButton (graphic, button);
+  XFlush (graphic[0].display);
+
+}
+
Index: /tags/kii-1-4/Ohana/src/kii/button/InButton.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/button/InButton.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/button/InButton.c	(revision 11911)
@@ -0,0 +1,22 @@
+# include "Ximage.h"
+
+int
+InButton (button_event, button)
+XButtonEvent *button_event;
+Button button[];
+{
+
+  int answer;
+  int x, y;
+
+  x = button_event[0].x;
+  y = button_event[0].y;
+  
+  answer = ((x >= button[0].x) && (x <= button[0].x + button[0].dx) &&
+	    (y >= button[0].y) && (y <= button[0].y + button[0].dy));
+
+  return (answer);
+
+}
+
+/*** make this a macro? ***/
Index: /tags/kii-1-4/Ohana/src/kii/button/InPicture.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/button/InPicture.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/button/InPicture.c	(revision 11911)
@@ -0,0 +1,21 @@
+# include "Ximage.h"
+
+int
+InPicture (button_event, picture)
+XButtonEvent *button_event;
+Picture picture[];
+{
+
+  int answer;
+  int x, y;
+
+  x = button_event[0].x;
+  y = button_event[0].y;
+  
+  answer = ((x >= picture[0].x) && (x <= picture[0].x + picture[0].dx) &&
+	    (y >= picture[0].y) && (y <= picture[0].y + picture[0].dy));
+
+  return (answer);
+
+}
+
Index: /tags/kii-1-4/Ohana/src/kii/button/InvertButton.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/button/InvertButton.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/button/InvertButton.c	(revision 11911)
@@ -0,0 +1,20 @@
+# include "Ximage.h"
+
+void InvertButton (Graphic *graphic, Button *button) {
+
+  unsigned long black, white;
+
+  black =  graphic[0].black;
+  white =  graphic[0].white;
+
+  graphic[0].black = white;
+  graphic[0].white = black;
+
+  DrawButton (graphic, button);
+  FlushDisplay (graphic[0].display);
+  
+  graphic[0].black = black;
+  graphic[0].white = white;
+
+}
+
Index: /tags/kii-1-4/Ohana/src/kii/button/JPEGit.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/button/JPEGit.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/button/JPEGit.c	(revision 11911)
@@ -0,0 +1,153 @@
+# include "Ximage.h"
+# include "jpeglib.h"
+
+int JPEGit (Graphic *graphic, Layout *layout) {
+  
+  struct jpeg_compress_struct cinfo;
+  struct jpeg_error_mgr jerr;
+  JSAMPROW row_pointer[1];	/* pointer to JSAMPLE row[s] */
+  JSAMPLE *image_buffer;	/* Points to data for current line */
+
+  int j, k, m;
+  unsigned char *buff;
+  double Nchar, Npix, start, slope, frac;
+  int quality;
+  unsigned long pcolor;
+
+  char filename[1024];
+  int Nbytes, status;
+
+  XImage *tmpimage;
+
+  FILE *f;
+  
+  /* expect a line telling the number of bytes and a filename */
+  status = read (layout[0].Ximage, filename, 16);
+  filename[16] = 0;
+  sscanf (filename, "%*s %d", &Nbytes);
+  status = read (layout[0].Ximage, filename, Nbytes);
+  filename[status] = 0; /* make the string easy to parse */
+
+  /* 
+  switch (graphic[0].Nbits) {
+  case 8:
+    break;
+  case 16:
+    fprintf (stderr, "converter to 16 bit not yet implemented\n");
+    return (TRUE);
+    break;
+  case 24:
+    fprintf (stderr, "converter to 24 bit not yet implemented\n");
+    return (TRUE);
+    break;
+  case 32:
+    fprintf (stderr, "converter to 32 bit not yet implemented\n");
+    return (TRUE);
+    break;
+  }
+  */
+
+  /* set up the error handler , initialize the JPEG compression object. */
+  cinfo.err = jpeg_std_error (&jerr);
+  jpeg_create_compress (&cinfo);
+
+  f = fopen (filename, "w");
+  if (f == (FILE *) NULL) {
+    fprintf (stderr, "failed to open %s for output\n", filename);
+    return (TRUE);
+  }
+  jpeg_stdio_dest(&cinfo, f);
+  
+  quality = 75;
+  cinfo.image_width = layout[0].picture.dx; 	/* image width and height, in pixels */
+  cinfo.image_height = layout[0].picture.dy;
+# ifdef GREYSCALE
+  cinfo.input_components = 1;		        /* # of color components per pixel */
+  cinfo.in_color_space = JCS_GRAYSCALE; 	/* colorspace of input image */
+# else 
+  cinfo.input_components = 3;		        
+  cinfo.in_color_space = JCS_RGB; 	
+# endif
+  jpeg_set_defaults (&cinfo);
+  jpeg_set_quality (&cinfo, quality, TRUE       /* limit to baseline-JPEG values */);
+  jpeg_start_compress (&cinfo, TRUE);
+
+  ALLOCATE (image_buffer, JSAMPLE, 3*layout[0].picture.dx);
+  buff = (unsigned char *)layout[0].picture.data;
+  slope = layout[0].slope;
+  start = layout[0].start;
+  Nchar = 255.0;                                /* range of output values */
+  Npix = layout[0].Npixels;
+  frac = Nchar / Npix;
+  
+  {
+    XWindowAttributes WindowAttributes;
+    Pixmap tmp_pixmap;
+    Window tmp_window;
+    
+    XGetWindowAttributes (graphic[0].display, graphic[0].window, &WindowAttributes);
+    
+    tmp_pixmap = XCreatePixmap (graphic[0].display, graphic[0].window, graphic[0].dx, graphic[0].dy, WindowAttributes.depth);
+
+    tmp_window = graphic[0].window;
+    graphic[0].window = tmp_pixmap;
+
+    Refresh (graphic, layout, 0);
+
+    tmpimage = XGetImage (graphic[0].display, graphic[0].window, layout[0].picture.x+1, layout[0].picture.y+1, layout[0].picture.dx, layout[0].picture.dy, 0xffffffff, ZPixmap);
+
+    for (j = 0; (j < layout[0].picture.dy) && (cinfo.next_scanline < cinfo.image_height); j++) {
+      for (k = 0; k < layout[0].picture.dx; k++) {
+	pcolor = XGetPixel (tmpimage, k, j);
+	if (pcolor == layout[0].white) { 
+	  image_buffer[3*k+0] = Nchar;
+	  image_buffer[3*k+1] = Nchar;
+	  image_buffer[3*k+2] = Nchar;
+	  continue;
+	}
+	if (pcolor == layout[0].overlay[0].color) { 
+	  image_buffer[3*k+0] = Nchar;
+	  image_buffer[3*k+1] = 0;
+	  image_buffer[3*k+2] = 0;
+	  continue;
+	}
+	if (pcolor == layout[0].overlay[1].color) { 
+	  image_buffer[3*k+0] = 0;
+	  image_buffer[3*k+1] = Nchar;
+	  image_buffer[3*k+2] = 0;
+	  continue;
+	}
+	if (pcolor == layout[0].overlay[2].color) { 
+	  image_buffer[3*k+0] = 0;
+	  image_buffer[3*k+1] = 0;
+	  image_buffer[3*k+2] = Nchar;
+	  continue;
+	}
+	if (pcolor == layout[0].overlay[3].color) { 
+	  image_buffer[3*k+0] = Nchar;
+	  image_buffer[3*k+1] = Nchar;
+	  image_buffer[3*k+2] = 0;
+	  continue;
+	}
+	for (m = 0; (layout[0].cmap[m].pixel != pcolor) && (m < Npix); m++);
+	/* val = Nchar - frac * MIN (MAX (start + m * slope, 0), Npix); */
+	image_buffer[3*k+0] = layout[0].cmap[m].red / 256;
+	image_buffer[3*k+1] = layout[0].cmap[m].green / 256;
+	image_buffer[3*k+2] = layout[0].cmap[m].blue / 256;
+      }
+      row_pointer[0] = image_buffer;
+      (void) jpeg_write_scanlines (&cinfo, row_pointer, 1);
+    }
+    graphic[0].window = tmp_window;
+    XFreePixmap (graphic[0].display, tmp_pixmap);
+  }
+
+  XDestroyImage (tmpimage);
+
+  jpeg_finish_compress (&cinfo);
+  fclose (f);
+  jpeg_destroy_compress (&cinfo);
+
+  return (TRUE);
+
+}
Index: /tags/kii-1-4/Ohana/src/kii/button/PSit.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/button/PSit.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/button/PSit.c	(revision 11911)
@@ -0,0 +1,373 @@
+# include "Ximage.h"
+/* Notice: we are using a fixed border size of 10 pt */
+void ConvertPixmap8  (Layout *layout, FILE *f);
+void ConvertPixmap16 (Layout *layout, FILE *f);
+void ConvertPixmap24 (Layout *layout, FILE *f);
+void ConvertPixmap32 (Layout *layout, FILE *f);
+
+int PSit (Graphic *graphic, Layout *layout, int Raw) {
+  
+  FILE *f;
+  int i;
+  double scale;
+  char filename[1024];
+  int Nbytes, status;
+
+  /* expect a line telling the number of bytes and a filename */
+  status = read (layout[0].Ximage, filename, 16);
+  filename[16] = 0;
+  sscanf (filename, "%*s %d", &Nbytes);
+  status = read (layout[0].Ximage, filename, Nbytes);
+  filename[status] = 0; /* make the string easy to parse */
+
+  f = fopen (filename, "w");
+  if (f == (FILE *) NULL) {
+    fprintf (stderr, "failed to open %s for output\n", filename);
+    return (TRUE);
+  }
+  
+  if (!USE_XWINDOW) {
+    fprintf (stderr, "PS not working yet\n");
+    return (TRUE);
+  }
+
+  scale = MIN ((500.0/(double)layout[0].picture.dx), (700.0/(double)layout[0].picture.dy));
+  if (!Raw) {
+    fprintf (f, "%%!PS-Adobe-2.0 EPSF-2.0\n");
+    fprintf (f, "%%%%Title: %s\n", layout[0].file);
+    fprintf (f, "%%%%Creator: Ki'i (0.95)\n");
+    fprintf (f, "%%%%BoundingBox: 10 40 %d %d \n", (int)(scale*layout[0].picture.dx + 30), (int)(scale*layout[0].picture.dy + 60));
+    fprintf (f, "%%%%Pages: 1\n");
+    fprintf (f, "%%%%DocumentFonts:\n");
+    fprintf (f, "%%%%EndComments\n");
+    fprintf (f, "%%%%EndProlog\n");
+    fprintf (f, "%%%%Page: 1 1\n\n");
+
+  }
+
+  fprintf (f, "gsave %% encloses picture\n");
+  fprintf (f, "%% local abbreviations\n");
+  fprintf (f, "/Times-Roman findfont 18 scalefont setfont\n");
+  fprintf (f, "/T {moveto show stroke} def\n");
+  fprintf (f, "/B { newpath moveto dup 0 exch rlineto exch dup 0 rlineto exch -1 mul\n");
+  fprintf (f, " 0 exch rlineto -1 mul 0 rlineto closepath stroke } def\n");
+  fprintf (f, "/C {0 360 arc stroke} def\n");
+  fprintf (f, "/L {newpath moveto lineto stroke} def\n\n");
+
+  if (!Raw) {
+    fprintf (f, " 20 50 translate\n");
+    fprintf (f, "  %f  %f scale\n", scale, scale);
+  }
+
+  fprintf (f, " newpath 0 0 moveto %d 0 lineto %d %d lineto 0 %d lineto closepath clip\n\n", 
+	   layout[0].picture.dx, layout[0].picture.dx, layout[0].picture.dy, layout[0].picture.dy);
+  fprintf (f, "gsave %% encloses image\n");
+  fprintf (f, "%d %d 8\n", layout[0].picture.dx, layout[0].picture.dy);
+  fprintf (f, "[1 0 0 1 0 0]\n");
+  fprintf (f, "{currentfile %d string readhexstring pop} image\n\n", layout[0].picture.dx);
+
+  /******** First we draw the picture itself ********/
+  /* in !USE_XWINDOW, we'll have to change this to use the JPEG function */
+  switch (graphic[0].Nbits) {
+  case 8:
+    ConvertPixmap8 (layout, f);
+    break;
+  case 16:
+    ConvertPixmap16 (layout, f);
+    break;
+  case 24:
+    ConvertPixmap24 (layout, f);
+    break;
+  case 32:
+    ConvertPixmap32 (layout, f);
+    break;
+  }
+
+  fprintf (f, "grestore %% end of image\n");
+  fprintf (f, "stroke\n");
+  fprintf (f, "%% plot overlay objects\n");
+  fprintf (f, "1 setgray\n");
+
+  for (i = 0; i < NOVERLAYS; i++) {
+    if (OVERLAY[i]) {
+      fprintf (f, "%% overlay %d\n", i);
+      DrawOverlay (graphic, layout, i, f, 0);
+    }
+  }
+  fprintf (f, "0 setgray\n");
+  for (i = 0; i < NOVERLAYS; i++) {
+    if (OVERLAY[i]) {
+      fprintf (f, "%% overlay %d\n", i);
+      DrawOverlay (graphic, layout, i, f, 1);
+    }
+  }
+  
+  fprintf (f, "grestore %% end of picture\n");
+
+  if (!Raw) fprintf (f, "showpage\n");
+
+  fclose (f);
+
+  return (TRUE);
+
+}
+
+# if (0)
+void ConvertPixmap (Layout *layout, File *f) {
+  
+  /* set up expansions */
+  expand = expand_in = expand_out = 1.0;
+  if (layout[0].expand == 0)
+    layout[0].expand = 1;
+  if (layout[0].expand > 0) {
+    expand = 1 / (1.0*layout[0].expand);
+    expand_out = layout[0].expand;
+    expand_in  = 1;
+  }
+  if (layout[0].expand < 0) {
+    expand = fabs((double)layout[0].expand);
+    expand_out = 1;
+    expand_in  = -layout[0].expand;
+  }
+
+  dx = layout[0].picture.dx;
+  dy = layout[0].picture.dy;
+  DX = layout[0].matrix.Naxis[0];
+  DY = layout[0].matrix.Naxis[1];
+
+  /* X,Y are the image coordinates of the first image pixel */
+  X = MAX(0.5*(DX - dx*expand) - layout[0].X, 0);
+  if ((int)X != X) 
+    X = (int) X + 1;
+  else 
+    X = (int) X;
+  Y = MAX(0.5*(DY - dy*expand) - layout[0].Y, 0);
+  if ((int)Y != Y) 
+    Y = (int) Y + 1;
+  else 
+    Y = (int) Y;
+
+  /* Rx,Ry are the screen coordinates of the first image pixel */
+  Rx = (X + layout[0].X - 0.5*DX)/expand + 0.5*dx;
+  Ry = (Y + layout[0].Y - 0.5*DY)/expand + 0.5*dy;
+
+  i_start = MIN (MAX (Rx, 0), dx - expand_out + 1);
+  j_start = MIN (MAX (Ry, 0), dy - expand_out + 1);
+  
+  if (layout[0].expand > 0) {
+    i_end = MAX (MIN (i_start + ((int)(expand*(dx-i_start)))/expand, expand_out*(DX-X) + Rx), 0);
+    j_end = MAX (MIN (j_start + ((int)(expand*(dy-j_start)))/expand, expand_out*(DY-Y) + Ry), 0);
+  } else {
+    i_end = MAX (MIN (dx, (DX-X)/expand + Rx), 0);
+    j_end = MAX (MIN (dy, (DY-Y)/expand + Ry), 0);
+  }    
+
+  dropback = expand_out - (i_end - i_start) % expand_out;
+  if ((i_end - i_start) % expand_out == 0) dropback = 0;
+
+  /* output line buffer */
+  ALLOCATE (line_buffer, char, dx);
+
+  in_pix_ref  = (unsigned char *) (layout[0].matrix.buffer) + DX*(int)MAX(Y,0) + (int)MAX(X,0);
+
+  /********** below we do the mapping from buffer pixels (in) to picture pixels (out) **********/
+
+  Nchar = 255.0;
+  Npix = layout[0].Npixels;
+  frac = Nchar / Npix;
+
+  /**** fill in bottom area ****/
+  out_pix = line_buffer;
+  for (i = 0; i < dx; i++, out_pix++) {
+    *out_pix = WHITE;
+  }
+  for (j = 0; j < j_start; j++) {
+    for (i = 0; i < dx; i++) {
+      fprintf (f, "%02x", val);
+      if ((Npt % 40) == 0) {
+	fprintf (f, "\n");
+      }
+    }
+  }
+  
+  /*** fill in the image data region ***/
+  for (j = j_start; j < j_end; j+= expand_out, in_pix_ref += expand_in*DX) {
+    
+    /* create one output image line */
+    in_pix = in_pix_ref;
+    out_pix = line_buffer;
+
+    /**** fill in area to the left of the picture ****/
+    for (i = 0; i < i_start; i++, out_pix+=3) {
+      *out_pix = WHITE;
+    }
+    
+    /*** fill in the picture region ***/
+    for (i = i_start; i < i_end; i+=expand_out, in_pix+=expand_in) {
+      for (ii = 0; ii < expand_out; ii++, out_pix++) {
+	*out_pix = *in_pix*frac;
+      }
+    }
+    
+    /**** fill in area to the right of the picture ****/
+    for (i = i_end; i < dx; i++, out_pix++) {
+      *out_pix = WHITE;
+    }
+
+    /* write out the image line expand_out times */
+    for (j = 0; j < expand_out; j++) {
+      for (i = 0; i < dx; i++) {
+	fprintf (f, "%02x", val);
+	if ((Npt % 40) == 0) {
+	  fprintf (f, "\n");
+	}
+      }
+    }
+  }
+
+  /**** fill in top area ****/
+  out_pix = line_buffer;
+  for (i = 0; i < dx; i++, out_pix++) { 
+    *out_pix = WHITE;
+  }
+  for (j = j_end; j < dy; j++) {
+    for (i = 0; i < dx; i++) {
+      fprintf (f, "%02x", val);
+      if ((Npt % 40) == 0) {
+	fprintf (f, "\n");
+      }
+    }
+  }
+}
+# endif
+
+void ConvertPixmap8 (Layout *layout, FILE *f) {
+
+  int i, k, m, val;
+  double Nchar, Npix, start, slope, frac;
+  unsigned char *buff;
+
+  Nchar = 255.0;
+  Npix = layout[0].Npixels;
+  frac = Nchar / Npix;
+  /* start at the last line, print lines in decending order */
+  buff = (unsigned char *)layout[0].picture.data + layout[0].picture.dx*(layout[0].picture.dy - 1);
+  slope = layout[0].slope;
+  start = layout[0].start;
+
+  for (i = 0; i < layout[0].picture.dy; i++) {
+    for (k = 0; k < layout[0].picture.dx; k++, buff++) {
+      if (*buff == layout[0].white) 
+	val = Nchar;
+      else {
+	for (m = 0; (layout[0].cmap[m].pixel != *buff) && (m < Npix); m++);
+	val = Nchar - frac * MIN (MAX (start + m * slope, 0), Npix);
+      }
+      fprintf (f, "%02x", val);
+      if (!((k+1) % 40)) fprintf (f, "\n"); 
+    }
+    fprintf (f, "\n");
+    buff -= 2*layout[0].picture.dx;
+  }
+  return;
+}
+
+void ConvertPixmap16 (Layout *layout, FILE *f) {
+
+  int i, k, m, val;
+  double Nchar, Npix, start, slope, frac;
+  unsigned short *buff;
+
+  Nchar = 255.0;
+  Npix = layout[0].Npixels;
+  frac = Nchar / Npix;
+  /* start at the last line, print lines in decending order */
+  buff = (unsigned short *)layout[0].picture.data + layout[0].picture.dx*(layout[0].picture.dy - 1);
+  slope = layout[0].slope;
+  start = layout[0].start;
+
+  for (i = 0; i < layout[0].picture.dy; i++) {
+    for (k = 0; k < layout[0].picture.dx; k++, buff++) {
+      if (*buff == layout[0].white) 
+	val = Nchar;
+      else {
+	for (m = 0; (layout[0].cmap[m].pixel != *buff) && (m < Npix); m++);
+	val = Nchar - frac * MIN (MAX (start + m * slope, 0), Npix);
+      }
+      fprintf (f, "%02x", val);
+      if (!((k+1) % 40)) fprintf (f, "\n"); 
+    }
+    fprintf (f, "\n");
+    buff -= 2*layout[0].picture.dx;
+  }
+  return;
+}
+
+void ConvertPixmap24 (Layout *layout, FILE *f) {
+
+  int i, k, m, dx, dy, val, extra;
+  unsigned char *buff;
+  unsigned long color, byte;
+  double Nchar, Npix, start, slope, frac;
+
+  Nchar = 255.0;
+  Npix = layout[0].Npixels;
+  frac = Nchar / Npix;
+  dx = layout[0].picture.dx;
+  dy = layout[0].picture.dy;
+  extra = 4 - (dx * 3) % 4;
+  /* start at the last line, print lines in decending order */
+  buff = (unsigned char *)&layout[0].picture.data[(dy - 1)*(3*dx + extra)];
+  slope = layout[0].slope;
+  start = layout[0].start;
+
+  for (i = 0; i < dy; i++) {
+    for (k = 0; k < dx; k++, buff+=3) {
+      color = 0;
+      byte = buff[2];
+      color = (byte << 16);
+      byte = buff[1];
+      color |= (byte << 8);
+      byte = buff[0];
+      color |= byte;
+      for (m = 0; (layout[0].cmap[m].pixel != color) && (m < Npix); m++);
+      val = Nchar - frac * MIN (MAX (start + m * slope, 0), Npix);
+      fprintf (f, "%02x", val);
+      if (!((k+1) % 40)) fprintf (f, "\n"); 
+    }
+    fprintf (f, "\n");
+    buff -= 2*3*dx + extra;
+  }
+  return;
+}
+
+void ConvertPixmap32 (Layout *layout, FILE *f) {
+
+  int i, k, m, val;
+  double Nchar, Npix, start, slope, frac;
+  unsigned int *buff;
+
+  Nchar = 255.0;
+  Npix = layout[0].Npixels;
+  frac = Nchar / Npix;
+  /* start at the last line, print lines in decending order */
+  buff = (unsigned int *)layout[0].picture.data + layout[0].picture.dx*(layout[0].picture.dy - 1);
+  slope = layout[0].slope;
+  start = layout[0].start;
+
+  for (i = 0; i < layout[0].picture.dy; i++) {
+    for (k = 0; k < layout[0].picture.dx; k++, buff++) {
+      if (*buff == layout[0].white) 
+	val = Nchar;
+      else {
+	for (m = 0; (layout[0].cmap[m].pixel != *buff) && (m < Npix); m++);
+	val = Nchar - frac * MIN (MAX (start + m * slope, 0), Npix);
+      }
+      fprintf (f, "%02x", val);
+      if (!((k+1) % 40)) fprintf (f, "\n"); 
+    }
+    fprintf (f, "\n");
+    buff -= 2*layout[0].picture.dx;
+  }
+  return;
+}
Index: /tags/kii-1-4/Ohana/src/kii/colorbar/CreateColorbar.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/colorbar/CreateColorbar.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/colorbar/CreateColorbar.c	(revision 11911)
@@ -0,0 +1,73 @@
+# include "Ximage.h"
+
+void CreateColorbar (Layout *layout, Graphic *graphic) {
+
+  int i, j, dx, dy, extra, start;
+  unsigned long  pixvalue;
+  unsigned int  *out24;
+  unsigned char *out8;
+
+  dx = layout[0].cmapbar.dx;
+  dy = layout[0].cmapbar.dy;
+
+  /* create the cmap scale */
+  switch (graphic[0].Nbits) {
+  case 8:
+    REALLOCATE (layout[0].cmapbar.data, char, dx*dy);
+    out8 = (unsigned char *) layout[0].cmapbar.data;
+    for (i = 0; i < dx; i++) {
+      pixvalue = layout[0].cmap[(int)(i*layout[0].Npixels/dx)].pixel;
+      for (j = 0; j < dy; j++) {
+	out8[j*dx + i] = pixvalue;
+      }
+    }
+    layout[0].cmapbar.pix = XCreateImage (graphic[0].display, graphic[0].visual, graphic[0].depth, ZPixmap, 0, 
+					  layout[0].cmapbar.data, dx, dy, 8, 0);
+    break;
+
+  case 16:
+    REALLOCATE (layout[0].cmapbar.data, char, 2*dy*dx);
+    out8 = (unsigned char *) layout[0].cmapbar.data;
+    for (i = 0; i < dx; i++) {
+      pixvalue = layout[0].cmap[(int)(i*layout[0].Npixels/dx)].pixel;
+      for (j = 0; j < dy; j++) {
+	start = 2*j*dx + 2*i;
+	out8[start + 0] = 0x0000ff & pixvalue;
+	out8[start + 1] = 0x0000ff & (pixvalue >> 8);
+      }
+    }
+    layout[0].cmapbar.pix = XCreateImage (graphic[0].display, graphic[0].visual, graphic[0].depth, ZPixmap, 0, 
+					  layout[0].cmapbar.data, dx, dy, 16, 0);
+    break;
+
+  case 24:
+    extra = 4 - (dx * 3) % 4;
+    REALLOCATE (layout[0].cmapbar.data, char, dy*(3*dx + extra));
+    out8 = (unsigned char *) layout[0].cmapbar.data;
+    for (i = 0; i < dx; i++) {
+      pixvalue = layout[0].cmap[(int)(i*layout[0].Npixels/dx)].pixel;
+      for (j = 0; j < dy; j++) {
+	start = j*(3*dx+extra) + 3*i;
+	out8[start + 0] = 0x0000ff & pixvalue;
+	out8[start + 1] = 0x0000ff & (pixvalue >> 8);
+	out8[start + 2] = 0x0000ff & (pixvalue >> 16);
+      }
+    }
+    layout[0].cmapbar.pix = XCreateImage (graphic[0].display, graphic[0].visual, graphic[0].depth, ZPixmap, 0, 
+					  layout[0].cmapbar.data, dx, dy, 32, 0);
+    break;
+
+  case 32:
+    REALLOCATE (layout[0].cmapbar.data, char, 4*dx*dy);
+    out24 = (unsigned int *) layout[0].cmapbar.data;
+    for (i = 0; i < dx; i++) {
+      pixvalue = layout[0].cmap[(int)(i*layout[0].Npixels/dx)].pixel;
+      for (j = 0; j < dy; j++) {
+	out24[j*dx + i] = pixvalue;
+      }
+    }
+    layout[0].cmapbar.pix = XCreateImage (graphic[0].display, graphic[0].visual, graphic[0].depth, ZPixmap, 0, 
+					  layout[0].cmapbar.data, dx, dy, 32, 0);
+    break;
+  }
+}
Index: /tags/kii-1-4/Ohana/src/kii/colorbar/DragColorbar.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/colorbar/DragColorbar.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/colorbar/DragColorbar.c	(revision 11911)
@@ -0,0 +1,107 @@
+# include "Ximage.h"
+/* future expansion: warp mouse to the right spot for the current settings */
+
+void DragColorbar (Graphic *graphic, Layout *layout, XButtonEvent *mouse_event) {
+
+  double          frac_x, oldfrac_x, frac_y, oldfrac_y, start, slope;
+  int             X, Y;
+  XEvent          event;
+  XMotionEvent   *move;
+  int             xstatus, Npix, center;
+
+  if (!graphic[0].visualclass) return;
+
+  X = mouse_event[0].x;
+  Y = mouse_event[0].y;
+  Npix = layout[0].Npixels;
+  slope = layout[0].slope;
+  start = layout[0].start;
+  oldfrac_x = oldfrac_y = 10;
+  
+  while (1) {
+    frac_x = X / (1.0*graphic[0].dx);
+    frac_x = MAX (0, frac_x);
+    frac_x = MIN (1, frac_x);
+    frac_y = Y / (1.0*graphic[0].dy);
+    frac_y = MAX (0, frac_y);
+    frac_y = MIN (1, frac_y);
+    switch (mouse_event[0].button) {
+    case 1:
+      center = frac_x*Npix;
+      slope = Npix / (1 + 4*frac_y*frac_y*Npix);
+      start = Npix/2.0 - center*slope;
+      break;
+    case 2:
+      start = 0;
+      slope = 1;
+      break;
+    case 3:
+      center = (Npix/2.0 - start) / slope;
+      slope = Npix / (1 + 4*frac_x*frac_x*Npix);
+      start = Npix/2.0 - center*slope;
+      break;
+    }
+
+    if ((frac_x != oldfrac_x) || (frac_y != oldfrac_y)) {
+      ResetColorbar (graphic, layout, start, slope);
+    }
+    oldfrac_x = frac_x;
+    oldfrac_y = frac_y;
+      
+    if ((xstatus = XCheckMaskEvent (graphic[0].display, EVENT_MASK, &event))) {
+      
+      switch (event.type)  {
+	
+      case MotionNotify:
+	if ((xstatus = XPending (graphic[0].display)) < 2) {
+	  move = (XMotionEvent *) &event;
+	  X = move[0].x;
+	  Y = move[0].y;
+	}
+	break;
+	
+      case ButtonPress:
+      case ButtonRelease:
+	layout[0].start = start;	
+	layout[0].slope = slope;
+	return;
+	break;
+	
+      }
+    }
+  }
+  
+}
+
+void ResetColorbar (Graphic *graphic, Layout *layout, double start, double slope) {
+
+  int i, j;
+  XColor cmap[256];
+
+  if (!graphic[0].visualclass) return;
+
+  for (i = 0; i < layout[0].Npixels; i++) {
+    cmap[i] = layout[0].cmap[i];
+    j = start + i * slope;
+    if (j < 0) {
+      cmap[i].red = layout[0].cmap[0].red;
+      cmap[i].blue = layout[0].cmap[0].blue;
+      cmap[i].green = layout[0].cmap[0].green;
+    }
+    else {
+      if (j >= layout[0].Npixels) {
+	cmap[i].red = layout[0].cmap[layout[0].Npixels-1].red;
+	cmap[i].blue = layout[0].cmap[layout[0].Npixels-1].blue;
+	cmap[i].green = layout[0].cmap[layout[0].Npixels-1].green;
+      }
+      else {
+	cmap[i].red = layout[0].cmap[j].red;
+	cmap[i].blue = layout[0].cmap[j].blue;
+	cmap[i].green = layout[0].cmap[j].green;
+      }
+    }
+  }
+
+  XStoreColors(graphic[0].display, graphic[0].colormap, cmap, layout[0].Npixels);
+
+}
Index: /tags/kii-1-4/Ohana/src/kii/colorbar/SetColormap.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/colorbar/SetColormap.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/colorbar/SetColormap.c	(revision 11911)
@@ -0,0 +1,101 @@
+# include "Ximage.h"
+
+/*** this function uses only private colormaps.  it should try the standard colormap
+     first to get better control over the smooth greyscales ***/
+
+int SetColormap (Graphic *graphic, Layout *layout, char *name) {
+
+  int i;
+
+  /* greyscale */
+  if ((!strcmp (name, "grayscale")) || (!strcmp (name, "greyscale"))) {
+    for (i = 0; i < layout[0].Npixels; i++) {  
+      layout[0].cmap[i].red = 256*(255 - 255*i/layout[0].Npixels);
+      layout[0].cmap[i].green = 256*(255 - 255*i/layout[0].Npixels);
+      layout[0].cmap[i].blue = 256*(255 - 255*i/layout[0].Npixels);
+      layout[0].cmap[i].flags = DoRed | DoGreen | DoBlue;
+    }
+    goto store_colors;
+  }
+  /* heat */
+  if (!strcmp (name, "Puns")) {
+    for (i = 0; i < (int)(0.25*layout[0].Npixels); i++) {  
+      layout[0].cmap[i].green = 0;
+      layout[0].cmap[i].blue = 0;
+      layout[0].cmap[i].red = MIN (256*255, 256*255*2*i/(1.0*layout[0].Npixels));  
+      layout[0].cmap[i].flags = DoRed | DoGreen | DoBlue;
+    }
+    for (i = (int)(0.25*layout[0].Npixels); i < (int)(0.50*layout[0].Npixels); i++) {  
+      layout[0].cmap[i].red = MIN (256*255, 256*255*2*i/(1.0*layout[0].Npixels));
+      layout[0].cmap[i].green = MIN (256*255, 256*255*2*(i/(1.0*layout[0].Npixels) - 0.25));
+      layout[0].cmap[i].blue = 0;
+      layout[0].cmap[i].flags = DoRed | DoGreen | DoBlue;
+    }
+    for (i = (int)(0.50*layout[0].Npixels); i < (int)(0.75*layout[0].Npixels); i++) {  
+      layout[0].cmap[i].red = 256*255;
+      layout[0].cmap[i].green = MIN (256*255, 256*255*2*(i/(1.0*layout[0].Npixels) - 0.25));
+      layout[0].cmap[i].blue = MIN (256*255, 256*255*2*(i/(1.0*layout[0].Npixels) - 0.50));
+      layout[0].cmap[i].flags = DoRed | DoGreen | DoBlue;
+    }
+    for (i = (int)(0.75*layout[0].Npixels); i < layout[0].Npixels; i++) {  
+      layout[0].cmap[i].red = 256*255;
+      layout[0].cmap[i].green = 256*255;
+      layout[0].cmap[i].blue = MIN (256*255, 256*255*2*(i/(1.0*layout[0].Npixels) - 0.50));
+      layout[0].cmap[i].flags = DoRed | DoGreen | DoBlue;
+    }
+    goto store_colors;
+  }
+  /* -grayscale */
+  if ((!strcmp (name, "-grayscale")) || (!strcmp (name, "-greyscale"))) {
+    for (i = 0; i < layout[0].Npixels; i++) {  
+      layout[0].cmap[i].red = 256*(255*i/layout[0].Npixels);
+      layout[0].cmap[i].green = 256*(255*i/layout[0].Npixels);
+      layout[0].cmap[i].blue = 256*(255*i/layout[0].Npixels);
+      layout[0].cmap[i].flags = DoRed | DoGreen | DoBlue;
+    }
+    goto store_colors;
+  }
+  /* rainbow */
+  if (!strcmp (name, "Rainbow")) {
+    for (i = 0; i < (int)(0.25*layout[0].Npixels); i++) {  
+      layout[0].cmap[i].red = 0;
+      layout[0].cmap[i].green = 0;
+      layout[0].cmap[i].blue = 256*(255*4*(i/(1.0*layout[0].Npixels)));  
+      layout[0].cmap[i].flags = DoRed | DoGreen | DoBlue;
+    }
+    for (i = (int)(0.25*layout[0].Npixels); i < (int)(0.50*layout[0].Npixels); i++) {  
+      layout[0].cmap[i].red = 256*(255*4*((i/(1.0*layout[0].Npixels)) - 0.25));
+      layout[0].cmap[i].green = 0;
+      layout[0].cmap[i].blue = 256*(255*4*(0.50 - (i/(1.0*layout[0].Npixels))));
+      layout[0].cmap[i].flags = DoRed | DoGreen | DoBlue;
+    }
+    for (i = (int)(0.50*layout[0].Npixels); i < (int)(0.75*layout[0].Npixels); i++) {  
+      layout[0].cmap[i].red = 256*255;
+      layout[0].cmap[i].green = 256*(255*4*((i/(1.0*layout[0].Npixels)) - 0.50));
+      layout[0].cmap[i].blue = 0;
+      layout[0].cmap[i].flags = DoRed | DoGreen | DoBlue;
+    }
+    for (i = (int)(0.75*layout[0].Npixels); i < layout[0].Npixels; i++) {  
+      layout[0].cmap[i].red = 256*255;
+      layout[0].cmap[i].green = 256*255;
+      layout[0].cmap[i].blue = 256*(255*4*((i/(1.0*layout[0].Npixels)) - 0.75));
+      layout[0].cmap[i].flags = DoRed | DoGreen | DoBlue;
+    }
+    goto store_colors;
+  }
+  return (FALSE);
+
+ store_colors:
+  if (!USE_XWINDOW) return (TRUE);
+  if (graphic[0].visualclass) {
+    XStoreColors(graphic[0].display, graphic[0].colormap, layout[0].cmap, layout[0].Npixels);
+  } else {
+    for (i = 0; i < layout[0].Npixels; i++) {
+      if (XAllocColor (graphic[0].display, graphic[0].colormap, &layout[0].cmap[i]) == 0) {
+	fprintf (stderr, "error on %d\n", i);
+      }
+    }
+  }
+  return (TRUE);
+}
+
Index: /tags/kii-1-4/Ohana/src/kii/doc/ChangeLog.txt
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/doc/ChangeLog.txt	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/doc/ChangeLog.txt	(revision 11911)
@@ -0,0 +1,22 @@
+
+- kii 1.4
+  * major work to allow noX operation
+  * added bDraw functions
+  * integrated with libkapa
+
+kii-1-3: released 2005.10.20
+  - changed cursor interaction (returns name for keys)
+  - minor changes to use new libohana (v1.5) / libfits (v1.4)
+
+kii-1-2:
+  - cleaned up the event loop to reduce CPU spinning
+
+kii-1-1: 
+  - cleaned up the update / refresh process to correctly handle
+    uncovered portions.
+  - cleaned up the event loop to handle slow traffic better
+  - cleanup up the cursor event loop in the same way
+  - fixed crash on non-printing cursor keys
+
+kii-1-0:
+  imported to CVS 
Index: /tags/kii-1-4/Ohana/src/kii/doc/VERSIONS
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/doc/VERSIONS	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/doc/VERSIONS	(revision 11911)
@@ -0,0 +1,9 @@
+
+tag names used by kapa:
+
+TAG         : Comment
+kii-1-0     : first version under CVS
+
+USES
+libfits-1-0
+libohana-1-0
Index: /tags/kii-1-4/Ohana/src/kii/event/CheckPipe.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/event/CheckPipe.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/event/CheckPipe.c	(revision 11911)
@@ -0,0 +1,138 @@
+# include "Ximage.h"
+# define STRCONST(A) ((int)(0x1000000*A[0] + 0x10000*A[1] + 0x100*A[2] + 0x1*A[3]))
+# define DEBUG 0
+
+static int ActiveCursor = FALSE;
+
+int CheckPipe (Graphic *graphic, Layout *layout) {
+
+  int status;
+  char buffer[20];
+
+  /* attempt to read 4 bytes from stdin */
+  bzero (buffer, 20);
+  status = read (layout[0].Ximage, buffer, 4);
+  buffer[4] = 0;
+
+  switch (status) {
+  case -1:
+    /* no input from pipe: continue */
+    return (TRUE);
+    break;
+
+  case 0:
+    fprintf (stderr, "pipe has died!\n");
+    return (FALSE);
+    break;
+
+  case 4:
+    if (DEBUG) fprintf (stderr, "got signal %s from pipe\n", buffer);
+    break;
+
+  default:
+    fprintf (stderr, "weird signal: too many or few bytes!  %d\n", status);
+    return (TRUE);
+    break;
+  }
+  
+  /* In Active Cursor mode, we can only receive the NCUR signal */
+  if (ActiveCursor) {
+    if (!strcmp (buffer, "NCUR")) {
+      ActiveCursor = FALSE;
+      return (2);
+    }
+    fprintf (stderr, "unknown signal (AC) %s\n", buffer);
+    return (TRUE);
+  }
+
+  /* If Active Cursor mode is off, we can receive other signal */
+  if (!strcmp (buffer, "QUIT")) {
+    if (DEBUG) fprintf (stderr, "Goodbye!\n");
+    return (FALSE);
+  }
+  
+  if (!strcmp (buffer, "READ")) {
+    status = NewPicture (graphic, layout);
+    return (status);
+  }
+
+  if (!strcmp (buffer, "CURS")) {
+    ActiveCursor = TRUE;
+    status = cursor (graphic, layout);
+    return (status);
+  }
+
+  if (!strcmp (buffer, "NCUR")) {
+    fprintf (stderr, "error: not in active cursor mode\n");
+    return (TRUE);
+  }
+
+  if (!strcmp (buffer, "ERAS")) {
+    status = EraseOverlay (graphic, layout);
+    return (status);
+  }
+
+  if (!strcmp (buffer, "LOAD")) {
+    status = LoadOverlay (graphic, layout);
+    return (status);
+  }
+
+  if (!strcmp (buffer, "TICK")) {
+    status = LoadTickmarks (graphic, layout);
+    return (status);
+  }
+
+  if (!strcmp (buffer, "SAVE")) {
+    status = SaveOverlay (graphic, layout);
+    return (status);
+  }
+
+  if (!strcmp (buffer, "PSIT")) {
+    /** this one needs work : ConvertPixmapN fails for !USE_XWINDOW */
+    status = PSit (graphic, layout, 0);
+    write (layout[0].Ximage, "DONE", 4);
+    return (status);
+  }
+
+  if (!strcmp (buffer, "PSRW")) {
+    /** this one needs work : ConvertPixmapN fails for !USE_XWINDOW */
+    status = PSit (graphic, layout, 1);
+    write (layout[0].Ximage, "DONE", 4);
+    return (status);
+  }
+
+  if (!strcmp (buffer, "JPEG")) {
+    status = JPEGit24 (graphic, layout);
+    write (layout[0].Ximage, "DONE", 4);
+    return (status);
+  }
+
+  if (!strcmp (buffer, "RSIZ")) {
+    status = Resize (graphic, layout);
+    return (status);
+  }
+
+  if (!strcmp (buffer, "CSVE")) {
+    status = CSaveOverlay (graphic, layout);
+    return (status);
+  }
+
+  if (!strcmp (buffer, "CENT")) {
+    status = Center (graphic, layout);
+    return (status);
+  }
+
+  if (!strcmp (buffer, "NPIX")) {
+    sprintf (buffer, "NPIX:   %8d", layout[0].Npixels);
+    write (layout[0].Ximage, buffer, 16);
+    return (TRUE);
+  }
+
+  fprintf (stderr, "unknown signal %s\n", buffer);
+
+  return (TRUE);
+
+}
+
+
+    
Index: /tags/kii-1-4/Ohana/src/kii/event/EventLoop.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/event/EventLoop.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/event/EventLoop.c	(revision 11911)
@@ -0,0 +1,72 @@
+# include "Ximage.h"
+
+# define IgnoreMask (long) (ClientMessage | ButtonReleaseMask)
+
+int LastEvent (Display *display, int type, XEvent *event) {
+
+  int found;
+
+  found = FALSE;
+  while (XCheckTypedEvent (display, type, event)) {
+    found = TRUE;
+  }
+  return (found);
+}
+
+int EventLoop (Graphic *graphic, Layout *layout) {
+  
+  XEvent          event;
+  int             status;
+  Display        *display;
+  
+  if (USE_XWINDOW) Refresh (graphic, layout, 1);
+
+  status = TRUE;
+  while (status) {
+    
+    if (!CheckPipe (graphic, layout))
+      return (FALSE);
+    
+    if (!USE_XWINDOW) {
+      usleep (50000);
+      continue;
+    }
+
+    if (XEventsQueued (graphic[0].display, QueuedAfterFlush) < 1) {
+      usleep (10000);
+      continue;
+    }
+
+    display = graphic[0].display;
+
+    /* grab the last entry for these events */
+    if (LastEvent (display, ConfigureNotify, &event)) Reconfig (graphic, layout, &event);
+    if (LastEvent (display, CirculateNotify, &event)) Reconfig (graphic, layout, &event);
+    if (LastEvent (display, Expose,          &event)) Refresh (graphic, layout, 1);
+    if (LastEvent (display, MotionNotify,    &event)) UpdatePointer (graphic, layout, (XMotionEvent *) &event);
+    if (LastEvent (display, ButtonPress,     &event)) InterpretPresses (graphic, layout, (XButtonEvent *) &event);
+    if (LastEvent (display, KeyPress,        &event)) InterpretKeys (graphic, layout, &event);
+
+    if (LastEvent (display, MappingNotify,   &event)) XRefreshKeyboardMapping ((XMappingEvent *) &event);
+
+    /* drop and ignore the following StructureNotifyMask events */
+    LastEvent (display, GravityNotify, &event);
+    LastEvent (display, ReparentNotify, &event);
+    LastEvent (display, MapNotify, &event);
+    LastEvent (display, UnmapNotify, &event);
+
+    /* remove those events we will ignore */
+    while (XCheckMaskEvent (display, IgnoreMask, &event)) continue;
+  }
+  return (status);
+}
+
+# if (0)
+/* WARNING: this is defined because the HP UX installation i have does not
+seem to know this structure, though it should.  Clearly a need for autoconf.. */
+struct Ktimeval {
+  unsigned long tv_sec;         /* seconds */
+  long          tv_usec;        /* and microseconds */
+};
+# endif
+
Index: /tags/kii-1-4/Ohana/src/kii/event/FlushDisplay.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/event/FlushDisplay.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/event/FlushDisplay.c	(revision 11911)
@@ -0,0 +1,32 @@
+# include "Ximage.h"
+
+static struct timeval reftime; 
+static char reftimeset = FALSE;
+# define DTIME(A,B) ((A.tv_sec - B.tv_sec) + 1e-6*(A.tv_usec - B.tv_usec))
+
+void FlushDisplay (Display *display) {
+
+  struct timeval now;
+  int flush;
+  double dtime;
+
+  flush = FALSE;
+  if (!reftimeset) {
+    flush = TRUE;
+    gettimeofday (&reftime, NULL);
+  } 
+
+  gettimeofday (&now, NULL);
+  dtime = DTIME (now, reftime);
+
+  if (dtime > 0.1) {
+    flush = TRUE;
+  }
+
+  if (flush) {
+    XFlush (display);
+    reftime = now;
+  }
+
+}
+
Index: /tags/kii-1-4/Ohana/src/kii/event/InterpretKeys.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/event/InterpretKeys.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/event/InterpretKeys.c	(revision 11911)
@@ -0,0 +1,39 @@
+# include "Ximage.h"
+
+int InterpretKeys (Graphic *graphic, Layout *layout, XEvent *event) {
+
+  int    status;
+  char   string[10];
+  KeySym keysym;
+  XComposeStatus  composestatus;
+
+  XLookupString ((XKeyEvent *)event, string, 9, &keysym, &composestatus);
+
+  switch (keysym) {
+
+  case XK_Tab:
+    MOVE_POINTER = MOVE_POINTER ^ TRUE;
+    if (MOVE_POINTER) UpdatePointer (graphic, layout, (XMotionEvent *)event);
+    status = TRUE;
+    break;
+
+  default:
+    status = TRUE;
+  }
+
+  return (status);
+
+}
+
+
+
+
+/************* the stuff below this line is old - remove eventually */
+/*
+  case XK_Right:
+  case XK_Left:
+  this is all old, but a good example for putting in the cursor motion.
+
+    break;
+*/
+
Index: /tags/kii-1-4/Ohana/src/kii/event/InterpretPresses.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/event/InterpretPresses.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/event/InterpretPresses.c	(revision 11911)
@@ -0,0 +1,51 @@
+# include "Ximage.h"
+
+int InterpretPresses (Graphic *graphic, Layout *layout, XButtonEvent *event) {
+
+  int             status, done, this_button;
+  Button         *button;
+
+  status = TRUE;
+  this_button = event[0].button;
+  
+  if ((event[0].type == ButtonPress) && InPicture (event, &layout[0].picture)) {
+    Reorient (graphic, layout, event);
+  }
+
+  if ((event[0].type == ButtonPress) && InPicture (event, &layout[0].cmapbar)) {
+    DragColorbar (graphic, layout, event);
+  }
+
+  /* if on an exisiting button, Invert, wait for release, then go (or not) */
+  if ((button = CheckButtons (event, layout)) != (Button *) NULL) {
+    InvertButton (graphic, button); 
+    done = FALSE;
+    while (!done) { /* wait for release of this button */
+      XNextEvent (graphic[0].display, (XEvent *) event);
+      if ((event[0].type == ButtonRelease) && (event[0].button == this_button)) {
+	done = TRUE;
+      }
+    }
+    DrawButton (graphic, button);
+    if (InButton (event, button)) {
+      switch (event[0].button) {
+      case 1:
+	status = button[0].function_1(graphic, layout);
+	break;
+      case 2:
+	status = button[0].function_2(graphic, layout);
+	break;
+      case 3:
+	status = button[0].function_3(graphic, layout);
+	break;
+      }
+    }
+    else {
+      return (status);
+    }
+  }
+
+  return (status);
+
+}
+
Index: /tags/kii-1-4/Ohana/src/kii/event/NextEvent.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/event/NextEvent.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/event/NextEvent.c	(revision 11911)
@@ -0,0 +1,20 @@
+# include "Ximage.h"
+
+/************** NextEvent *************/
+void
+NextEvent (graphic, event, keysym)
+Graphic graphic[];
+XEvent *event;
+KeySym *keysym;
+{
+  int status;
+
+  status = FALSE;
+
+  while (!status) {
+    XNextEvent (graphic[0].display, event);
+    status = ParseEvent (graphic, event, keysym);
+  }
+}
+
+
Index: /tags/kii-1-4/Ohana/src/kii/event/ParseEvent.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/event/ParseEvent.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/event/ParseEvent.c	(revision 11911)
@@ -0,0 +1,61 @@
+# include "Ximage.h"
+
+/************** ParseEvent *************/
+int
+ParseEvent (graphic, event, keysym)
+Graphic graphic[];
+XEvent *event;
+KeySym *keysym;
+{
+
+  XComposeStatus composestatus;
+  char string[10];
+  int status;
+ 
+  status = FALSE;
+  switch (event[0].type) {
+  case ButtonPress:
+    status = TRUE;
+    break;
+  case ButtonRelease:
+    status = TRUE;
+    break;
+  case ClientMessage:
+    status = TRUE;
+    break;
+  case MotionNotify:
+    status = TRUE;
+    break;
+  case PropertyNotify:
+    status = TRUE;
+    break;
+  case SelectionClear:
+    status = TRUE;
+    break;
+  case SelectionNotify:
+    status = TRUE;
+    break;
+  case SelectionRequest:
+    status = TRUE;
+    break;
+  case ConfigureNotify:
+    if ((graphic[0].dx != event[0].xconfigure.width) || 
+	(graphic[0].dy != event[0].xconfigure.height))
+      status = TRUE;
+    break;
+  case Expose:
+    status = TRUE;
+    if (event[0].xexpose.count != 0)
+      status = FALSE;
+    break;
+  case KeyPress:
+    status = TRUE;
+    XLookupString ((XKeyEvent *)event, string, 9, keysym, &composestatus);
+    break;
+  case MappingNotify:
+    XRefreshKeyboardMapping ((XMappingEvent *)event);
+    break;
+  }
+
+  return (status);
+}
Index: /tags/kii-1-4/Ohana/src/kii/event/Reconfig.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/event/Reconfig.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/event/Reconfig.c	(revision 11911)
@@ -0,0 +1,20 @@
+# include "Ximage.h"
+# define MAX_STRING 100
+
+int Reconfig (Graphic *graphic, Layout *layout, XEvent *event) {
+  
+  if ((graphic[0].dx == event[0].xconfigure.width) &&
+      (graphic[0].dy == event[0].xconfigure.height)) 
+    return (TRUE);
+
+  graphic[0].dx = MAX(event[0].xconfigure.width,  MIN_WIDTH); 
+  graphic[0].dy = MAX(event[0].xconfigure.height, MIN_HEIGHT);
+
+  XClearWindow (graphic[0].display, graphic[0].window);
+  PositionPictures (layout, graphic);
+  CreateColorbar (layout, graphic);
+  CreatePicture (layout, graphic);
+  Remap (graphic, layout, &layout[0].matrix); 
+  Refresh (graphic, layout, 1);
+  return (TRUE);
+}
Index: /tags/kii-1-4/Ohana/src/kii/event/Refresh.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/event/Refresh.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/event/Refresh.c	(revision 11911)
@@ -0,0 +1,55 @@
+# 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 */
+
Index: /tags/kii-1-4/Ohana/src/kii/event/Stop.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/event/Stop.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/event/Stop.c	(revision 11911)
@@ -0,0 +1,19 @@
+# include "Ximage.h"
+# define XBorder 10
+# define YBorder 2
+
+int
+Stop (graphic, layout)
+Graphic   graphic[];
+Layout    layout[];
+{
+  return (FALSE);
+}
+
+
+
+
+
+
+/******  this function looks stupid, but it has to be like this:
+  it is called as a pointer to function **/
Index: /tags/kii-1-4/Ohana/src/kii/include/Ximage.h
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/include/Ximage.h	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/include/Ximage.h	(revision 11911)
@@ -0,0 +1,8 @@
+# include <Xohana.h>
+# include <dvo.h>
+# include <kapa.h>
+# include "constants.h"
+# include "structures.h"
+# include "prototypes.h"
+
+/* dvo.h is used only for Coords */
Index: /tags/kii-1-4/Ohana/src/kii/include/alphabet.h
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/include/alphabet.h	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/include/alphabet.h	(revision 11911)
@@ -0,0 +1,53 @@
+# include "../rotfont/times8.h"
+# include "../rotfont/times12.h"
+# include "../rotfont/times14.h"
+# include "../rotfont/times18.h"
+# include "../rotfont/times24.h"
+
+# include "../rotfont/courier8.h"
+# include "../rotfont/courier12.h"
+# include "../rotfont/courier14.h"
+# include "../rotfont/courier18.h"
+# include "../rotfont/courier24.h"
+
+# include "../rotfont/helvetica8.h"
+# include "../rotfont/helvetica12.h"
+# include "../rotfont/helvetica14.h"
+# include "../rotfont/helvetica18.h"
+# include "../rotfont/helvetica24.h"
+
+# include "../rotfont/symbol8.h"
+# include "../rotfont/symbol12.h"
+# include "../rotfont/symbol14.h"
+# include "../rotfont/symbol18.h"
+# include "../rotfont/symbol24.h"
+
+# define DEFFONT 1
+static FontSet HardwiredFonts[] = {
+  {times8font,  "times", 8},
+  {times12font, "times", 12},
+  {times14font, "times", 14},
+  {times18font, "times", 18},
+  {times24font, "times", 24},
+  
+  {courier8font,  "courier", 8},
+  {courier12font, "courier", 12},
+  {courier14font, "courier", 14},
+  {courier18font, "courier", 18},
+  {courier24font, "courier", 24},
+  
+  {helvetica8font,  "helvetica", 8},
+  {helvetica12font, "helvetica", 12},
+  {helvetica14font, "helvetica", 14},
+  {helvetica18font, "helvetica", 18},
+  {helvetica24font, "helvetica", 24},
+  
+  {symbol8font,  "symbol", 8},
+  {symbol12font, "symbol", 12},
+  {symbol14font, "symbol", 14},
+  {symbol18font, "symbol", 18},
+  {symbol24font, "symbol", 24}
+};
+
+/* put these as static in RotFont.c with accessor functions */
+# define NROT 256
Index: /tags/kii-1-4/Ohana/src/kii/include/bDraw.h
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/include/bDraw.h	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/include/bDraw.h	(revision 11911)
@@ -0,0 +1,52 @@
+# include <png.h>
+
+typedef png_byte bDrawColor;
+
+typedef struct {
+  int Nx, Ny;
+  bDrawColor **pixels;
+} bDrawBuffer;
+
+# if (0)
+int bDrawObjects (Layout *layout);
+void bDrawConnect (Layout *layout, Gobjects *object);
+void bDrawClipLine (double x0, double y0, double x1, double y1, double X0, double Y1, double X1, double Y0);
+void bDrawHistogram (Layout *layout, Gobjects *object);
+void bDrawPoints (Layout *layout, Gobjects *object);
+void bDrawXErrors (Layout *layout, Gobjects *object);
+void bDrawYErrors (Layout *layout, Gobjects *object);
+int bDrawFrame (Layout *layout);
+void bDrawTick (double fx, double fy, double dfx, double dfy, int P, double min, double max, double value, int mode, int naxis);
+void bDrawLabels (Layout *layout);
+void bDrawPtext (Layout *layout);
+# endif
+
+bDrawBuffer *bDrawBufferCreate (int Nx, int Ny);
+void bDrawBufferFree (bDrawBuffer *buffer);
+void bDrawSetBuffer (bDrawBuffer *buffer);
+void bDrawSetStyle (bDrawColor color, int lw, int lt);
+void bDrawPoint (int x, int y);
+void bDrawPointf (float x, float y);
+
+void bDrawArc (double Xc, double Yc, double Xr, double Yr, double Ts, double Te);
+void bDrawCircle (double Xc, double Yc, double radius);
+void bDrawCircleFill (double xc, double yc, double radius);
+
+void bDrawLine (double x1, double y1, double x2, double y2);
+void bDrawLineWeight (int X1, int Y1, int X2, int Y2, int swapcoords);
+void bDrawLineBresen (int X1, int Y1, int X2, int Y2, int swapcoords);
+void bDrawLineHorizontal (int X1, int X2, int Y);
+void bDrawLineVertical (int X, int Y1, int Y2);
+
+png_color *MakePNGPalette (int *Npalette);
+bDrawColor GetColorByName (char *name);
+bDrawBuffer *bDrawIt ();
+
+void bDrawRectOpen (double x1, double y1, double x2, double y2);
+void bDrawRectFill (double x1, double y1, double x2, double y2);
+void bDrawTriOpen (double x1, double y1, double x2, double y2, double x3, double y3);
+void bDrawTriFill (double x1, double y1, double x2, double y2, double x3, double y3);
+int bDrawRotText (int x, int y, char *string, int pos, double angle);
+int bDrawRotBitmap (int x, int y, int dx, int dy, unsigned char *bitmap, int mode, double angle, double scale);
+
+void bDrawOverlay (Layout *layout, int N);
Index: /tags/kii-1-4/Ohana/src/kii/include/buttons.h
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/include/buttons.h	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/include/buttons.h	(revision 11911)
@@ -0,0 +1,120 @@
+#define PS_width 25
+#define PS_height 25
+static char PS_bits[] = {
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x81, 0x3f, 0x00,
+   0x82, 0x67, 0x60, 0x00, 0x02, 0x26, 0x40, 0x00, 0x02, 0x24, 0x40, 0x00,
+   0x02, 0x24, 0x00, 0x00, 0x02, 0x24, 0x00, 0x00, 0x02, 0x24, 0x00, 0x00,
+   0x02, 0x24, 0x00, 0x00, 0x02, 0x64, 0x00, 0x00, 0x02, 0xc6, 0x00, 0x00,
+   0x82, 0x07, 0x07, 0x00, 0xfe, 0x01, 0x0c, 0x00, 0x02, 0x00, 0x18, 0x00,
+   0x02, 0x00, 0x20, 0x00, 0x02, 0x00, 0x60, 0x00, 0x02, 0x00, 0x40, 0x00,
+   0x02, 0x00, 0xc0, 0x00, 0x02, 0x10, 0x80, 0x00, 0x02, 0x10, 0xc0, 0x00,
+   0x02, 0x60, 0x60, 0x00, 0x02, 0x80, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00}; 
+#define grey_width 25
+#define grey_height 25
+static char grey_bits[] = {
+   0x90, 0x40, 0xf7, 0x01, 0x04, 0xaa, 0xad, 0x01, 0x68, 0xd5, 0xfe, 0x01,
+   0x82, 0x28, 0xdb, 0x01, 0x10, 0xd2, 0x75, 0x01, 0x40, 0xad, 0xee, 0x01,
+   0xac, 0x50, 0xbf, 0x01, 0x00, 0xaa, 0xf9, 0x01, 0x52, 0xd5, 0xd6, 0x01,
+   0x80, 0x28, 0x6f, 0x01, 0x28, 0xd2, 0xfd, 0x01, 0x44, 0xad, 0xba, 0x01,
+   0x90, 0x50, 0xf7, 0x01, 0x02, 0xaa, 0xcd, 0x01, 0x68, 0xd5, 0x7e, 0x01,
+   0x80, 0x28, 0xfb, 0x01, 0x14, 0xd2, 0xb5, 0x01, 0x40, 0xad, 0xee, 0x01,
+   0xaa, 0x50, 0xdf, 0x01, 0x00, 0xaa, 0x79, 0x01, 0x50, 0xd5, 0xf6, 0x01,
+   0x84, 0x28, 0xaf, 0x01, 0x28, 0xd2, 0xfd, 0x01, 0x40, 0xad, 0xda, 0x01,
+   0x90, 0x50, 0x77, 0x01};
+#define rainbow_width 25
+#define rainbow_height 25
+static char rainbow_bits[] = {
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x80, 0xff, 0x00, 0x00, 0x70, 0x00, 0x01, 0x00, 0x0c, 0x7f, 0x00,
+   0x00, 0xe3, 0x80, 0x01, 0xc0, 0x9c, 0xff, 0x00, 0x20, 0x62, 0x00, 0x01,
+   0x90, 0x99, 0xff, 0x00, 0x48, 0x76, 0x00, 0x01, 0x24, 0x09, 0x00, 0x00,
+   0x94, 0x06, 0x00, 0x00, 0x52, 0x01, 0x00, 0x00, 0xaa, 0x00, 0x00, 0x00,
+   0xa5, 0x00, 0x00, 0x00, 0x55, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00,
+   0x2a, 0x00, 0x00, 0x00, 0x2a, 0x00, 0x00, 0x00, 0x16, 0x00, 0x00, 0x00,
+   0x15, 0x00, 0x00, 0x00, 0x15, 0x00, 0x00, 0x00, 0x15, 0x00, 0x00, 0x00,
+   0x15, 0x00, 0x00, 0x00};
+#define recenter_width 25
+#define recenter_height 25
+static char recenter_bits[] = {
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x00, 0x00,
+   0x80, 0xef, 0x03, 0x00, 0xe0, 0x00, 0x0e, 0x00, 0x30, 0x00, 0x18, 0x00,
+   0x10, 0x00, 0x10, 0x00, 0x18, 0x00, 0x30, 0x00, 0x08, 0x00, 0x20, 0x00,
+   0x0c, 0x00, 0x60, 0x00, 0x0c, 0x38, 0x60, 0x00, 0x0c, 0x7c, 0x60, 0x00,
+   0x04, 0x7c, 0x40, 0x00, 0x0c, 0x7c, 0x60, 0x00, 0x0c, 0x38, 0x60, 0x00,
+   0x0c, 0x00, 0x60, 0x00, 0x08, 0x00, 0x20, 0x00, 0x18, 0x00, 0x30, 0x00,
+   0x10, 0x00, 0x10, 0x00, 0x30, 0x00, 0x18, 0x00, 0xe0, 0x00, 0x0e, 0x00,
+   0x80, 0xef, 0x03, 0x00, 0x00, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00};
+#define puns_width 25
+#define puns_height 25
+static char puns_bits[] = {
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x07, 0xd8, 0x01,
+   0x00, 0x0c, 0x37, 0x00, 0xf8, 0xc9, 0x6f, 0x00, 0x0c, 0xde, 0xf0, 0x00,
+   0x06, 0x5b, 0x1f, 0x00, 0x7b, 0xd9, 0x0c, 0x00, 0xc9, 0x70, 0x06, 0x00,
+   0x81, 0x71, 0x03, 0x00, 0x78, 0xb9, 0x39, 0x00, 0xc8, 0xdb, 0x0f, 0x00,
+   0x84, 0xf7, 0x7f, 0x00, 0x04, 0xff, 0xc3, 0x00, 0xe6, 0xfe, 0x8e, 0x00,
+   0x9a, 0x7d, 0x0b, 0x00, 0x08, 0xbc, 0x01, 0x00, 0x08, 0xfc, 0x3f, 0x00,
+   0x0c, 0xff, 0x78, 0x00, 0x84, 0x39, 0x60, 0x00, 0x40, 0x38, 0x40, 0x00,
+   0x60, 0x38, 0x40, 0x00, 0x20, 0x38, 0x00, 0x00, 0x00, 0x7c, 0x00, 0x00,
+   0x00, 0xd6, 0x00, 0x00};
+#define red_width 25
+#define red_height 25
+static char red_bits[] = {
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0xfc, 0x03, 0x00,
+   0x20, 0x07, 0x06, 0x00, 0xe0, 0x00, 0x0c, 0x00, 0x20, 0x00, 0x08, 0x00,
+   0x20, 0x00, 0x08, 0x00, 0x20, 0x00, 0x08, 0x00, 0x20, 0x00, 0x08, 0x00,
+   0x20, 0x00, 0x0c, 0x00, 0x20, 0x00, 0x06, 0x00, 0x20, 0x80, 0x01, 0x00,
+   0x20, 0xe0, 0x00, 0x00, 0x20, 0x7e, 0x00, 0x00, 0xe0, 0xc3, 0x00, 0x00,
+   0x20, 0xc0, 0x00, 0x00, 0x20, 0x80, 0x00, 0x00, 0x20, 0x80, 0x01, 0x00,
+   0x20, 0x00, 0x01, 0x00, 0x20, 0x00, 0x01, 0x00, 0x20, 0x00, 0x03, 0x00,
+   0x20, 0x00, 0x06, 0x00, 0x20, 0x00, 0x0c, 0x00, 0x20, 0x00, 0x18, 0x00,
+   0x00, 0x00, 0x00, 0x00};
+#define green_width 25
+#define green_height 25
+static char green_bits[] = {
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x07, 0x00,
+   0x00, 0x06, 0x04, 0x00, 0x80, 0x03, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00,
+   0x40, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00,
+   0x40, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00,
+   0x40, 0x00, 0x00, 0x00, 0x40, 0x80, 0x0f, 0x00, 0x40, 0xc0, 0x30, 0x00,
+   0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0x40, 0x00,
+   0x40, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0x80, 0x01, 0x08, 0x00,
+   0x00, 0x03, 0x08, 0x00, 0x00, 0x7e, 0x0e, 0x00, 0x00, 0xc0, 0x03, 0x00,
+   0x00, 0x00, 0x00, 0x00};
+#define blue_width 25
+#define blue_height 25
+static char blue_bits[] = {
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0xfe, 0x00, 0x00,
+   0xc0, 0x83, 0x07, 0x00, 0xc0, 0x00, 0x0c, 0x00, 0x40, 0x00, 0x08, 0x00,
+   0x40, 0x00, 0x08, 0x00, 0x40, 0x00, 0x08, 0x00, 0x40, 0x00, 0x08, 0x00,
+   0x40, 0x00, 0x0c, 0x00, 0x40, 0x00, 0x04, 0x00, 0x40, 0x00, 0x02, 0x00,
+   0x40, 0x80, 0x07, 0x00, 0x40, 0xe0, 0x0c, 0x00, 0xc0, 0x3f, 0x08, 0x00,
+   0x40, 0x00, 0x08, 0x00, 0x40, 0x00, 0x08, 0x00, 0x40, 0x00, 0x08, 0x00,
+   0x40, 0x00, 0x0c, 0x00, 0x40, 0x00, 0x06, 0x00, 0x40, 0x00, 0x02, 0x00,
+   0xc0, 0x80, 0x03, 0x00, 0x40, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00};
+#define yellow_width 25
+#define yellow_height 25
+static char yellow_bits[] = {
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x18, 0x00,
+   0x80, 0x01, 0x0c, 0x00, 0x00, 0x03, 0x06, 0x00, 0x00, 0x02, 0x02, 0x00,
+   0x00, 0x84, 0x01, 0x00, 0x00, 0xcc, 0x00, 0x00, 0x00, 0x58, 0x00, 0x00,
+   0x00, 0x30, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00,
+   0x00, 0x10, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00,
+   0x00, 0x20, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00,
+   0x00, 0x30, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00,
+   0x00, 0x30, 0x00, 0x00, 0x00, 0xcc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00};
+#define hms_width 25
+#define hms_height 25
+static char hms_bits[] = {
+   0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
+   0x02, 0x00, 0x00, 0x00, 0x02, 0x01, 0xf0, 0x00, 0x1e, 0xef, 0x89, 0x00,
+   0x22, 0x11, 0x09, 0x00, 0x22, 0x11, 0x71, 0x00, 0x22, 0x11, 0x81, 0x00,
+   0x22, 0x11, 0x89, 0x00, 0x22, 0x01, 0x79, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x1e, 0xc7, 0xf1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x80, 0x80, 0x00,
+   0x40, 0x80, 0x80, 0x00, 0x40, 0x80, 0x80, 0x00, 0x40, 0x80, 0x80, 0x00,
+   0x40, 0x80, 0x80, 0x00, 0x5c, 0xb8, 0xb8, 0x00, 0x62, 0xc4, 0xc4, 0x00,
+   0x42, 0x84, 0x84, 0x00, 0x42, 0x84, 0x84, 0x00, 0x62, 0xc4, 0xc4, 0x00,
+   0x5c, 0xb9, 0xb8, 0x00};
Index: /tags/kii-1-4/Ohana/src/kii/include/constants.h
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/include/constants.h	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/include/constants.h	(revision 11911)
@@ -0,0 +1,58 @@
+# define PAD1  5
+# define PAD2  3
+# define TEXTPAD 25
+# define COLORPAD 10
+# define TEXT_Y 15
+# define ZOOM_X 170
+# define ZOOM_Y 170
+# define NOVERLAYS 4
+/* number of overlays is defined here.
+   the number is also crucial in the following files:
+   PositionPictures.c
+   MakeColormap.c
+   prototypes.h
+*/
+
+# define DEFAULT_CURSOR XC_crosshair
+# define BORDER_WIDTH 2
+# define MIN_WIDTH 10
+# define MIN_HEIGHT 20
+# define AssignText(X,T) allocate (X, char, strlen (T)); strcpy (X, T);
+# define AssignData(X,T,N) allocate (X, char, N); bcopy (T, X, N);
+
+int OVERLAY[NOVERLAYS];
+int MOVE_POINTER;
+int DECIMAL_DEG;
+int DEBUG;
+int FOREGROUND;
+int USE_XWINDOW;
+int MAP_WINDOW;
+char *NAME_WINDOW;
+
+# define EVENT_MASK (long) \
+(ButtonPressMask \
+ | ClientMessage \
+ | ButtonReleaseMask \
+ | KeyPressMask \
+ | ExposureMask \
+ | StructureNotifyMask \
+ | PointerMotionMask)
+
+/* EVENT_MASK consists of:
+
+ExposureMask        : Expose
+StructureNotifyMask : CirculateNotify | 
+                      ConfigureNotify | 
+                      DestroyNotify   | 
+		      GravityNotify   | 
+		      MapNotify       |
+		      ReparentNotify  |
+		      UnmapNotify
+ButtonPressMask     : ButtonPress
+ButtonReleaseMask   : ButtonRelease
+KeyPressMask        : KeyPress
+PointerMotionMask   : MotionNotify
+(always)            : ClientMessage 
+(always)            : MappingNotify
+
+*/
Index: /tags/kii-1-4/Ohana/src/kii/include/icons/R0.h
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/include/icons/R0.h	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/include/icons/R0.h	(revision 11911)
@@ -0,0 +1,4 @@
+#define R0_width 9
+#define R0_height 6
+static char R0_bits[] = {
+   0x00, 0x00, 0x7c, 0x00, 0x82, 0x00, 0x01, 0x01, 0x82, 0x00, 0x7c, 0x00};
Index: /tags/kii-1-4/Ohana/src/kii/include/icons/R1.h
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/include/icons/R1.h	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/include/icons/R1.h	(revision 11911)
@@ -0,0 +1,4 @@
+#define R1_width 9
+#define R1_height 6
+static char R1_bits[] = {
+   0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0xff, 0x01, 0x02, 0x01, 0x04, 0x01};
Index: /tags/kii-1-4/Ohana/src/kii/include/icons/R2.h
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/include/icons/R2.h	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/include/icons/R2.h	(revision 11911)
@@ -0,0 +1,4 @@
+#define R2_width 9
+#define R2_height 6
+static char R2_bits[] = {
+   0x00, 0x00, 0x0e, 0x01, 0x11, 0x01, 0x21, 0x01, 0x41, 0x01, 0x86, 0x01};
Index: /tags/kii-1-4/Ohana/src/kii/include/icons/R3.h
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/include/icons/R3.h	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/include/icons/R3.h	(revision 11911)
@@ -0,0 +1,4 @@
+#define R3_width 9
+#define R3_height 6
+static char R3_bits[] = {
+   0x00, 0x00, 0xe3, 0x00, 0x15, 0x01, 0x19, 0x01, 0x11, 0x01, 0x81, 0x00};
Index: /tags/kii-1-4/Ohana/src/kii/include/icons/R4.h
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/include/icons/R4.h	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/include/icons/R4.h	(revision 11911)
@@ -0,0 +1,4 @@
+#define R4_width 9
+#define R4_height 6
+static char R4_bits[] = {
+   0x00, 0x00, 0x40, 0x00, 0xff, 0x01, 0x44, 0x00, 0x58, 0x00, 0x60, 0x00};
Index: /tags/kii-1-4/Ohana/src/kii/include/icons/R5.h
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/include/icons/R5.h	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/include/icons/R5.h	(revision 11911)
@@ -0,0 +1,4 @@
+#define R5_width 9
+#define R5_height 6
+static char R5_bits[] = {
+   0x00, 0x00, 0xf1, 0x00, 0x09, 0x01, 0x09, 0x01, 0x11, 0x01, 0x9f, 0x00};
Index: /tags/kii-1-4/Ohana/src/kii/include/icons/R6.h
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/include/icons/R6.h	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/include/icons/R6.h	(revision 11911)
@@ -0,0 +1,4 @@
+#define R6_width 9
+#define R6_height 6
+static char R6_bits[] = {
+   0x00, 0x00, 0xe2, 0x00, 0x11, 0x01, 0x11, 0x01, 0x11, 0x01, 0xfe, 0x00};
Index: /tags/kii-1-4/Ohana/src/kii/include/icons/R7.h
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/include/icons/R7.h	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/include/icons/R7.h	(revision 11911)
@@ -0,0 +1,4 @@
+#define R7_width 9
+#define R7_height 6
+static char R7_bits[] = {
+   0x00, 0x00, 0x03, 0x00, 0x0d, 0x00, 0x31, 0x00, 0xc1, 0x01, 0x01, 0x00};
Index: /tags/kii-1-4/Ohana/src/kii/include/icons/R8.h
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/include/icons/R8.h	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/include/icons/R8.h	(revision 11911)
@@ -0,0 +1,4 @@
+#define R8_width 9
+#define R8_height 6
+static char R8_bits[] = {
+   0x00, 0x00, 0xee, 0x00, 0x11, 0x01, 0x11, 0x01, 0x11, 0x01, 0xee, 0x00};
Index: /tags/kii-1-4/Ohana/src/kii/include/icons/R9.h
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/include/icons/R9.h	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/include/icons/R9.h	(revision 11911)
@@ -0,0 +1,4 @@
+#define R9_width 9
+#define R9_height 6
+static char R9_bits[] = {
+   0x00, 0x00, 0xfe, 0x00, 0x11, 0x01, 0x11, 0x01, 0x11, 0x01, 0x8e, 0x00};
Index: /tags/kii-1-4/Ohana/src/kii/include/icons/Rd.h
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/include/icons/Rd.h	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/include/icons/Rd.h	(revision 11911)
@@ -0,0 +1,4 @@
+#define Rd_width 9
+#define Rd_height 6
+static char Rd_bits[] = {
+   0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0xc0, 0x01, 0x80, 0x00, 0x00, 0x00};
Index: /tags/kii-1-4/Ohana/src/kii/include/icons/Re.h
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/include/icons/Re.h	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/include/icons/Re.h	(revision 11911)
@@ -0,0 +1,4 @@
+#define Re_width 9
+#define Re_height 6
+static char Re_bits[] = {
+   0x00, 0x00, 0xb0, 0x00, 0x28, 0x01, 0x28, 0x01, 0x28, 0x01, 0xf0, 0x00};
Index: /tags/kii-1-4/Ohana/src/kii/include/icons/Rm.h
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/include/icons/Rm.h	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/include/icons/Rm.h	(revision 11911)
@@ -0,0 +1,4 @@
+#define Rm_width 9
+#define Rm_height 6
+static char Rm_bits[] = {
+   0x00, 0x00, 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0x10, 0x00};
Index: /tags/kii-1-4/Ohana/src/kii/include/icons/Rp.h
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/include/icons/Rp.h	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/include/icons/Rp.h	(revision 11911)
@@ -0,0 +1,4 @@
+#define Rp_width 9
+#define Rp_height 6
+static char Rp_bits[] = {
+   0x00, 0x00, 0x10, 0x00, 0x10, 0x00, 0x7c, 0x00, 0x10, 0x00, 0x10, 0x00};
Index: /tags/kii-1-4/Ohana/src/kii/include/icons/arrow.h
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/include/icons/arrow.h	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/include/icons/arrow.h	(revision 11911)
@@ -0,0 +1,4 @@
+#define arrow_width 6
+#define arrow_height 9
+static char arrow_bits[] = {
+   0x00, 0x02, 0x06, 0x0e, 0x1e, 0x0e, 0x06, 0x02, 0x00};
Index: /tags/kii-1-4/Ohana/src/kii/include/icons/back.h
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/include/icons/back.h	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/include/icons/back.h	(revision 11911)
@@ -0,0 +1,6 @@
+#define back_width 16
+#define back_height 16
+static char back_bits[] = {
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x3c, 0x00, 0x3f, 0xc0, 0x3f,
+   0xf0, 0x3f, 0xfc, 0x3f, 0xfc, 0x3f, 0xf0, 0x3f, 0xc0, 0x3f, 0x00, 0x3f,
+   0x00, 0x3c, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00};
Index: /tags/kii-1-4/Ohana/src/kii/include/icons/down.h
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/include/icons/down.h	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/include/icons/down.h	(revision 11911)
@@ -0,0 +1,4 @@
+#define down_width 9
+#define down_height 6
+static char down_bits[] = {
+   0x00, 0x00, 0xfe, 0x00, 0x7c, 0x00, 0x38, 0x00, 0x10, 0x00, 0x00, 0x00};
Index: /tags/kii-1-4/Ohana/src/kii/include/icons/fore.h
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/include/icons/fore.h	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/include/icons/fore.h	(revision 11911)
@@ -0,0 +1,6 @@
+#define fore_width 16
+#define fore_height 16
+static char fore_bits[] = {
+   0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x3c, 0x00, 0xfc, 0x00, 0xfc, 0x03,
+   0xfc, 0x0f, 0xfc, 0x3f, 0xfc, 0x3f, 0xfc, 0x0f, 0xfc, 0x03, 0xfc, 0x00,
+   0x3c, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00};
Index: /tags/kii-1-4/Ohana/src/kii/include/icons/icon.h
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/include/icons/icon.h	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/include/icons/icon.h	(revision 11911)
@@ -0,0 +1,13 @@
+#define icon_width 30
+#define icon_height 30
+static char icon_bits[] = {
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x01, 0x00,
+   0x00, 0xfe, 0x0f, 0x00, 0x00, 0xff, 0x1f, 0x00, 0xc0, 0x0f, 0x7e, 0x00,
+   0xe0, 0x01, 0xf0, 0x00, 0xe0, 0xff, 0xff, 0x00, 0xf0, 0xff, 0xff, 0x01,
+   0xb8, 0xff, 0xbf, 0x03, 0xb8, 0x03, 0xb8, 0x03, 0xb8, 0xe3, 0xb8, 0x03,
+   0x9c, 0xf3, 0x39, 0x07, 0x9c, 0xfb, 0x3b, 0x07, 0x9c, 0xfb, 0x3b, 0x07,
+   0x9c, 0xfb, 0x3b, 0x07, 0x9c, 0xf3, 0x39, 0x07, 0xb8, 0xe3, 0xb8, 0x03,
+   0xb8, 0x03, 0xb8, 0x03, 0xb8, 0xff, 0xbf, 0x03, 0xf0, 0xff, 0xff, 0x01,
+   0xe0, 0xff, 0xff, 0x00, 0xe0, 0x01, 0xf0, 0x00, 0xc0, 0x0f, 0x7e, 0x00,
+   0x00, 0xff, 0x1f, 0x00, 0x00, 0xfe, 0x0f, 0x00, 0x00, 0xf0, 0x01, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
Index: /tags/kii-1-4/Ohana/src/kii/include/icons/stop.h
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/include/icons/stop.h	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/include/icons/stop.h	(revision 11911)
@@ -0,0 +1,6 @@
+#define stop_width 16
+#define stop_height 16
+static char stop_bits[] = {
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x1f, 0xf8, 0x1f, 0xf8, 0x1f,
+   0xf8, 0x1f, 0xf8, 0x1f, 0xf8, 0x1f, 0xf8, 0x1f, 0xf8, 0x1f, 0xf8, 0x1f,
+   0xf8, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
Index: /tags/kii-1-4/Ohana/src/kii/include/prototypes.h
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/include/prototypes.h	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/include/prototypes.h	(revision 11911)
@@ -0,0 +1,109 @@
+
+int args (int *argc, char **argv);
+
+void bDrawOverlay (Layout *layout, int N);
+
+int SetColormap (Graphic *graphic, Layout *layout, char *name);
+void FlushDisplay (Display *display);
+int Recenter (Graphic *graphic, Layout *layout);
+void DrawOverlay (Graphic *graphic, Layout *layout, int N, FILE *f, int extra);
+int cursor (Graphic *graphic, Layout *layout);
+int PSit (Graphic *graphic, Layout *layout, int Raw);
+int JPEGit (Graphic *graphic, Layout *layout);
+int JPEGit24 (Graphic *graphic, Layout *layout);
+int Resize (Graphic *graphic, Layout *layout);
+int Center (Graphic *graphic, Layout *layout);
+int LoadTickmarks (Graphic *graphic, Layout *layout);
+void PaintTickmarks (Graphic *graphic, Layout *layout);
+void Screen_to_Image (double *x1, double *y1, double x2, double y2, Layout *layout);
+void Image_to_Screen (double *x1, double *y1, double x2, double y2, Layout *layout);
+void UpdateStatusBox (Graphic *graphic, Layout *layout, double x, double y, double z, int mode);
+void Remap8 (Graphic *graphic, Layout *layout, Matrix *matrix);
+void Remap16 (Graphic *graphic, Layout *layout, Matrix *matrix);
+void Remap24 (Graphic *graphic, Layout *layout, Matrix *matrix);
+void Remap32 (Graphic *graphic, Layout *layout, Matrix *matrix);
+void CheckVisual (Graphic *graphic, int *argc, char **argv);
+void CreateZoom8 (Layout *layout, Graphic *graphic, double x, double y);
+void CreateZoom16 (Layout *layout, Graphic *graphic, double x, double y);
+void CreateZoom24 (Layout *layout, Graphic *graphic, double x, double y);
+void CreateZoom32 (Layout *layout, Graphic *graphic, double x, double y);
+
+/***** Prototypes for image ***************/
+
+void          PositionPictures    PROTO((Layout *, Graphic *));
+void          CreateColorbar      PROTO((Layout *, Graphic *));
+void          CreatePicture       PROTO((Layout *, Graphic *));
+void          CreateZoom          PROTO((Layout *, Graphic *, double, double));
+void          Remap               PROTO((Graphic *, Layout *, Matrix  *));
+int           NewPicture          PROTO((Graphic *, Layout *));
+void          Reorient            PROTO((Graphic *, Layout *, XButtonEvent *));
+int           UpdatePointer       PROTO((Graphic *, Layout *, XMotionEvent *));
+void          CrossHairs          PROTO((Graphic *, Layout *));
+int           LoadOverlay         PROTO((Graphic *, Layout *));
+int           SaveOverlay         PROTO((Graphic *, Layout *));
+int           CSaveOverlay         PROTO((Graphic *, Layout *));
+int           EraseOverlay        PROTO((Graphic *, Layout *));
+void          StatusBox           PROTO((Graphic *, Layout *));
+void          PaintOverlay        PROTO((Graphic *, Layout *, int));
+
+/***** Prototypes for action ***************/
+
+int           CheckPipe           PROTO((Graphic *, Layout *));
+void          DefineLayout        PROTO((Layout *, Graphic *, int, char **));
+int           EventLoop           PROTO((Graphic *, Layout *));
+int           InPicture           PROTO((XButtonEvent *, Picture *));
+int           InterpretKeys       PROTO((Graphic *, Layout *, XEvent *));
+int           InterpretPresses    PROTO((Graphic *, Layout *, XButtonEvent *));
+int           Reconfig            PROTO((Graphic *, Layout *, XEvent *));
+void          Refresh             PROTO((Graphic *, Layout *, int));
+int           Stop                PROTO((Graphic *, Layout *));
+int           PSit                PROTO((Graphic *, Layout *, int));
+int           get_argument        PROTO((int, char **, char *));
+int           remove_argument     PROTO((int, int *, char **));
+void          DragColorbar        PROTO((Graphic *, Layout *, XButtonEvent *));
+void          ResetColorbar       PROTO((Graphic *, Layout *, double, double));
+void          MakeColormap        PROTO((Graphic *, Layout *, int, char **));
+
+/***** Prototypes for button ***************/
+
+Button       *CheckButtons        PROTO((XButtonEvent *, Layout *));
+void          DrawButton          PROTO((Graphic *, Button *));
+void          FlashButton         PROTO((Graphic *, Button *));
+int           InButton            PROTO((XButtonEvent *, Button *));
+void          InvertButton        PROTO((Graphic *, Button *));
+int           greycolors          PROTO((Graphic *, Layout *));
+int           rainbow             PROTO((Graphic *, Layout *));
+int           puns                PROTO((Graphic *, Layout *));
+int           Recenter            PROTO((Graphic *, Layout *));
+int           RecenterRescale     PROTO((Graphic *, Layout *));
+int           Rescale             PROTO((Graphic *, Layout *));
+int           ToggleDEG           PROTO((Graphic *, Layout *));
+int           Overlay0            PROTO((Graphic *, Layout *));
+int           Overlay1            PROTO((Graphic *, Layout *));
+int           Overlay2            PROTO((Graphic *, Layout *));
+int           Overlay3            PROTO((Graphic *, Layout *));
+
+/***** Prototypes for xtools ***************/
+
+void          CheckColors         PROTO((Graphic *, int *, char **));
+void          CheckDisplayName    PROTO((int *, char **, char *));
+void          CheckFontName       PROTO((int *, char **, char *));
+void          CheckGeometry       PROTO((int *, char **, Graphic *));
+void          CloseDisplay        PROTO((Graphic *));
+void          CreateWindow        PROTO((Graphic *, Window, int, long));
+void          DrawBitmap          PROTO((Graphic *, int, int, int, int, char *, int));
+unsigned long GetColor            PROTO((Display *, char *, Colormap, unsigned long));
+void          LoadFont            PROTO((Graphic *, int *, char **, char *));
+void          MakeCursor          PROTO((Graphic *, unsigned int));
+void          MakeGC              PROTO((Graphic *));
+void          MapWindow           PROTO((Graphic *));
+void          NameWindow          PROTO((Graphic *, char *));
+Display      *OpenDisplay         PROTO((char *, int *));
+void          QuitX               PROTO((Display *, char *, char *));
+void          SetNormalHints      PROTO((Graphic *));
+void          SetUpDisplay        PROTO((Graphic *, int *, char **));
+void          SetUpWindow         PROTO((Graphic *, int *, char **));
+void          SetWMHints          PROTO((Graphic *, Icon *));
+void          TopWindow           PROTO((Graphic *, Icon *));
+
+void          hh_hms              PROTO((char *, double, double, char));
Index: /tags/kii-1-4/Ohana/src/kii/include/rotletters.h
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/include/rotletters.h	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/include/rotletters.h	(revision 11911)
@@ -0,0 +1,56 @@
+#define R0_width 9
+#define R0_height 6
+static char R0_bits[] = {
+   0x00, 0x00, 0x7c, 0x00, 0x82, 0x00, 0x01, 0x01, 0x82, 0x00, 0x7c, 0x00};
+#define R1_width 9
+#define R1_height 6
+static char R1_bits[] = {
+   0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0xff, 0x01, 0x02, 0x01, 0x04, 0x01};
+#define R2_width 9
+#define R2_height 6
+static char R2_bits[] = {
+   0x00, 0x00, 0x0e, 0x01, 0x11, 0x01, 0x21, 0x01, 0x41, 0x01, 0x86, 0x01};
+#define R3_width 9
+#define R3_height 6
+static char R3_bits[] = {
+   0x00, 0x00, 0xe3, 0x00, 0x15, 0x01, 0x19, 0x01, 0x11, 0x01, 0x81, 0x00};
+#define R4_width 9
+#define R4_height 6
+static char R4_bits[] = {
+   0x00, 0x00, 0x40, 0x00, 0xff, 0x01, 0x44, 0x00, 0x58, 0x00, 0x60, 0x00};
+#define R5_width 9
+#define R5_height 6
+static char R5_bits[] = {
+   0x00, 0x00, 0xf1, 0x00, 0x09, 0x01, 0x09, 0x01, 0x11, 0x01, 0x9f, 0x00};
+#define R6_width 9
+#define R6_height 6
+static char R6_bits[] = {
+   0x00, 0x00, 0xe2, 0x00, 0x11, 0x01, 0x11, 0x01, 0x11, 0x01, 0xfe, 0x00};
+#define R7_width 9
+#define R7_height 6
+static char R7_bits[] = {
+   0x00, 0x00, 0x03, 0x00, 0x0d, 0x00, 0x31, 0x00, 0xc1, 0x01, 0x01, 0x00};
+#define R8_width 9
+#define R8_height 6
+static char R8_bits[] = {
+   0x00, 0x00, 0xee, 0x00, 0x11, 0x01, 0x11, 0x01, 0x11, 0x01, 0xee, 0x00};
+#define R9_width 9
+#define R9_height 6
+static char R9_bits[] = {
+   0x00, 0x00, 0xfe, 0x00, 0x11, 0x01, 0x11, 0x01, 0x11, 0x01, 0x8e, 0x00};
+#define Rd_width 9
+#define Rd_height 6
+static char Rd_bits[] = {
+   0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0xc0, 0x01, 0x80, 0x00, 0x00, 0x00};
+#define Re_width 9
+#define Re_height 6
+static char Re_bits[] = {
+   0x00, 0x00, 0xb0, 0x00, 0x28, 0x01, 0x28, 0x01, 0x28, 0x01, 0xf0, 0x00};
+#define Rm_width 9
+#define Rm_height 6
+static char Rm_bits[] = {
+   0x00, 0x00, 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0x10, 0x00};
+#define Rp_width 9
+#define Rp_height 6
+static char Rp_bits[] = {
+   0x00, 0x00, 0x10, 0x00, 0x10, 0x00, 0x7c, 0x00, 0x10, 0x00, 0x10, 0x00};
Index: /tags/kii-1-4/Ohana/src/kii/include/structures.h
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/include/structures.h	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/include/structures.h	(revision 11911)
@@ -0,0 +1,128 @@
+/**************** Graphic carries X info around ****************/
+typedef struct {
+  Display       *display;
+  int            screen;
+  int            depth;
+  Window         window;
+  Visual        *visual;
+  int            visualclass;
+  GC             gc;
+  XFontStruct   *font;
+  Cursor         cursor;
+  int            x,  y;
+  int            dx, dy;
+  Colormap       colormap;
+  unsigned long  Npixels, pixels[256];
+  int            Nbits;
+  /*
+  unsigned long  fore;
+  unsigned long  back;
+  */
+  unsigned long  black, white;
+} 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 Nobjects;
+  unsigned long color;
+  Object *objects;
+} Overlay;
+  
+/******** Here we define the Layout struct specific to this program  *******/
+typedef struct {
+  /* objects on the mana window */
+  Picture  picture;
+  Picture  cmapbar;
+  Picture  zoom;
+  Button   PS_button;
+  Button   recenter_button;
+  Button   hms_button; /* toggle HMS/DECIMAL mode (DECIMAL_DEG macro) */
+  Button   grey_button;
+  Button   rainbow_button;
+  Button   puns_button;
+  Button   overlay_button[NOVERLAYS];
+  Overlay  overlay[NOVERLAYS];
+  Overlay  tickmarks;
+  int      text_x, text_y;
+
+  /* file descriptor for socket connection to mana */
+  int Ximage; 
+
+  /* data mana needs */
+  Matrix   matrix;         /* data for picture */
+  double   X, Y;           /* image pixel at screen center */
+  int      expand;         /* zoomscale */
+  double   zero, range;    /* zero, range for picture to cmap */
+  double   max, min;       /* zero, range for data to z-value */
+  double   start, slope;   /* zero, range for cmap to pixels */
+  double   x, y, z;        /* last pointer coords */
+  Coords   coords;
+  char     file[1024];     /* name of file */
+  char     buffer_name[1024];  /* name of buffer */
+
+  /* fundamental pieces */
+  unsigned long  black;
+  unsigned long  white;
+  XColor   cmap[256];
+  int      Npixels;
+
+} Layout;
+
+/* this routine is independent of the number of overlays */
+
+
Index: /tags/kii-1-4/Ohana/src/kii/misc/hh_hms.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/misc/hh_hms.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/misc/hh_hms.c	(revision 11911)
@@ -0,0 +1,28 @@
+# include "Ximage.h"
+
+void hh_hms (char *line, double ra, double dec, char sep) {
+
+  int h, m, flag;
+  double s;
+  
+  ra /= 15.0;  /* convert from degrees to hours */
+  flag = SIGN(ra);
+  ra *= flag;
+  h = ra;
+  m = 60.000001*(ra - h);
+  s = 3600*(ra - h - m / 60.0);
+  if (flag > 0)
+    sprintf (line, " %02d%c%02d%c%04.1f  ", h, sep, m, sep, s);
+  else
+    sprintf (line, "-%02d%c%02d%c%04.1f  ", h, sep, m, sep, s);
+  
+  flag = SIGN(dec);
+  dec *= flag;
+  h = dec;
+  m = 60.000001*(dec - h);
+  s = 3600*(dec - h - m / 60.0);
+  if (flag > 0)
+    sprintf (&line[13], " %02d%c%02d%c%04.1f", h, sep, m, sep, s);
+  else
+    sprintf (&line[13], "-%02d%c%02d%c%04.1f", h, sep, m, sep, s);
+}
Index: /tags/kii-1-4/Ohana/src/kii/overlay/CSaveOverlay.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/overlay/CSaveOverlay.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/overlay/CSaveOverlay.c	(revision 11911)
@@ -0,0 +1,51 @@
+# include "Ximage.h"
+
+/*************/
+int CSaveOverlay (Graphic *graphic, Layout *layout) {
+
+  char buffer[256], filename[256];
+  int i, status, Nbytes, N;
+  double ra, dec, ra1, dec1, x1, y1, dra, ddec;
+  FILE *f;
+
+  status = read (layout[0].Ximage, buffer, 16); 
+  buffer[16] = 0; 
+  sscanf (buffer, "%*s %d", &Nbytes); 
+  status = read (layout[0].Ximage, buffer, Nbytes); 
+  buffer[Nbytes] = 0; 
+  sscanf (buffer, "%*s %d %s", &N, filename);
+  
+  f = fopen (filename, "w");
+  if (f == NULL) {
+    fprintf (stderr, "could not open %s\n", filename);
+    return (TRUE);
+  }
+
+  for (i = 0; i < layout[0].overlay[N].Nobjects; i++) {
+    if (!strcmp (layout[0].overlay[N].objects[i].type, "LINE")) {
+      XY_to_RD (&ra, &dec, layout[0].overlay[N].objects[i].x, layout[0].overlay[N].objects[i].y, &layout[0].coords);
+      x1 = layout[0].overlay[N].objects[i].x + layout[0].overlay[N].objects[i].dx;
+      y1 = layout[0].overlay[N].objects[i].y + layout[0].overlay[N].objects[i].dy;
+      XY_to_RD (&ra1, &dec1, x1, y1, &layout[0].coords);
+      dra = (ra1 - ra);
+      ddec = (dec1 - dec);
+    } else {
+      XY_to_RD (&ra, &dec, layout[0].overlay[N].objects[i].x, layout[0].overlay[N].objects[i].y, &layout[0].coords);
+      x1 = layout[0].overlay[N].objects[i].x;
+      y1 = layout[0].overlay[N].objects[i].y + layout[0].overlay[N].objects[i].dy;
+      XY_to_RD (&ra1, &dec1, x1, y1, &layout[0].coords);
+      ddec = fabs (dec1 - dec);
+      x1 = layout[0].overlay[N].objects[i].x + layout[0].overlay[N].objects[i].dx;
+      y1 = layout[0].overlay[N].objects[i].y;
+      XY_to_RD (&ra1, &dec1, x1, y1, &layout[0].coords);
+      dra = cos (dec*RAD_DEG) * fabs (ra1 - ra);
+    }
+    fprintf (f, "%s %lf %lf %lf %lf\n", layout[0].overlay[N].objects[i].type, ra, dec, dra, ddec);
+   }
+  fclose (f);
+  return (TRUE);
+}
+
+
+/* this routine is independent of the number of overlays */
+
Index: /tags/kii-1-4/Ohana/src/kii/overlay/DrawOverlay.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/overlay/DrawOverlay.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/overlay/DrawOverlay.c	(revision 11911)
@@ -0,0 +1,82 @@
+# include "Ximage.h"
+# define INFRONT 3
+
+void DrawOverlay (Graphic *graphic, Layout *layout, int N, FILE *f, int extra) {
+
+  int i;
+  double X, Y, dX, dY;
+  int Xmin, Ymin, Xmax, Ymax;
+  double expand, X0, Y0;
+ 
+  expand = 1.0;
+  if (layout[0].expand > 0) {
+    expand = 1 / (1.0*layout[0].expand);
+  }
+  if (layout[0].expand < 0) {
+    expand = fabs((double)layout[0].expand);
+  }
+  /*  
+  X0 =  (layout[0].X + 1 - 0.5*layout[0].matrix.Naxis[0])/expand + 0.5*layout[0].picture.dx;
+  Y0 =  (layout[0].Y + 1 - 0.5*layout[0].matrix.Naxis[1])/expand + 0.5*layout[0].picture.dy;
+  */
+  Image_to_Screen (&X0, &Y0, 0.0, 0.0, layout);
+  X0 -= layout[0].picture.x;
+  Y0 -= layout[0].picture.y;
+
+  Xmin = 0;
+  Ymin = 0;
+  Xmax = layout[0].picture.dx;
+  Ymax = layout[0].picture.dy;
+
+  for (i = 0; i < layout[0].overlay[N].Nobjects; i++) {
+    if (N == INFRONT) {
+      X  = layout[0].overlay[N].objects[i].x * Xmax;
+      Y  = layout[0].overlay[N].objects[i].y * Ymax;
+      dX = layout[0].overlay[N].objects[i].dx * Xmax;
+      dY = layout[0].overlay[N].objects[i].dy * Ymax;
+    } else {
+      X  = (layout[0].overlay[N].objects[i].x)/expand + X0;
+      Y =  Ymax - (layout[0].overlay[N].objects[i].y)/expand - Y0;
+      dX = (layout[0].overlay[N].objects[i].dx)/expand;
+      dY = (layout[0].overlay[N].objects[i].dy)/expand;
+    }
+    
+    if (!strcmp (layout[0].overlay[N].objects[i].type, "LINE")) {
+      if (((X < Xmin) && (X + dX < Xmin)) || ((X > Xmax) && (X + dX > Xmax)) ||
+	  ((Y < Ymin) && (Y + dY < Ymin)) || ((Y > Ymax) && (Y + dY > Ymax))) {
+	continue;
+      }
+      fprintf (f, " %6.1f %6.1f %6.1f %6.1f L\n", X + extra, Y + extra, (X+dX + extra), (Y-dY + extra));
+      continue;
+    }
+    if (!strcmp (layout[0].overlay[N].objects[i].type, "TEXT")) {
+      if (((X < Xmin) && (X + dX < Xmin)) || ((X > Xmax) && (X + dX > Xmax)) ||
+	  ((Y < Ymin) && (Y + dY < Ymin)) || ((Y > Ymax) && (Y + dY > Ymax))) {
+	continue;
+      }
+      fprintf (f, "(%s) %6.1f %6.1f T\n", layout[0].overlay[N].objects[i].text, X + extra, Y + extra); 
+      continue;
+    }
+    if (!strcmp (layout[0].overlay[N].objects[i].type, "BOX")) {
+      if (((X - 0.5*dX < Xmin) && (X + 0.5*dX < Xmin)) || ((X - 0.5*dX > Xmax) && (X + 0.5*dX > Xmax)) ||
+	  ((Y - 0.5*dY < Ymin) && (Y + 0.5*dY < Ymin)) || ((Y - 0.5*dY > Ymax) && (Y + 0.5*dY > Ymax))) {
+	continue;
+      }
+      fprintf (f, " %6.1f %6.1f %6.1f %6.1f B\n", (dX + 2*extra), (dY + 2*extra), (X - 0.5*dX - extra), (Y - 0.5*dY - extra));
+      continue;
+    }
+    if (!strcmp (layout[0].overlay[N].objects[i].type, "CIRCLE")) {
+      if (((X - dX < Xmin) && (X + dX < Xmin)) || ((X - dX > Xmax) && (X + dX > Xmax)) ||
+	  ((Y - dY < Ymin) && (Y + dY < Ymin)) || ((Y - dY > Ymax) && (Y + dY > Ymax))) {
+	continue;
+      }
+      fprintf (f, " %6.1f %6.1f %6.1f C\n", X, Y, fabs(dX + extra));
+      continue;
+    }
+    fprintf (stderr, "don't know %s, skipping\n", layout[0].overlay[N].objects[i].type);
+  }
+  
+}
+
+/* this routine is independent of the number of overlays */
+
Index: /tags/kii-1-4/Ohana/src/kii/overlay/EraseOverlay.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/overlay/EraseOverlay.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/overlay/EraseOverlay.c	(revision 11911)
@@ -0,0 +1,30 @@
+# include "Ximage.h"
+
+int EraseOverlay (Graphic *graphic, Layout *layout) {
+
+  char buffer[256];
+  int i, status, N;
+
+  fcntl (layout[0].Ximage, F_SETFL, !O_NONBLOCK);  
+  status = read (layout[0].Ximage, buffer, 16); 
+  buffer[16] = 0; 
+  sscanf (buffer, "%*s %d", &N); 
+  if (N > NOVERLAYS) {
+    REALLOCATE (layout[0].tickmarks.objects, Object, 1);
+    layout[0].tickmarks.Nobjects = 0;
+  } else {
+    for (i = 0; i < layout[0].overlay[N].Nobjects; i++) {
+      if (!strcmp (layout[0].overlay[N].objects[i].type, "TEXT")) {
+	free (layout[0].overlay[N].objects[i].text);
+      }
+    }
+    REALLOCATE (layout[0].overlay[N].objects, Object, 1);
+    layout[0].overlay[N].Nobjects = 0;
+    OVERLAY[N] = FALSE;
+  }
+
+  if (USE_XWINDOW) Refresh (graphic, layout, 0);
+
+  fcntl (layout[0].Ximage, F_SETFL, O_NONBLOCK);  
+  return (TRUE);
+}
Index: /tags/kii-1-4/Ohana/src/kii/overlay/LoadOverlay.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/overlay/LoadOverlay.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/overlay/LoadOverlay.c	(revision 11911)
@@ -0,0 +1,104 @@
+# include "Ximage.h"
+
+int LoadOverlay (graphic, layout)
+     Graphic graphic[];
+     Layout  layout[];
+{
+  
+  char line[17], *buffer, *buff, type[16], string[128];
+  double x, y, dx, dy;
+  int Nin, bytes, status;
+  int i, N, NOBJECTS, Nobjects, Nstart, done;
+
+  ALLOCATE (buffer, char, 65536);  /* space for 512 lines of 128 bytes */
+  bzero (buffer, 65536);
+  done = FALSE;
+
+  fcntl (layout[0].Ximage, F_SETFL, !O_NONBLOCK);  
+
+  status = read (layout[0].Ximage, line, 16); 
+  line[16] = 0; 
+  sscanf (line, "%*s %d", &N); 
+  Nstart = layout[0].overlay[N].Nobjects;
+
+  while (!done) {
+    status = read (layout[0].Ximage, line, 16); 
+    line[16] = 0; 
+    
+    if (!strncmp (line, "DONE", 4)) {
+      done = TRUE;
+      break;
+    }
+
+    if (!strncmp (line, "NLINES", 6)) {
+      sscanf (line, "%*s %d", &Nin);
+      buff = buffer;
+      bytes = 128*Nin;
+      fcntl (layout[0].Ximage, F_SETFL, O_NONBLOCK);  
+      while (bytes > 0) { 
+	status = read (layout[0].Ximage, buff, bytes);
+	if (status == 0) {  /* No more pipe */
+	  fprintf (stderr, "error: pipe closed\n");
+	  free (buffer);
+	  fcntl (layout[0].Ximage, F_SETFL, O_NONBLOCK);  
+	  return (FALSE);
+	}
+	if (status != -1) { /* pipe has data */
+	  bytes -= status;
+	  buff = (char *)(buff + status);
+	}
+      }
+      fcntl (layout[0].Ximage, F_SETFL, !O_NONBLOCK);  
+      /* parse buffer data */
+      NOBJECTS = layout[0].overlay[N].Nobjects + Nin;
+      Nobjects = layout[0].overlay[N].Nobjects;
+      REALLOCATE (layout[0].overlay[N].objects, Object, NOBJECTS);
+      for (i = 0; i < Nin; i++) {
+	sscanf (&buffer[i*128], "%s %lf %lf %lf %lf\n", type, &x, &y, &dx, &dy);
+
+	if (strcasecmp (type, "TEXT") && strcasecmp (type, "LINE") && strcasecmp (type, "BOX") && strcasecmp (type, "CIRCLE")) {  /* skip */
+	  fprintf (stderr, "don't know %s, skipping\n", type);
+	  continue;
+	}
+
+	if (!strcasecmp (type, "TEXT")) { /* end of objects */
+	  sscanf (&buffer[i*128], "%s %lf %lf %s\n", type, &x, &y, string);
+	}
+	
+	strcpy (layout[0].overlay[N].objects[Nobjects].type, type);
+	layout[0].overlay[N].objects[Nobjects].x = x;
+	layout[0].overlay[N].objects[Nobjects].y = y;
+	if (!strcmp (type, "TEXT")) {
+	  layout[0].overlay[N].objects[Nobjects].dx = 0;
+	  layout[0].overlay[N].objects[Nobjects].dy = 0;
+	  layout[0].overlay[N].objects[Nobjects].text = strcreate (string);
+	} else {
+	  layout[0].overlay[N].objects[Nobjects].dx = dx;
+	  layout[0].overlay[N].objects[Nobjects].dy = dy;
+	}
+	Nobjects++;
+      }
+      REALLOCATE (layout[0].overlay[N].objects, Object, MAX(Nobjects, 1));
+      layout[0].overlay[N].Nobjects = Nobjects;
+    }
+  }
+
+  free (buffer);
+  REALLOCATE (layout[0].overlay[N].objects, Object, MAX (1, layout[0].overlay[N].Nobjects));
+  OVERLAY[N] = TRUE;
+  /*  Refresh (graphic, layout, 0); */
+  if (USE_XWINDOW) {
+    for (i = 0; i < NOVERLAYS; i++) {
+      if (OVERLAY[i])
+	PaintOverlay (graphic, layout, i);
+    }
+    PaintTickmarks (graphic, layout);
+    XFlush (graphic[0].display);
+  }
+  fcntl (layout[0].Ximage, F_SETFL, O_NONBLOCK);  
+  return (TRUE);
+
+}
+
+
+/* this routine is independent of the number of overlays */
Index: /tags/kii-1-4/Ohana/src/kii/overlay/LoadTickmarks.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/overlay/LoadTickmarks.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/overlay/LoadTickmarks.c	(revision 11911)
@@ -0,0 +1,65 @@
+# include "Ximage.h"
+
+int LoadTickmarks (Graphic *graphic, Layout *layout) {
+  
+  char line[129], type[16];
+  double x, y, dx, dy;
+  int status, NOBJECTS, Nobjects, done;
+
+  fcntl (layout[0].Ximage, F_SETFL, !O_NONBLOCK);  
+
+  Nobjects = layout[0].tickmarks.Nobjects;
+  NOBJECTS = Nobjects + 100;
+  REALLOCATE (layout[0].tickmarks.objects, Object, NOBJECTS);
+  
+  done = FALSE;
+  while (!done) {
+    status = read (layout[0].Ximage, line, 128); 
+    line[128] = 0; 
+
+    if (!strncmp (line, "DONE", 4)) {
+      done = TRUE;
+      break;
+    }
+    
+    sscanf (line, "%s %lf %lf %lf %lf\n", type, &x, &y, &dx, &dy);
+    
+    if (strcmp (type, "TEXT") && strcmp (type, "LINE") && strcmp (type, "BOX") && strcmp (type, "CIRCLE")) {  /* skip */
+      fprintf (stderr, "don't know %s, skipping\n", type);
+      continue;
+    }
+    
+    strcpy (layout[0].tickmarks.objects[Nobjects].type, type);
+    layout[0].tickmarks.objects[Nobjects].x = x;
+    layout[0].tickmarks.objects[Nobjects].y = y;
+    layout[0].tickmarks.objects[Nobjects].dx = dx;
+    layout[0].tickmarks.objects[Nobjects].dy = dy;
+    
+    if (!strcmp (type, "TEXT")) { /* dx = Nchar, dy = angle (not yet used) */
+      status = read (layout[0].Ximage, line, 128); 
+      line[128] = 0; 
+      ALLOCATE (layout[0].tickmarks.objects[Nobjects].text, char, (int) dx + 1);
+      strncpy (layout[0].tickmarks.objects[Nobjects].text, line, (int) dx);
+      layout[0].tickmarks.objects[Nobjects].text[(int)dx] = 0;
+    }      
+    
+    Nobjects++;
+    if (Nobjects >= NOBJECTS) {
+      NOBJECTS = Nobjects + 100;
+      REALLOCATE (layout[0].tickmarks.objects, Object, NOBJECTS);
+    }
+
+  }
+
+  REALLOCATE (layout[0].tickmarks.objects, Object, MAX(Nobjects, 1));
+  layout[0].tickmarks.Nobjects = Nobjects;
+
+  if (USE_XWINDOW) Refresh (graphic, layout, 0);
+
+  fcntl (layout[0].Ximage, F_SETFL, O_NONBLOCK);  
+  return (TRUE);
+  
+}
+
+
+/* this routine is independent of the number of overlays */
Index: /tags/kii-1-4/Ohana/src/kii/overlay/PaintOverlay.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/overlay/PaintOverlay.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/overlay/PaintOverlay.c	(revision 11911)
@@ -0,0 +1,85 @@
+# include "Ximage.h"
+# define INFRONT 4
+
+void PaintOverlay (Graphic *graphic, Layout *layout, int N) {
+
+  int i;
+  int dX, dY, dx, dy;
+  int X, Y, Xmin, Ymin, Xmax, Ymax, Xrange, Yrange;
+  double expand, X0, Y0;
+ 
+  XSetForeground (graphic[0].display, graphic[0].gc, layout[0].overlay[N].color);
+  
+  expand = 1.0;
+  if (layout[0].expand > 0) {
+    expand = 1 / (1.0*layout[0].expand);
+  }
+  if (layout[0].expand < 0) {
+    expand = fabs((double)layout[0].expand);
+  }
+  /* 
+  X = 0.5*layout[0].matrix.Naxis[0] - expand*((int)(0.5*layout[0].picture.dx + 0.5) - 0.0) - layout[0].X;
+  Y = 0.5*layout[0].matrix.Naxis[1] - expand*((int)(0.5*layout[0].picture.dy + 0.5) - 0.0) - layout[0].Y;  
+  X0 =  (layout[0].X + 1 - (int)(0.5*layout[0].matrix.Naxis[0] + 0.5) - X + (int)X)/expand + layout[0].picture.x + 0.5*layout[0].picture.dx;
+  Y0 =  (layout[0].Y + 1 - (int)(0.5*layout[0].matrix.Naxis[1] + 0.5) - Y + (int)Y)/expand + layout[0].picture.y + 0.5*layout[0].picture.dy;
+  */
+
+  Image_to_Screen (&X0, &Y0, 0.0, 0.0, layout);
+
+  Xmin = layout[0].picture.x;
+  Ymin = layout[0].picture.y;
+  Xmax = layout[0].picture.x + layout[0].picture.dx;
+  Ymax = layout[0].picture.y + layout[0].picture.dy;
+  Xrange = layout[0].picture.dx;
+  Yrange = layout[0].picture.dy;
+
+  for (i = 0; i < layout[0].overlay[N].Nobjects; i++) {
+    if (N == INFRONT) {
+      X  = layout[0].overlay[N].objects[i].x * Xrange + Xmin;
+      Y  = layout[0].overlay[N].objects[i].y * Yrange + Ymin;
+      dX = layout[0].overlay[N].objects[i].dx * Xrange;
+      dY = layout[0].overlay[N].objects[i].dy * Yrange;
+    } else {
+      X  = layout[0].overlay[N].objects[i].x/expand + X0;
+      Y =  layout[0].overlay[N].objects[i].y/expand + Y0;
+      dX = layout[0].overlay[N].objects[i].dx/expand;
+      dY = layout[0].overlay[N].objects[i].dy/expand;
+    }
+    if ((X + dX < Xmin) || (X - dX > Xmax) ||
+	(Y + dY < Ymin) || (Y - dY > Ymax)) {
+      continue;
+    }
+
+    /* for a LINE, (x, y) is the start, (dx, dy) is the distance to end
+       for a CIRCLE (x, y) is the center, (dx, dy) is the radius 
+       for a BOX (x, y) is the center, (dx, dy) is the width */
+
+    if (!strcasecmp (layout[0].overlay[N].objects[i].type, "LINE")) {
+      XDrawLine (graphic[0].display, graphic[0].window, graphic[0].gc, X, Y, (X+dX), (Y+dY));
+      continue;
+    }
+    if (!strcasecmp (layout[0].overlay[N].objects[i].type, "TEXT")) {
+      XDrawString (graphic[0].display, graphic[0].window, graphic[0].gc, X, Y, layout[0].overlay[N].objects[i].text, strlen(layout[0].overlay[N].objects[i].text));
+      continue;
+    }
+    if (!strcasecmp (layout[0].overlay[N].objects[i].type, "BOX")) {
+      dx = MAX (abs(dX),2) / 2;
+      dy = MAX (abs(dY),2) / 2;
+      XDrawRectangle (graphic[0].display, graphic[0].window, graphic[0].gc, (X - dx), (Y - dy), 2*dx, 2*dy);
+       continue;
+    }
+    if (!strcasecmp (layout[0].overlay[N].objects[i].type, "CIRCLE")) {
+      dx = MAX (abs(dX),2);
+      dy = MAX (abs(dY),2);
+      XDrawArc (graphic[0].display, graphic[0].window, graphic[0].gc, (X - dx), (Y - dy), 2*dx, 2*dy, 0, 23040);
+      continue;
+    }
+    fprintf (stderr, "don't know %s, skipping (PO)\n", layout[0].overlay[N].objects[i].type);
+  }
+  
+  XSetForeground (graphic[0].display, graphic[0].gc, graphic[0].black);
+
+}
+
+/* this routine is independent of the number of overlays */
+
Index: /tags/kii-1-4/Ohana/src/kii/overlay/PaintTickmarks.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/overlay/PaintTickmarks.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/overlay/PaintTickmarks.c	(revision 11911)
@@ -0,0 +1,66 @@
+# include "Ximage.h"
+# define INFRONT 3
+/* # include "rotletters.h" */
+
+void PaintTickmarks (Graphic *graphic, Layout *layout) {
+
+  int i;
+  int X, Y, dX, dY;
+  int Xmin, Ymin, Xmax, Ymax, Xrange, Yrange;
+ 
+  XSetForeground (graphic[0].display, graphic[0].gc, graphic[0].black);
+
+  Xmin = layout[0].picture.x;
+  Ymin = layout[0].picture.y;
+  Xmax = layout[0].picture.x + layout[0].picture.dx;
+  Ymax = layout[0].picture.y + layout[0].picture.dy;
+  Xrange = layout[0].picture.dx;
+  Yrange = layout[0].picture.dy;
+
+  for (i = 0; i < layout[0].tickmarks.Nobjects; i++) {
+    X  = layout[0].tickmarks.objects[i].x * Xrange + Xmin;
+    Y  = layout[0].tickmarks.objects[i].y * Yrange + Ymin;
+    dX = layout[0].tickmarks.objects[i].dx * Xrange;
+    dY = layout[0].tickmarks.objects[i].dy * Yrange;
+
+    if (!strcmp (layout[0].tickmarks.objects[i].type, "LINE")) {
+      XDrawLine (graphic[0].display, graphic[0].window, graphic[0].gc, X, Y, (X+dX), (Y+dY));
+      continue;
+    }
+    if (!strcmp (layout[0].tickmarks.objects[i].type, "TEXT")) {
+      if (layout[0].tickmarks.objects[i].dy == 0) {
+	XSetForeground (graphic[0].display, graphic[0].gc, layout[0].white);
+	XFillRectangle (graphic[0].display, graphic[0].window, graphic[0].gc, X, Y-11, 6*strlen(layout[0].tickmarks.objects[i].text), 11); 
+	XSetForeground (graphic[0].display, graphic[0].gc, layout[0].black);
+	XDrawString (graphic[0].display, graphic[0].window, graphic[0].gc, X, Y, layout[0].tickmarks.objects[i].text, strlen(layout[0].tickmarks.objects[i].text));
+      }
+      if (layout[0].tickmarks.objects[i].dy == 90) {
+	XSetForeground (graphic[0].display, graphic[0].gc, layout[0].white);
+	XFillRectangle (graphic[0].display, graphic[0].window, graphic[0].gc, X, Y-6*strlen(layout[0].tickmarks.objects[i].text), 11, 6*strlen(layout[0].tickmarks.objects[i].text)); 
+	XSetForeground (graphic[0].display, graphic[0].gc, layout[0].black);
+	/* XDrawRotString (graphic[0].display, graphic[0].window, graphic[0].gc, X, Y, layout[0].tickmarks.objects[i].text, strlen(layout[0].tickmarks.objects[i].text)); */
+      }
+      continue;
+    }
+    if (!strcmp (layout[0].tickmarks.objects[i].type, "BOX")) {
+      XDrawRectangle (graphic[0].display, graphic[0].window, graphic[0].gc, (int)(X - 0.5*dX), (int)(Y - 0.5*dY), abs(dX), abs(dY));
+       continue;
+    }
+    if (!strcmp (layout[0].tickmarks.objects[i].type, "CIRCLE")) {
+      XDrawArc (graphic[0].display, graphic[0].window, graphic[0].gc, X - dX, Y - dY, abs(2*dX), abs(2*dY), 0, 23040);
+      continue;
+    }
+    fprintf (stderr, "don't know %s, skipping (PO)\n", layout[0].tickmarks.objects[i].type);
+  }
+  
+  XSetForeground (graphic[0].display, graphic[0].gc, graphic[0].black);
+
+}
+
+/* this routine is independent of the number of overlays */
+
+
+/*
+XDrawRotString (dpy, win, gc, X, Y, text, len)
+     
+*/
Index: /tags/kii-1-4/Ohana/src/kii/overlay/RotFont.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/overlay/RotFont.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/overlay/RotFont.c	(revision 11911)
@@ -0,0 +1,124 @@
+# include "Ximage.h"
+# include "alphabet.h"
+  
+static int Nrotfonts;
+static FontSet *RotFonts;
+
+static char currentname[64];
+static int  currentsize;
+static double currentscale;
+static RotFont *currentfont;
+
+void InitRotFonts () {
+
+  int i, Nhardwired;
+
+  Nhardwired = sizeof (HardwiredFonts) / sizeof (FontSet);
+  
+  Nrotfonts = Nhardwired;
+  ALLOCATE (RotFonts, FontSet, Nrotfonts);
+  
+  for (i = 0; i < Nhardwired; i++) {
+    RotFonts[i] = HardwiredFonts[i];
+  }
+
+  currentfont = RotFonts[DEFFONT].font;
+  currentscale = 1.0;
+  strcpy (currentname, RotFonts[DEFFONT].name);
+  currentsize = RotFonts[DEFFONT].size;
+}
+
+int SetRotFont (char *name, int size) {
+  
+  int i, nsize, msize, bsize, bigger, dsize, match, good;
+
+  bigger = good = match = -1;
+  dsize = 10000;
+  bsize = 10000;
+  for (i = 0; i < Nrotfonts; i++) {
+    if (!strcasecmp (RotFonts[i].name, name)) {
+      good = i;
+      nsize = abs (RotFonts[i].size - size);
+      if (nsize < dsize) {
+	match = i;
+	dsize = nsize;
+      }
+      msize = RotFonts[i].size - size;
+      if ((msize < bsize) && (msize >= 0)) {
+	bigger = i;
+	bsize = msize;
+      }
+    }
+  }
+  
+  if ((match == -1) && (good != -1)) match = good;
+  if (bigger != -1) match = bigger;
+  if (match != -1) {
+    currentfont = RotFonts[match].font;
+    currentscale = (double) size / RotFonts[match].size;
+    currentsize = size;
+    strcpy (currentname, name);
+    return (TRUE);
+  } else {
+    fprintf (stderr, "no matching font\n");
+    return (FALSE);
+  }
+
+}
+  
+char *GetRotFont (int *size) {
+
+  *size = currentsize;
+  return (currentname);
+
+}
+
+RotFont *GetRotFontData (double *scale) {
+  *scale = currentscale;
+  return (currentfont);
+}
+
+int RotStrlen (char *c) {
+
+  int i, N, dX, code;
+  double scale; 
+  
+  scale = currentscale;
+
+  /* find string length */
+  dX = 0;
+
+  code = FALSE;
+  for (i = 0; i < strlen (c); i++) {
+    N = (int)(c[i]);
+    /* skip non-printing characters */
+    if ((N < 0) || (N >= NROT)) continue;
+
+    /* check for special characters */
+    if (!code) {
+      if (N == 94) { /* super-script */
+	scale *= 0.8;
+	continue;
+      }
+      if (N == 95) { /* sub-script */
+	scale *= 0.8;
+	continue;
+      }
+      if (N == 124) { /* normal-script */
+	scale = currentscale;
+	continue;
+      }
+      if (N == 92) { /* backslash */
+	code = TRUE;
+	continue;
+      } 
+      if (N == 38) { /* font-code */
+	i++;
+	continue;
+      }
+    }
+    code = FALSE;
+    dX += scale*currentfont[N].dx + 1;
+  }
+  return (dX);
+}
Index: /tags/kii-1-4/Ohana/src/kii/overlay/SaveOverlay.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/overlay/SaveOverlay.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/overlay/SaveOverlay.c	(revision 11911)
@@ -0,0 +1,41 @@
+# include "Ximage.h"
+
+/*************/
+int 
+SaveOverlay (graphic, layout)
+     Graphic graphic[];
+     Layout  layout[];
+{
+
+  char buffer[256], filename[256];
+  int i, status, Nbytes, N;
+  FILE *f;
+
+  status = read (layout[0].Ximage, buffer, 16); 
+  buffer[16] = 0; 
+  sscanf (buffer, "%*s %d", &Nbytes); 
+  status = read (layout[0].Ximage, buffer, Nbytes); 
+  buffer[Nbytes] = 0; 
+  sscanf (buffer, "%*s %d %s", &N, filename);
+  
+  f = fopen (filename, "w");
+  if (f == NULL) {
+    fprintf (stderr, "could not open %s\n", filename);
+    return (TRUE);
+  }
+
+  for (i = 0; i < layout[0].overlay[N].Nobjects; i++) {
+    fprintf (f, "%s %lf %lf %lf %lf\n", 
+	     layout[0].overlay[N].objects[i].type,
+	     layout[0].overlay[N].objects[i].x,
+	     layout[0].overlay[N].objects[i].y,
+	     layout[0].overlay[N].objects[i].dx,
+	     layout[0].overlay[N].objects[i].dy);
+  }
+  fclose (f);
+  return (TRUE);
+}
+
+
+/* this routine is independent of the number of overlays */
+
Index: /tags/kii-1-4/Ohana/src/kii/overlay/bDrawColormap.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/overlay/bDrawColormap.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/overlay/bDrawColormap.c	(revision 11911)
@@ -0,0 +1,72 @@
+# include "Ximage.h"
+
+/* this list must match the one in mana/include/package.h, and equiv
+ * we need to define library calls to the kapa and kii packages which mana
+ * and other programs would link against.  This would allow them to have 
+ * access to the list of available colors.  Or... we need to have mana, etc
+ * query kapa/kii about it list of colors...
+ */
+
+/* the three columns here are : (opihi name) : (X11 name) : (PostScript coordinate) */
+# define NGRAPHCOLORS 23
+static char GRAPHCOLORS[NGRAPHCOLORS][3][16] = {
+{"black",    	 "black",    	 "0.00 0.00 0.00"}, 
+{"white",    	 "white",    	 "1.00 1.00 1.00"}, 
+{"red",      	 "red",      	 "1.00 0.00 0.00"}, 
+{"pink",     	 "pink",     	 "1.00 0.75 0.80"}, 
+{"orange",   	 "orange",   	 "1.00 0.65 0.00"}, 
+{"yellow",   	 "yellow",   	 "1.00 1.00 0.00"}, 
+{"wheat",    	 "wheat",    	 "0.96 0.87 0.70"}, 
+{"gold",     	 "gold",     	 "1.00 0.84 0.00"}, 
+{"green",    	 "green",    	 "0.00 1.00 0.00"}, 
+{"darkgreen",	 "darkgreen",	 "0.00 0.40 0.00"}, 
+{"blue",     	 "blue",     	 "0.00 0.00 1.00"}, 
+{"skyblue",  	 "skyblue",  	 "0.53 0.81 0.92"}, 
+{"indigo",   	 "mediumpurple", "0.57 0.44 0.86"}, 
+{"violet",   	 "darkviolet", 	 "0.58 0.00 0.88"},
+{"grey10",   	 "grey10",   	 "0.10 0.10 0.10"},
+{"grey20",   	 "grey20",   	 "0.20 0.20 0.20"},
+{"grey30",   	 "grey30",   	 "0.30 0.30 0.30"},
+{"grey40",   	 "grey40",   	 "0.40 0.40 0.40"},
+{"grey50",   	 "grey50",   	 "0.50 0.50 0.50"},
+{"grey60",   	 "grey60",   	 "0.60 0.60 0.60"},
+{"grey70",   	 "grey70",   	 "0.70 0.70 0.70"},
+{"grey80",   	 "grey80",   	 "0.80 0.80 0.80"},
+{"grey90",   	 "grey90",   	 "0.90 0.90 0.90"}};
+
+png_color *MakePNGPalette (int *Npalette) {
+
+  int i;
+  float red, green, blue;
+  png_color *palette;
+
+  ALLOCATE (palette, png_color, NGRAPHCOLORS);
+
+  /* define the palette */
+  for (i = 0; i < NGRAPHCOLORS; i++) {
+    sscanf (GRAPHCOLORS[i][2], "%f %f %f", &red, &green, &blue);
+    palette[i].red = (0xff * red);
+    palette[i].green = (0xff * green);
+    palette[i].blue = (0xff * blue);
+  }
+  *Npalette = NGRAPHCOLORS;
+  return (palette);
+}
+
+/* default to black */
+bDrawColor GetColorByName (char *name) {
+
+  bDrawColor i;
+
+  for (i = 0; i < NGRAPHCOLORS; i++) {
+    if (!strcasecmp (name, GRAPHCOLORS[i][0])) return (i);
+  }
+  return (0);
+}
+
+/*
+
+kapa objects, bDraw, and png all use the same pallete sequence, defined by
+GRAPHCOLORS above.  the color correspond to a color sequence.  
+
+*/
Index: /tags/kii-1-4/Ohana/src/kii/overlay/bDrawFrame.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/overlay/bDrawFrame.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/overlay/bDrawFrame.c	(revision 11911)
@@ -0,0 +1,89 @@
+# include "Ximage.h"
+
+int bDrawFrame (Layout *layout) {
+  
+  int i, P, IsLabel, fontsize;
+  double fx, fy, dfx, dfy, range, major, minor, first, next;
+  char *fontname;
+
+  /* each axis is drawn independently */
+  fontname = GetRotFont (&fontsize);
+  for (i = 0; i < 4; i++) {
+    fx  = layout[0].axis[i].fx;
+    fy  = layout[0].axis[i].fy;
+    dfx = layout[0].axis[i].dfx;
+    dfy = layout[0].axis[i].dfy;
+    P = hypot ((double)layout[0].axis[(i+1)%2].dfx, (double)layout[0].axis[(i+1)%2].dfy);
+
+    if (layout[0].axis[i].isaxis) { 
+      bDrawLine (fx, fy, fx+dfx, fy+dfy); 
+    }
+    
+    if (layout[0].axis[i].areticks) {
+      range = layout[0].axis[i].max - layout[0].axis[i].min;
+
+      AxisTickScale (&layout[0].axis[i], &major, &minor);
+
+      first = minor*((int)(layout[0].axis[i].min/minor));
+      if ((range > 0) && (first < layout[0].axis[i].min)) {
+	first += minor;
+      }
+      if ((range < 0) && (first > layout[0].axis[i].min)) {
+	first -= minor;
+      }
+      for (next = first; ((range > 0) && (next <= layout[0].axis[i].max)) || ((range < 0) && (next >= layout[0].axis[i].max));) {
+	IsLabel = FALSE;
+	if ((fabs((int)(next/major) - (next/major)) < 0.5*(minor/major)) || 
+	    (fabs ((int)((next + 0.5*minor)/major) - (next/major)) < 0.5*(minor/major)) ||
+	    (fabs ((int)((next - 0.5*minor)/major) - (next/major)) < 0.5*(minor/major)))
+	  IsLabel = layout[0].axis[i].islabel;
+	bDrawTick (fx, fy, dfx, dfy, P, layout[0].axis[i].min, layout[0].axis[i].max, next, IsLabel, i);
+	if (range > 0) 
+	  next += minor;
+	else 
+	  next -= minor;
+      }
+    }
+  }
+  return (TRUE);
+}
+
+void bDrawTick (double fx, double fy, double dfx, double dfy, int P, double min, double max, double value, int mode, int naxis) {
+  
+  int pos, dir, fontsize;
+  double size, n, x, y, dx, dy;
+  char string[64], *fontname;
+
+  pos = size = 0;
+
+  if (mode == 1) { size = MAX (0.02, 7.0 / P); }
+  if (mode == 0) { size = MAX (0.01, 4.0 / P); }
+  
+  n = P / sqrt ((double)(dfx*dfx + dfy*dfy));
+  x = fx + (value-min)*dfx/(max - min);
+  y = fy + (value-min)*dfy/(max - min);
+
+  dir = +1;
+  if ((naxis == 0) || (naxis == 1)) dir *= -1;
+  dx = dir*size*dfy*n;	
+  dy = dir*size*dfx*n;
+  
+  bDrawLine (x, y, x+dx, y+dy);
+
+  if (mode == 1) {
+    fontname = GetRotFont (&fontsize);
+
+    /* temporarily assume rectilinear axes */
+    if (naxis == 0) { dx = 0; dy = -dir*(0.8*fontsize + 1); pos = 1; }
+    if (naxis == 2) { dx = 0; dy = -dir*(0.8*fontsize + 1); pos = 7; }
+
+    if (naxis == 1) { dy = 0; dx = -(0.8*fontsize + 1); pos = 3; }
+    if (naxis == 3) { dy = 0; dx = +(0.8*fontsize + 1); pos = 5; }
+
+    x = fx + (value-min)*dfx/(max - min) + dx;
+    y = fy + (value-min)*dfy/(max - min) + dy;
+    if (fabs(value) < 1e-14) { value = 0.0; }
+    sprintf (string, "%g", value);
+    bDrawRotText ((int)x, (int)y, string, pos, 0.0);
+  }
+}
Index: /tags/kii-1-4/Ohana/src/kii/overlay/bDrawFuncs.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/overlay/bDrawFuncs.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/overlay/bDrawFuncs.c	(revision 11911)
@@ -0,0 +1,417 @@
+# include "Ximage.h"
+
+static int bWeight;
+static int bType;
+static bDrawColor bColor;
+static bDrawBuffer *bBuffer;
+
+bDrawBuffer *bDrawBufferCreate (int Nx, int Ny) {
+
+  int i, j;
+  bDrawColor white;
+  bDrawBuffer *buffer;
+
+  white = GetColorByName ("white");
+
+  ALLOCATE (buffer, bDrawBuffer, 1);
+  buffer[0].Nx = Nx;
+  buffer[0].Ny = Ny;
+
+  ALLOCATE (buffer[0].pixels, bDrawColor *, Ny);
+  for (i = 0; i < Ny; i++) {
+    ALLOCATE (buffer[0].pixels[i], bDrawColor, Nx);
+    for (j = 0; j < Nx; j++) {
+      buffer[0].pixels[i][j] = white;
+    }
+  }
+  return (buffer);
+}
+
+void bDrawBufferFree (bDrawBuffer *buffer) {
+
+  int i;
+
+  for (i = 0; i < buffer[0].Ny; i++) {
+    free (buffer[0].pixels[i]);
+  }
+  free (buffer[0].pixels);
+  free (buffer);
+  return;
+}
+
+void bDrawSetBuffer (bDrawBuffer *buffer) {
+  bBuffer = buffer;
+  return;
+}
+
+void bDrawSetStyle (bDrawColor color, int lw, int lt) {
+  bColor = color;
+  bWeight = lw;
+  bType = lt;
+  return;
+}
+
+// draw a point in the current color 
+void bDrawPoint (int x, int y) {
+
+  if (x < 0) return;
+  if (y < 0) return;
+  if (x >= bBuffer[0].Nx) return;
+  if (y >= bBuffer[0].Ny) return;
+  bBuffer[0].pixels[y][x] = bColor;
+  return;
+}
+
+// draw a point in the current color 
+void bDrawPointf (float x, float y) {
+
+  bDrawPoint (ROUND(x), ROUND(y));
+  return;
+}
+
+void bDrawTriOpen (double x1, double y1, double x2, double y2, double x3, double y3) {
+
+  bDrawLine (x1, y1, x2, y2);
+  bDrawLine (x2, y2, x3, y3);
+  bDrawLine (x3, y3, x1, y1);
+
+  return;
+}
+
+void bDrawRectOpen (double x1, double y1, double x2, double y2) {
+
+  int X1, Y1, X2, Y2;
+
+  if (x1 > x2) SWAP (x1, x2);
+  if (y1 > y2) SWAP (y1, y2);
+
+  X1 = MIN (MAX (ROUND (x1), 0), bBuffer[0].Nx - 1);
+  X2 = MIN (MAX (ROUND (x2), 1), bBuffer[0].Nx);
+
+  Y1 = MIN (MAX (ROUND (y1), 0), bBuffer[0].Ny - 1);
+  Y2 = MIN (MAX (ROUND (y2), 1), bBuffer[0].Ny);
+
+  bDrawLineHorizontal (X1, X2, Y1);
+  bDrawLineHorizontal (X1, X2, Y2);
+  bDrawLineVertical (X1, Y1, Y2);
+  bDrawLineVertical (X2, Y1, Y2);
+  return;
+}
+
+void bDrawRectFill (double x1, double y1, double x2, double y2) {
+
+  int i;
+  int X1, Y1, X2, Y2;
+
+  if (x1 > x2) SWAP (x1, x2);
+  if (y1 > y2) SWAP (y1, y2);
+
+  X1 = MIN (MAX (ROUND (x1), 0), bBuffer[0].Nx - 1);
+  X2 = MIN (MAX (ROUND (x2), 1), bBuffer[0].Nx);
+
+  Y1 = MIN (MAX (ROUND (y1), 0), bBuffer[0].Ny - 1);
+  Y2 = MIN (MAX (ROUND (y2), 0), bBuffer[0].Ny);
+
+  for (i = Y1; i < Y2; i++) {
+    bDrawLineHorizontal (X1, X2, i);
+  } 
+  return;
+}
+
+// identify the quadrant and draw the correct line
+void bDrawLine (double x1, double y1, double x2, double y2) {
+
+  int FlipDirect, FlipCoords;
+  int X1, Y1, X2, Y2, dX, dY;
+
+  /* rather than draw the line from float positions, we find the closest
+     integer end-points and draw the line between those pixels */ 
+
+  X1 = ROUND(x1);
+  Y1 = ROUND(y1);
+  X2 = ROUND(x2);
+  Y2 = ROUND(y2);
+
+  dX = X2 - X1;
+  dY = Y2 - Y1;
+
+  FlipCoords = (abs(dX) < abs(dY));
+  FlipDirect = FlipCoords ? (y1 > y2) : (x1 > x2);
+
+  if (!FlipDirect && !FlipCoords) bDrawLineWeight (X1, Y1, X2, Y2, FALSE);
+  if ( FlipDirect && !FlipCoords) bDrawLineWeight (X2, Y2, X1, Y1, FALSE);
+  if (!FlipDirect &&  FlipCoords) bDrawLineWeight (Y1, X1, Y2, X2, TRUE);
+  if ( FlipDirect &&  FlipCoords) bDrawLineWeight (Y2, X2, Y1, X1, TRUE);
+
+  return;
+}
+
+// draw a series of lines to give the line weight
+void bDrawLineWeight (int X1, int Y1, int X2, int Y2, int swapcoords) {
+
+  int dN, dNs, dNe;
+
+  dNs = -0.5*(bWeight - 1); 
+  /* 0, 0, 0, -1, -1, -2, -2 */
+
+  dNe = +0.5*bWeight + 1; 
+  /* 1, 1, 2, 2, 2, 3, 3 */
+
+  for (dN = dNs; dN < dNe; dN++) {
+    bDrawLineBresen (X1, Y1 + dN, X2, Y2 + dN, swapcoords);
+  }
+  return;
+}
+
+// use the Bresenham line drawing technique
+// integer-only Bresenham line-draw version which is fast
+void bDrawLineBresen (int X1, int Y1, int X2, int Y2, int swapcoords) {
+
+  int X, Y, dX, dY;
+  int e, e2;
+  int N, DashOn;
+
+  dX = X2 - X1;
+  dY = Y2 - Y1;
+
+  DashOn = TRUE;
+
+  Y = Y1;
+  e = 0;
+  for (X = X1, N = 0; X <= X2; X++, N++) {
+    if (bType == 1) { DashOn = (N % 10) < 5; }
+    if (bType == 2) { DashOn = (N % 6) < 3; }
+    if (swapcoords) {
+      if (DashOn) bDrawPoint (Y,X);
+    } else {
+      if (DashOn) bDrawPoint (X,Y);
+    }
+    e += dY;
+    e2 = 2 * e;
+    if (e2 > dX) {
+      Y++;
+      e -= dX;
+    } 
+    if (e2 < -dX) {
+      Y--;
+      e += dX;
+    }
+  }
+  return;
+}
+
+void bDrawLineHorizontal (int X1, int X2, int Y) {
+  
+  int i;
+
+  for (i = X1; i < X2; i++) {
+    bBuffer[0].pixels[Y][i] = bColor;
+  }
+  return;
+}
+
+void bDrawLineVertical (int X, int Y1, int Y2) {
+  
+  int i;
+
+  for (i = Y1; i < Y2; i++) {
+    bBuffer[0].pixels[i][X] = bColor;
+  }
+  return;
+}
+
+void bDrawTriFill (double x1, double y1, double x2, double y2, double x3, double y3) {
+
+  bDrawTriOpen (x1, y1, x2, y2, x3, y3);
+  return;
+}
+
+void bDrawArc (double Xc, double Yc, double Xr, double Yr, double Ts, double Te) {
+
+  float t, dt;
+  int x, y;
+
+  /* drawing a complete circle */
+//  if ((fabs(Te - Ts) > 360.0) && (Xr == Yr)) {
+//    bDrawCircle (Xc, Yc, Xr);
+//    return;
+//  }
+
+  /* only draw a single loop */
+  if (fabs(Te - Ts) > 360.0) {
+    Te = 360.0;
+    Ts = 0.0;
+  }
+
+  /* smallest angle is 1/Rmax */
+  dt = MAX (fabs(Xr * sin(Ts*RAD_DEG)), fabs(Yr * cos(Ts*RAD_DEG)));
+  dt = 1.0 / dt;
+
+  for (t = Ts*RAD_DEG; t <= Te*RAD_DEG; t += dt) {
+    x = Xr*cos(t) + Xc;
+    y = Yr*sin(t) + Yc;
+
+    /* we could use the value of MAX(dy/dt,dx/dt) to set dt */
+    bDrawPoint (x,y);
+
+    dt = MAX (fabs(Xr * sin(t)), fabs(Yr * cos(t)));
+    dt = 1.0 / dt;
+  }
+  return;
+}
+
+// draw a series of circles to give line weight
+void bDrawCircle (double xc, double yc, double radius) {
+
+  int dN, dNs, dNe;
+
+  dNs = -0.5*(bWeight - 1); 
+  /* 0, 0, 0, -1, -1, -2, -2 */
+
+  dNe = +0.5*bWeight + 1; 
+  /* 1, 1, 2, 2, 2, 3, 3 */
+
+  for (dN = dNs; dN < dNe; dN++) {
+    bDrawCircle (xc, yc, radius + dN);
+  }
+  return;
+}
+
+// draw a pure circle  
+void bDrawCircleSingle (double xc, double yc, double radius) {
+
+  int Xc, Yc, Radius;
+  int x, y, d;
+
+  Xc = ROUND(xc);
+  Yc = ROUND(yc);
+  Radius = ROUND(radius);
+
+  x = 0;
+  y = Radius;
+
+  // d = 3 - 2*Radius;
+  d = 5 - 4*radius;
+
+  while (x <= y) {
+    bDrawPoint (Xc+x, Yc+y);
+    bDrawPoint (Xc+x, Yc-y);
+    bDrawPoint (Xc-x, Yc+y);
+    bDrawPoint (Xc-x, Yc-y);
+    bDrawPoint (Xc+y, Yc+x);
+    bDrawPoint (Xc+y, Yc-x);
+    bDrawPoint (Xc-y, Yc+x);
+    bDrawPoint (Xc-y, Yc-x);
+
+    if (d < 0) {
+      // d = d + 4*x + 6;
+      d = d + 8*x + 4;
+    } else {
+      // d = d + 4*(x-y) + 10;
+      d = d + 8*(x-y) + 8;
+      y--;
+    }
+    x++;
+  }
+}
+
+// draw a pure circle  
+void bDrawCircleFill (double xc, double yc, double radius) {
+
+  int Xc, Yc, Radius;
+  int x, y, d;
+
+  Xc = ROUND(xc);
+  Yc = ROUND(yc);
+  Radius = ROUND(radius);
+
+  x = 0;
+  y = Radius;
+
+  // d = 3 - 2*Radius;
+  d = 5 - 4*radius;
+
+  while (x <= y) {
+    bDrawLineHorizontal (Xc-x, Xc+x, Yc+y);
+    bDrawLineHorizontal (Xc-x, Xc+x, Yc-y);
+    bDrawLineHorizontal (Xc-y, Xc+y, Yc+x);
+    bDrawLineHorizontal (Xc-y, Xc+y, Yc-x);
+
+    if (d < 0) {
+      // d = d + 4*x + 6;
+      d = d + 8*x + 4;
+    } else {
+      // d = d + 4*(x-y) + 10;
+      d = d + 8*(x-y) + 8;
+      y--;
+    }
+    x++;
+  }
+}
+
+/* 
+the discriminant of inside or outside the circle is:
+
+f(x,y) = x^2 + y^2 - r^2
+
+- negative: (x,y) inside circle
+- positive: (x,y) outside circle
+
+given d(0) = f(x,y); find d(1) = f(x+1,y):
+d(1) = (x+1)^2 + y^2 - r^2
+d(1) = d(0) + 2x + 1
+(use d(1) if d(0) < 0, ie inside circle)
+
+given d(0) = f(x,y); find d(1) = f(x+1,y-1):
+d(1) = (x+1)^2 + (y-1)^2 - r^2
+d(1) = d(0) + 2x + 1 - 2y + 1
+d(1) = d(0) + 2(x-y) + 2
+
+* init d to f(1,r-1/2) instead of r, keeping the effective boundary 
+  between two pixels (also, an inside point)
+
+f(1,r-1/2) = 1 + (r-1/2)^2 - r^2 = 5/4 - r
+f(1,r-1/4) = 1 + (r-1/4)^2 - r^2 = 1 + r/2 + 1/16 = 17/16 + r/2
+
+f(1,r-x)   = 1 + (r-x)^2 - r^2 = 1 - 2xr + x^2 = A (3 - 2r)
+
+1+x^2 = 3A
+-2x = -2A
+
+A = x
+
+1 - 3x + x^2 = 0
+
+(3 +/- sqrt(9 - 4))/2 = (3 - sqrt(5))/2
+
+multiply all d values by 4 to get integer tests:
+
+d'(0) = 5 - 4r
+d'(in) = d' + 8x + 4
+d'(out) = d' + 8(x-y) + 8
+
+*/
+
+/* This is the Bresenham line-drawing algorithm for 1st and 4th quandrant
+   vectors with positive and negative slopes < 1. this is the sequence if we use
+   float errors and tests it is easy to understand, but slower than it could be
+
+  { 
+    float e, m;
+    m = dY / dX;
+    Y = Y1;
+    e = 0;
+    for (X = X1; X <= X2; X++) {
+      plot (X,Y);
+      e += m;
+      if (e > 0.5) {
+	Y++;
+	e -= 1.0;
+      }
+      if (e < -0.5) {
+	Y--;
+	e += 1.0;
+      }
+    }
+  }
+*/
Index: /tags/kii-1-4/Ohana/src/kii/overlay/bDrawOverlay.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/overlay/bDrawOverlay.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/overlay/bDrawOverlay.c	(revision 11911)
@@ -0,0 +1,93 @@
+# include "Ximage.h"
+# define INFRONT 4
+
+static char name[4][16] = {"red", "green", "blue", "yellow"};
+
+void bDrawOverlay (Layout *layout, int N) {
+
+  int i;
+  int dX, dY, dx, dy;
+  int X, Y, Xmin, Ymin, Xmax, Ymax, Xrange, Yrange;
+  double expand, X0, Y0;
+  bDrawColor color;
+ 
+  /* translate color to bDrawColors : layout[0].overlay[N].color */
+  color = KapaColorByName (name[N]);
+  bDrawSetStyle (color, 0, 0);
+  
+  expand = 1.0;
+  if (layout[0].expand > 0) {
+    expand = 1 / (1.0*layout[0].expand);
+  }
+  if (layout[0].expand < 0) {
+    expand = fabs((double)layout[0].expand);
+  }
+  /* 
+  X = 0.5*layout[0].matrix.Naxis[0] - expand*((int)(0.5*layout[0].picture.dx + 0.5) - 0.0) - layout[0].X;
+  Y = 0.5*layout[0].matrix.Naxis[1] - expand*((int)(0.5*layout[0].picture.dy + 0.5) - 0.0) - layout[0].Y;  
+  X0 =  (layout[0].X + 1 - (int)(0.5*layout[0].matrix.Naxis[0] + 0.5) - X + (int)X)/expand + layout[0].picture.x + 0.5*layout[0].picture.dx;
+  Y0 =  (layout[0].Y + 1 - (int)(0.5*layout[0].matrix.Naxis[1] + 0.5) - Y + (int)Y)/expand + layout[0].picture.y + 0.5*layout[0].picture.dy;
+  */
+
+  Image_to_Screen (&X0, &Y0, 0.0, 0.0, layout);
+  X0 -= layout[0].picture.x;
+  Y0 -= layout[0].picture.y;
+
+  Xmin = 0;
+  Ymin = 0;
+  Xmax = layout[0].picture.dx;
+  Ymax = layout[0].picture.dy;
+  Xrange = layout[0].picture.dx;
+  Yrange = layout[0].picture.dy;
+
+  for (i = 0; i < layout[0].overlay[N].Nobjects; i++) {
+    if (N == INFRONT) {
+      X  = layout[0].overlay[N].objects[i].x * Xrange;
+      Y  = layout[0].overlay[N].objects[i].y * Yrange;
+      dX = layout[0].overlay[N].objects[i].dx * Xrange;
+      dY = layout[0].overlay[N].objects[i].dy * Yrange;
+    } else {
+      X  = layout[0].overlay[N].objects[i].x/expand + X0;
+      Y =  layout[0].overlay[N].objects[i].y/expand + Y0;
+      dX = layout[0].overlay[N].objects[i].dx/expand;
+      dY = layout[0].overlay[N].objects[i].dy/expand;
+    }
+    if ((X + dX < Xmin) || (X - dX > Xmax) ||
+	(Y + dY < Ymin) || (Y - dY > Ymax)) {
+      continue;
+    }
+
+    /* for a LINE, (x, y) is the start, (dx, dy) is the distance to end
+       for a CIRCLE (x, y) is the center, (dx, dy) is the radius 
+       for a BOX (x, y) is the center, (dx, dy) is the width */
+
+    if (!strcasecmp (layout[0].overlay[N].objects[i].type, "LINE")) {
+      bDrawLine (X, Y, (X+dX), (Y+dY));
+      continue;
+    }
+    if (!strcasecmp (layout[0].overlay[N].objects[i].type, "TEXT")) {
+      bDrawRotText (X, Y, layout[0].overlay[N].objects[i].text, 8, 0.0);
+      continue;
+    }
+    if (!strcasecmp (layout[0].overlay[N].objects[i].type, "BOX")) {
+      dx = MAX (abs(dX),2) / 2;
+      dy = MAX (abs(dY),2) / 2;
+      bDrawRectOpen ((X-dx), (Y-dy), (X+dx), (Y+dy));
+      // bDrawRectOpen ((X-dx), (Y-dy), (X), (Y));
+       continue;
+    }
+    if (!strcasecmp (layout[0].overlay[N].objects[i].type, "CIRCLE")) {
+      dx = MAX (abs(dX),2);
+      dy = MAX (abs(dY),2);
+      bDrawArc (X, Y, dx, dy, 0, 360);
+      continue;
+    }
+    fprintf (stderr, "don't know %s, skipping (PO)\n", layout[0].overlay[N].objects[i].type);
+  }
+  
+  /* translate color to bDrawColors : layout[0].overlay[N].color */
+  bDrawSetStyle (color, 0, 0);
+}
+
+/* this routine is independent of the number of overlays */
+
Index: /tags/kii-1-4/Ohana/src/kii/overlay/bDrawRotFont.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/overlay/bDrawRotFont.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/overlay/bDrawRotFont.c	(revision 11911)
@@ -0,0 +1,211 @@
+# include "Ximage.h"
+
+# define NROTCHARS 256
+# define XPROC(x,y) (scale*(cs*((x) - x0) - sn*((y) - y0)) + X0)
+# define YPROC(x,y) (scale*(cs*((y) - y0) + sn*((x) - x0)) + Y0)
+# define NEARINT(x) ((x < 0) ? ((int)(x - 0.5)) : ((int)(x + 0.5)))
+  
+static bDrawColor black;
+static bDrawColor white;
+
+int bDrawRotText (int x, int y, char *string, int pos, double angle) {
+
+  unsigned char *bitmap;
+  char *currentname, basename[64], *c; 
+  int i, dy, dx, N, X, Y, code;
+  int dX, Xoff, dY, Yoff, YoffBase;
+  int currentsize, basesize;
+  double cs, sn, currentscale;
+  RotFont *currentfont;
+
+  white = GetColorByName ("white");
+  black = GetColorByName ("black");
+
+  currentname = GetRotFont (&currentsize);
+  currentfont = GetRotFontData (&currentscale);
+  strcpy (basename, currentname);
+  basesize = currentsize;
+
+  /* strip leading whitespace */
+  for (c = string; (*c == ' ') || (*c == '\t'); c++);
+  if (*c == 0) return (FALSE);
+  
+  /* compute string length */
+  cs = cos(angle*RAD_DEG);
+  sn = sin(angle*RAD_DEG);
+  dX = RotStrlen (c);
+  dY = currentfont[65].ascent;
+
+  /* apply appropriate offset */
+  Xoff = Yoff = 0;
+  switch (pos) {
+  case 0: Xoff =     -dX; Yoff = dY; break;
+  case 1: Xoff = -0.5*dX; Yoff = dY; break;
+  case 2: Xoff =       0; Yoff = dY; break;
+  case 3: Xoff =     -dX; Yoff = 0.5*dY; break;
+  case 4: Xoff = -0.5*dX; Yoff = 0.5*dY; break;
+  case 5: Xoff =       0; Yoff = 0.5*dY; break;
+  case 6: Xoff =     -dX; Yoff = 0; break;
+  case 7: Xoff = -0.5*dX; Yoff = 0; break;
+  case 8: Xoff =       0; Yoff = 0; break;
+  }
+
+  code = FALSE;
+
+  YoffBase = Yoff;
+  /* draw characters one-by-one */
+  for (i = 0; i < strlen(c); i++) {
+    N = (int)(c[i]);
+    if ((N < 0) || (N >= NROTCHARS)) continue;
+
+    /* check for special characters */
+    if (!code) {
+      if (N == 94) {
+	SetRotFont (currentname, (int)(0.8*currentsize));
+	currentfont = GetRotFontData (&currentscale);
+	Yoff -= 0.5*currentscale*dY;
+	continue;
+      }
+      if (N == 95) { 
+	SetRotFont (currentname, (int)(0.8*currentsize));
+	currentfont = GetRotFontData (&currentscale);
+	Yoff += 0.5*currentscale*dY;
+	continue;
+      }
+      if (N == 124) {
+	SetRotFont (currentname, basesize);
+	currentfont = GetRotFontData (&currentscale);
+	Yoff = YoffBase;
+	continue;
+      }
+      if (N == 92) {
+	code = TRUE;
+	continue;
+      } 
+      if (N == 38) {
+	if (c[i+1] == 'h') {
+	  SetRotFont ("helvetica", currentsize);
+	  currentfont = GetRotFontData (&currentscale);
+	}
+	if (c[i+1] == 't') {
+	  SetRotFont ("times", currentsize);
+	  currentfont = GetRotFontData (&currentscale);
+	}
+	if (c[i+1] == 'c') {
+	  SetRotFont ("courier", currentsize);
+	  currentfont = GetRotFontData (&currentscale);
+	}
+	if (c[i+1] == 's') {
+	  SetRotFont ("symbol", currentsize);
+	  currentfont = GetRotFontData (&currentscale);
+	}
+	i++;
+	continue;
+      }
+    }
+    code = FALSE;
+
+    bitmap = currentfont[N].bits;
+    dx = currentfont[N].dx;
+    dy = currentfont[N].dy;
+    X = x + (int)(Xoff*cs - Yoff*sn) + (int)(currentscale*currentfont[N].ascent*sn);
+    Y = y + (int)(Xoff*sn + Yoff*cs) - (int)(currentscale*currentfont[N].ascent*cs);
+    bDrawRotBitmap (X, Y, dx, dy, bitmap, TRUE, angle, currentscale);
+    Xoff += 1 + (int)(currentscale*dx + 0.5);
+  }
+  SetRotFont (basename, basesize);
+  return (TRUE);
+}
+
+int bDrawRotBitmap (int x, int y, int dx, int dy, unsigned char *bitmap, int mode, double angle, double scale) {
+
+  int ii, jj, byte_line, byte, bit, flag;
+  bDrawColor color;
+  double i, j, cs, sn, rscale, tmp;
+  int X, Y, X0, X1, X2, Y0, Y1, Y2, x0, y0;
+
+  /* this mode option is nort actually used... */
+  if (mode) {
+    color = black;
+  } else {
+    color = white;
+  } 
+    
+  byte_line = (int) ((dx + 7) / 8);
+
+  cs = cos(angle*RAD_DEG);  sn = sin(angle*RAD_DEG);
+  rscale = 1.0 / scale;
+
+  X0 = 0;
+  Y0 = 0;
+  x0 = 0;
+  y0 = 0;
+
+  X2 = X1 = XPROC (0,0);
+  Y2 = Y1 = YPROC (0,0);
+
+  X = XPROC (dx,0);
+  Y = YPROC (dx,0);
+# ifdef DRAWBOXES
+  bDrawLine (x+X, y+Y, x+X1, y+Y1);
+  Xt = X;
+  Yt = Y;
+# endif
+  X1 = MIN (X, X1);
+  X2 = MAX (X, X2);
+  Y1 = MIN (Y, Y1);
+  Y2 = MAX (Y, Y2);
+
+  X = XPROC (dx,dy);
+  Y = YPROC (dx,dy);
+# ifdef DRAWBOXES
+  bDrawLine (x+X, y+Y, x+Xt, y+Yt);
+  Xt = X;
+  Yt = Y;
+# endif
+  Y1 = MIN (Y, Y1);
+  Y2 = MAX (Y, Y2);
+  X1 = MIN (X, X1);
+  X2 = MAX (X, X2);
+
+  X = XPROC (0,dy);
+  Y = YPROC (0,dy);
+# ifdef DRAWBOXES
+  bDrawLine (x+X, y+Y, x+Xt, y+Yt);
+  Xt = X;
+  Yt = Y;
+# endif
+  Y1 = MIN (Y, Y1);
+  Y2 = MAX (Y, Y2);
+  X1 = MIN (X, X1);
+  X2 = MAX (X, X2);
+
+  bDrawSetStyle (color, 0, 0);
+  if (scale > 1) {
+    for (i = X1; i <= X2; i+=1) {
+      for (j = Y1; j <= Y2; j+=1) {
+	tmp = rscale*(cs*(i - X0) + sn*(j - Y0)) + x0;  ii = NEARINT (tmp);
+	tmp = rscale*(cs*(j - Y0) - sn*(i - X0)) + y0;  jj = NEARINT (tmp);
+	if ((ii < 0) || (ii >= dx) || (jj < 0) || (jj >= dy)) continue;
+	byte = byte_line * jj + (ii / 8);
+	bit = ii % 8;
+	flag = 0x01 & (bitmap[byte] >> bit);
+	if (flag) bDrawPointf (x + i, y + j);
+      }
+    }
+  } else {
+    for (i = X1; i <= X2; i+=scale) {
+      for (j = Y1; j <= Y2; j+=scale) {
+	tmp = rscale*(cs*(i - X0) + sn*(j - Y0)) + x0;  ii = NEARINT (tmp);
+	tmp = rscale*(cs*(j - Y0) - sn*(i - X0)) + y0;  jj = NEARINT (tmp);
+	if ((ii < 0) || (ii >= dx) || (jj < 0) || (jj >= dy)) continue;
+	byte = byte_line * jj + (ii / 8);
+	bit = ii % 8;
+	flag = 0x01 & (bitmap[byte] >> bit);
+	if (flag) bDrawPointf (x + i, y + j);
+      }
+    }
+  }
+  bDrawSetStyle (black, 0, 0);
+  return (TRUE);
+}
Index: /tags/kii-1-4/Ohana/src/kii/picture/Center.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/picture/Center.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/picture/Center.c	(revision 11911)
@@ -0,0 +1,32 @@
+# include "Ximage.h"
+
+int Center (Graphic *graphic, Layout *layout) {
+
+  char buffer[1024];
+  int status, zoom, Nbytes;
+  double X, Y;
+
+  fcntl (layout[0].Ximage, F_SETFL, !O_NONBLOCK);  
+  status = read (layout[0].Ximage, buffer, 16); 
+  buffer[16] = 0; 
+  sscanf (buffer, "%*s %d", &Nbytes); 
+  status = read (layout[0].Ximage, buffer, Nbytes); 
+  buffer[status] = 0; /* make the string easy to parse */ 
+  sscanf (buffer, "%lf %lf %d", &X,  &Y, &zoom);
+
+  layout[0].X = 0.5*layout[0].matrix.Naxis[0] - X;
+  layout[0].Y = 0.5*layout[0].matrix.Naxis[1] - Y;
+  if ((zoom != 0) && (zoom != -1)) {
+    layout[0].expand = zoom;
+  }
+
+  if (USE_XWINDOW) {
+    Remap (graphic, layout, &layout[0].matrix);
+    Refresh (graphic, layout, 0);
+    XFlush (graphic[0].display);
+  }
+
+  fcntl (layout[0].Ximage, F_SETFL, O_NONBLOCK);  
+  return (TRUE);
+}
+
Index: /tags/kii-1-4/Ohana/src/kii/picture/CreatePicture.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/picture/CreatePicture.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/picture/CreatePicture.c	(revision 11911)
@@ -0,0 +1,67 @@
+# include "Ximage.h"
+
+void CreatePicture (Layout *layout, Graphic *graphic) {
+
+  int i, j, extra;
+  unsigned char *c;
+  unsigned int *l;
+  unsigned int start, start1, start2, start3;
+
+  start = layout[0].white;
+
+  switch (graphic[0].Nbits) {
+  case 8:
+    REALLOCATE (layout[0].picture.data, char, layout[0].picture.dx*layout[0].picture.dy);
+    c = (unsigned char *) layout[0].picture.data;
+    for (i = 0; i < (layout[0].picture.dx*layout[0].picture.dy); i++, c++)
+      *c = start;
+    layout[0].picture.pix = XCreateImage (graphic[0].display, graphic[0].visual, graphic[0].depth, ZPixmap, 0, 
+					  layout[0].picture.data, layout[0].picture.dx, layout[0].picture.dy, 8, 0);
+    break;
+
+  case 16:
+    REALLOCATE (layout[0].picture.data, char, 2*layout[0].picture.dy*layout[0].picture.dx);
+    c = (unsigned char *) layout[0].picture.data;
+    start1 = 0x0000ff & (start);
+    start2 = 0x0000ff & (start >> 8);
+    for (i = 0; i < layout[0].picture.dy; i++) {
+      for (j = 0; j < layout[0].picture.dx; j++, c+=2) {
+	c[0] = start1;
+	c[1] = start2;
+      }
+    }
+    layout[0].picture.pix = XCreateImage (graphic[0].display, graphic[0].visual, graphic[0].depth, ZPixmap, 0, 
+					  layout[0].picture.data, layout[0].picture.dx, layout[0].picture.dy, 16, 0);
+    break;
+
+  case 24:
+    extra = 4 - (layout[0].picture.dx * 3) % 4;
+    REALLOCATE (layout[0].picture.data, char, layout[0].picture.dy*(3*layout[0].picture.dx+extra));
+    c = (unsigned char *) layout[0].picture.data;
+    start1 = 0x0000ff & (start);
+    start2 = 0x0000ff & (start >> 8);
+    start3 = 0x0000ff & (start >> 16);
+    for (i = 0; i < layout[0].picture.dy; i++) {
+      for (j = 0; j < layout[0].picture.dx; j++, c+=3) {
+	c[0] = start1;
+	c[1] = start2;
+	c[2] = start3;
+      }
+      c+=extra;
+    }
+    layout[0].picture.pix = XCreateImage (graphic[0].display, graphic[0].visual, graphic[0].depth, ZPixmap, 0, 
+					  layout[0].picture.data, layout[0].picture.dx, layout[0].picture.dy, 24, 0);
+    break;
+
+  case 32:
+    ALLOCATE (layout[0].picture.data, char, (4*layout[0].picture.dx*layout[0].picture.dy + 32));
+    memset (layout[0].picture.data, 0xbd, 4*layout[0].picture.dx*layout[0].picture.dy + 30);
+    l = (unsigned int *) layout[0].picture.data;
+    for (i = 0; i < (layout[0].picture.dx*layout[0].picture.dy); i++, l++)
+      *l = start;
+    layout[0].picture.pix = XCreateImage (graphic[0].display, graphic[0].visual, graphic[0].depth, ZPixmap, 0, 
+					  layout[0].picture.data, layout[0].picture.dx, layout[0].picture.dy, 32, 0);
+    break;
+  }
+    
+}
Index: /tags/kii-1-4/Ohana/src/kii/picture/CursorOps.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/picture/CursorOps.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/picture/CursorOps.c	(revision 11911)
@@ -0,0 +1,37 @@
+# include "Ximage.h"
+
+void Screen_to_Image (double *x1, double *y1, double x2, double y2, Layout *layout) {
+
+  double expand;
+
+  expand = 1.0;
+  if (layout[0].expand > 0) {
+    expand = 1 / (1.0*layout[0].expand);
+  }
+  if (layout[0].expand < 0) {
+    expand = fabs((double)layout[0].expand);
+  }
+  
+  *x1 = expand*(x2 - layout[0].picture.x - 0.5*layout[0].picture.dx) + 0.5*layout[0].matrix.Naxis[0] - layout[0].X;
+  *y1 = expand*(y2 - layout[0].picture.y - 0.5*layout[0].picture.dy) + 0.5*layout[0].matrix.Naxis[1] - layout[0].Y;
+  
+}
+
+void Image_to_Screen (double *x1, double *y1, double x2, double y2, Layout *layout) {
+
+  double expand;
+
+  /* notice that here, expand is the reciprocal of the expand above */
+  expand = 1.0;
+  if (layout[0].expand > 0) {
+    expand = abs(layout[0].expand);
+  }
+  if (layout[0].expand < 0) {
+    expand = 1 / ((double)abs(layout[0].expand));
+  }
+  
+  *x1 = (x2 - 0.5*layout[0].matrix.Naxis[0] + layout[0].X) * expand + layout[0].picture.x + 0.5*layout[0].picture.dx;
+  *y1 = (y2 - 0.5*layout[0].matrix.Naxis[1] + layout[0].Y) * expand + layout[0].picture.y + 0.5*layout[0].picture.dy;
+  
+}
+
Index: /tags/kii-1-4/Ohana/src/kii/picture/JPEGit24.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/picture/JPEGit24.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/picture/JPEGit24.c	(revision 11911)
@@ -0,0 +1,225 @@
+# include "Ximage.h"
+# include "jpeglib.h"
+
+# define WHITE_R 255
+# define WHITE_G 255
+# define WHITE_B 255
+
+int JPEGit24 (Graphic *graphic, Layout *layout) {
+
+  struct jpeg_compress_struct cinfo;
+  struct jpeg_error_mgr jerr;
+  JSAMPROW row_pointer[1];	/* pointer to JSAMPLE row[s] */
+  JSAMPLE *image_buffer;	/* Points to data for current line */
+  JSAMPLE *line_buffer;	        /* Points to data for current line */
+
+  int ii, i, j;
+  int i_start, i_end, j_start, j_end;
+  int dropback;  /* this is a bit of a kludge... */
+  int dx, dy, DX, DY;
+  int status, Nbytes, quality;
+  int expand_in, expand_out;
+  double expand, Rx, Ry, X, Y;
+  unsigned char *out_pix, *in_pix, *in_pix_ref;
+  unsigned char pixel1[256], pixel2[256], pixel3[256];
+  char filename[1024];
+  FILE *f;
+
+  /* expect a line telling the number of bytes and a filename */
+  status = read (layout[0].Ximage, filename, 16);
+  filename[16] = 0;
+  sscanf (filename, "%*s %d", &Nbytes);
+  status = read (layout[0].Ximage, filename, Nbytes);
+  filename[status] = 0; /* make the string easy to parse */
+
+  /***** JPEG init calls */
+  cinfo.err = jpeg_std_error (&jerr);
+  jpeg_create_compress (&cinfo);
+
+  f = fopen (filename, "w");
+  if (f == (FILE *) NULL) {
+    fprintf (stderr, "Kii: failed to open %s for output\n", filename);
+    return (TRUE);
+  }
+  jpeg_stdio_dest(&cinfo, f);
+  
+  quality = 75;
+  cinfo.image_width = layout[0].picture.dx; 	/* image width and height, in pixels */
+  cinfo.image_height = layout[0].picture.dy;
+# ifdef GREYSCALE
+  cinfo.input_components = 1;		        /* # of color components per pixel */
+  cinfo.in_color_space = JCS_GRAYSCALE; 	/* colorspace of input image */
+# else 
+  cinfo.input_components = 3;		        
+  cinfo.in_color_space = JCS_RGB; 	
+# endif
+  jpeg_set_defaults (&cinfo);
+  jpeg_set_quality (&cinfo, quality, TRUE       /* limit to baseline-JPEG values */);
+  jpeg_start_compress (&cinfo, TRUE);
+
+  /** cmap[i].pixel must be defined even if X is not used **/
+  for (i = 0; i < 256; i++) { /* set up pixel array */
+    pixel1[i] = layout[0].cmap[i].red >> 8;
+    pixel2[i] = layout[0].cmap[i].green >> 8;
+    pixel3[i] = layout[0].cmap[i].blue >> 8;
+  }
+
+  expand = expand_in = expand_out = 1.0;
+  if (layout[0].expand == 0) /* set up expansions */
+    layout[0].expand = 1;
+  if (layout[0].expand > 0) {
+    expand = 1 / (1.0*layout[0].expand);
+    expand_out = layout[0].expand;
+    expand_in  = 1;
+  }
+  if (layout[0].expand < 0) {
+    expand = fabs((double)layout[0].expand);
+    expand_out = 1;
+    expand_in  = -layout[0].expand;
+  }
+
+  dx = layout[0].picture.dx;
+  dy = layout[0].picture.dy;
+  DX = layout[0].matrix.Naxis[0];
+  DY = layout[0].matrix.Naxis[1];
+
+  /* X,Y are the image coordinates of the first image pixel */
+  X = MAX(0.5*(DX - dx*expand) - layout[0].X, 0);
+  if ((int)X != X) 
+    X = (int) X + 1;
+  else 
+    X = (int) X;
+  Y = MAX(0.5*(DY - dy*expand) - layout[0].Y, 0);
+  if ((int)Y != Y) 
+    Y = (int) Y + 1;
+  else 
+    Y = (int) Y;
+
+  /* Rx,Ry are the screen coordinates of the first image pixel */
+  Rx = (X + layout[0].X - 0.5*DX)/expand + 0.5*dx;
+  Ry = (Y + layout[0].Y - 0.5*DY)/expand + 0.5*dy;
+
+  i_start = MIN (MAX (Rx, 0), dx - expand_out + 1);
+  j_start = MIN (MAX (Ry, 0), dy - expand_out + 1);
+  
+  if (layout[0].expand > 0) {
+    i_end = MAX (MIN (i_start + ((int)(expand*(dx-i_start)))/expand, expand_out*(DX-X) + Rx), 0);
+    j_end = MAX (MIN (j_start + ((int)(expand*(dy-j_start)))/expand, expand_out*(DY-Y) + Ry), 0);
+  } else {
+    i_end = MAX (MIN (dx, (DX-X)/expand + Rx), 0);
+    j_end = MAX (MIN (dy, (DY-Y)/expand + Ry), 0);
+  }    
+
+  dropback = expand_out - (i_end - i_start) % expand_out;
+  if ((i_end - i_start) % expand_out == 0) dropback = 0;
+
+  /* output line buffer */
+  ALLOCATE (image_buffer, JSAMPLE, 3*dx*dy);
+  ALLOCATE (line_buffer, JSAMPLE, 3*dx);
+
+  in_pix_ref  = (unsigned char *) (layout[0].matrix.buffer) + DX*(int)MAX(Y,0) + (int)MAX(X,0);
+
+  /********** below we do the mapping from buffer pixels (in) to picture pixels (out) **********/
+
+  /**** fill in bottom area ****/
+  out_pix = line_buffer;
+  for (i = 0; i < dx; i++, out_pix+=3) {
+    out_pix[0] = WHITE_R;
+    out_pix[1] = WHITE_G;
+    out_pix[2] = WHITE_B;
+  }
+  for (j = 0; j < j_start; j++) {
+    memcpy (&image_buffer[j*3*dx], line_buffer, 3*dx);
+  }
+  
+  /*** fill in the image data region ***/
+  for (j = j_start; j < j_end; j+= expand_out, in_pix_ref += expand_in*DX) {
+    
+    /* create one output image line */
+    in_pix = in_pix_ref;
+    out_pix = line_buffer;
+
+    /**** fill in area to the left of the picture ****/
+    for (i = 0; i < i_start; i++, out_pix+=3) {
+      out_pix[0] = WHITE_R;
+      out_pix[1] = WHITE_G;
+      out_pix[2] = WHITE_B;
+    }
+    
+    /*** fill in the picture region ***/
+    for (i = i_start; i < i_end; i+=expand_out, in_pix+=expand_in) {
+      for (ii = 0; ii < expand_out; ii++, out_pix+=3) {
+	out_pix[0] = pixel1[*in_pix];
+	out_pix[1] = pixel2[*in_pix];
+	out_pix[2] = pixel3[*in_pix];
+      }
+    }
+    
+    /**** fill in area to the right of the picture ****/
+    for (i = i_end; i < dx; i++, out_pix+=3) {
+      out_pix[0] = WHITE_R;
+      out_pix[1] = WHITE_G;
+      out_pix[2] = WHITE_B;
+    }
+
+    /* write out the image line expand_out times */
+    for (i = 0; i < expand_out; i++) {
+      memcpy (&image_buffer[(j + i)*3*dx], line_buffer, 3*dx);
+    }
+  }
+
+  /**** fill in top area ****/
+  out_pix = line_buffer;
+  for (i = 0; i < dx; i++, out_pix+=3) { 
+    out_pix[0] = WHITE_R;
+    out_pix[1] = WHITE_G;
+    out_pix[2] = WHITE_B;
+  }
+  for (j = j_end; j < dy; j++) {
+    memcpy (&image_buffer[j*3*dx], line_buffer, 3*dx);
+  }
+
+
+  /* I need to write the overlay objects on the jpeg image.
+     if i can write / overwrite data in jpeg buffer, then do it here,
+     otherwise i need to create a temporary image buffer, then write the 
+     scanlines to that buffer */
+
+  {
+    int Npalette;
+    png_color *palette;
+    bDrawColor white, color;
+    bDrawBuffer *buffer;
+
+    palette = KapaPNGPalette (&Npalette);
+
+    buffer = bDrawBufferCreate (dx, dy);
+    bDrawSetBuffer (buffer);
+    for (i = 0; i < NOVERLAYS; i++) {
+      if (OVERLAY[i]) bDrawOverlay (layout, i);
+    }
+
+    white = KapaColorByName ("white");
+    for (j = 0; j < dy; j++) {
+      for (i = 0; i < dx; i++) {
+	color = buffer[0].pixels[j][i];
+	if (color == white) continue;
+	image_buffer[j*3*dx + 3*i + 0] = palette[color].red;
+	image_buffer[j*3*dx + 3*i + 1] = palette[color].green;
+	image_buffer[j*3*dx + 3*i + 2] = palette[color].blue;
+      }
+    }
+    bDrawBufferFree (buffer);
+  }
+
+  for (i = 0; i < dy; i++) {
+    row_pointer[0] = &image_buffer[i*3*dx];
+    (void) jpeg_write_scanlines (&cinfo, row_pointer, 1);
+  }
+
+  jpeg_finish_compress (&cinfo);
+  fclose (f);
+  jpeg_destroy_compress (&cinfo);
+
+  return (TRUE);
+}
Index: /tags/kii-1-4/Ohana/src/kii/picture/NewPicture.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/picture/NewPicture.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/picture/NewPicture.c	(revision 11911)
@@ -0,0 +1,72 @@
+# include "Ximage.h"
+
+int NewPicture (Graphic *graphic, Layout *layout) {
+
+  Header header;
+  char *buff;
+  int status, bytes_left, socket;
+ 
+  socket = layout[0].Ximage;
+
+  KiiSendMessage (socket, "%d", layout[0].Npixels);
+
+  fcntl (socket, F_SETFL, !O_NONBLOCK);  
+
+  header.Naxes = 2;
+
+  KiiScanMessage (socket, "%d %d %d %d %lf %lf", &header.Naxis[0], &header.Naxis[1]);
+  KiiScanMessage (socket, "%d %d %d %d %lf %lf", &header.bitpix, &header.unsign, &header.bzero, &header.bscale);
+  KiiScanMessage (socket, "%lf %lf",  &layout[0].zero, &layout[0].range);
+  KiiScanMessage (socket, "%lf %lf %d", &layout[0].min,  &layout[0].max, &header.size);
+  KiiScanMessage (socket, "%lf %f %f %f %f", &layout[0].coords.crval1, &layout[0].coords.crpix1, &layout[0].coords.cdelt1, &layout[0].coords.pc1_1, &layout[0].coords.pc1_2);
+  KiiScanMessage (socket, "%lf %f %f %f %f", &layout[0].coords.crval2, &layout[0].coords.crpix2, &layout[0].coords.cdelt2, &layout[0].coords.pc2_1, &layout[0].coords.pc2_2);
+	  
+  KiiScanMessage (socket, "%s %s %s", layout[0].coords.ctype, layout[0].file, layout[0].buffer_name);
+
+  fits_free_matrix (&layout[0].matrix);
+  fits_create_matrix (&header, &layout[0].matrix);
+
+  fcntl (socket, F_SETFL, O_NONBLOCK);  
+
+  status = 1;
+  buff = layout[0].matrix.buffer;
+  bytes_left = header.size;
+  layout[0].matrix.size = 0;
+  while (bytes_left > 0) {
+    status = read (socket, buff, bytes_left);
+    if (status == 0) {  /* No more pipe */
+      fprintf (stderr, "error: pipe closed\n");
+      return (FALSE);
+    }
+    if (status != -1) { /* pipe has data */
+      layout[0].matrix.size += status;
+      bytes_left -= status;
+      buff = (char *)(buff + status);
+    }
+  }
+
+  if (DEBUG) fprintf (stderr, "read %d bytes\n", layout[0].matrix.size);
+  /* it it not obvious this condition should kill kii, but ... */
+  if (layout[0].matrix.size != header.size) {  
+    fprintf (stderr, "error: expected %d bytes, but got only %d\n", header.size, layout[0].matrix.size);
+    return (FALSE);
+  }
+
+  if (!USE_XWINDOW) return (TRUE);
+
+  Remap (graphic, layout, &layout[0].matrix);
+  if (DEBUG) fprintf (stderr, "remapped image\n");
+  Refresh (graphic, layout, 0);
+  if (DEBUG) fprintf (stderr, "refreshed\n");
+  XFlush (graphic[0].display);
+
+  return (TRUE);
+
+}
+
+/*
+   layout[0].X = 0;
+   layout[0].Y = 0;
+   layout[0].expand = 1;
+*/
+  
Index: /tags/kii-1-4/Ohana/src/kii/picture/PositionPictures.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/picture/PositionPictures.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/picture/PositionPictures.c	(revision 11911)
@@ -0,0 +1,152 @@
+# include "Ximage.h" 
+# include "buttons.h"
+# define BUTTON_WIDTH 28
+# define BUTTON_HEIGHT 28
+
+void PositionPictures (Layout *layout, Graphic *graphic) {
+
+  layout[0].cmapbar.dx = graphic[0].dx - 2*PAD1; 
+  layout[0].cmapbar.dy = COLORPAD;
+  layout[0].cmapbar.x = PAD1;
+  layout[0].cmapbar.y = PAD1;
+
+  layout[0].zoom.dx = ZOOM_X; 
+  layout[0].zoom.dy = ZOOM_Y;
+  layout[0].zoom.x = graphic[0].dx - PAD1 - ZOOM_X;
+  layout[0].zoom.y = layout[0].cmapbar.y + layout[0].cmapbar.dy + PAD2;
+
+  layout[0].picture.dx = layout[0].zoom.x - 2*PAD1 - 25; 
+  layout[0].picture.dy = graphic[0].dy - 2*PAD1 - PAD2 - COLORPAD - 25;
+  layout[0].picture.x = PAD1 + 25;
+  layout[0].picture.y = PAD1 + PAD2 + COLORPAD;
+
+  /** everything below is tied in x-dir to the zoom box **/
+  layout[0].text_x = layout[0].zoom.x;
+  layout[0].text_y = layout[0].zoom.y + layout[0].zoom.dy + PAD2;
+
+  /*  layout[0].PS_button.y = graphic[0].dy - BUTTON_HEIGHT - PAD1; */
+  layout[0].PS_button.x = layout[0].zoom.x + 5;
+  layout[0].PS_button.y = 2*ZOOM_Y;
+  layout[0].PS_button.dx = BUTTON_WIDTH;
+  layout[0].PS_button.dy = BUTTON_HEIGHT;
+  layout[0].PS_button.text = FALSE;
+  layout[0].PS_button.width = PS_width;
+  layout[0].PS_button.height = PS_height;
+  layout[0].PS_button.bitmap = PS_bits;
+  layout[0].PS_button.function_1 = PSit;
+  layout[0].PS_button.function_2 = PSit;
+  layout[0].PS_button.function_3 = PSit;
+
+  /** everything below is tied to the PS_button in y-dir **/
+  layout[0].grey_button.x = layout[0].PS_button.x + layout[0].PS_button.dx + PAD1;
+  layout[0].grey_button.y = layout[0].PS_button.y;
+  layout[0].grey_button.dx = BUTTON_WIDTH;
+  layout[0].grey_button.dy = BUTTON_HEIGHT;
+  layout[0].grey_button.text = FALSE;
+  layout[0].grey_button.width = grey_width;
+  layout[0].grey_button.height = grey_height;
+  layout[0].grey_button.bitmap = grey_bits;
+  layout[0].grey_button.function_1 = greycolors;
+  layout[0].grey_button.function_2 = greycolors;
+  layout[0].grey_button.function_3 = greycolors;
+
+  layout[0].rainbow_button.x = layout[0].grey_button.x + layout[0].grey_button.dx + PAD1;
+  layout[0].rainbow_button.y = layout[0].PS_button.y;
+  layout[0].rainbow_button.dx = BUTTON_WIDTH;
+  layout[0].rainbow_button.dy = BUTTON_HEIGHT;
+  layout[0].rainbow_button.text = FALSE;
+  layout[0].rainbow_button.width = rainbow_width;
+  layout[0].rainbow_button.height = rainbow_height;
+  layout[0].rainbow_button.bitmap = rainbow_bits;
+  layout[0].rainbow_button.function_1 = rainbow;
+  layout[0].rainbow_button.function_2 = rainbow;
+  layout[0].rainbow_button.function_3 = rainbow;
+
+  layout[0].puns_button.x = layout[0].rainbow_button.x + layout[0].rainbow_button.dx + PAD1;
+  layout[0].puns_button.y = layout[0].PS_button.y;
+  layout[0].puns_button.dx = BUTTON_WIDTH;
+  layout[0].puns_button.dy = BUTTON_HEIGHT;
+  layout[0].puns_button.text = FALSE;
+  layout[0].puns_button.width = puns_width;
+  layout[0].puns_button.height = puns_height;
+  layout[0].puns_button.bitmap = puns_bits;
+  layout[0].puns_button.function_1 = puns;
+  layout[0].puns_button.function_2 = puns;
+  layout[0].puns_button.function_3 = puns;
+
+  layout[0].recenter_button.x = layout[0].puns_button.x + layout[0].puns_button.dx + PAD1;
+  layout[0].recenter_button.y = layout[0].PS_button.y;
+  layout[0].recenter_button.dx = BUTTON_WIDTH;
+  layout[0].recenter_button.dy = BUTTON_HEIGHT;
+  layout[0].recenter_button.text = FALSE;
+  layout[0].recenter_button.width = recenter_width;
+  layout[0].recenter_button.height = recenter_height;
+  layout[0].recenter_button.bitmap = recenter_bits;
+  layout[0].recenter_button.function_1 = Recenter;
+  layout[0].recenter_button.function_2 = RecenterRescale;
+  layout[0].recenter_button.function_3 = Rescale;
+
+  layout[0].overlay_button[0].x = layout[0].zoom.x + 5;
+  layout[0].overlay_button[0].y = layout[0].PS_button.y - BUTTON_HEIGHT - PAD1;
+  layout[0].overlay_button[0].dx = BUTTON_WIDTH;
+  layout[0].overlay_button[0].dy = BUTTON_HEIGHT;
+  layout[0].overlay_button[0].text = FALSE;
+  layout[0].overlay_button[0].width = red_width;
+  layout[0].overlay_button[0].height = red_height;
+  layout[0].overlay_button[0].bitmap = red_bits;
+  layout[0].overlay_button[0].function_1 = Overlay0;
+  layout[0].overlay_button[0].function_2 = Overlay0;
+  layout[0].overlay_button[0].function_3 = Overlay0;
+		   	   
+  layout[0].overlay_button[1].x = layout[0].overlay_button[0].x + layout[0].overlay_button[0].dx + PAD1;
+  layout[0].overlay_button[1].y = layout[0].PS_button.y - BUTTON_HEIGHT - PAD1;
+  layout[0].overlay_button[1].dx = BUTTON_WIDTH;
+  layout[0].overlay_button[1].dy = BUTTON_HEIGHT;
+  layout[0].overlay_button[1].text = FALSE;
+  layout[0].overlay_button[1].width = green_width;
+  layout[0].overlay_button[1].height = green_height;
+  layout[0].overlay_button[1].bitmap = green_bits;
+  layout[0].overlay_button[1].function_1 = Overlay1;
+  layout[0].overlay_button[1].function_2 = Overlay1;
+  layout[0].overlay_button[1].function_3 = Overlay1;
+
+  layout[0].overlay_button[2].x = layout[0].overlay_button[1].x + layout[0].overlay_button[1].dx + PAD1;
+  layout[0].overlay_button[2].y = layout[0].PS_button.y - BUTTON_HEIGHT - PAD1;
+  layout[0].overlay_button[2].dx = BUTTON_WIDTH;
+  layout[0].overlay_button[2].dy = BUTTON_HEIGHT;
+  layout[0].overlay_button[2].text = FALSE;
+  layout[0].overlay_button[2].width = blue_width;
+  layout[0].overlay_button[2].height = blue_height;
+  layout[0].overlay_button[2].bitmap = blue_bits;
+  layout[0].overlay_button[2].function_1 = Overlay2;
+  layout[0].overlay_button[2].function_2 = Overlay2;
+  layout[0].overlay_button[2].function_3 = Overlay2;
+		   	   
+  layout[0].overlay_button[3].x = layout[0].overlay_button[2].x + layout[0].overlay_button[2].dx + PAD1;
+  layout[0].overlay_button[3].y = layout[0].PS_button.y - BUTTON_HEIGHT - PAD1;
+  layout[0].overlay_button[3].dx = BUTTON_WIDTH;
+  layout[0].overlay_button[3].dy = BUTTON_HEIGHT;
+  layout[0].overlay_button[3].text = FALSE;
+  layout[0].overlay_button[3].width = yellow_width;
+  layout[0].overlay_button[3].height = yellow_height;
+  layout[0].overlay_button[3].bitmap = yellow_bits;
+  layout[0].overlay_button[3].function_1 = Overlay3;
+  layout[0].overlay_button[3].function_2 = Overlay3;
+  layout[0].overlay_button[3].function_3 = Overlay3;
+
+  layout[0].hms_button.x = layout[0].overlay_button[3].x + layout[0].overlay_button[3].dx + PAD1;
+  layout[0].hms_button.y = layout[0].PS_button.y - BUTTON_HEIGHT - PAD1;
+  layout[0].hms_button.dx = BUTTON_WIDTH;
+  layout[0].hms_button.dy = BUTTON_HEIGHT;
+  layout[0].hms_button.text = FALSE;
+  layout[0].hms_button.width = hms_width;
+  layout[0].hms_button.height = hms_height;
+  layout[0].hms_button.bitmap = hms_bits;
+  layout[0].hms_button.function_1 = ToggleDEG;
+  layout[0].hms_button.function_2 = ToggleDEG;
+  layout[0].hms_button.function_3 = ToggleDEG;
+
+}
+
+
+/* this routine is dependent on the number of Overlays */
Index: /tags/kii-1-4/Ohana/src/kii/picture/Remap.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/picture/Remap.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/picture/Remap.c	(revision 11911)
@@ -0,0 +1,21 @@
+# include "Ximage.h"
+
+void Remap (Graphic *graphic, Layout *layout, Matrix *matrix) {
+
+  switch (graphic[0].Nbits) {
+  case 8:
+    Remap8 (graphic, layout, matrix);
+    break;
+  case 16:
+    Remap16 (graphic, layout, matrix);
+    break;
+  case 24:
+    Remap24 (graphic, layout, matrix);
+    break;
+  case 32:
+    Remap32 (graphic, layout, matrix);
+    break;
+  }
+
+}
+
Index: /tags/kii-1-4/Ohana/src/kii/picture/Remap16.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/picture/Remap16.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/picture/Remap16.c	(revision 11911)
@@ -0,0 +1,153 @@
+# include "Ximage.h"
+# define FRAC(a) ((a) - (int)(a))
+
+void Remap16 (Graphic *graphic, Layout *layout, Matrix *matrix) {
+
+  int i, j, ii, jj;
+  int i_start, i_end, j_start, j_end;
+  int dropback;  /* this is a bit of a kludge... */
+  int dx, dy, DX, DY;
+  double expand, Rx, Ry, X, Y;
+  int expand_in, expand_out;
+  unsigned char *out_pix, *out_pix2, *data;
+  unsigned char *in_pix,  *in_pix2;
+  unsigned char pixel1[256], pixel2[256], pixel3[256];
+  unsigned char pixvalue1, pixvalue2;
+  unsigned long white;
+  unsigned char white1, white2;
+
+  for (i = 0; i < 256; i++) { /* set up pixel array */
+    pixel1[i] = 0x0000ff & layout[0].cmap[i].pixel;
+    pixel2[i] = 0x0000ff & (layout[0].cmap[i].pixel >> 8);
+    pixel3[i] = 0x0000ff & (layout[0].cmap[i].pixel >> 16);
+  }
+  white = layout[0].white;
+  white1 = 0x00ff & white;
+  white2 = 0x00ff & (white >> 8);
+
+  expand = expand_in = expand_out = 1.0;
+  if (layout[0].expand == 0) /* set up expansions */
+    layout[0].expand = 1;
+  if (layout[0].expand > 0) {
+    expand = 1 / (1.0*layout[0].expand);
+    expand_out = layout[0].expand;
+    expand_in  = 1;
+  }
+  if (layout[0].expand < 0) {
+    expand = fabs((double)layout[0].expand);
+    expand_out = 1;
+    expand_in  = -layout[0].expand;
+  }
+
+  dx = layout[0].picture.dx;
+  dy = layout[0].picture.dy;
+  DX = matrix[0].Naxis[0];
+  DY = matrix[0].Naxis[1];
+
+  /* X,Y are the image coordinates of the first image pixel */
+  X = MAX(0.5*(DX - dx*expand) - layout[0].X, 0);
+  if ((int)X != X) 
+    X = (int) X + 1;
+  else 
+    X = (int) X;
+  Y = MAX(0.5*(DY - dy*expand) - layout[0].Y, 0);
+  if ((int)Y != Y) 
+    Y = (int) Y + 1;
+  else 
+    Y = (int) Y;
+
+  /* Rx,Ry are the screen coordinates of the first image pixel */
+  Rx = (X + layout[0].X - 0.5*DX)/expand + 0.5*dx;
+  Ry = (Y + layout[0].Y - 0.5*DY)/expand + 0.5*dy;
+
+  i_start = MIN (MAX (Rx, 0), dx - expand_out + 1);
+  j_start = MIN (MAX (Ry, 0), dy - expand_out + 1);
+  
+  if (layout[0].expand > 0) {
+    i_end = MAX (MIN (i_start + ((int)(expand*(dx-i_start)))/expand, expand_out*(DX-X) + Rx), 0);
+    j_end = MAX (MIN (j_start + ((int)(expand*(dy-j_start)))/expand, expand_out*(DY-Y) + Ry), 0);
+  } else {
+    i_end = MAX (MIN (dx, (DX-X)/expand + Rx), 0);
+    j_end = MAX (MIN (dy, (DY-Y)/expand + Ry), 0);
+  }    
+
+  dropback = expand_out - (i_end - i_start) % expand_out;
+  if ((i_end - i_start) % expand_out == 0) dropback = 0;
+
+  data = out_pix = (unsigned char *) layout[0].picture.data;
+  in_pix  = (unsigned char *) (matrix[0].buffer) + DX*(int)MAX(Y,0) + (int)MAX(X,0);
+
+  /********** below we do the mapping from buffer pixels (in) to picture pixels (out) **********/
+
+  /**** fill in bottom area ****/
+  for (j = 0; j < j_start; j++) {
+    for (i = 0; i < dx; i++, out_pix+=2) {
+      out_pix[0] = white1;
+      out_pix[1] = white2;
+    }
+  }
+  
+  for (j = j_start; j < j_end; j+= expand_out, in_pix += expand_in*DX) {
+    out_pix = &data[2*j*dx];
+
+    /**** fill in area to the left of the picture ****/
+    for (jj = 0; (i_start > 0) && (jj < expand_out); jj++) { 
+      out_pix2 = out_pix + 2*jj*dx;
+      for (i = 0; i < i_start; i++, out_pix2+=2) {
+	out_pix2[0] = white1;
+	out_pix2[1] = white2;
+      }
+    }
+    out_pix += 2*i_start;
+    
+    /*** fill in the picture region ***/
+    in_pix2 = in_pix;
+    if (expand_out == 1) {
+      for (i = i_start; i < i_end; i++, in_pix2+= expand_in, out_pix+=2) {
+	out_pix[0] = pixel1[*in_pix2];
+	out_pix[1] = pixel2[*in_pix2];
+      }
+    }
+    else {
+      for (i = i_start; i < i_end; i+= expand_out, in_pix2++, out_pix+= 2*expand_out) { 
+	pixvalue1 = pixel1[*in_pix2];
+	pixvalue2 = pixel2[*in_pix2];
+	out_pix2 = out_pix;
+	for (jj = 0; jj < expand_out; jj++, out_pix2+=2*(dx-expand_out)) {
+	  for (ii = 0; ii < expand_out; ii++, out_pix2+=2) {
+	    out_pix2[0] = pixvalue1; 
+	    out_pix2[1] = pixvalue2; 
+	  }
+	}
+      }
+    }
+    out_pix -= 2*dropback;
+    
+    /**** fill in area to the right of the picture ****/
+    for (jj = 0; jj < expand_out; jj++) {
+      out_pix2 = out_pix + 2*jj*dx;
+      for (i = i_end; i < dx; i++, out_pix2+=2) {
+	out_pix2[0] = white1;
+	out_pix2[1] = white2;
+      }
+    }
+  } 
+  
+  /*
+  if ((j_end - j_start) % expand_out > 0)
+    out_pix -= expand_out - (j_end - j_start) % expand_out;
+  */
+  
+  out_pix = &data[2*j_end*dx];
+  /**** fill in top area ****/
+  for (j = 0; j < (dy - j_end); j++) {
+    for (i = 0; i < dx; i++, out_pix+=2) { 
+      out_pix[0] = white1;
+      out_pix[1] = white2;
+    }
+  }
+
+  layout[0].picture.pix = XCreateImage (graphic[0].display, graphic[0].visual, graphic[0].depth, ZPixmap, 0, 
+					layout[0].picture.data, layout[0].picture.dx, layout[0].picture.dy, 16, 0);
+}
+
Index: /tags/kii-1-4/Ohana/src/kii/picture/Remap24.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/picture/Remap24.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/picture/Remap24.c	(revision 11911)
@@ -0,0 +1,164 @@
+# include "Ximage.h"
+# define FRAC(a) ((a) - (int)(a))
+
+void Remap24 (Graphic *graphic, Layout *layout, Matrix *matrix) {
+
+  int i, j, ii, jj;
+  int i_start, i_end, j_start, j_end;
+  int dropback, extra;  /* this is a bit of a kludge... */
+  int dx, dy, DX, DY;
+  double expand, Rx, Ry, X, Y;
+  int expand_in, expand_out;
+  unsigned char *out_pix, *out_pix2, *data;
+  unsigned char *in_pix,  *in_pix2;
+  unsigned char pixel1[256], pixel2[256], pixel3[256];
+  unsigned char pixvalue1, pixvalue2, pixvalue3;
+  unsigned long white;
+  unsigned char white1, white2, white3;
+
+  for (i = 0; i < 256; i++) { /* set up pixel array */
+    pixel1[i] = 0x0000ff & layout[0].cmap[i].pixel;
+    pixel2[i] = 0x0000ff & (layout[0].cmap[i].pixel >> 8);
+    pixel3[i] = 0x0000ff & (layout[0].cmap[i].pixel >> 16);
+  }
+  white = layout[0].white;
+  white1 = 0x0000ff & white;
+  white2 = 0x0000ff & (white >> 8);
+  white3 = 0x0000ff & (white >> 16);
+
+  expand = expand_in = expand_out = 1.0;
+  if (layout[0].expand == 0) /* set up expansions */
+    layout[0].expand = 1;
+  if (layout[0].expand > 0) {
+    expand = 1 / (1.0*layout[0].expand);
+    expand_out = layout[0].expand;
+    expand_in  = 1;
+  }
+  if (layout[0].expand < 0) {
+    expand = fabs((double)layout[0].expand);
+    expand_out = 1;
+    expand_in  = -layout[0].expand;
+  }
+
+  dx = layout[0].picture.dx;
+  dy = layout[0].picture.dy;
+  DX = matrix[0].Naxis[0];
+  DY = matrix[0].Naxis[1];
+  extra = 4 - (dx * 3) % 4;
+
+  /* X,Y are the image coordinates of the first image pixel */
+  X = MAX(0.5*(DX - dx*expand) - layout[0].X, 0);
+  if ((int)X != X) 
+    X = (int) X + 1;
+  else 
+    X = (int) X;
+  Y = MAX(0.5*(DY - dy*expand) - layout[0].Y, 0);
+  if ((int)Y != Y) 
+    Y = (int) Y + 1;
+  else 
+    Y = (int) Y;
+
+  /* Rx,Ry are the screen coordinates of the first image pixel */
+  Rx = (X + layout[0].X - 0.5*DX)/expand + 0.5*dx;
+  Ry = (Y + layout[0].Y - 0.5*DY)/expand + 0.5*dy;
+
+  i_start = MIN (MAX (Rx, 0), dx - expand_out + 1);
+  j_start = MIN (MAX (Ry, 0), dy - expand_out + 1);
+  
+  if (layout[0].expand > 0) {
+    i_end = MAX (MIN (i_start + ((int)(expand*(dx-i_start)))/expand, expand_out*(DX-X) + Rx), 0);
+    j_end = MAX (MIN (j_start + ((int)(expand*(dy-j_start)))/expand, expand_out*(DY-Y) + Ry), 0);
+  } else {
+    i_end = MAX (MIN (dx, (DX-X)/expand + Rx), 0);
+    j_end = MAX (MIN (dy, (DY-Y)/expand + Ry), 0);
+  }    
+
+  dropback = expand_out - (i_end - i_start) % expand_out;
+  if ((i_end - i_start) % expand_out == 0) dropback = 0;
+
+  data = out_pix = (unsigned char *) layout[0].picture.data;
+  in_pix  = (unsigned char *) (matrix[0].buffer) + DX*(int)MAX(Y,0) + (int)MAX(X,0);
+
+  /********** below we do the mapping from buffer pixels (in) to picture pixels (out) **********/
+
+  /**** fill in bottom area ****/
+  for (j = 0; j < j_start; j++) {
+    for (i = 0; i < dx; i++, out_pix+=3) {
+      out_pix[0] = white1;
+      out_pix[1] = white2;
+      out_pix[2] = white3;
+    }
+    out_pix += extra;
+  }
+  
+  for (j = j_start; j < j_end; j+= expand_out, in_pix += expand_in*DX) {
+    out_pix = &data[j*(3*dx+extra)];
+
+    /**** fill in area to the left of the picture ****/
+    for (jj = 0; (i_start > 0) && (jj < expand_out); jj++) { 
+      out_pix2 = out_pix + jj*(3*dx + extra);
+      for (i = 0; i < i_start; i++, out_pix2+=3) {
+	out_pix2[0] = white1;
+	out_pix2[1] = white2;
+	out_pix2[2] = white3;
+      }
+    }
+    out_pix += 3*i_start;
+    
+    /*** fill in the picture region ***/
+    in_pix2 = in_pix;
+    if (expand_out == 1) {
+      for (i = i_start; i < i_end; i++, in_pix2+= expand_in, out_pix+=3) {
+	out_pix[0] = pixel1[*in_pix2];
+	out_pix[1] = pixel2[*in_pix2];
+	out_pix[2] = pixel3[*in_pix2];
+      }
+    }
+    else {
+      for (i = i_start; i < i_end; i+= expand_out, in_pix2++, out_pix+= 3*expand_out) { 
+	pixvalue1 = pixel1[*in_pix2];
+	pixvalue2 = pixel2[*in_pix2];
+	pixvalue3 = pixel3[*in_pix2];
+	out_pix2 = out_pix;
+	for (jj = 0; jj < expand_out; jj++, out_pix2+=3*(dx-expand_out)+extra) {
+	  for (ii = 0; ii < expand_out; ii++, out_pix2+=3) {
+	    out_pix2[0] = pixvalue1; 
+	    out_pix2[1] = pixvalue2; 
+	    out_pix2[2] = pixvalue3; 
+	  }
+	}
+      }
+    }
+    out_pix -= 3*dropback;
+    
+    /**** fill in area to the right of the picture ****/
+    for (jj = 0; jj < expand_out; jj++) {
+      out_pix2 = out_pix + jj*(3*dx+extra);
+      for (i = i_end; i < dx; i++, out_pix2+=3) {
+	out_pix2[0] = white1;
+	out_pix2[1] = white2;
+	out_pix2[2] = white3;
+      }
+    }
+  } 
+  
+  /*
+  if ((j_end - j_start) % expand_out > 0)
+    out_pix -= expand_out - (j_end - j_start) % expand_out;
+  */
+  
+  out_pix = &data[j_end*(3*dx+extra)];
+  /**** fill in top area ****/
+  for (j = 0; j < (dy - j_end); j++) {
+    for (i = 0; i < dx; i++, out_pix+=3) { 
+      out_pix[0] = white1;
+      out_pix[1] = white2;
+      out_pix[2] = white3;
+    }
+    out_pix+=extra;
+  }
+
+  layout[0].picture.pix = XCreateImage (graphic[0].display, graphic[0].visual, graphic[0].depth, ZPixmap, 0, 
+					layout[0].picture.data, layout[0].picture.dx, layout[0].picture.dy, 32, 0);
+}
+
Index: /tags/kii-1-4/Ohana/src/kii/picture/Remap32.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/picture/Remap32.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/picture/Remap32.c	(revision 11911)
@@ -0,0 +1,132 @@
+# include "Ximage.h"
+# define FRAC(a) ((a) - (int)(a))
+
+void Remap32 (Graphic *graphic, Layout *layout, Matrix *matrix) {
+
+  int i, j, ii, jj;
+  int i_start, i_end, j_start, j_end;
+  int dropback;  /* this is a bit of a kludge... */
+  int dx, dy, DX, DY;
+  double expand, Rx, Ry, X, Y;
+  int expand_in, expand_out;
+  unsigned int *out_pix, *out_pix2;
+  unsigned char *in_pix,  *in_pix2;
+  unsigned long pixel[256], pixvalue;
+  unsigned long white;
+
+  for (i = 0; i < 256; i++) { /* set up pixel array */
+    pixel[i] = layout[0].cmap[i].pixel;
+  }
+  white = layout[0].white;
+
+  expand = expand_in = expand_out = 1.0;
+  if (layout[0].expand == 0) /* set up expansions */
+    layout[0].expand = 1;
+  if (layout[0].expand > 0) {
+    expand = 1 / (1.0*layout[0].expand);
+    expand_out = layout[0].expand;
+    expand_in  = 1;
+  }
+  if (layout[0].expand < 0) {
+    expand = fabs((double)layout[0].expand);
+    expand_out = 1;
+    expand_in  = -layout[0].expand;
+  }
+
+  dx = layout[0].picture.dx;
+  dy = layout[0].picture.dy;
+  DX = matrix[0].Naxis[0];
+  DY = matrix[0].Naxis[1];
+  /* X,Y are the image coordinates of the first image pixel */
+  X = MAX(0.5*(DX - dx*expand) - layout[0].X, 0);
+  if ((int)X != X) 
+    X = (int) X + 1;
+  else 
+    X = (int) X;
+  Y = MAX(0.5*(DY - dy*expand) - layout[0].Y, 0);
+  if ((int)Y != Y) 
+    Y = (int) Y + 1;
+  else 
+    Y = (int) Y;
+
+  /* Rx,Ry are the screen coordinates of the first image pixel */
+  Rx = (X + layout[0].X - 0.5*DX)/expand + 0.5*dx;
+  Ry = (Y + layout[0].Y - 0.5*DY)/expand + 0.5*dy;
+
+  i_start = MIN (MAX (Rx, 0), dx - expand_out + 1);
+  j_start = MIN (MAX (Ry, 0), dy - expand_out + 1);
+  
+  if (layout[0].expand > 0) {
+    i_end = MAX (MIN (i_start + ((int)(expand*(dx-i_start)))/expand, expand_out*(DX-X) + Rx), 0);
+    j_end = MAX (MIN (j_start + ((int)(expand*(dy-j_start)))/expand, expand_out*(DY-Y) + Ry), 0);
+  } else {
+    i_end = MAX (MIN (dx, (DX-X)/expand + Rx), 0);
+    j_end = MAX (MIN (dy, (DY-Y)/expand + Ry), 0);
+  }    
+
+  dropback = expand_out - (i_end - i_start) % expand_out;
+  if ((i_end - i_start) % expand_out == 0) dropback = 0;
+
+  out_pix = (unsigned int *) layout[0].picture.data;
+  in_pix  = (unsigned char *) (matrix[0].buffer) + DX*(int)MAX(Y,0) + (int)MAX(X,0);
+
+  /********** below we do the mapping from buffer pixels (in) to picture pixels (out) **********/
+
+  /**** fill in bottom area ****/
+  for (j = 0; j < dx*j_start; j++, out_pix++) 
+    *out_pix = white;
+  
+  for (j = j_start; j < j_end; j+= expand_out, out_pix+=(expand_out-1)*dx, in_pix += expand_in*DX) {
+
+    /**** fill in area to the left of the picture ****/
+    for (jj = 0; (i_start > 0) && (jj < expand_out); jj++) { 
+      out_pix2 = out_pix + jj*dx;
+      for (i = 0; i < i_start; i++, out_pix2++) {
+	*out_pix2 = white;
+      }
+    }
+    out_pix += i_start;
+    
+    /*** fill in the picture region ***/
+    in_pix2 = in_pix;
+    if (expand_out == 1) {
+      for (i = i_start; i < i_end; i++, in_pix2+= expand_in, out_pix++) {
+	*out_pix = pixel[*in_pix2];
+      }
+      /* *out_pix = *(pixel + *in_pix2);  */
+    }
+    else {
+      for (i = i_start; i < i_end; i+= expand_out, in_pix2++, out_pix+= expand_out) { 
+	pixvalue = pixel[*in_pix2];
+	out_pix2 = out_pix;
+	for (jj = 0; jj < expand_out; jj++, out_pix2+=(dx-expand_out)) {
+	  for (ii = 0; ii < expand_out; ii++, out_pix2++) {
+	    *out_pix2 = pixvalue;
+	  }
+	}
+      }
+    }
+    out_pix -= dropback;
+    
+    /**** fill in area to the right of the picture ****/
+    for (jj = 0; jj < expand_out; jj++) {
+      out_pix2 = out_pix + jj*dx;
+      for (i = i_end; i < dx; i++, out_pix2++) {
+	*out_pix2 = white;
+      }
+    }
+    out_pix += (dx - i_end);
+    
+  } 
+  
+  if ((j_end - j_start) % expand_out > 0)
+    out_pix -= expand_out - (j_end - j_start) % expand_out;
+  
+  /**** fill in top area ****/
+  for (j = 0; (j < dx*(dy - j_end)) && (out_pix - (unsigned int *)layout[0].picture.data < dx*dy); j++, out_pix++) { 
+    *out_pix = white;
+  }
+  layout[0].picture.pix = XCreateImage (graphic[0].display, graphic[0].visual, graphic[0].depth, ZPixmap, 0, 
+					layout[0].picture.data, layout[0].picture.dx, layout[0].picture.dy, 32, 0);
+}
+
Index: /tags/kii-1-4/Ohana/src/kii/picture/Remap8.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/picture/Remap8.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/picture/Remap8.c	(revision 11911)
@@ -0,0 +1,132 @@
+# include "Ximage.h"
+# define FRAC(a) ((a) - (int)(a))
+
+void Remap8 (Graphic *graphic, Layout *layout, Matrix *matrix) {
+
+  int i, j, ii, jj;
+  int i_start, i_end, j_start, j_end;
+  int dropback;  /* this is a bit of a kludge... */
+  int dx, dy, DX, DY;
+  double expand, Rx, Ry, X, Y;
+  int expand_in, expand_out;
+  unsigned char *out_pix, *out_pix2;
+  unsigned char *in_pix,  *in_pix2;
+  unsigned long pixel[256], pixvalue;
+  unsigned long white;
+
+  for (i = 0; i < 256; i++) { /* set up pixel array */
+    pixel[i] = layout[0].cmap[i].pixel;
+  }
+  white = layout[0].white;
+
+  expand = expand_in = expand_out = 1.0;
+  if (layout[0].expand == 0) /* set up expansions */
+    layout[0].expand = 1;
+  if (layout[0].expand > 0) {
+    expand = 1 / (1.0*layout[0].expand);
+    expand_out = layout[0].expand;
+    expand_in  = 1;
+  }
+  if (layout[0].expand < 0) {
+    expand = fabs((double)layout[0].expand);
+    expand_out = 1;
+    expand_in  = -layout[0].expand;
+  }
+
+  dx = layout[0].picture.dx;
+  dy = layout[0].picture.dy;
+  DX = matrix[0].Naxis[0];
+  DY = matrix[0].Naxis[1];
+  /* X,Y are the image coordinates of the first image pixel */
+  X = MAX(0.5*(DX - dx*expand) - layout[0].X, 0);
+  if ((int)X != X) 
+    X = (int) X + 1;
+  else 
+    X = (int) X;
+  Y = MAX(0.5*(DY - dy*expand) - layout[0].Y, 0);
+  if ((int)Y != Y) 
+    Y = (int) Y + 1;
+  else 
+    Y = (int) Y;
+
+  /* Rx,Ry are the screen coordinates of the first image pixel */
+  Rx = (X + layout[0].X - 0.5*DX)/expand + 0.5*dx;
+  Ry = (Y + layout[0].Y - 0.5*DY)/expand + 0.5*dy;
+
+  i_start = MIN (MAX (Rx, 0), dx - expand_out + 1);
+  j_start = MIN (MAX (Ry, 0), dy - expand_out + 1);
+  
+  if (layout[0].expand > 0) {
+    i_end = MAX (MIN (i_start + ((int)(expand*(dx-i_start)))/expand, expand_out*(DX-X) + Rx), 0);
+    j_end = MAX (MIN (j_start + ((int)(expand*(dy-j_start)))/expand, expand_out*(DY-Y) + Ry), 0);
+  } else {
+    i_end = MAX (MIN (dx, (DX-X)/expand + Rx), 0);
+    j_end = MAX (MIN (dy, (DY-Y)/expand + Ry), 0);
+  }    
+
+  dropback = expand_out - (i_end - i_start) % expand_out;
+  if ((i_end - i_start) % expand_out == 0) dropback = 0;
+
+  out_pix = (unsigned char *) layout[0].picture.data;
+  in_pix  = (unsigned char *) matrix[0].buffer + DX*(int)MAX(Y,0) + (int)MAX(X,0);
+
+  /********** below we do the mapping from buffer pixels (in) to picture pixels (out) **********/
+
+  /**** fill in bottom area ****/
+  for (j = 0; j < dx*j_start; j++, out_pix++) 
+    *out_pix = white;
+  
+  for (j = j_start; j < j_end; j+= expand_out, out_pix+=(expand_out-1)*dx, in_pix += expand_in*DX) {
+
+    /**** fill in area to the left of the picture ****/
+    for (jj = 0; (i_start > 0) && (jj < expand_out); jj++) { 
+      out_pix2 = out_pix + jj*dx;
+      for (i = 0; i < i_start; i++, out_pix2++) {
+	*out_pix2 = white;
+      }
+    }
+    out_pix += i_start;
+    
+    /*** fill in the picture region ***/
+    in_pix2 = in_pix;
+    if (expand_out == 1) {
+      for (i = i_start; i < i_end; i++, in_pix2+= expand_in, out_pix++) {
+	*out_pix = pixel[*in_pix2];
+      }
+      /* *out_pix = *(pixel + *in_pix2);  */
+    }
+    else {
+      for (i = i_start; i < i_end; i+= expand_out, in_pix2++, out_pix+= expand_out) { 
+	pixvalue = pixel[*in_pix2];
+	out_pix2 = out_pix;
+	for (jj = 0; jj < expand_out; jj++, out_pix2+=(dx-expand_out)) {
+	  for (ii = 0; ii < expand_out; ii++, out_pix2++) {
+	    *out_pix2 = pixvalue;
+	  }
+	}
+      }
+    }
+    out_pix -= dropback;
+    
+    /**** fill in area to the right of the picture ****/
+    for (jj = 0; jj < expand_out; jj++) {
+      out_pix2 = out_pix + jj*dx;
+      for (i = i_end; i < dx; i++, out_pix2++) {
+	*out_pix2 = white;
+      }
+    }
+    out_pix += (dx - i_end);
+    
+  } 
+  
+  if ((j_end - j_start) % expand_out > 0)
+    out_pix -= expand_out - (j_end - j_start) % expand_out;
+  
+  /**** fill in top area ****/
+  for (j = 0; (j < dx*(dy - j_end)) && (out_pix - (unsigned char *)layout[0].picture.data < dx*dy); j++, out_pix++) { 
+    *out_pix = white;
+  }
+  layout[0].picture.pix = XCreateImage (graphic[0].display, graphic[0].visual, graphic[0].depth, ZPixmap, 0, 
+					layout[0].picture.data, layout[0].picture.dx, layout[0].picture.dy, 8, 0);
+}
+
Index: /tags/kii-1-4/Ohana/src/kii/picture/Reorient.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/picture/Reorient.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/picture/Reorient.c	(revision 11911)
@@ -0,0 +1,65 @@
+# include "Ximage.h"
+
+void Reorient (Graphic *graphic, Layout *layout, XButtonEvent *mouse_event) {
+
+  int x, y, dummy2;
+  double X0, Y0;
+  unsigned int dummy3;
+  Window dummy1;
+
+  if (layout[0].expand == 0)
+    layout[0].expand = 1;
+
+  Screen_to_Image (&X0, &Y0, (double)mouse_event[0].x, (double)mouse_event[0].y, layout);
+  X0 = 0.5*layout[0].matrix.Naxis[0] - X0;
+  Y0 = 0.5*layout[0].matrix.Naxis[1] - Y0;
+
+  switch (mouse_event[0].button) {
+  case 1:
+    if ((layout[0].X != X0) || (layout[0].Y != Y0)) {
+      layout[0].X = X0;
+      layout[0].Y = Y0;
+    }
+    break;
+  case 2: 
+    layout[0].expand--;
+    if ((layout[0].expand == 0) || (layout[0].expand == -1))
+      layout[0].expand = -2;
+    if (layout[0].expand < -30) {
+      fprintf (stderr, "can't get smaller!\n");
+      layout[0].expand = -30;
+      return;
+    }
+    layout[0].X = X0;
+    layout[0].Y = Y0;
+    break;
+  case 3:
+    layout[0].expand++;
+    if ((layout[0].expand == 0) || (layout[0].expand == -1))
+      layout[0].expand = 1;
+    if (layout[0].expand > 30) {
+      fprintf (stderr, "can't get bigger!\n");
+      layout[0].expand = 30;
+      return;
+    }
+    layout[0].X = X0;
+    layout[0].Y = Y0;
+    break;
+  }
+
+  Remap (graphic, layout, &layout[0].matrix);
+  Refresh (graphic, layout, 0);
+ 
+# ifndef NOWARP  /* the "warp" function seems to be a problem on SUNs for some reason */
+  XQueryPointer (graphic[0].display, graphic[0].window, &dummy1, &dummy1, &dummy2, &dummy2, &x, &y, &dummy3); 
+  if ((x > layout[0].picture.x) && (x < layout[0].picture.x + layout[0].picture.dx) &&
+      (y > layout[0].picture.y) && (y < layout[0].picture.y + layout[0].picture.dy) &&
+      ((mouse_event[0].button == 2) || (mouse_event[0].button == 3))) {
+    XWarpPointer (graphic[0].display, None, graphic[0].window, 0, 0, 0, 0, 
+		  layout[0].picture.x + 0.5*layout[0].picture.dx,
+		  layout[0].picture.y + 0.5*layout[0].picture.dy);
+  }
+# endif
+
+  XFlush (graphic[0].display);
+}
Index: /tags/kii-1-4/Ohana/src/kii/picture/Rescale.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/picture/Rescale.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/picture/Rescale.c	(revision 11911)
@@ -0,0 +1,16 @@
+# include "Ximage.h"
+
+void
+Rescale (graphic, layout)
+Graphic graphic[];
+Layout  layout[];
+{
+
+  fprintf (stdout, "enter new zero, range: ");
+  fscanf (stdin, "%lf%lf", &layout[0].zero, &layout[0].range);
+
+  Remap (graphic, layout, &layout[0].matrix);
+  Refresh (graphic, layout, 0);
+  
+  XFlush (graphic[0].display);
+}
Index: /tags/kii-1-4/Ohana/src/kii/picture/Resize.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/picture/Resize.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/picture/Resize.c	(revision 11911)
@@ -0,0 +1,31 @@
+# include "Ximage.h"
+
+int Resize (Graphic *graphic, Layout *layout) {
+ 
+  unsigned int NX, NY;
+
+  KiiScanMessage (layout[0].Ximage, "%d %d", &NX, &NY);
+
+  NX += ZOOM_X + 3*PAD1 + 25;
+  NY += 2*PAD1 + PAD2 + COLORPAD + 25;
+
+  if ((graphic[0].dx == NX) && (graphic[0].dy == NY)) 
+    return (TRUE);
+
+  graphic[0].dx = MAX(NX, 50); 
+  graphic[0].dy = MAX(NY, 50); 
+
+  if (USE_XWINDOW) XResizeWindow (graphic[0].display, graphic[0].window, NX, NY);
+
+  PositionPictures (layout, graphic);
+
+  if (USE_XWINDOW) {
+    CreateColorbar (layout, graphic);
+    CreatePicture (layout, graphic);
+    Remap (graphic, layout, &layout[0].matrix); 
+    XClearWindow (graphic[0].display, graphic[0].window);
+    Refresh (graphic, layout, 1);
+  }
+
+  return (TRUE);
+}
Index: /tags/kii-1-4/Ohana/src/kii/picture/StatusBox.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/picture/StatusBox.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/picture/StatusBox.c	(revision 11911)
@@ -0,0 +1,27 @@
+# include "Ximage.h"
+
+void
+StatusBox (graphic, layout)
+Graphic        graphic[];
+Layout         layout[];
+{
+
+  double  x, y, z;
+
+  if (MOVE_POINTER) {
+    x = 0.5*layout[0].matrix.Naxis[0];
+    y = 0.5*layout[0].matrix.Naxis[1];
+    z = -1;
+    layout[0].x = x;
+    layout[0].y = y;
+    layout[0].z = z;
+  }
+  else {
+    x = layout[0].x;
+    y = layout[0].y;
+    z = layout[0].z;
+  }
+  
+  UpdateStatusBox (graphic, layout, x, y, z, 1);
+  
+}
Index: /tags/kii-1-4/Ohana/src/kii/picture/TestPicture.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/picture/TestPicture.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/picture/TestPicture.c	(revision 11911)
@@ -0,0 +1,59 @@
+# include "Ximage.h"
+
+int 
+TestPicture (graphic, layout)
+     Graphic graphic[];
+     Layout  layout[];
+{
+
+  Header header;
+  char buffer[1024], *buff;
+  int status, bytes_left, Nbytes, i, j;
+  double frac;
+
+  fits_free_matrix (&layout[0].matrix);
+
+  header.Naxes = 2;
+  header.Naxis[0] = 512;
+  header.Naxis[1] = 512;
+  header.bitpix = 8;
+  header.unsign = 0;
+  header.bzero = 0;
+  header.bscale = 1;
+
+  layout[0].zero = 0;
+  layout[0].range = layout[0].Npixels;
+  layout[0].min = 0; 
+  layout[0].max = layout[0].Npixels;
+  
+  fits_create_matrix (&header, &layout[0].matrix);
+
+  frac = layout[0].Npixels / (512.0*512.0);
+  buff = layout[0].matrix.buffer;
+  for (i = 0; i < 512; i++) {
+    for (j = 0; j < 512; j++, buff++) {
+      *buff = (int)(i*j*frac);
+    }
+  }
+
+/*
+  Remap (layout, &layout[0].matrix);
+  layout[0].picture.pix = XCreateImage (graphic[0].display, graphic[0].visual, graphic[0].depth, ZPixmap, 0, 
+					layout[0].picture.data, 
+					layout[0].picture.dx, layout[0].picture.dy, 8, 0);
+
+  (DEBUG) && fprintf (stderr, "remapped image\n", layout[0].matrix.size);
+  Refresh (graphic, layout);
+  
+  (DEBUG) && fprintf (stderr, "refreshed\n", layout[0].matrix.size);
+  XFlush (graphic[0].display);
+*/
+}
+
+
+/*
+   layout[0].X = 0;
+   layout[0].Y = 0;
+   layout[0].expand = 1;
+*/
+  
Index: /tags/kii-1-4/Ohana/src/kii/picture/cursor.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/picture/cursor.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/picture/cursor.c	(revision 11911)
@@ -0,0 +1,70 @@
+# include "Ximage.h"
+
+int LastEvent (Display *display, int type, XEvent *event);
+
+int cursor (Graphic *graphic, Layout *layout) {
+
+  Display        *display;
+  XEvent          event;
+  KeySym          keysym;
+  int             status;
+  XComposeStatus  composestatus;
+  char            string[10], line[40], *name;
+  double          x, y;
+  
+  while (1) {
+    
+    status = CheckPipe (graphic, layout);
+    if (status == 0) return (FALSE);
+    if (status == 2) return (TRUE);
+    if (status == 1) goto events;
+
+  events:
+    if (XEventsQueued (graphic[0].display, QueuedAfterFlush) < 1) {
+      usleep (10000);
+      continue;
+    }
+
+    display = graphic[0].display;
+
+    /* only do the last entry for these events */
+    /* this ignores the return status from these functions */
+    if (LastEvent (display, ConfigureNotify, &event)) Reconfig (graphic, layout, &event);
+    if (LastEvent (display, Expose,          &event)) Refresh (graphic, layout, 1);
+    if (LastEvent (display, MappingNotify,   &event)) XRefreshKeyboardMapping ((XMappingEvent *) &event);
+    if (LastEvent (display, MotionNotify,    &event)) UpdatePointer (graphic, layout, (XMotionEvent *) &event);
+    if (LastEvent (display, ButtonPress,     &event)) InterpretPresses (graphic, layout, (XButtonEvent *) &event);
+    if (LastEvent (display, KeyPress,        &event)) {
+      status = XLookupString ((XKeyEvent *) &event, string, 9, &keysym, &composestatus);
+
+      if (event.xkey.x < layout[0].picture.x) continue;
+      if (event.xkey.x > layout[0].picture.x + layout[0].picture.dx) continue;
+      if (event.xkey.y < layout[0].picture.y) continue;
+      if (event.xkey.y > layout[0].picture.y + layout[0].picture.dy) continue;
+	
+      Screen_to_Image (&x, &y, (double)event.xkey.x, (double)event.xkey.y, layout);
+      name = XKeysymToString (keysym);
+
+      // skip the following keys: 
+      if (!strcmp (name, "Shift_L")) continue;
+      if (!strcmp (name, "Shift_R")) continue;
+      if (!strcmp (name, "Control_L")) continue;
+      if (!strcmp (name, "Control_R")) continue;
+      if (!strcmp (name, "Alt_L")) continue;
+      if (!strcmp (name, "Alt_R")) continue;
+      if (!strcmp (name, "Super_L")) continue;
+      if (!strcmp (name, "Super_R")) continue;
+      if (!strcmp (name, "Caps_Lock")) continue;
+      if (!strcmp (name, "Pause")) continue;
+      if (!strcmp (name, "Continue")) continue;
+      if (!strcmp (name, "Num_Lock")) continue;
+      if (!strcmp (name, "Scroll_Lock")) continue;
+      if (!strcmp (name, "Print")) continue;
+      if (!strcmp (name, "(null)")) continue;
+
+      snprintf (line, 40, "%12s %12.6f %12.6f ", name, x, y);
+      write (layout[0].Ximage, line, 40);
+    }
+  }
+  return (FALSE);
+}
Index: /tags/kii-1-4/Ohana/src/kii/scrollbar/DownArrow.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/scrollbar/DownArrow.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/scrollbar/DownArrow.c	(revision 11911)
@@ -0,0 +1,20 @@
+# include "Ximage"
+# include "ScrollBars.h"
+
+int 
+DownArrow (button_event, height, width, SB_x, SB_y)
+XButtonEvent *button_event;
+int height, width, SB_x, SB_y;
+{
+
+  int answer, m_x, m_y;
+
+  m_x = button_event -> x;
+  m_y = button_event -> y;
+  answer = ((m_y > (height - SB_y)) && 
+	    (m_x > (width - SB_y)));
+    return (answer);
+
+}
+
+
Index: /tags/kii-1-4/Ohana/src/kii/scrollbar/LeftArrow.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/scrollbar/LeftArrow.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/scrollbar/LeftArrow.c	(revision 11911)
@@ -0,0 +1,18 @@
+# include "Ximage"
+# include "ScrollBars.h"
+
+int
+LeftArrow (button_event, height, width, SB_x, SB_y) 
+XButtonEvent *button_event;
+int height, width, SB_x, SB_y;
+{
+
+  int answer, m_x, m_y;
+
+  m_x = button_event -> x;
+  m_y = button_event -> y;
+  answer = ((m_x < SB_x) && (m_y < SB_x));
+  return (answer);
+
+}
+
Index: /tags/kii-1-4/Ohana/src/kii/scrollbar/RightArrow.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/scrollbar/RightArrow.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/scrollbar/RightArrow.c	(revision 11911)
@@ -0,0 +1,20 @@
+# include "Ximage"
+# include "ScrollBars.h"
+
+int
+RightArrow (button_event, height, width, SB_x, SB_y) 
+XButtonEvent *button_event;
+int height, width, SB_x, SB_y;
+{
+
+  int answer, m_x, m_y;
+
+  m_x = button_event -> x;
+  m_y = button_event -> y;
+  answer = ((m_x < SB_x) && 
+	    (m_y > (height - SB_x - SB_y)) && 
+	    (m_y < (height - SB_y)));
+  return (answer);
+
+}
+
Index: /tags/kii-1-4/Ohana/src/kii/scrollbar/ScrollBars.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/scrollbar/ScrollBars.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/scrollbar/ScrollBars.c	(revision 11911)
@@ -0,0 +1,38 @@
+# include "Ximage"
+# include "ScrollBars.h"
+
+void
+ScrollBars (display, window, gc, height, width, SB_x, SB_y, f_x, f_y)
+Display *display;
+Window window;
+GC gc;
+int width, height, SB_x, SB_y;
+double f_x, f_y;
+{
+  
+  int x, y;
+
+  y = height - SB_y;
+  XDrawLine (display, window, gc, 0, y, width, y);
+  XDrawLine (display, window, gc, SB_x, 0, SB_x, height);
+  XDrawLine (display, window, gc, 0, SB_x, SB_x, SB_x);
+  x = width - SB_y;
+  y = height - SB_y;
+  XDrawLine (display, window, gc, x, y, x, height);
+  y = height - SB_x - SB_y;
+  XDrawLine (display, window, gc, 0, y, SB_x, y);
+  x = SB_y + SB_x;
+  y = height - SB_y;
+  XDrawLine (display, window, gc, x, y, x, height);
+  x = (width - 2*SB_y - SB_x) * f_x + SB_x + SB_y;
+  y = (height - 2*SB_x - SB_y) * f_y + SB_x;
+  XDrawLine (display, window, gc, x, height - SB_y, x, height);
+  XDrawLine (display, window, gc, x + 1, height - SB_y, x + 1, height);
+  XDrawLine (display, window, gc, 0, y, SB_x, y);
+  XDrawLine (display, window, gc, 0, y+1, SB_x, y+1);
+  y = height - SB_y;
+  XFillRectangle (display, window, gc, 0, y, SB_x, SB_y);
+
+}
+
+
Index: /tags/kii-1-4/Ohana/src/kii/scrollbar/UpArrow.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/scrollbar/UpArrow.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/scrollbar/UpArrow.c	(revision 11911)
@@ -0,0 +1,20 @@
+# include "Ximage"
+# include "ScrollBars.h"
+
+int
+UpArrow (button_event, height, width, SB_x, SB_y) 
+XButtonEvent *button_event;
+int height, width, SB_x, SB_y;
+{
+
+  int answer, m_x, m_y;
+
+  m_x = button_event -> x;
+  m_y = button_event -> y;
+  answer = ((m_y > (height - SB_y)) && 
+	    (m_x > SB_x) && 
+	    (m_x < (SB_x + SB_y)));
+  return (answer);
+
+}
+
Index: /tags/kii-1-4/Ohana/src/kii/scrollbar/xScrollBar.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/scrollbar/xScrollBar.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/scrollbar/xScrollBar.c	(revision 11911)
@@ -0,0 +1,26 @@
+# include "Ximage"
+# include "ScrollBars.h"
+
+int 
+xScrollBar (button_event, height, width, SB_x, SB_y, f)
+XButtonEvent *button_event;
+int height, width, SB_x, SB_y;
+double *f;
+{
+
+  int answer, m_x, m_y;
+  double f1, f2;
+
+  m_x = button_event -> x;
+  m_y = button_event -> y;
+  answer = ((m_x < SB_x) && 
+	    (m_y > SB_x) && 
+	    (m_y < (height - SB_x - SB_y)));
+  f1 = (double)(m_y - SB_x);
+  f2 = (double)(height - 2*SB_x - SB_y);
+  *f = f1 / f2;
+  return (answer);
+
+}
+
+
Index: /tags/kii-1-4/Ohana/src/kii/scrollbar/yScrollBar.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/scrollbar/yScrollBar.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/scrollbar/yScrollBar.c	(revision 11911)
@@ -0,0 +1,26 @@
+# include "Ximage"
+# include "ScrollBars.h"
+
+int
+yScrollBar (button_event, height, width, SB_x, SB_y, f)
+XButtonEvent *button_event;
+int height, width, SB_x, SB_y;
+double *f;
+{
+
+  int answer, m_x, m_y;
+  double f1, f2;
+
+  m_x = button_event -> x;
+  m_y = button_event -> y;
+  answer = ((m_y > (height - SB_y)) && 
+	    (m_x > (SB_x + SB_y)) && 
+	    (m_x < (width - SB_y)));
+  f1 = (double)(m_x - SB_x - SB_y);
+  f2 = (double)(width - 2*SB_y - SB_x);
+  *f = f1 / f2;
+  return (answer);
+
+}
+
+	
Index: /tags/kii-1-4/Ohana/src/kii/setup/CheckColors.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/setup/CheckColors.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/setup/CheckColors.c	(revision 11911)
@@ -0,0 +1,40 @@
+# include "Ximage.h"
+
+/************** CheckColors *************/
+void CheckColors (Graphic *graphic, int *argc, char **argv) {
+
+  char *temp_name;
+  int N;
+
+  /* here we define the values for "black" (blackground) and "white" (whiteground)
+     if -fg, or -bg exist, or if Foreground or Background are set in .Xdefaults, 
+     use those.  blackground defaults to Black, whiteground defaults to White. */
+
+  graphic[0].black = BlackPixel (graphic[0].display, graphic[0].screen);
+  temp_name = XGetDefault (graphic[0].display, argv[0], "Foreground");
+  if ((N = get_argument (*argc, argv, "-fg"))) {
+    if (N + 1 < *argc) {
+      temp_name = argv[N+1];
+    } else {
+      fprintf (stderr, "error: usage is -fg color\n");
+      exit (0);
+    }
+  }
+  if (temp_name != (char *)NULL) 
+    graphic[0].black = GetColor (graphic[0].display, temp_name, graphic[0].colormap, graphic[0].black);
+
+  graphic[0].white = WhitePixel (graphic[0].display, graphic[0].screen);
+  temp_name = XGetDefault (graphic[0].display, argv[0], "Background");
+  if ((N = get_argument (*argc, argv, "-bg"))) {
+    if (N + 1 < *argc) {
+      temp_name = argv[N+1];
+    } else {
+      fprintf (stderr, "error: usage is -bg color\n");
+      exit (0);
+    }
+  }  
+  if (temp_name != (char *)NULL) 
+    graphic[0].white = GetColor (graphic[0].display, temp_name, graphic[0].colormap, graphic[0].white);
+ 
+}
+
Index: /tags/kii-1-4/Ohana/src/kii/setup/CheckDisplayName.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/setup/CheckDisplayName.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/setup/CheckDisplayName.c	(revision 11911)
@@ -0,0 +1,30 @@
+# include "Ximage.h"
+
+/************** CheckDisplayName *************/
+void CheckDisplayName (int *argc, char **argv, char *display_name) {
+
+  int N;
+
+  display_name[0] = 0;
+  if ((N = get_argument (*argc, argv, "-d"))) {
+    if (N + 1 < *argc) {
+      strcpy (display_name, argv[N + 1]);
+      remove_argument(N, argc, argv);
+      remove_argument(N, argc, argv);
+    } else {
+      fprintf (stderr, "error: usage is [-display/-d] DisplayName\n");
+      exit (0);
+    }
+  }
+  if ((N = get_argument (*argc, argv, "-display"))) {
+    if (N + 1 < *argc) {
+      strcpy (display_name, argv[N + 1]);
+      remove_argument(N, argc, argv);
+      remove_argument(N, argc, argv);
+    } else {
+      fprintf (stderr, "error: usage is [-display/-d] DisplayName\n");
+      exit (0);
+    }
+  }
+}
+
Index: /tags/kii-1-4/Ohana/src/kii/setup/CheckFontName.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/setup/CheckFontName.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/setup/CheckFontName.c	(revision 11911)
@@ -0,0 +1,29 @@
+# include "Ximage.h"
+
+/************** CheckFontName *************/
+void CheckFontName (int *argc, char **argv, char *fontname) {
+
+  int N;
+
+  if ((N = get_argument (*argc, argv, "-font"))) {
+    if (N + 1 < *argc) {
+      strcpy (fontname, argv[N + 1]);
+      remove_argument(N, argc, argv);
+      remove_argument(N, argc, argv);
+    } else {
+      fprintf (stderr, "error: usage is -font fontname\n");
+      exit (0);
+    }
+  }   
+  if ((N = get_argument (*argc, argv, "-fn"))) {
+    if (N + 1 < *argc) {
+      strcpy (fontname, argv[N + 1]);
+      remove_argument(N, argc, argv);
+      remove_argument(N, argc, argv);
+    } else {
+      fprintf (stderr, "error: usage is -fn fontname\n");
+      exit (0);
+    }
+  }   
+}
+
Index: /tags/kii-1-4/Ohana/src/kii/setup/CheckGeometry.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/setup/CheckGeometry.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/setup/CheckGeometry.c	(revision 11911)
@@ -0,0 +1,50 @@
+# include "Ximage.h"
+
+/************** CheckGeometry *************/
+void CheckGeometry (int *argc, char **argv, Graphic *graphic) {
+
+  int status, x, y, N;
+  unsigned int dx, dy;
+  int X, Y, dX, dY;
+  char *temp_name;
+  
+  temp_name = XGetDefault (graphic[0].display, argv[0], "geometry");
+  if ((N = get_argument (*argc, argv, "-geom"))) {
+    if (N + 1 < *argc) {
+      temp_name = argv[N+1];
+    }
+    else {
+      fprintf (stderr, "error: usage is -geom DisplayName\n");
+      exit (0);
+    }
+  }
+  X = 10;
+  Y = 10;
+  dX = 512 + 2*PAD1 + PAD1 + ZOOM_X;
+  dY = 512 + 2*PAD1 + PAD2 + COLORPAD;
+  if (temp_name != (char *)NULL) {  
+    status = XParseGeometry (temp_name, &x, &y, &dx, &dy);
+    if (status & XValue)
+      X = x;
+    if (status & YValue)
+      Y = y;
+    if (status & WidthValue) {
+      dX = dx + 2*PAD1 + PAD1 + ZOOM_X;
+      dX = MAX (dX, MIN_WIDTH);
+    }
+    if (status & HeightValue) {
+      dY = dy + 2*PAD1 + PAD2 + COLORPAD + 42;
+      dY = MAX (dY, MIN_HEIGHT);
+    }
+    if (status & XNegative)
+      X  = DisplayWidth  (graphic[0].display, graphic[0].screen) - dX + X;
+    if (status & YNegative)
+      Y  = DisplayHeight (graphic[0].display, graphic[0].screen) - dY + Y;
+  }
+
+  graphic[0].x = X;
+  graphic[0].y = Y;
+  graphic[0].dx = dX;
+  graphic[0].dy = dY; 
+  
+}
Index: /tags/kii-1-4/Ohana/src/kii/setup/CheckVisual.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/setup/CheckVisual.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/setup/CheckVisual.c	(revision 11911)
@@ -0,0 +1,196 @@
+# include "Ximage.h"
+# define NPIXELS 64
+
+/* DirectColor doesn't seem to work, even though it is available:
+   I cannot use XAllocColorCells to get pixels under DirectColor
+*/
+
+/* static int try_visual[] = {5, 3, 1, 4, 2, 0}; */
+
+void CheckVisual (Graphic *graphic, int *argc, char **argv) {
+
+  int i, Nfound, N;
+  int col, def, dyn;
+  XVisualInfo *visual_list, visual_temp;
+  unsigned long planes[3];
+  XPixmapFormatValues *pixmaps;
+  int Npixmaps;
+
+  if (DEBUG) {
+    fprintf (stderr, "DirectColor: %d\n", DirectColor);
+    fprintf (stderr, "PseudoColor: %d\n", PseudoColor);
+    fprintf (stderr, "TrueColor: %d\n", TrueColor);
+    fprintf (stderr, "GrayScale: %d\n", GrayScale);
+    fprintf (stderr, "StaticColor: %d\n", StaticColor);
+    fprintf (stderr, "StaticGray: %d\n", StaticGray);
+  }
+
+  visual_temp.screen = graphic[0].screen;
+  
+  /* find available visuals */
+  visual_list = XGetVisualInfo (graphic[0].display, VisualScreenMask, &visual_temp, &Nfound);
+  if (Nfound == 0) {
+    fprintf (stderr, "error finding useful visual\n");
+    exit (0);
+  }
+  
+  /* check default visual first */ 
+  for (i = 0; (i < Nfound) && (graphic[0].visual != visual_list[i].visual); i++);
+  if (i == Nfound) {
+    fprintf (stderr, "default visual not found??\n");
+    exit (0);
+  }
+
+  col = def = dyn = FALSE;
+  if (DEBUG) fprintf (stderr, "default visual class is %d\n", visual_list[i].class);
+  switch (visual_list[i].class) {
+  case PseudoColor:
+    col = def = dyn = TRUE;
+    graphic[0].visual = visual_list[i].visual;
+    graphic[0].visualclass = TRUE;
+    goto test_pixels;
+    break;
+  default:
+    break;
+  }
+
+  for (i = 0; i < Nfound; i++) {
+    switch (visual_list[i].class) {
+    case PseudoColor:
+      if (DEBUG) fprintf (stderr, "selected visual class is %d\n", visual_list[i].class);
+      col = dyn = TRUE;
+      if (graphic[0].visual == visual_list[i].visual) {
+	def = TRUE;
+      } else {
+	graphic[0].visual = visual_list[i].visual;
+      }
+      graphic[0].visualclass = TRUE;
+      goto test_pixels;
+      break;
+    default:
+      break;
+    }
+  }
+
+  for (i = 0; i < Nfound; i++) {
+    switch (visual_list[i].class) {
+    case GrayScale:
+      if (DEBUG) fprintf (stderr, "selected visual class is %d\n", visual_list[i].class);
+      dyn = TRUE;
+      if (graphic[0].visual == visual_list[i].visual) {
+	def = TRUE;
+      } else {
+	graphic[0].visual = visual_list[i].visual;
+      }
+      graphic[0].visualclass = TRUE;
+      goto test_pixels;
+      break;
+    default:
+      break;
+    }
+  }
+
+  for (i = 0; (i < Nfound) && (visual_list[i].class != TrueColor); i++);
+  if (i != Nfound) {
+    col = TRUE;
+    if (DEBUG) fprintf (stderr, "visual class is %d\n", visual_list[i].class);
+    if (graphic[0].visual == visual_list[i].visual) {
+      def = TRUE;
+    } else {
+      graphic[0].visual = visual_list[i].visual;
+    }
+    graphic[0].visualclass = FALSE;
+    goto test_pixels;
+  }
+
+  for (i = 0; (i < Nfound) && (visual_list[i].class != StaticColor); i++);
+  if (i != Nfound) {
+    if (DEBUG) fprintf (stderr, "visual class is %d\n", visual_list[i].class);
+    if (graphic[0].visual == visual_list[i].visual) {
+      def = TRUE;
+    } else {
+      graphic[0].visual = visual_list[i].visual;
+    }
+    graphic[0].visualclass = FALSE;
+    goto test_pixels;
+  }
+
+  for (i = 0; (i < Nfound) && (visual_list[i].class != StaticGray); i++);
+  if (i != Nfound) {
+    if (DEBUG) fprintf (stderr, "visual class is %d\n", visual_list[i].class);
+    if (graphic[0].visual == visual_list[i].visual) {
+      def = TRUE;
+    } else {
+      graphic[0].visual = visual_list[i].visual;
+    }
+    graphic[0].visualclass = FALSE;
+    goto test_pixels;
+  }
+
+  test_pixels:
+
+  /* need to make a colormap if 
+     1) the selected visual is not the default 
+     2) there are not enough colors available */
+
+  /* NEED TO ADD A COUPLE LINES DEFINING THE VARIOUS HARD COLORS (BLACK, WHITE, AND THE OVERLAYS) */
+
+  if ((N = get_argument (*argc, argv, "-private"))) {
+    remove_argument(N, argc, argv);
+    def = FALSE;
+  } 
+
+  if (!def) {
+    if (DEBUG) fprintf (stderr, "allocated private colormap\n");
+    graphic[0].colormap = XCreateColormap (graphic[0].display, RootWindow (graphic[0].display, graphic[0].screen), graphic[0].visual, AllocNone);
+  }
+
+  if (dyn) {
+    /* allocate color cells  */
+    for (graphic[0].Npixels = NPIXELS;
+	 ((graphic[0].Npixels >= 16) && 
+	  !XAllocColorCells (graphic[0].display, graphic[0].colormap, FALSE, planes, 1, graphic[0].pixels, graphic[0].Npixels));
+	 graphic[0].Npixels -= 4) {
+      if (DEBUG) fprintf (stderr, "trying %d colors\n", (int) graphic[0].Npixels);
+    }
+
+
+    /* make private colormap  */
+    if (graphic[0].Npixels < 16) {
+      fprintf (stderr, "can't allocate enough cells, using private colormap\n");
+      graphic[0].colormap = XCreateColormap (graphic[0].display, RootWindow (graphic[0].display, graphic[0].screen), graphic[0].visual, AllocNone);
+      for (graphic[0].Npixels = NPIXELS;
+	   ((graphic[0].Npixels >= 16) && 
+	    !XAllocColorCells (graphic[0].display, graphic[0].colormap, FALSE, planes, 1, graphic[0].pixels, graphic[0].Npixels));
+	   graphic[0].Npixels -= 4);
+
+      if ((N = get_argument (*argc, argv, "-colorcount"))) {
+	fprintf (stderr, "kii can grab %d colors\n", (int) graphic[0].Npixels);
+	exit (0);
+      } 
+      if (graphic[0].Npixels < 16) {
+	fprintf (stderr, "can't even allocate enough cells in private colormap\n");
+	exit (0);
+      }
+    }
+  }
+
+  if (!dyn) {
+    graphic[0].Npixels = 256;
+    fprintf (stderr, "can't use dynamic colors, color scrollbar inactive\n");
+    fprintf (stderr, " this can be avoided by using a dynamic visual class\n");
+    fprintf (stderr, " (see Kii help page for details)\n");
+  }
+
+  if ((N = get_argument (*argc, argv, "-colorcount"))) {
+    fprintf (stderr, "kii can grab %d colors\n", (int) graphic[0].Npixels);
+    exit (0);
+  } 
+  
+  pixmaps = XListPixmapFormats (graphic[0].display, &Npixmaps);
+  for (i = 0; i < Npixmaps; i++) {
+    if (pixmaps[i].depth == graphic[0].depth) {
+      graphic[0].Nbits = pixmaps[i].bits_per_pixel;
+    }
+  }
+}
Index: /tags/kii-1-4/Ohana/src/kii/setup/CloseDisplay.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/setup/CloseDisplay.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/setup/CloseDisplay.c	(revision 11911)
@@ -0,0 +1,15 @@
+# include "Ximage.h"
+
+/************** CloseDisplay *************/
+void CloseDisplay (Graphic *graphic) {
+
+  XFlush (graphic[0].display);
+  XFreeFont (graphic[0].display, graphic[0].font); 
+  XFreeGC (graphic[0].display, graphic[0].gc);
+  XDestroySubwindows (graphic[0].display, graphic[0].window);
+  XDestroyWindow (graphic[0].display, graphic[0].window);
+  XFlush (graphic[0].display);
+  XCloseDisplay (graphic[0].display);
+  return;
+}
+
Index: /tags/kii-1-4/Ohana/src/kii/setup/CreateWindow.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/setup/CreateWindow.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/setup/CreateWindow.c	(revision 11911)
@@ -0,0 +1,33 @@
+# include "Ximage.h"
+
+/************** CreateWindow *************/
+void
+CreateWindow (graphic, parent, border, events)
+Graphic       graphic[];
+Window        parent;
+int           border;
+long          events;
+{
+
+  XSetWindowAttributes attributes;
+  unsigned long attribute_mask;
+
+  attributes.background_pixel = graphic[0].white;
+  attributes.border_pixel     = graphic[0].black;
+  attributes.event_mask       = events;
+  attributes.colormap         = graphic[0].colormap;
+  attribute_mask              = CWBackPixel | CWBorderPixel | CWEventMask | CWColormap;
+
+  graphic[0].window = XCreateWindow (graphic[0].display, parent, 
+				     graphic[0].x, graphic[0].y, 
+				     graphic[0].dx, graphic[0].dy, 
+				     border, graphic[0].depth,
+				     InputOutput, graphic[0].visual, 
+				     attribute_mask, &attributes);
+
+  if (graphic[0].window == (Window) None)
+    QuitX (graphic[0].display, "", "error: could not open window");
+
+  XSelectInput (graphic[0].display, graphic[0].window, events);
+}
+
Index: /tags/kii-1-4/Ohana/src/kii/setup/DefineLayout.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/setup/DefineLayout.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/setup/DefineLayout.c	(revision 11911)
@@ -0,0 +1,64 @@
+# 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 */
Index: /tags/kii-1-4/Ohana/src/kii/setup/DrawBitmap.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/setup/DrawBitmap.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/setup/DrawBitmap.c	(revision 11911)
@@ -0,0 +1,52 @@
+# include "Ximage.h"
+
+void
+DrawBitmap (graphic, x, y, dx, dy, bitmap, mode)
+Graphic     graphic[];
+int         x, y, dx, dy;
+char        bitmap[];
+int         mode;
+{
+
+  int i, j, byte_line, byte, bit, flag;
+  unsigned long int black, white;
+
+  black = graphic[0].black;
+  white = graphic[0].white;
+
+  if (mode == 0) {
+    black = graphic[0].black;
+    white = graphic[0].white;
+    graphic[0].black = white;
+    graphic[0].white = white;
+  }
+    
+  if (mode == 2) {
+    black = graphic[0].black;
+    white = graphic[0].white;
+    graphic[0].black = white;
+    graphic[0].white = black;
+  }
+    
+  
+  byte_line = (int) ((dx + 7) / 8);
+  for (i = 0; i < dy; i++) {
+    for (j = 0; j < dx; j++) {
+      byte = byte_line * i + (j / 8);
+      bit = j % 8;
+      flag = 0x01 & (bitmap[byte] >> bit);
+      if (flag)
+	XSetForeground (graphic[0].display, graphic[0].gc, graphic[0].black);
+      else 
+	XSetForeground (graphic[0].display, graphic[0].gc, graphic[0].white);
+      XDrawPoint (graphic[0].display, graphic[0].window, 
+		  graphic[0].gc, x + j, y + i);
+    }
+  }
+  if (mode == 0) {
+    graphic[0].black = black;
+    graphic[0].white = white;
+  }
+  XSetForeground (graphic[0].display, graphic[0].gc, graphic[0].black);
+}
+
Index: /tags/kii-1-4/Ohana/src/kii/setup/GetColor.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/setup/GetColor.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/setup/GetColor.c	(revision 11911)
@@ -0,0 +1,25 @@
+# include "Ximage.h"
+
+/************** GetColor *************/
+unsigned long 
+GetColor (display, name, colormap, default_color)
+Display  *display;
+char      name[];
+Colormap  colormap;
+unsigned long default_color;
+{
+
+  unsigned long color;
+  XColor rgbcolor, hardwarecolor;
+  int status;
+
+  color = default_color;
+  status = XLookupColor (display, colormap, name, &rgbcolor, &hardwarecolor);
+  if (status) {
+    status = XAllocColor (display, colormap, &hardwarecolor);
+    if (status) {
+      color = hardwarecolor.pixel;
+    }
+  }
+  return (color);
+}
Index: /tags/kii-1-4/Ohana/src/kii/setup/LoadFont.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/setup/LoadFont.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/setup/LoadFont.c	(revision 11911)
@@ -0,0 +1,31 @@
+# include "Ximage.h"
+
+/************** LoadFont *************/
+void
+LoadFont (graphic, argc, argv, default_name)
+Graphic   graphic[];
+int      *argc;
+char     *argv[];
+char      default_name[];
+{
+
+  char name[400];
+
+  strcpy (name, default_name);
+  CheckFontName (argc, argv, name);
+  graphic[0].font = XLoadQueryFont (graphic[0].display, name);
+  if (graphic[0].font == (XFontStruct *) NULL) {
+    fprintf (stderr, "Could not load fond %s, using %s\n", name, default_name);
+    graphic[0].font = XLoadQueryFont (graphic[0].display, default_name);
+    if (graphic[0].font == (XFontStruct *) NULL) {
+      graphic[0].font = XLoadQueryFont (graphic[0].display, "fixed");
+      fprintf (stderr, "Could not load fond %s, using %s\n", 
+	       default_name, "fixed");
+    }
+  }
+  if (graphic[0].font != (XFontStruct *) NULL) 
+    XSetFont (graphic[0].display, graphic[0].gc, graphic[0].font[0].fid);
+  else
+    QuitX (graphic[0].display, "Error: could not load font", name);
+}
+
Index: /tags/kii-1-4/Ohana/src/kii/setup/MakeColormap.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/setup/MakeColormap.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/setup/MakeColormap.c	(revision 11911)
@@ -0,0 +1,54 @@
+# include "Ximage.h"
+# define NPIXELS 64
+
+static char default_cmap[] = "grayscale";
+
+void MakeColormap (Graphic *graphic, Layout *layout, int argc, char **argv) {
+
+  int i, N, status;
+  char *temp_name;
+
+  /* hardwired colors - white, black -- for drawing text and overlay graphics */
+  layout[0].white = graphic[0].white;
+  layout[0].black = graphic[0].black;
+  layout[0].start = 0;
+  layout[0].slope = 1;
+  temp_name = XGetDefault (graphic[0].display, argv[0], "ROverlay");
+  layout[0].overlay[0].color = GetColor (graphic[0].display, (temp_name == (char *) NULL ? "red"    : temp_name), graphic[0].colormap, graphic[0].black);
+  temp_name = XGetDefault (graphic[0].display, argv[0], "GOverlay");
+  layout[0].overlay[1].color = GetColor (graphic[0].display, (temp_name == (char *) NULL ? "green"  : temp_name), graphic[0].colormap, graphic[0].black);
+  temp_name = XGetDefault (graphic[0].display, argv[0], "BOverlay");
+  layout[0].overlay[2].color = GetColor (graphic[0].display, (temp_name == (char *) NULL ? "blue"   : temp_name), graphic[0].colormap, graphic[0].black);
+  temp_name = XGetDefault (graphic[0].display, argv[0], "YOverlay");
+  layout[0].overlay[3].color = GetColor (graphic[0].display, (temp_name == (char *) NULL ? "yellow" : temp_name), graphic[0].colormap, graphic[0].black);
+
+  layout[0].Npixels = graphic[0].Npixels;
+  for (i = 0; i < layout[0].Npixels; i++) 
+    layout[0].cmap[i].pixel = graphic[0].pixels[i];
+
+  /* decide on a color map */
+  temp_name = XGetDefault (graphic[0].display, argv[0], "Colormap");
+  if ((N = get_argument (argc, argv, "-cm"))) {
+    if (N + 1 < argc) {
+      temp_name = argv[N+1];
+    } else {
+      fprintf (stderr, "error: usage is -cm ColormapName\n");
+      exit (1);
+    }
+  }
+  if (temp_name == (char *) NULL) temp_name = default_cmap;
+
+  status = SetColormap (graphic, layout, temp_name);
+  if (!status) {
+    fprintf (stderr, "invalid colormap, using default %s\n", default_cmap);
+    temp_name = default_cmap;
+    status = SetColormap (graphic, layout, temp_name);
+    if (!status) {
+      fprintf (stderr, "problem with default colormap\n");
+      exit (1);
+    }
+  }
+}
+
+/* this routine is NOT independent of the number of overlays */
+
Index: /tags/kii-1-4/Ohana/src/kii/setup/MakeCursor.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/setup/MakeCursor.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/setup/MakeCursor.c	(revision 11911)
@@ -0,0 +1,16 @@
+# include "Ximage.h"
+
+/************** MakeCursor *************/
+void
+MakeCursor  (graphic, which_cursor)
+Graphic      graphic[];
+unsigned int which_cursor;
+{
+
+  graphic[0].cursor = XCreateFontCursor (graphic[0].display, 
+					 (unsigned) which_cursor);
+  if (graphic[0].cursor != (Cursor) None)
+    XDefineCursor (graphic[0].display, graphic[0].window, graphic[0].cursor);
+}
+
+
Index: /tags/kii-1-4/Ohana/src/kii/setup/MakeGC.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/setup/MakeGC.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/setup/MakeGC.c	(revision 11911)
@@ -0,0 +1,15 @@
+# include "Ximage.h"
+
+/************** MakeGC *************/
+void MakeGC (Graphic *graphic) {
+
+  XGCValues gcvalues;
+
+  gcvalues.foreground = graphic[0].black;
+  gcvalues.background = graphic[0].white;
+  graphic[0].gc = XCreateGC (graphic[0].display, graphic[0].window, 
+			     GCForeground | GCBackground, &gcvalues);
+  if (graphic[0].gc == 0)
+    QuitX (graphic[0].display, "Error in creating a Graphics Context", "");
+}
+
Index: /tags/kii-1-4/Ohana/src/kii/setup/MapWindow.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/setup/MapWindow.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/setup/MapWindow.c	(revision 11911)
@@ -0,0 +1,13 @@
+# include "Ximage.h"
+
+/************** MapWindow *************/
+void
+MapWindow (graphic)
+Graphic    graphic[];
+{
+
+  XMapRaised (graphic[0].display, graphic[0].window);
+  XMapSubwindows (graphic[0].display, graphic[0].window);
+  XFlush (graphic[0].display);
+}
+
Index: /tags/kii-1-4/Ohana/src/kii/setup/NameWindow.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/setup/NameWindow.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/setup/NameWindow.c	(revision 11911)
@@ -0,0 +1,23 @@
+# include "Ximage.h"
+
+/************** NameWindow *************/
+void NameWindow (Graphic *graphic, char *name) {
+
+  char       *class_name;
+  char       *class_type;
+  XClassHint *classhints;
+
+  class_type = class_name = name;
+
+  classhints = XAllocClassHint ();
+
+  if (classhints != (XClassHint *) NULL)  {
+    classhints[0].res_name = class_name;
+    classhints[0].res_class = class_type;
+    XSetClassHint (graphic[0].display, graphic[0].window, classhints);
+    XFree (classhints);
+  }
+  
+  XStoreName (graphic[0].display, graphic[0].window, name);
+  XSetIconName (graphic[0].display, graphic[0].window, name);
+}
Index: /tags/kii-1-4/Ohana/src/kii/setup/OpenDisplay.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/setup/OpenDisplay.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/setup/OpenDisplay.c	(revision 11911)
@@ -0,0 +1,19 @@
+# include "Ximage.h"
+
+/************** OpenDisplay *************/
+Display *OpenDisplay (char *display_name, int *screen) {
+
+  Display *display;
+  
+  display = XOpenDisplay (display_name);
+  if (display != (Display *) NULL)
+    *screen = DefaultScreen (display);
+  if (display == (Display *) NULL) {
+    fprintf (stderr, "Error could not open X display to %s\n", 
+	     XDisplayName (display_name));
+    exit (0);
+  }
+
+  return (display);
+}
+
Index: /tags/kii-1-4/Ohana/src/kii/setup/QuitX.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/setup/QuitX.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/setup/QuitX.c	(revision 11911)
@@ -0,0 +1,15 @@
+# include "Ximage.h"
+
+/************** QuitX *************/
+void
+QuitX (display, error_message, error_file)
+Display *display;
+char error_message[], error_file[];
+{
+
+  fprintf (stderr, "Error: %s%s\n", error_message, error_file);
+  XCloseDisplay (display);
+  exit (0);
+}
+
+
Index: /tags/kii-1-4/Ohana/src/kii/setup/SetNormalHints.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/setup/SetNormalHints.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/setup/SetNormalHints.c	(revision 11911)
@@ -0,0 +1,30 @@
+# include "Ximage.h"
+
+/************** SetNormalHints  *************/
+void
+SetNormalHints (graphic)
+Graphic         graphic[];
+{
+
+  XSizeHints *sizehints;
+
+  sizehints = XAllocSizeHints ();
+
+  if (sizehints != (XSizeHints *) NULL)  {
+    sizehints[0].x = graphic[0].x;
+    sizehints[0].y = graphic[0].x;
+    sizehints[0].width = graphic[0].dx;
+    sizehints[0].height = graphic[0].dy;
+    sizehints[0].min_width = MIN_WIDTH;
+    sizehints[0].min_height = MIN_HEIGHT;    
+    sizehints[0].flags = USPosition | USSize | PMinSize;
+
+    sizehints[0].base_width = graphic[0].dx;
+    sizehints[0].base_height = graphic[0].dy;
+    sizehints[0].flags |= PBaseSize;
+    
+    XSetWMNormalHints (graphic[0].display, graphic[0].window, sizehints);
+    XFree (sizehints);
+  }
+}
+
Index: /tags/kii-1-4/Ohana/src/kii/setup/SetUpDisplay.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/setup/SetUpDisplay.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/setup/SetUpDisplay.c	(revision 11911)
@@ -0,0 +1,20 @@
+# include "Ximage.h"
+
+/************** SetUpDisplay *************/
+void SetUpDisplay (Graphic *graphic, int *argc, char **argv) {
+
+  char display_name[120];
+
+  CheckDisplayName (argc, argv, display_name); 
+
+  /* set default values */
+  graphic[0].display  = OpenDisplay (display_name, &graphic[0].screen);
+  graphic[0].colormap = DefaultColormap (graphic[0].display, graphic[0].screen);
+  graphic[0].depth    = DefaultDepth    (graphic[0].display, graphic[0].screen);
+  graphic[0].visual   = DefaultVisual   (graphic[0].display, graphic[0].screen);
+
+  /* get the basic colors */
+  CheckVisual (graphic, argc, argv);
+  CheckColors (graphic, argc, argv);
+}
+
Index: /tags/kii-1-4/Ohana/src/kii/setup/SetUpWindow.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/setup/SetUpWindow.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/setup/SetUpWindow.c	(revision 11911)
@@ -0,0 +1,34 @@
+# include "Ximage.h"
+# include "icons/icon.h"
+
+/************** SetUpWindow *************/
+void SetUpWindow (Graphic *graphic, int *argc, char **argv) {
+
+  Icon icon;
+  char *name;
+
+  icon.width = icon_width;
+  icon.height = icon_height;
+  icon.bits = icon_bits;
+
+  CheckGeometry (argc, argv, graphic);
+  TopWindow (graphic, &icon);
+  LoadFont (graphic, argc, argv, "fixed"); 
+
+  XFlush (graphic[0].display);
+  XSetWindowBackground (graphic[0].display, graphic[0].window, graphic[0].white);
+
+  SetNormalHints (graphic);
+  SetWMHints (graphic, &icon);
+
+  if (NAME_WINDOW == NULL) {
+    NameWindow (graphic, "Ki'i");
+  } else {
+    ALLOCATE (name, char, strlen(NAME_WINDOW) + 10);
+    sprintf (name, "Ki'i %s", NAME_WINDOW);
+    NameWindow (graphic, name);
+    free (name);
+  }
+
+  if (MAP_WINDOW) MapWindow (graphic);
+}
Index: /tags/kii-1-4/Ohana/src/kii/setup/SetWMHints.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/setup/SetWMHints.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/setup/SetWMHints.c	(revision 11911)
@@ -0,0 +1,27 @@
+# include "Ximage.h"
+
+/************** SetWMHints  *************/
+void
+SetWMHints (graphic, icon) 
+Graphic     graphic[];
+Icon        icon[];
+{
+  XWMHints *wmhints;
+
+  wmhints = XAllocWMHints ();
+  if (wmhints != (XWMHints *)NULL) {
+    wmhints[0].initial_state = NormalState;
+    wmhints[0].input = True;
+    if (icon[0].pixmap != (Pixmap) None) {
+      wmhints[0].icon_pixmap = icon[0].pixmap;
+      wmhints[0].icon_mask = icon[0].pixmap;
+      wmhints[0].flags = StateHint | InputHint | IconPixmapHint | IconMaskHint;
+    }
+    else 
+      wmhints[0].flags = StateHint | InputHint;
+    
+    XSetWMHints (graphic[0].display, graphic[0].window, wmhints);
+    XFree (wmhints);
+  }
+}
+
Index: /tags/kii-1-4/Ohana/src/kii/setup/TopWindow.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/setup/TopWindow.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/setup/TopWindow.c	(revision 11911)
@@ -0,0 +1,21 @@
+# include "Ximage.h"
+
+/************** TopWindow *************/
+void TopWindow (Graphic *graphic, Icon *icon) {
+
+  Window rootwindow;
+
+  rootwindow = RootWindow (graphic[0].display, graphic[0].screen);
+
+  CreateWindow (graphic, rootwindow, BORDER_WIDTH, EVENT_MASK);
+  MakeGC (graphic);
+  icon[0].pixmap = XCreateBitmapFromData (graphic[0].display,
+					graphic[0].window, 
+					icon[0].bits, 
+					icon[0].width, 
+					icon[0].height);
+  MakeCursor (graphic, DEFAULT_CURSOR);
+  XFreeCursor (graphic[0].display, graphic[0].cursor);
+  XFlush (graphic[0].display);
+}
+
Index: /tags/kii-1-4/Ohana/src/kii/setup/Ximage.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/setup/Ximage.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/setup/Ximage.c	(revision 11911)
@@ -0,0 +1,29 @@
+# include "Ximage.h"
+
+int main (int argc, char **argv) {
+
+  Graphic graphic;
+  Layout  layout;
+  
+  args (&argc, argv);
+
+  bzero (&graphic, sizeof(Graphic));
+  bzero (&layout, sizeof(Layout));
+
+  if (USE_XWINDOW) SetUpDisplay (&graphic, &argc, argv);
+  if (USE_XWINDOW) {
+    SetUpWindow (&graphic, &argc, argv);
+  } else {
+    graphic.x = 10;
+    graphic.y = 10;
+    graphic.dx = 512 + 2*PAD1 + PAD1 + ZOOM_X;
+    graphic.dy = 512 + 2*PAD1 + PAD2 + COLORPAD;
+  }
+
+  DefineLayout (&layout, &graphic, argc, argv);
+  EventLoop (&graphic, &layout);
+
+  if (USE_XWINDOW) CloseDisplay (&graphic);
+  exit (0);
+}
+
Index: /tags/kii-1-4/Ohana/src/kii/setup/args.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/setup/args.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/setup/args.c	(revision 11911)
@@ -0,0 +1,39 @@
+# include "Ximage.h"
+
+int args (int *argc, char **argv) {
+
+  int N;
+
+  MAP_WINDOW = TRUE;
+  if ((N = get_argument (*argc, argv, "-nomap"))) {
+    remove_argument(N, argc, argv);
+    MAP_WINDOW = FALSE;
+  }
+
+  NAME_WINDOW = NULL;
+  if ((N = get_argument (*argc, argv, "-name"))) {
+    remove_argument(N, argc, argv);
+    NAME_WINDOW = strcreate (argv[N]);
+    remove_argument(N, argc, argv);
+  }
+
+  USE_XWINDOW = TRUE;
+  if ((N = get_argument (*argc, argv, "-noX"))) {
+    remove_argument(N, argc, argv);
+    USE_XWINDOW = FALSE;
+  }
+
+  DEBUG = FALSE;
+  if ((N = get_argument (*argc, argv, "-debug"))) {
+    remove_argument(N, argc, argv);
+    DEBUG = TRUE;
+  }
+
+  FOREGROUND = FALSE;
+  if ((N = get_argument (*argc, argv, "-fg"))) {
+    remove_argument(N, argc, argv);
+    FOREGROUND = TRUE;
+  }
+
+  return (TRUE);
+}
Index: /tags/kii-1-4/Ohana/src/kii/textline/CheckTextLines.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/textline/CheckTextLines.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/textline/CheckTextLines.c	(revision 11911)
@@ -0,0 +1,28 @@
+# include "Ximage.h"
+
+/******** Here we test the TextLines specific to this program  ****
+TextLine *
+CheckTextLines (graphic, event, layout)
+Graphic         graphic[];
+XEvent          event[];
+Layout          layout[];
+{
+
+  TextLine *textline;
+  textline = (TextLine *) NULL;
+
+  if (InTextLine (graphic, event, &layout[0].zero))
+    textline = &layout[0].zero;
+  if (InTextLine (graphic, event, &layout[0].range))
+    textline = &layout[0].range;
+  if (InTextLine (graphic, event, &layout[0].effects))
+    textline = &layout[0].effects;
+  if (InTextLine (graphic, event, &layout[0].command))
+    textline = &layout[0].command;
+
+  return (textline);
+
+}
+
+
+***/
Index: /tags/kii-1-4/Ohana/src/kii/textline/DrawCursor.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/textline/DrawCursor.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/textline/DrawCursor.c	(revision 11911)
@@ -0,0 +1,45 @@
+# include "Ximage.h"
+# define XBorder 5
+# define YBorder 2
+
+
+
+DrawCursor (graphic, textline)    
+Graphic       graphic[];
+TextLine      textline[];
+{
+
+  int dx, label_width, DX, text_width, i;
+
+  label_width  = XTextWidth (graphic[0].font, 
+			     textline[0].label,
+			     strlen(textline[0].label));
+  
+  text_width  = XTextWidth (graphic[0].font, 
+			    textline[0].text,
+			    strlen(textline[0].text));
+
+  XSetForeground (graphic[0].display, graphic[0].gc, graphic[0].black);
+
+  if (label_width + text_width + 2*XBorder > textline[0].dx) {
+    DX = textline[0].dx - label_width - 2*XBorder - arrow_width;
+    for (i = 1; (i < strlen (textline[0].text)) && (text_width > DX); i++) {
+      text_width  = XTextWidth (graphic[0].font, 
+				&textline[0].text[i],
+				strlen(&textline[0].text[i]));
+    }
+    dx  = XTextWidth (graphic[0].font, &textline[0].text[i - 1], 
+		      textline[0].cursor - i + 1) + arrow_width;
+  }
+  else 
+    dx  = XTextWidth (graphic[0].font, textline[0].text, textline[0].cursor);
+
+  XDrawLine (graphic[0].display, 
+	     graphic[0].window, 
+	     graphic[0].gc, 
+	     textline[0].x + label_width + XBorder + dx, 
+	     textline[0].y + YBorder,
+	     textline[0].x + label_width + XBorder + dx, 
+	     textline[0].y + textline[0].dy - YBorder);
+
+}
Index: /tags/kii-1-4/Ohana/src/kii/textline/DrawTextBox.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/textline/DrawTextBox.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/textline/DrawTextBox.c	(revision 11911)
@@ -0,0 +1,63 @@
+# include "Ximage.h"
+# define XBorder 10
+# define YBorder 2
+# define arrow_width 6
+# define arrow_height 9
+static char arrow_bits[] = {
+  0x00, 0x02, 0x06, 0x0e, 0x1e, 0x0e, 0x06, 0x02, 0x00};
+#define down_width 9
+#define down_height 6
+static char down_bits[] = {
+   0x00, 0x00, 0xfe, 0x00, 0x7c, 0x00, 0x38, 0x00, 0x10, 0x00, 0x00, 0x00};
+
+/******************* DrawTextBox ****************/
+DrawTextBox (graphic, textbox)
+Graphic      graphic[];
+TextBox      textbox[];
+{
+
+  int X, Y, y, dy, Nlines, i;
+
+  XSetForeground (graphic[0].display, graphic[0].gc, graphic[0].white);
+  XFillRectangle (graphic[0].display, 
+		  graphic[0].window,
+		  graphic[0].gc,
+		  textbox[0].x  + 1,  textbox[0].y + 1,
+		  XBorder - 2, textbox[0].dy - 2);
+  XSetForeground (graphic[0].display, graphic[0].gc, graphic[0].black);
+  if (textbox[0].outline) {
+    XDrawRectangle (graphic[0].display, 
+		    graphic[0].window,
+		    graphic[0].gc,
+		    textbox[0].x,  textbox[0].y,
+		    textbox[0].dx, textbox[0].dy);
+  }
+
+  dy = graphic[0].font[0].ascent + graphic[0].font[0].descent;
+  Nlines = (textbox[0].dy - 2*YBorder) / dy;
+
+  for (i = 0; (i < Nlines) && (i < textbox[0].Nlines); i++) {
+    y = textbox[0].y + graphic[0].font[0].ascent + dy*i + YBorder;
+    XDrawString (graphic[0].display, 
+		 graphic[0].window, 
+		 graphic[0].gc, 
+		 textbox[0].x + XBorder, y,
+		 textbox[0].text[i], 
+		 strlen(textbox[0].text[i]));
+  }
+
+  if (Nlines < textbox[0].Nlines) {
+    DrawBitmap (graphic, 
+		textbox[0].x + textbox[0].dx - down_width - 2,
+		textbox[0].y + textbox[0].dy - down_height - 2,
+		down_width, down_height, down_bits, 1);
+  }
+
+  XSetForeground (graphic[0].display, graphic[0].gc, graphic[0].black);
+  if (textbox[0].cursor_line != -1) {
+    Y = textbox[0].y + dy*textbox[0].cursor_line + YBorder + (dy - arrow_height)/2;
+    X = textbox[0].x + (XBorder - arrow_width) / 2;
+    DrawBitmap (graphic, X, Y, arrow_width, arrow_height, arrow_bits, 1);
+  }
+}
+
Index: /tags/kii-1-4/Ohana/src/kii/textline/DrawTextLine.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/textline/DrawTextLine.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/textline/DrawTextLine.c	(revision 11911)
@@ -0,0 +1,34 @@
+# include "Ximage.h"
+# define XBorder 5
+# define YBorder 2
+
+DrawTextLine (graphic, textline)
+Graphic  graphic[];
+TextLine textline[];
+{
+
+  int y;
+
+  XSetForeground (graphic[0].display, graphic[0].gc, graphic[0].black);
+  if (textline[0].outline) {
+    XDrawRectangle (graphic[0].display, 
+		    graphic[0].window,
+		    graphic[0].gc,
+		    textline[0].x,  textline[0].y,
+		    textline[0].dx, textline[0].dy);
+  }
+
+  y = textline[0].y + (textline[0].dy + graphic[0].font[0].ascent) / 2;
+  XDrawString (graphic[0].display, 
+	       graphic[0].window, 
+	       graphic[0].gc, 
+	       textline[0].x + XBorder, y,
+	       textline[0].label, 
+	       strlen(textline[0].label));
+  RedrawString (graphic, textline);
+
+  if (textline[0].cursor != -1)
+    DrawCursor (graphic, textline);
+
+}
+
Index: /tags/kii-1-4/Ohana/src/kii/textline/InTextBox.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/textline/InTextBox.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/textline/InTextBox.c	(revision 11911)
@@ -0,0 +1,57 @@
+# include "Ximage.h"
+# define XBorder 10
+# define YBorder 2
+# define arrow_width 6
+# define arrow_height 9
+static char arrow_bits[] = {
+  0x00, 0x02, 0x06, 0x0e, 0x1e, 0x0e, 0x06, 0x02, 0x00};
+#define down_width 9
+#define down_height 6
+static char down_bits[] = {
+   0x00, 0x00, 0xfe, 0x00, 0x7c, 0x00, 0x38, 0x00, 0x10, 0x00, 0x00, 0x00};
+
+/******************* InTextBox ****************/
+int
+InTextBox (graphic, event, textbox)
+Graphic          graphic[];
+XButtonEvent    *event;
+TextBox          textbox[];
+{
+
+  int answer;
+  int i, x, y, Y, X, dy;
+  int minX, maxX, minY, maxY;
+  
+  x = event[0].x;
+  y = event[0].y;
+  dy = graphic[0].font[0].ascent + graphic[0].font[0].descent;
+  
+  minX = textbox[0].x;
+  maxX = textbox[0].x + textbox[0].dx;
+  minY = textbox[0].y;
+  maxY = textbox[0].y + textbox[0].dy;
+  if (dy*textbox[0].Nlines + 2*YBorder < textbox[0].dy)
+    maxY = textbox[0].y + dy*textbox[0].Nlines + 2*YBorder;
+
+  answer = ((x >= minX) && (x <= maxX) && (y >= minY) && (y <= maxY));
+  
+  /* find the cursor position, erase the old arrow and draw a new arrow */
+  if (answer) {
+    if (textbox[0].cursor_line != -1) {
+      Y = textbox[0].y + dy*textbox[0].cursor_line + YBorder + (dy - arrow_height)/2;
+      X = textbox[0].x + (XBorder - arrow_width) / 2;
+      DrawBitmap (graphic, X, Y, arrow_width, arrow_height, arrow_bits, 0);
+    }
+    textbox[0].cursor_line = (y - textbox[0].y - YBorder)/dy;
+    X = textbox[0].x + (XBorder - arrow_width) / 2;
+    Y = textbox[0].y + dy*textbox[0].cursor_line + YBorder + (dy - arrow_height)/2;
+    DrawBitmap (graphic, X, Y, arrow_width, arrow_height, arrow_bits, 1);
+    textbox[0].cursor_x = x;
+    textbox[0].cursor_y = y;
+    XFlush (graphic[0].display);
+  }
+  
+  return (answer);
+  
+}
+
Index: /tags/kii-1-4/Ohana/src/kii/textline/InTextLine.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/textline/InTextLine.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/textline/InTextLine.c	(revision 11911)
@@ -0,0 +1,58 @@
+# include "Ximage.h"
+# define XBorder 5
+# define YBorder 2
+
+int
+InTextLine (graphic, event, textline)
+Graphic          graphic[];
+XButtonEvent    *event;
+TextLine         textline[];
+{
+
+  int answer, done;
+  int i, x, dx, y, text_width, label_width;
+  int minX, maxX, minY, maxY;
+  char testline[1000];
+
+  x = event[0].x;
+  y = event[0].y;
+  
+  label_width  = XTextWidth (graphic[0].font, 
+			     textline[0].label,
+			     strlen(textline[0].label));
+  
+  minX = textline[0].x + XBorder + label_width;
+  maxX = textline[0].x + textline[0].dx;
+  minY = textline[0].y;
+  maxY = textline[0].y + textline[0].dy;
+
+  answer = ((x >= minX) && (x <= maxX) && (y >= minY) && (y <= maxY));
+
+  /* find the cursor position and draw a vertical bar */
+  if (answer) {
+    text_width  = XTextWidth (graphic[0].font, 
+			      textline[0].text,
+			      strlen(textline[0].text));
+    
+    if (x >= minX + text_width) {
+      textline[0].cursor = strlen (textline[0].text);
+    }
+    else {
+      for (i = 1, done = FALSE; (i <= strlen (textline[0].text)) && !done; i++) {
+	dx  = XTextWidth (graphic[0].font, 
+			  textline[0].text, i);
+	if (x < minX + dx) {
+	  textline[0].cursor = i - 1;
+	  done = TRUE;
+	}
+      }
+    }
+    DrawCursor (graphic, textline);
+  }    
+  XFlush (graphic[0].display);
+  
+  return (answer);
+  
+}
+
+
Index: /tags/kii-1-4/Ohana/src/kii/textline/RedrawString.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/textline/RedrawString.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/textline/RedrawString.c	(revision 11911)
@@ -0,0 +1,73 @@
+# include "Ximage.h"
+# define XBorder 5
+# define YBorder 2
+
+
+#define arrow_width 6
+#define arrow_height 9
+RedrawString (graphic, textline)
+Graphic       graphic[];
+TextLine      textline[];
+{
+
+  int label_width, text_width, y, i, DX;
+  static char arrow_bits[] = {
+    0x00, 0x10, 0x18, 0x1c, 0x1e, 0x1c, 0x18, 0x10, 0x00};
+  
+  label_width  = XTextWidth (graphic[0].font, 
+			     textline[0].label,
+			     strlen(textline[0].label));
+  
+  text_width  = XTextWidth (graphic[0].font, 
+			    textline[0].text,
+			    strlen(textline[0].text));
+
+  if (label_width + text_width + 2*XBorder > textline[0].dx) {
+    XSetForeground (graphic[0].display, graphic[0].gc, graphic[0].white);
+    XFillRectangle (graphic[0].display, graphic[0].window, graphic[0].gc, 
+		    textline[0].x + XBorder + label_width, 
+		    textline[0].y + YBorder, 
+		    textline[0].dx - XBorder - label_width, 
+		    textline[0].dy - 2*YBorder + 1);
+    
+    DX = textline[0].dx - label_width - 2*XBorder - arrow_width;
+    for (i = 1; (i < strlen (textline[0].text)) && (text_width > DX); i++) {
+      text_width  = XTextWidth (graphic[0].font, 
+				&textline[0].text[i],
+				strlen(&textline[0].text[i]));
+    }
+
+    y = textline[0].y + (textline[0].dy + graphic[0].font[0].ascent) / 2;
+    XSetForeground (graphic[0].display, graphic[0].gc, graphic[0].black);
+    DrawBitmap (graphic, 
+		textline[0].x + XBorder + label_width,
+		textline[0].y + YBorder + (textline[0].dy - arrow_height)/2,
+		arrow_width, arrow_height, arrow_bits, 1);
+    XDrawString (graphic[0].display, 
+		 graphic[0].window, 
+		 graphic[0].gc, 
+		 textline[0].x + XBorder + label_width + arrow_width, y,
+		 &textline[0].text[i - 1], 
+		 strlen(&textline[0].text[i - 1]));
+    XFlush (graphic[0].display);
+  }
+  else {
+    XSetForeground (graphic[0].display, graphic[0].gc, graphic[0].white);
+    XFillRectangle (graphic[0].display, graphic[0].window, graphic[0].gc, 
+		    textline[0].x + XBorder + label_width, 
+		    textline[0].y + YBorder, 
+		    textline[0].dx - XBorder - label_width, 
+		    textline[0].dy - 2*YBorder + 1);
+    
+    y = textline[0].y + (textline[0].dy + graphic[0].font[0].ascent) / 2;
+    
+    XSetForeground (graphic[0].display, graphic[0].gc, graphic[0].black);
+    XDrawString (graphic[0].display, 
+		 graphic[0].window, 
+		 graphic[0].gc, 
+		 textline[0].x + XBorder + label_width, y,
+		 textline[0].text, 
+		 strlen(textline[0].text));
+  }
+
+}
Index: /tags/kii-1-4/Ohana/src/kii/textline/TextLineEntry.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/textline/TextLineEntry.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/textline/TextLineEntry.c	(revision 11911)
@@ -0,0 +1,81 @@
+# include "Ximage.h"
+# define XBorder 5
+# define YBorder 2
+
+int 
+TextLineEntry (graphic, textline, keyevent)
+Graphic        graphic[];
+TextLine       textline[];
+XKeyEvent     *keyevent;
+{
+
+  int i, status, N;
+  char dummy[3];
+  XComposeStatus compose_status;
+  KeySym keysym;
+
+  status = TRUE;
+  strcpy (textline[0].old_text, textline[0].text);
+  bzero (&textline[0].text[strlen(textline[0].text)], 
+	 1024 - strlen(textline[0].text));
+  i = textline[0].cursor;
+
+
+  N = XLookupString (keyevent, dummy, 1, &keysym, &compose_status);
+  switch (keysym) {
+  case XK_BackSpace:
+  case XK_Delete:
+    if (textline[0].cursor > 0) {
+      bcopy (&textline[0].text[i], &textline[0].text[i - 1], 
+	     strlen(&textline[0].text[i]) + 1);
+      RedrawString (graphic, textline);
+      textline[0].cursor --;
+      DrawCursor (graphic, textline);
+    }
+    break;
+  case XK_Left:
+    RedrawString (graphic, textline);
+    textline[0].cursor --;
+    if (textline[0].cursor < 0)
+      textline[0].cursor = 0;
+    DrawCursor (graphic, textline);
+    break;
+  case XK_Right:
+    RedrawString (graphic, textline);
+    textline[0].cursor ++;
+    if (textline[0].cursor > strlen (textline[0].text))
+      textline[0].cursor = strlen (textline[0].text);
+    DrawCursor (graphic, textline);
+    break;
+  case XK_Return:
+    RedrawString (graphic, textline);
+    textline[0].cursor = -1;
+    status = FALSE;
+    break;
+  case XK_d:
+  case XK_D: 
+    if (dummy[0] == 4) { /* a control-d was typed! */
+      if (textline[0].cursor < strlen(textline[0].text)) {
+	bcopy (&textline[0].text[i + 1], &textline[0].text[i], 
+	       strlen(&textline[0].text[i]));
+	RedrawString (graphic, textline);
+	DrawCursor (graphic, textline);
+      }
+      break;  /* WARNING: this case MUST come before default.
+		 anything between this and default will be executed
+		 if no cntl-d is typed! */
+    }
+  default:
+    if (N != 0) {
+      bcopy (&textline[0].text[i], &textline[0].text[i + 1], 
+	     strlen(&textline[0].text[i]));
+      textline[0].text[i] = dummy[0];
+      RedrawString (graphic, textline);
+      textline[0].cursor ++;
+      DrawCursor (graphic, textline);
+    }
+  }
+  return (status);
+}
+
+
Index: /tags/kii-1-4/Ohana/src/kii/zoom/CreateZoom.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/zoom/CreateZoom.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/zoom/CreateZoom.c	(revision 11911)
@@ -0,0 +1,26 @@
+# include "Ximage.h"
+# define XPIX(x,Rx,S) (x*S + Rx)
+# define ZPIX(value,Rz1,Rz2) (value*Rz1 - Rz2)
+# define FRAC(a) ((a) - (int)(a))
+
+void CreateZoom (Layout *layout, Graphic *graphic, double x, double y) {
+
+  switch (graphic[0].Nbits) {
+  case 8:
+    CreateZoom8 (layout, graphic, x, y);
+    break;
+
+  case 16:
+    CreateZoom16 (layout, graphic, x, y);
+    break;
+
+  case 24:
+    CreateZoom24 (layout, graphic, x, y);
+    break;
+
+  case 32:
+    CreateZoom32 (layout, graphic, x, y);
+    break;
+  }    
+
+}
Index: /tags/kii-1-4/Ohana/src/kii/zoom/CreateZoom.new
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/zoom/CreateZoom.new	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/zoom/CreateZoom.new	(revision 11911)
@@ -0,0 +1,112 @@
+# include "Ximage.h"
+# define XPIX(x,Rx,S) (x*S + Rx)
+
+void
+CreateZoom (layout, graphic, x, y)
+Layout layout[];
+Graphic graphic[];
+double x, y;
+{
+
+  int i, j, ii, jj, X, Y;
+  int zvalue;
+  double value, expand, zero, range, zoomscale;
+  double X0, Y0, Rx, Ry, Rz1, Rz2;
+  int expand_int, dx, dy, DX, DY, Npixels, yfac;
+  Visual *visual = CopyFromParent;
+  unsigned long pixel;
+
+
+  /* create a test pattern image to put in layout[0].picture */
+  if (layout[0].matrix.size == 0) {
+    REALLOCATE (layout[0].zoom.data, char, layout[0].zoom.dx*layout[0].zoom.dy);
+    bzero (layout[0].zoom.data, layout[0].zoom.dx*layout[0].zoom.dy);
+  }
+  else {
+    for (i = 0; i < 256; i++) 
+      pixel[i] = layout[0].cmap[i].pixel;
+    white = layout[0].white;
+    
+    zoomscale = MAX (5, layout[0].expand + 5);
+    expand = 1 / zoomscale;
+    expand_out = (int) zoomscale;
+    expand_in  = 1;
+    
+    dx = layout[0].zoom.dx;
+    dy = layout[0].zoom.dy;
+    DX = layout[0].matrix.Naxis[0];
+    DY = layout[0].matrix.Naxis[1];
+    Rx = DX/2 - dx*expand/2.0 - X0;
+    Ry = DY/2 - dy*expand/2.0 - Y0;  
+    
+    /* reassign as much for speed as clarity here */
+    X0 = 0.5*layout[0].matrix.Naxis[0] - x;
+    Y0 = 0.5*layout[0].matrix.Naxis[1] - y;
+    dx = layout[0].picture.dx;
+    dy = layout[0].picture.dy;
+    DX = matrix[0].Naxis[0];
+    DY = matrix[0].Naxis[1];
+    Rx = DX/2 - dx*expand/2.0 - X0;
+    Ry = DY/2 - dy*expand/2.0 - Y0;
+    
+    i_start = MAX (-Rx / expand, 0);
+    j_start = MAX (-Ry / expand, 0);
+    i_end   = MIN ((DX - Rx)/expand, dx - expand_out + 1);
+    j_end   = MIN ((DY - Ry)/expand, dy - expand_out + 1);
+    
+    in_pix = (short *) matrix[0].buffer;
+    out_pix = layout[0].zoom.data;
+    for (j = 0; j < j_start; j++) {
+      for (i = 0; i < dx; i++, out_pix++) {
+	*out_pix = white;
+      }
+    }
+    
+  for (j = j_start; j < j_end; j+= expand_out) {
+    Y = XPIX (j, Ry, expand);
+    for (jj = 0; jj < expand_out; jj++) {
+      out_pix = layout[0].zoom.data + (j+jj)*dx;  /* fencepost errors? */
+      for (i = 0; i < i_start; i++, out_pix++) {
+	*out_pix = white;
+      }
+    }
+    out_pix = layout[0].zoom.data + j*dx + i_start;  
+    X = XPIX (i_start, Rx, expand);
+    in_pix2 = in_pix + DX*Y + X;
+    for (i = i_start; i < i_end; i+= expand_out, in_pix2+= expand_in) { 
+      zvalue = 0x003f & *in_pix2;
+      for (ii = 0; ii < expand_out; ii++, out_pix++) {
+	for (jj = 0; jj < expand_out; jj++) {
+	  *(out_pix + jj*dx) = *(pixel + zvalue);
+	}
+      }
+    }
+    for (jj = 0; jj < expand_out; jj++) {
+      out_pix = layout[0].zoom.data + (j+jj)*dx + i_end;  /* fencepost errors? */
+      for (i = i_end; i < dx; i++, out_pix++) {
+	*out_pix = white;
+      }
+    }
+  }
+  for (j = j_end; j < dy; j++) {
+    out_pix = layout[0].picture.data + j*dx;
+    for (i = 0; i < dx; i++, out_pix++) {
+      *out_pix = white;
+    }
+  }
+}
+	
+  /*** here, if expand is < 1 (fractional expansion), we sparsely sample the 
+    original image, instead of box averaging - do we like this?  well, 
+    it speeds things up alot! ***/
+
+
+
+
+  layout[0].zoom.pix = XCreateImage (graphic[0].display, visual, graphic[0].depth, ZPixmap, 0, 
+					layout[0].zoom.data, 
+					layout[0].zoom.dx, layout[0].zoom.dy, 8, 0);
+  
+}
+
+ 
Index: /tags/kii-1-4/Ohana/src/kii/zoom/CreateZoom16.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/zoom/CreateZoom16.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/zoom/CreateZoom16.c	(revision 11911)
@@ -0,0 +1,134 @@
+# include "Ximage.h"
+# define XPIX(x,Rx,S) (x*S + Rx)
+# define ZPIX(value,Rz1,Rz2) (value*Rz1 - Rz2)
+# define FRAC(a) ((a) - (int)(a))
+
+void CreateZoom16 (Layout *layout, Graphic *graphic, double x, double y) {
+
+  int i, j, ii, jj;
+  int i_start, i_end, j_start, j_end;
+  int dropback;  /* this is a bit of a kludge... */
+  int dx, dy, DX, DY;
+  double expand, zoomscale, Rx, Ry;
+  int expand_in, expand_out;
+  unsigned char *out_pix, *out_pix2, *data;
+  unsigned char *in_pix,  *in_pix2;
+  unsigned char pixel1[256], pixel2[256];
+  unsigned char pixvalue1, pixvalue2;
+  unsigned long white;
+  unsigned char white1, white2;
+
+  dx = layout[0].zoom.dx;
+  dy = layout[0].zoom.dy;
+
+  if (layout[0].matrix.size == 0) {  /* create a test pattern */
+    REALLOCATE (layout[0].zoom.data, char, 2*dy*dx);
+    bzero (layout[0].zoom.data, layout[0].zoom.dx*layout[0].zoom.dy);
+    layout[0].zoom.pix = XCreateImage (graphic[0].display, graphic[0].visual, graphic[0].depth, ZPixmap, 0, 
+				       layout[0].zoom.data, layout[0].zoom.dx, layout[0].zoom.dy, 16, 0);
+    return;
+  }
+
+  for (i = 0; i < 256; i++) { /* set up pixel array */
+    pixel1[i] = 0x0000ff & layout[0].cmap[i].pixel;
+    pixel2[i] = 0x0000ff & (layout[0].cmap[i].pixel >> 8);
+  }
+  white = layout[0].white;
+  white1 = 0x0000ff & white;
+  white2 = 0x0000ff & (white >> 8);
+
+  zoomscale = MAX (5, layout[0].expand + 5);
+  expand = 1 / zoomscale;
+  expand_out = (int) zoomscale;
+  expand_in  = 1;
+
+  DX = layout[0].matrix.Naxis[0];
+  DY = layout[0].matrix.Naxis[1];
+  Rx = x - expand*(int)(0.5*(dx + 1)) + 1;
+  Ry = y - expand*(int)(0.5*(dy + 1)) + 1;
+
+  i_start = MIN (MAX (-Rx / expand, (1 - FRAC(Rx)) / expand), dx - expand_out + 1);
+  j_start = MIN (MAX (-Ry / expand, (1 - FRAC(Ry)) / expand), dy - expand_out + 1);
+  i_end   = MAX (MIN ((DX-Rx) / expand, dx - expand_out + 1), 0);
+  j_end   = MAX (MIN ((DY-Ry) / expand, dy - expand_out + 1), 0);
+  dropback = expand_out - (i_end - i_start) % expand_out;
+  if ((i_end - i_start) % expand_out == 0) dropback = 0;
+
+  data = out_pix = (unsigned char *) layout[0].zoom.data;
+  in_pix  = (unsigned char *) (layout[0].matrix.buffer) + DX*(int)MAX(Ry,0) + (int)MAX(Rx,0);
+
+  /********** below we do the mapping from buffer pixels (in) to picture pixels (out) **********/
+
+  if ((i_end < i_start) || (j_end < j_start)) {
+    for (j = 0; j < dx*dy; j++, out_pix++) 
+      *out_pix = white;
+    return;
+  } 
+  
+  /**** fill in bottom area ****/
+  for (j = 0; j < j_start; j++) {
+    for (i = 0; i < dx; i++, out_pix+=2) {
+      out_pix[0] = white1;
+      out_pix[1] = white2;
+    }
+  }
+
+  for (j = j_start; j < j_end; j+= expand_out, in_pix += expand_in*DX) {
+    out_pix = &data[2*j*dx];
+
+    /**** fill in area to the left of the picture ****/
+    for (jj = 0; jj < expand_out; jj++) { 
+      out_pix2 = out_pix + 2*jj*dx;
+      for (i = 0; i < i_start; i++, out_pix2+=2) {
+	out_pix2[0] = white1;
+	out_pix2[1] = white2;
+      }
+    }
+    out_pix += 2*i_start;
+    
+    /*** fill in the picture region ***/
+    in_pix2 = in_pix;
+    if (expand_out == 1) {
+      for (i = i_start; i < i_end; i++, in_pix2+= expand_in, out_pix+=2) {
+	out_pix[0] = pixel1[*in_pix2];
+	out_pix[1] = pixel2[*in_pix2];
+      }
+    }
+    else {
+      for (i = i_start; i < i_end; i+= expand_out, in_pix2++, out_pix+= 2*expand_out) { 
+	pixvalue1 = pixel1[*in_pix2];
+	pixvalue2 = pixel2[*in_pix2];
+	out_pix2 = out_pix;
+	for (jj = 0; jj < expand_out; jj++, out_pix2+=2*(dx-expand_out)) {
+	  for (ii = 0; ii < expand_out; ii++, out_pix2+=2) {
+	    out_pix2[0] = pixvalue1; 
+	    out_pix2[1] = pixvalue2; 
+	  }
+	}
+      }
+    }
+    out_pix -= 2*dropback;
+    
+    /**** fill in area to the right of the picture ****/
+    for (jj = 0; jj < expand_out; jj++) {
+      out_pix2 = out_pix + 2*jj*dx;
+      for (i = i_end; i < dx; i++, out_pix2+=2) {
+	out_pix2[0] = white1;
+	out_pix2[1] = white2;
+      }
+    }
+  } 
+  
+  out_pix = &data[2*j_end*dx];
+  /**** fill in top area ****/
+  for (j = 0; j < (dy - j_end); j++) {
+    for (i = 0; i < dx; i++, out_pix+=2) { 
+      out_pix[0] = white1;
+      out_pix[1] = white2;
+    }
+  }
+
+  layout[0].zoom.pix = XCreateImage (graphic[0].display, graphic[0].visual, 16, ZPixmap, 0, 
+					layout[0].zoom.data, layout[0].zoom.dx, layout[0].zoom.dy, 32, 0);
+  
+}
Index: /tags/kii-1-4/Ohana/src/kii/zoom/CreateZoom24.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/zoom/CreateZoom24.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/zoom/CreateZoom24.c	(revision 11911)
@@ -0,0 +1,167 @@
+# include "Ximage.h"
+# define XPIX(x,Rx,S) (x*S + Rx)
+# define ZPIX(value,Rz1,Rz2) (value*Rz1 - Rz2)
+# define FRAC(a) ((a) - (int)(a))
+
+void CreateZoom24 (Layout *layout, Graphic *graphic, double x, double y) {
+
+  int i, j, ii, jj, extra;
+  int i_start, i_end, j_start, j_end;
+  int dropback;  /* this is a bit of a kludge... */
+  int dx, dy, DX, DY;
+  double expand, zoomscale, Rx, Ry;
+  int expand_in, expand_out;
+  unsigned char *out_pix, *out_pix2, *data;
+  unsigned char *in_pix,  *in_pix2;
+  unsigned char pixel1[256], pixel2[256], pixel3[256];
+  unsigned char pixvalue1, pixvalue2, pixvalue3;
+  unsigned long white;
+  unsigned char white1, white2, white3;
+
+  dx = layout[0].zoom.dx;
+  dy = layout[0].zoom.dy;
+  extra = 4 - (dx * 3) % 4;
+
+  if (layout[0].matrix.size == 0) {  /* create a test pattern */
+    REALLOCATE (layout[0].zoom.data, char, dy*(3*dx+extra));
+    bzero (layout[0].zoom.data, layout[0].zoom.dx*layout[0].zoom.dy);
+    layout[0].zoom.pix = XCreateImage (graphic[0].display, graphic[0].visual, graphic[0].depth, ZPixmap, 0, 
+				       layout[0].zoom.data, layout[0].zoom.dx, layout[0].zoom.dy, 32, 0);
+    return;
+  }
+
+  for (i = 0; i < 256; i++) { /* set up pixel array */
+    pixel1[i] = 0x0000ff & layout[0].cmap[i].pixel;
+    pixel2[i] = 0x0000ff & (layout[0].cmap[i].pixel >> 8);
+    pixel3[i] = 0x0000ff & (layout[0].cmap[i].pixel >> 16);
+  }
+  white = layout[0].white;
+  white1 = 0x0000ff & white;
+  white2 = 0x0000ff & (white >> 8);
+  white3 = 0x0000ff & (white >> 16);
+
+  zoomscale = MAX (5, layout[0].expand + 5);
+  expand = 1 / zoomscale;
+  expand_out = (int) zoomscale;
+  expand_in  = 1;
+
+  DX = layout[0].matrix.Naxis[0];
+  DY = layout[0].matrix.Naxis[1];
+  Rx = x - expand*(int)(0.5*(dx + 1)) + 1;
+  Ry = y - expand*(int)(0.5*(dy + 1)) + 1;
+
+  i_start = MIN (MAX (-Rx / expand, (1 - FRAC(Rx)) / expand), dx - expand_out + 1);
+  j_start = MIN (MAX (-Ry / expand, (1 - FRAC(Ry)) / expand), dy - expand_out + 1);
+  i_end   = MAX (MIN ((DX-Rx) / expand, dx - expand_out + 1), 0);
+  j_end   = MAX (MIN ((DY-Ry) / expand, dy - expand_out + 1), 0);
+  dropback = expand_out - (i_end - i_start) % expand_out;
+  if ((i_end - i_start) % expand_out == 0) dropback = 0;
+
+  data = out_pix = (unsigned char *) layout[0].zoom.data;
+  in_pix  = (unsigned char *) (layout[0].matrix.buffer) + DX*(int)MAX(Ry,0) + (int)MAX(Rx,0);
+
+  /********** below we do the mapping from buffer pixels (in) to picture pixels (out) **********/
+
+  if ((i_end < i_start) || (j_end < j_start)) {
+    for (j = 0; j < dx*dy; j++, out_pix++) 
+      *out_pix = white;
+    return;
+  } 
+  
+  /**** fill in bottom area ****/
+  for (j = 0; j < j_start; j++) {
+    for (i = 0; i < dx; i++, out_pix+=3) {
+      out_pix[0] = white1;
+      out_pix[1] = white2;
+      out_pix[2] = white3;
+    }
+    out_pix += extra;
+  }
+
+  for (j = j_start; j < j_end; j+= expand_out, in_pix += expand_in*DX) {
+    out_pix = &data[j*(3*dx+extra)];
+
+    /**** fill in area to the left of the picture ****/
+    for (jj = 0; jj < expand_out; jj++) { 
+      out_pix2 = out_pix + jj*(3*dx + extra);
+      for (i = 0; i < i_start; i++, out_pix2+=3) {
+	out_pix2[0] = white1;
+	out_pix2[1] = white2;
+	out_pix2[2] = white3;
+      }
+    }
+    out_pix += 3*i_start;
+    
+    /*** fill in the picture region ***/
+    in_pix2 = in_pix;
+    if (expand_out == 1) {
+      for (i = i_start; i < i_end; i++, in_pix2+= expand_in, out_pix+=3) {
+	out_pix[0] = pixel1[*in_pix2];
+	out_pix[1] = pixel2[*in_pix2];
+	out_pix[2] = pixel3[*in_pix2];
+      }
+    }
+    else {
+      for (i = i_start; i < i_end; i+= expand_out, in_pix2++, out_pix+= 3*expand_out) { 
+	pixvalue1 = pixel1[*in_pix2];
+	pixvalue2 = pixel2[*in_pix2];
+	pixvalue3 = pixel3[*in_pix2];
+	out_pix2 = out_pix;
+	for (jj = 0; jj < expand_out; jj++, out_pix2+=3*(dx-expand_out)+extra) {
+	  for (ii = 0; ii < expand_out; ii++, out_pix2+=3) {
+	    out_pix2[0] = pixvalue1; 
+	    out_pix2[1] = pixvalue2; 
+	    out_pix2[2] = pixvalue3; 
+	  }
+	}
+      }
+    }
+    out_pix -= 3*dropback;
+    
+    /**** fill in area to the right of the picture ****/
+    for (jj = 0; jj < expand_out; jj++) {
+      out_pix2 = out_pix + jj*(3*dx+extra);
+      for (i = i_end; i < dx; i++, out_pix2+=3) {
+	out_pix2[0] = white1;
+	out_pix2[1] = white2;
+	out_pix2[2] = white3;
+      }
+    }
+  } 
+  
+  /*
+  if ((j_end - j_start) % expand_out > 0)
+    out_pix -= (expand_out - (j_end - j_start) % expand_out);
+  */
+
+  out_pix = &data[j_end*(3*dx+extra)];
+  /**** fill in top area ****/
+  for (j = 0; j < (dy - j_end); j++) {
+    for (i = 0; i < dx; i++, out_pix+=3) { 
+      out_pix[0] = white1;
+      out_pix[1] = white2;
+      out_pix[2] = white3;
+    }
+    out_pix+=extra;
+  }
+
+  /*
+  out_pix = (unsigned char *) layout[0].zoom.data;
+  for (i = 0; i < dx*dy; i++) {
+    out_pix[3*i + 0] = white1;
+    out_pix[3*i + 1] = white2;
+    out_pix[3*i + 2] = white3;
+  }
+  for (j = 0; j < dy/2; j++) {
+    for (i = 0; i < dx; i++) {
+      out_pix[j*(extra + 3*dx) + 3*i + 0] = pixel1[10];
+      out_pix[j*(extra + 3*dx) + 3*i + 1] = pixel2[10];
+      out_pix[j*(extra + 3*dx) + 3*i + 2] = pixel3[10];
+    }
+
+  }
+  */
+  layout[0].zoom.pix = XCreateImage (graphic[0].display, graphic[0].visual, 24, ZPixmap, 0, 
+					layout[0].zoom.data, layout[0].zoom.dx, layout[0].zoom.dy, 32, 0);
+  
+}
Index: /tags/kii-1-4/Ohana/src/kii/zoom/CreateZoom32.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/zoom/CreateZoom32.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/zoom/CreateZoom32.c	(revision 11911)
@@ -0,0 +1,122 @@
+# include "Ximage.h"
+# define XPIX(x,Rx,S) (x*S + Rx)
+# define ZPIX(value,Rz1,Rz2) (value*Rz1 - Rz2)
+# define FRAC(a) ((a) - (int)(a))
+
+void CreateZoom32 (Layout *layout, Graphic *graphic, double x, double y) {
+
+  int i, j, ii, jj;
+  int i_start, i_end, j_start, j_end;
+  int dropback;  /* this is a bit of a kludge... */
+  int dx, dy, DX, DY;
+  double expand, zoomscale, Rx, Ry;
+  int expand_in, expand_out;
+  unsigned int *out_pix, *out_pix2, *data;
+  unsigned char  *in_pix,  *in_pix2;
+  unsigned long pixel[256], pixvalue;
+  unsigned long white;
+
+  if (layout[0].matrix.size == 0) {  /* create a test pattern */
+    REALLOCATE (layout[0].zoom.data, char, 4*layout[0].zoom.dx*layout[0].zoom.dy);
+    layout[0].zoom.pix = XCreateImage (graphic[0].display, graphic[0].visual, graphic[0].depth, ZPixmap, 0, 
+				       layout[0].zoom.data, layout[0].zoom.dx, layout[0].zoom.dy, 32, 0);
+    return;
+  }
+
+  for (i = 0; i < 256; i++) { /* set up pixel array */
+    pixel[i] = layout[0].cmap[i].pixel;
+  }
+  white = layout[0].white;
+
+  zoomscale = MAX (5, layout[0].expand + 5);
+  expand = 1 / zoomscale;
+  expand_out = (int) zoomscale;
+  expand_in  = 1;
+
+  dx = layout[0].zoom.dx;
+  dy = layout[0].zoom.dy;
+  DX = layout[0].matrix.Naxis[0];
+  DY = layout[0].matrix.Naxis[1];
+  Rx = x - expand*(int)(0.5*(dx + 1)) + 1;
+  Ry = y - expand*(int)(0.5*(dy + 1)) + 1;
+
+  i_start = MIN (MAX (-Rx / expand, (1 - FRAC(Rx)) / expand), dx - expand_out + 1);
+  j_start = MIN (MAX (-Ry / expand, (1 - FRAC(Ry)) / expand), dy - expand_out + 1);
+  i_end   = MAX (MIN ((DX-Rx) / expand, dx - expand_out + 1), 0);
+  j_end   = MAX (MIN ((DY-Ry) / expand, dy - expand_out + 1), 0);
+  dropback = expand_out - (i_end - i_start) % expand_out;
+  if ((i_end - i_start) % expand_out == 0) dropback = 0;
+
+  out_pix = (unsigned int *) layout[0].zoom.data;
+  data = (unsigned int *) layout[0].zoom.data;
+  in_pix  = (unsigned char *) (layout[0].matrix.buffer) + DX*(int)MAX(Ry,0) + (int)MAX(Rx,0);
+
+  /********** below we do the mapping from buffer pixels (in) to picture pixels (out) **********/
+
+  if ((i_end < i_start) || (j_end < j_start)) {
+    for (j = 0; j < dx*dy; j++, out_pix++) 
+      *out_pix = white;
+    return;
+  } 
+  
+
+  /**** fill in bottom area ****/
+  for (j = 0; j < dx*j_start; j++, out_pix++) {
+    out_pix[0] = white;
+  }
+
+  for (j = j_start; j < j_end; j+= expand_out, out_pix+=(expand_out-1)*dx, in_pix += expand_in*DX) {
+
+    /**** fill in area to the left of the picture ****/
+    for (jj = 0; jj < expand_out; jj++) { 
+      out_pix2 = out_pix + jj*dx;
+      for (i = 0; i < i_start; i++, out_pix2++) {
+	out_pix[0] = white;
+      }
+    }
+    out_pix += i_start;
+    
+    /*** fill in the picture region ***/
+    in_pix2 = in_pix;
+    if (expand_out == 1) {
+      for (i = i_start; i < i_end; i++, in_pix2+= expand_in, out_pix++) {
+	out_pix[0] = pixel[*in_pix2];
+      }
+    }
+    else {
+      for (i = i_start; i < i_end; i+= expand_out, in_pix2++, out_pix+= expand_out) { 
+	pixvalue = *(pixel + *in_pix2);
+	out_pix2 = out_pix;
+	for (jj = 0; jj < expand_out; jj++, out_pix2+=(dx-expand_out)) {
+	  for (ii = 0; ii < expand_out; ii++, out_pix2++) {
+	    out_pix2[0] = pixvalue; 
+	  }
+	}
+      }
+    }
+    out_pix -= dropback;
+
+    
+    /**** fill in area to the right of the picture ****/
+    for (jj = 0; jj < expand_out; jj++) {
+      out_pix2 = out_pix + jj*dx;
+      for (i = i_end; i < dx; i++, out_pix2++) {
+	out_pix2[0] = white;
+      }
+    }
+    out_pix += (dx - i_end);
+  } 
+  
+  if ((j_end - j_start) % expand_out > 0)
+    out_pix -= (expand_out - (j_end - j_start) % expand_out);
+  
+  /**** fill in top area ****/
+  for (j = 0; (j < dx*(dy - j_end)) && (out_pix - (unsigned int *)layout[0].zoom.data < dx*dy); j++, out_pix++) { 
+    out_pix[0] = white;
+  }
+
+  out_pix = (unsigned int *)layout[0].zoom.data;
+  layout[0].zoom.pix = XCreateImage (graphic[0].display, graphic[0].visual, graphic[0].depth, ZPixmap, 0, 
+					layout[0].zoom.data, layout[0].zoom.dx, layout[0].zoom.dy, 32, 0);
+  
+}
Index: /tags/kii-1-4/Ohana/src/kii/zoom/CreateZoom8.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/zoom/CreateZoom8.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/zoom/CreateZoom8.c	(revision 11911)
@@ -0,0 +1,140 @@
+# include "Ximage.h"
+# define XPIX(x,Rx,S) (x*S + Rx)
+# define ZPIX(value,Rz1,Rz2) (value*Rz1 - Rz2)
+# define FRAC(a) ((a) - (int)(a))
+
+void CreateZoom8 (Layout *layout, Graphic *graphic, double x, double y) {
+
+  int i, j, ii, jj;
+  int i_start, i_end, j_start, j_end;
+  int dropback;  /* this is a bit of a kludge... */
+  int dx, dy, DX, DY;
+  double expand, zoomscale, Rx, Ry;
+  int expand_in, expand_out;
+  char  *out_pix, *out_pix2;
+  char  *in_pix,  *in_pix2;
+  unsigned long pixel[256], pixvalue;
+  unsigned long white;
+
+  if (layout[0].matrix.size == 0) {  /* create a test pattern */
+    REALLOCATE (layout[0].zoom.data, char, layout[0].zoom.dx*layout[0].zoom.dy);
+    bzero (layout[0].zoom.data, layout[0].zoom.dx*layout[0].zoom.dy);
+    layout[0].zoom.pix = XCreateImage (graphic[0].display, graphic[0].visual, graphic[0].depth, ZPixmap, 0, 
+				       layout[0].zoom.data, layout[0].zoom.dx, layout[0].zoom.dy, 8, 0);
+    return;
+  }
+
+  for (i = 0; i < 256; i++) { /* set up pixel array */
+    pixel[i] = layout[0].cmap[i].pixel;
+  }
+  white = layout[0].white;
+
+  zoomscale = MAX (5, layout[0].expand + 5);
+  expand = 1 / zoomscale;
+  expand_out = (int) zoomscale;
+  expand_in  = 1;
+
+  /*
+  dx = layout[0].zoom.dx;
+  dy = layout[0].zoom.dy;
+  DX = layout[0].matrix.Naxis[0];
+  DY = layout[0].matrix.Naxis[1];
+  Rx = 0.5*(DX - (dx - 1)*expand) - x;
+  Ry = 0.5*(DY - (dy - 1)*expand) - y;
+  data coords of 0,0 point in pic array 
+  X = 0.5*layout[0].matrix.Naxis[0] - expand*((int)(0.5*layout[0].zoom.dx + 0.5) - 0.0) - layout[0].X;
+  Y = 0.5*layout[0].matrix.Naxis[1] - expand*((int)(0.5*layout[0].zoom.dy + 0.5) - 0.0) - layout[0].Y;  
+  i_start = MIN (MAX (-Rx / expand, 0), dx - expand_out + 1);
+  j_start = MIN (MAX (-Ry / expand, 0), dy - expand_out + 1);
+  i_end   = MAX (MIN ((DX-Rx) / expand, dx - expand_out + 1), 0);
+  j_end   = MAX (MIN ((DY-Ry) / expand, dy - expand_out + 1), 0);
+  dropback = expand_out - (i_end - i_start) % expand_out;
+  if ((i_end - i_start) % expand_out == 0) dropback = 0;
+
+  out_pix = layout[0].zoom.data;
+  in_pix  = (char *) (layout[0].matrix.buffer) + DX*(int)MAX(Y,0) + (int)MAX(X,0);
+
+  */
+
+  dx = layout[0].zoom.dx;
+  dy = layout[0].zoom.dy;
+  DX = layout[0].matrix.Naxis[0];
+  DY = layout[0].matrix.Naxis[1];
+  Rx = x - expand*(int)(0.5*(dx + 1)) + 1;
+  Ry = y - expand*(int)(0.5*(dy + 1)) + 1;
+
+  i_start = MIN (MAX (-Rx / expand, (1 - FRAC(Rx)) / expand), dx - expand_out + 1);
+  j_start = MIN (MAX (-Ry / expand, (1 - FRAC(Ry)) / expand), dy - expand_out + 1);
+  i_end   = MAX (MIN ((DX-Rx) / expand, dx - expand_out + 1), 0);
+  j_end   = MAX (MIN ((DY-Ry) / expand, dy - expand_out + 1), 0);
+  dropback = expand_out - (i_end - i_start) % expand_out;
+  if ((i_end - i_start) % expand_out == 0) dropback = 0;
+
+  out_pix = (char *) layout[0].zoom.data;
+  in_pix  = (char *) (layout[0].matrix.buffer) + DX*(int)MAX(Ry,0) + (int)MAX(Rx,0);
+
+  /********** below we do the mapping from buffer pixels (in) to picture pixels (out) **********/
+
+  if ((i_end < i_start) || (j_end < j_start)) {
+    for (j = 0; j < dx*dy; j++, out_pix++) 
+      *out_pix = white;
+    return;
+  } 
+  
+  /**** fill in bottom area ****/
+  for (j = 0; j < dx*j_start; j++, out_pix++) 
+    *out_pix = white;
+  
+  for (j = j_start; j < j_end; j+= expand_out, out_pix+=(expand_out-1)*dx, in_pix += expand_in*DX) {
+
+    /**** fill in area to the left of the picture ****/
+    for (jj = 0; jj < expand_out; jj++) { 
+      out_pix2 = out_pix + jj*dx;
+      for (i = 0; i < i_start; i++, out_pix2++) {
+	*out_pix2 = white;
+      }
+    }
+    out_pix += i_start;
+    
+    /*** fill in the picture region ***/
+    in_pix2 = in_pix;
+    if (expand_out == 1) {
+      for (i = i_start; i < i_end; i++, in_pix2+= expand_in, out_pix++)
+	*out_pix = *(pixel + *in_pix2); 
+    }
+    else {
+      for (i = i_start; i < i_end; i+= expand_out, in_pix2++, out_pix+= expand_out) { 
+	pixvalue = *(pixel + *in_pix2);
+	out_pix2 = out_pix;
+	for (jj = 0; jj < expand_out; jj++, out_pix2+=(dx-expand_out)) {
+	  for (ii = 0; ii < expand_out; ii++, out_pix2++) {
+	    *out_pix2 = pixvalue;
+	  }
+	}
+      }
+    }
+    out_pix -= dropback;
+    
+    /**** fill in area to the right of the picture ****/
+    for (jj = 0; jj < expand_out; jj++) {
+      out_pix2 = out_pix + jj*dx;
+      for (i = i_end; i < dx; i++, out_pix2++) {
+	*out_pix2 = white;
+      }
+    }
+    out_pix += (dx - i_end);
+    
+  } 
+  
+  if ((j_end - j_start) % expand_out > 0)
+    out_pix -= expand_out - (j_end - j_start) % expand_out;
+  
+  /**** fill in top area ****/
+  for (j = 0; (j < dx*(dy - j_end)) && (out_pix - layout[0].zoom.data < dx*dy); j++, out_pix++) { 
+    *out_pix = white;
+  }
+
+  layout[0].zoom.pix = XCreateImage (graphic[0].display, graphic[0].visual, graphic[0].depth, ZPixmap, 0, 
+					layout[0].zoom.data, layout[0].zoom.dx, layout[0].zoom.dy, 8, 0);
+  
+}
Index: /tags/kii-1-4/Ohana/src/kii/zoom/CrossHairs.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/zoom/CrossHairs.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/zoom/CrossHairs.c	(revision 11911)
@@ -0,0 +1,66 @@
+# include "Ximage.h"
+
+void CrossHairs (Graphic *graphic, Layout *layout) {
+
+  int x0, x1, x5, x7;
+  int y0, y2, y4, y5;
+  double zoomscale;
+
+  zoomscale = MAX (5, layout[0].expand + 5);
+  x0 = (zoomscale) * (0.5 * (ZOOM_X + 1) / zoomscale - 2.5) + layout[0].zoom.x;
+  x5 = (zoomscale) * (0.5 * (ZOOM_X + 1) / zoomscale - 0.5) + layout[0].zoom.x;
+  x7 = (zoomscale) * (0.5 * (ZOOM_X + 1) / zoomscale + 0.5) + layout[0].zoom.x;
+  x1 = (zoomscale) * (0.5 * (ZOOM_X + 1) / zoomscale + 2.5) + layout[0].zoom.x;
+						    	 
+  y4 = (zoomscale) * (0.5 * (ZOOM_Y + 1) / zoomscale - 2.5) + layout[0].zoom.y;
+  y2 = (zoomscale) * (0.5 * (ZOOM_Y + 1) / zoomscale - 0.5) + layout[0].zoom.y;
+  y0 = (zoomscale) * (0.5 * (ZOOM_Y + 1) / zoomscale + 0.5) + layout[0].zoom.y;
+  y5 = (zoomscale) * (0.5 * (ZOOM_Y + 1) / zoomscale + 2.5) + layout[0].zoom.y;
+
+
+  XSetForeground (graphic[0].display, graphic[0].gc, graphic[0].black);
+  
+  XDrawLine (graphic[0].display, graphic[0].window, graphic[0].gc, 
+	     x0, y0, x5, y0);
+  XDrawLine (graphic[0].display, graphic[0].window, graphic[0].gc, 
+	     x5, y0, x5, y5);
+
+  XDrawLine (graphic[0].display, graphic[0].window, graphic[0].gc, 
+	     x7, y5, x7, y0);
+  XDrawLine (graphic[0].display, graphic[0].window, graphic[0].gc, 
+	     x7, y0, x1, y0);
+
+  XDrawLine (graphic[0].display, graphic[0].window, graphic[0].gc, 
+	     x0, y2, x5, y2);
+  XDrawLine (graphic[0].display, graphic[0].window, graphic[0].gc, 
+	     x5, y2, x5, y4);
+
+  XDrawLine (graphic[0].display, graphic[0].window, graphic[0].gc, 
+	     x7, y4, x7, y2);
+  XDrawLine (graphic[0].display, graphic[0].window, graphic[0].gc, 
+	     x7, y2, x1, y2);
+
+  XSetForeground (graphic[0].display, graphic[0].gc, graphic[0].white);
+  XDrawLine (graphic[0].display, graphic[0].window, graphic[0].gc, 
+	     x0, y0+1, x5-1, y0+1);
+  XDrawLine (graphic[0].display, graphic[0].window, graphic[0].gc, 
+	     x5-1, y0+1, x5-1, y5);
+
+  XDrawLine (graphic[0].display, graphic[0].window, graphic[0].gc, 
+	     x7+1, y5, x7+1, y0+1);
+  XDrawLine (graphic[0].display, graphic[0].window, graphic[0].gc, 
+	     x7+1, y0+1, x1, y0+1);
+
+  XDrawLine (graphic[0].display, graphic[0].window, graphic[0].gc, 
+	     x0, y2-1, x5-1, y2-1);
+  XDrawLine (graphic[0].display, graphic[0].window, graphic[0].gc, 
+	     x5-1, y2-1, x5-1, y4);
+
+  XDrawLine (graphic[0].display, graphic[0].window, graphic[0].gc, 
+	     x7+1, y4, x7+1, y2-1);
+  XDrawLine (graphic[0].display, graphic[0].window, graphic[0].gc, 
+	     x7+1, y2-1, x1, y2-1);
+
+  XSetForeground (graphic[0].display, graphic[0].gc, graphic[0].black);
+
+}
Index: /tags/kii-1-4/Ohana/src/kii/zoom/UpdatePointer.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/zoom/UpdatePointer.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/zoom/UpdatePointer.c	(revision 11911)
@@ -0,0 +1,58 @@
+# 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);
+}
Index: /tags/kii-1-4/Ohana/src/kii/zoom/UpdateStatusBox.c
===================================================================
--- /tags/kii-1-4/Ohana/src/kii/zoom/UpdateStatusBox.c	(revision 11911)
+++ /tags/kii-1-4/Ohana/src/kii/zoom/UpdateStatusBox.c	(revision 11911)
@@ -0,0 +1,63 @@
+# include "Ximage.h"
+
+void UpdateStatusBox (Graphic *graphic, Layout *layout, double x, double y, double z, int mode) {
+
+  int textpad;
+  double ra, dec; 
+  char line[100];
+
+  XY_to_RD (&ra, &dec, x, y, &layout[0].coords);
+
+  textpad = graphic[0].font[0].ascent;
+
+  if (mode) {
+    XSetForeground (graphic[0].display, graphic[0].gc, graphic[0].white);
+    XFillRectangle (graphic[0].display, graphic[0].window, graphic[0].gc,
+		    layout[0].text_x, layout[0].text_y, ZOOM_X, 6*textpad+7*PAD1);  
+    XSetForeground (graphic[0].display, graphic[0].gc, graphic[0].black);
+    XDrawRectangle (graphic[0].display, graphic[0].window, graphic[0].gc,
+		    layout[0].text_x, layout[0].text_y, ZOOM_X, 6*textpad+7*PAD1);
+  
+    bzero (line, 100);
+    sprintf (line, "(%d x %d) @ %d                                         ", 
+	     layout[0].picture.dx, layout[0].picture.dy, layout[0].expand); 
+    XDrawString (graphic[0].display, graphic[0].window, graphic[0].gc, 
+		 layout[0].text_x + PAD1, layout[0].text_y + 4*textpad + 4*PAD1, line, 25);
+    
+    bzero (line, 100);
+    sprintf (line, "%-25s", layout[0].file); 
+    XDrawString (graphic[0].display, graphic[0].window, graphic[0].gc, 
+		 layout[0].text_x + PAD1, layout[0].text_y + 5*textpad + 5*PAD1, line, strlen(line));
+    
+    bzero (line, 100);
+    sprintf (line, "(%s)                                          ", layout[0].buffer_name); 
+    XDrawString (graphic[0].display, graphic[0].window, graphic[0].gc, 
+		 layout[0].text_x + PAD1, layout[0].text_y + 6*textpad + 6*PAD1, line, 25);
+    
+  } else {
+    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, 3*textpad+3*PAD1 +1);  
+    XSetForeground (graphic[0].display, graphic[0].gc, graphic[0].black);
+  }
+  bzero (line, 100);
+  sprintf (line, "%25.3f", 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));
+  
+  bzero (line, 100);
+  sprintf (line, "%12.1f %12.1f", x, y);
+  XDrawString (graphic[0].display, graphic[0].window, graphic[0].gc, 
+	       layout[0].text_x + PAD1, layout[0].text_y + 2*textpad + 2*PAD1, line, strlen(line));
+  
+  bzero (line, 100);
+  if (DECIMAL_DEG) {
+    sprintf (line, "%12.6f %12.6f", ra, dec); 
+  } else {
+    hh_hms (line, ra, dec, ':');
+  }
+  XDrawString (graphic[0].display, graphic[0].window, graphic[0].gc, 
+	       layout[0].text_x + PAD1, layout[0].text_y + 3*textpad + 3*PAD1, line, strlen(line));
+  
+ 
+}
