#include "rectanglesfml.h"

RectangleSFML::RectangleSFML(sf::RenderTarget * const render_target) :
    _render_target(render_target)
{}

void RectangleSFML::setRect(const kku::Area<float>& rect)
{
    _rectangle.setPosition(rect.left, rect.top);
    _rectangle.setSize({rect.width, rect.height});
}

kku::Area<float> RectangleSFML::getRect() const
{
    const auto position = _rectangle.getPosition();
    const auto size = _rectangle.getSize();

    return kku::Area<float>{position.x, position.y, size.x, size.y};
}

void RectangleSFML::move(const kku::Vector2<float>& delta)
{
    _rectangle.move({delta.first, delta.second});
}

void RectangleSFML::setPosition(const kku::Point& position)
{
    _rectangle.setPosition({position.x, position.y});
}

kku::Point RectangleSFML::getPosition() const
{
    const auto position = _rectangle.getPosition();
    return kku::Point{position.x, position.y};
}

void RectangleSFML::setColor(const kku::Color& color)
{
    _rectangle.setFillColor(sf::Color{color.red, color.green,
                                      color.blue, color.alpha});
}

kku::Color RectangleSFML::getColor() const
{
    const auto color = _rectangle.getFillColor();
    return kku::Color{color.r, color.g, color.b, color.a};
}

bool RectangleSFML::contains(const kku::Point& position) const
{
    return _rectangle.getGlobalBounds().contains(position.x, position.y);
}

void RectangleSFML::display()
{
    _render_target->draw(_rectangle);
}
