#include "s_sprite.h"
#include "surface.h" // Para Surface

// Constructor
SSprite::SSprite(std::shared_ptr<Surface> surface, int x, int y, int w, int h)
	: surface_(surface),
	  pos_((SDL_Rect){x, y, w, h}),
	  clip_((SDL_Rect){0, 0, pos_.w, pos_.h}) {}

SSprite::SSprite(std::shared_ptr<Surface> surface, SDL_Rect rect)
	: surface_(surface),
	  pos_(rect),
	  clip_((SDL_Rect){0, 0, pos_.w, pos_.h}) {}

SSprite::SSprite(std::shared_ptr<Surface> surface)
	: surface_(surface),
	  pos_({0, 0, surface_->getWidth(), surface_->getHeight()}),
	  clip_(pos_) {}

// Muestra el sprite por pantalla
void SSprite::render()
{
	surface_->render(pos_.x, pos_.y, &clip_);
}

void SSprite::render(Uint8 source_color, Uint8 target_color)
{
	surface_->renderWithColorReplace(pos_.x, pos_.y, source_color, target_color, &clip_);
}

// Establece la posición del objeto
void SSprite::setPosition(int x, int y)
{
	pos_.x = x;
	pos_.y = y;
}

// Establece la posición del objeto
void SSprite::setPosition(SDL_Point p)
{
	pos_.x = p.x;
	pos_.y = p.y;
}

// Reinicia las variables a cero
void SSprite::clear()
{
	pos_ = {0, 0, 0, 0};
	clip_ = {0, 0, 0, 0};
}