#include "BoxSprite.h"

#include "SDL.h"
#include "Visualisation.h"
#include "GameException.h"

BoxSprite::BoxSprite(const SpriteID &id, const unsigned int &w, const unsigned int &h, const ColourRGB &borderColour, const ColourRGB &fillColour, unsigned int borderSize /* = 1 */)
: Sprite(id)
{
	m_numFrames = 1; //Only one frame for procedural boxes so far, animation could be added later.
	SDL_Surface* pScreen = Visualisation::getSingleton()->GetScreen();
	m_pFrames = SDL_CreateRGBSurface(SDL_HWSURFACE, w, h, pScreen->format->BitsPerPixel, pScreen->format->Rmask, pScreen->format->Gmask, pScreen->format->Bmask, pScreen->format->Amask);

	if(!m_pFrames)
	{
		throw GameException(eMajorError, "BoxSprite: Constructor failed due to failed SDL_CreateRGBSurface() call.");
		return;
	}

	for(size_t x = 0; x < w; x++)
	{
		for(size_t y = 0; y < h; y++)
		{
			if(x < borderSize || x > w - borderSize || y < borderSize || y > h - borderSize)
				WritePixel(m_pFrames, x, y, borderColour);
			else
				WritePixel(m_pFrames, x, y, fillColour);
		}
	}
}
