2021-12-29 09:59:18 -05:00
|
|
|
#include "rectanglesfml.h"
|
|
|
|
|
2022-01-12 09:09:43 -05:00
|
|
|
RectangleSFML::RectangleSFML(sf::RenderTarget * const render_target) :
|
2021-12-29 09:59:18 -05:00
|
|
|
_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});
|
|
|
|
}
|
|
|
|
|
2022-02-05 20:33:09 -05:00
|
|
|
kku::Color RectangleSFML::getColor() const
|
|
|
|
{
|
|
|
|
const auto color = _rectangle.getFillColor();
|
|
|
|
return kku::Color{color.r, color.g, color.b, color.a};
|
|
|
|
}
|
|
|
|
|
2021-12-29 09:59:18 -05:00
|
|
|
bool RectangleSFML::contains(const kku::Point& position) const
|
|
|
|
{
|
|
|
|
return _rectangle.getGlobalBounds().contains(position.x, position.y);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RectangleSFML::display()
|
|
|
|
{
|
|
|
|
_render_target->draw(_rectangle);
|
|
|
|
}
|