# include "Ximage.h"

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

  Picture *picture;

  picture = &image[0].picture;

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

  if ((picture[0].X == X) && (picture[0].Y == Y) && (mode == 0)) {
    Refresh ();
    XFlush (graphic[0].display);
    return;
  }

  switch (mode) {
  case 0:
    if ((picture[0].X != X) || (picture[0].Y != Y)) {
      picture[0].X = X;
      picture[0].Y = Y;
    }
    break;
  case -1: 
    picture[0].expand--;
    if ((picture[0].expand == 0) || (picture[0].expand == -1)) picture[0].expand = -2;
    picture[0].X = X;
    picture[0].Y = Y;
    break;
  case +1:
    picture[0].expand++;
    if ((picture[0].expand == 0) || (picture[0].expand == -1)) picture[0].expand = 1;
    picture[0].X = X;
    picture[0].Y = Y;
    break;
  }

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