# include "Ximage.h"
  
/* Draw text centered at x,y */

void DrawText (int x, int y, char *string, int pos) {

  char *c;
  int dx, dy;

  for (c = string; (*c == ' ') || (*c == '\t'); c++);
  if (*c == 0) return;
  
  dx  = XTextWidth (graphic.font, c, strlen(c));
  dy  = graphic.font[0].ascent;
  switch (pos) {
  case 0: XDrawString (graphic.display, graphic.window, graphic.gc, x - dx,   y + dy,   c, strlen(c)); break;
  case 1: XDrawString (graphic.display, graphic.window, graphic.gc, x - dx/2, y + dy,   c, strlen(c)); break;
  case 2: XDrawString (graphic.display, graphic.window, graphic.gc, x,        y + dy,   c, strlen(c)); break;
  case 3: XDrawString (graphic.display, graphic.window, graphic.gc, x - dx,   y + dy/2, c, strlen(c)); break;
  case 4: XDrawString (graphic.display, graphic.window, graphic.gc, x - dx/2, y + dy/2, c, strlen(c)); break;
  case 5: XDrawString (graphic.display, graphic.window, graphic.gc, x,        y + dy/2, c, strlen(c)); break;
  case 6: XDrawString (graphic.display, graphic.window, graphic.gc, x - dx,   y,        c, strlen(c)); break;
  case 7: XDrawString (graphic.display, graphic.window, graphic.gc, x - dx/2, y,        c, strlen(c)); break;
  case 8: XDrawString (graphic.display, graphic.window, graphic.gc, x,        y,        c, strlen(c)); break;
  }
}

/*
            
 6____7___8
  |       | 
  |       | 
 3|   4   |5
  |       |
  |       |
  ---------
 0    1   2

*/
