#include "DangerousRacers/Meter.h"

Meter::Meter(const int x, const int y, const float w, const float h, const sf::Color color, const float value) {
    for (const auto& shape : {&outline, &fillBar}) {
        shape->setSize({ w, h });
        shape->setOrigin(0, h);
        shape->setPosition(x, y);
    }

    outline.setFillColor(sf::Color::Transparent);
    outline.setOutlineColor(color);
    outline.setOutlineThickness(2);

    fillBar.setFillColor(color);
    fillBar.setFillColor({color.r, color.g, color.b, 128});
    setValue(.5f);
}

void Meter::setValue(const float value) {
    fillBar.setScale(1, value);
}

void Meter::render(sf::RenderWindow &window) const {
    for (const auto& shape : {&outline, &fillBar}) {
        window.draw(*shape);
    }
}
