// Jason Brillante "Damdoshi"
// Hanged Bunny Studio 2014-2015
//
// Sewer Glue

#include		"SewerGlue.hpp"

void			hbs::SewerGlue::Display(void)
{
  sf::Image		image = lowres_screen.getTexture().copyToImage();
  sf::RectangleShape	shape;
  unsigned int		y;
  unsigned int		x;

  int			sy;
  int			sx;

  screen.clear();

  /// Random background
  shape.setSize(sf::Vector2f(screen.getSize().x, y_tilesize));
  for (y = 0; y < screen.getSize().y; y += y_tilesize)
    {
      shape.setPosition(0, y);
      shape.setFillColor(vic20palette[rand() % 16] * sf::Color(255, 255, 255, 64));
      screen.draw(shape);
    }

  /// Transform low res graphics to window graphics
  sx = (screen.getSize().x - x_tilesize * lowres_screen.getSize().x) / 2;
  sy = (screen.getSize().y - y_tilesize * lowres_screen.getSize().y) / 2 - 2;
  shape.setSize(sf::Vector2f(x_tilesize, y_tilesize));
  for (y = 0; y < lowres_screen.getSize().y; ++y)
    for (x = 0; x < lowres_screen.getSize().x; ++x)
      {
	shape.setPosition(x * x_tilesize + sx, y * y_tilesize + sy);
	shape.setFillColor(image.getPixel(x, y));
	screen.draw(shape);
      }

  /// Display all
  screen.display();
}
