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