# include "Ximage.h"

void Reorient (Graphic *graphic, KapaImageWidget *image, double X, double Y, int mode) {

  if (image[0].expand == 0) image[0].expand = 1;

  switch (mode) {
  case 0:
    if ((image[0].X != X) || (image[0].Y != Y)) {
      image[0].X = X;
      image[0].Y = Y;
    }
    break;
  case -1: 
    image[0].expand--;
    if ((image[0].expand == 0) || (image[0].expand == -1))
      image[0].expand = -2;
    if (image[0].expand < -30) {
      fprintf (stderr, "can't get smaller!\n");
      image[0].expand = -30;
      return;
    }
    image[0].X = X;
    image[0].Y = Y;
    break;
  case +1:
    image[0].expand++;
    if ((image[0].expand == 0) || (image[0].expand == -1))
      image[0].expand = 1;
    if (image[0].expand > 30) {
      fprintf (stderr, "can't get bigger!\n");
      image[0].expand = 30;
      return;
    }
    image[0].X = X;
    image[0].Y = Y;
    break;
  }

  Remap (graphic, image, &image[0].matrix);
  Refresh ();
 
  XFlush (graphic[0].display);
}

# if (0) /* 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 > image[0].picture.x) && (x < image[0].picture.x + image[0].picture.dx) &&
      (y > image[0].picture.y) && (y < image[0].picture.y + image[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, 
		  image[0].picture.x + 0.5*image[0].picture.dx,
		  image[0].picture.y + 0.5*image[0].picture.dy);
  }
# endif

