# 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)
     
*/
