#include "ZGo.h"



//---- ZGoChecker ------------------------------------------------------------//

//---- ZGoChecker

ZGoChecker::ZGoChecker(ZGo *zgo, ZGoPARAMS *input, ZGoPARAMS *output)
{
  this->zgo = zgo;
  this->input = input->setInput(this);
  this->output = output->setOutput(this);

  this->fnType = new ZGoNAME(zgo, "ZGoChecker");

  //  Parameters

  tile1 = (ZGoIMAGE *)input->get("tile1");
  tile2 = (ZGoIMAGE *)input->get("tile2");
  xoffset = (ZGoREAL *)input->get("xoffset");
  yoffset = (ZGoREAL *)input->get("yoffset");
  result = (ZGoIMAGE *)output->get("result");
}



//---- process

void ZGoChecker::process()
{
  tile1->process();
  tile2->process();
  xoffset->process();
  yoffset->process();

  int i, j;

  int w = tile1->w > tile2->w ? tile1->w : tile2->w;
  int h = tile1->h > tile2->h ? tile1->h : tile2->h;

  //- Calculate offset

  double x = xoffset->value;
  double y = yoffset->value;

  x -= ((int)x) & -2;
  y -= ((int)y) & -2;

  //  Put tiles

  for(j = -h*2; j <= result->h; j += h*2) for(i = -w*2; i <= result->w; i += w*2)
  {
    result->putImage(tile1, i +     (int)(x*w), j +     (int)(y*h));
    result->putImage(tile2, i + w + (int)(x*w), j +     (int)(y*h));
    result->putImage(tile2, i +     (int)(x*w), j + h + (int)(y*h));
    result->putImage(tile1, i + w + (int)(x*w), j + h + (int)(y*h));
  }
}



//---- end of file -----------------------------------------------------------//
