|
|
|
@ -6,6 +6,10 @@ BPMCalculatorWidget::BPMCalculatorWidget(const std::shared_ptr<BPMCalculator>& b
|
|
|
|
|
_bpm_calculator(bpm_calculator),
|
|
|
|
|
_slider(std::make_shared<BPMSlider>())
|
|
|
|
|
{
|
|
|
|
|
_bpm_value.setFont(*_font);
|
|
|
|
|
_bpm_value.setCharacterSize(40);
|
|
|
|
|
_bpm_value.setFillColor(sf::Color::Black);
|
|
|
|
|
_bpm_value.setString("--");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BPMCalculatorWidget::input(const sf::Event& event)
|
|
|
|
@ -29,6 +33,12 @@ void BPMCalculatorWidget::input(const sf::Event& event)
|
|
|
|
|
void BPMCalculatorWidget::update(const sf::Time& dt)
|
|
|
|
|
{
|
|
|
|
|
Window::update(dt);
|
|
|
|
|
|
|
|
|
|
const auto approximation = _bpm_calculator->getCurrentApproximation();
|
|
|
|
|
if (approximation != 0)
|
|
|
|
|
{
|
|
|
|
|
_bpm_value.setString(std::to_string(approximation));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BPMCalculatorWidget::draw(sf::RenderTarget& target, sf::RenderStates states) const
|
|
|
|
@ -36,7 +46,11 @@ void BPMCalculatorWidget::draw(sf::RenderTarget& target, sf::RenderStates states
|
|
|
|
|
Window::draw(target, states);
|
|
|
|
|
|
|
|
|
|
if (_is_visible)
|
|
|
|
|
{
|
|
|
|
|
_slider->draw(target, states);
|
|
|
|
|
_button_start->draw(target, states);
|
|
|
|
|
target.draw(_bpm_value, states);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BPMCalculatorWidget::setRect(const sf::FloatRect& rect)
|
|
|
|
@ -45,16 +59,38 @@ void BPMCalculatorWidget::setRect(const sf::FloatRect& rect)
|
|
|
|
|
_slider->setRect(sf::FloatRect{0, 0, rect.width / 8 * 6, 100});
|
|
|
|
|
_slider->setPosition({_window_content.getGlobalBounds().left + rect.width / 8,
|
|
|
|
|
_window_content.getGlobalBounds().top + rect.height / 8 * 3});
|
|
|
|
|
|
|
|
|
|
_button_start->setRect(sf::FloatRect{0, 0, rect.width / 10 * 3, 30});
|
|
|
|
|
_button_start->setPosition({_window_content.getGlobalBounds().left + rect.width / 7,
|
|
|
|
|
_window_content.getGlobalBounds().top + _window_content.getGlobalBounds().height - 40});
|
|
|
|
|
|
|
|
|
|
_bpm_value.setPosition({_window_content.getGlobalBounds().left + rect.width / 8,
|
|
|
|
|
_window_content.getGlobalBounds().top + rect.height / 8 });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BPMCalculatorWidget::move(const sf::Vector2f &delta)
|
|
|
|
|
{
|
|
|
|
|
Window::move(delta);
|
|
|
|
|
_slider->move(delta);
|
|
|
|
|
_bpm_value.move(delta);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BPMCalculatorWidget::setPosition(const sf::Vector2f &position)
|
|
|
|
|
{
|
|
|
|
|
Window::setPosition(position);
|
|
|
|
|
_slider->setPosition(position);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BPMCalculatorWidget::init()
|
|
|
|
|
{
|
|
|
|
|
auto& bpm_calculator = _bpm_calculator;
|
|
|
|
|
|
|
|
|
|
_button_start = std::make_shared<PushButton>("Start", _font);
|
|
|
|
|
_button_start->setCallback([bpm_calculator, button_start=_button_start]()
|
|
|
|
|
{
|
|
|
|
|
bpm_calculator->music()->play();
|
|
|
|
|
bpm_calculator->start();
|
|
|
|
|
button_start->setVisibility(false);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
addChild(_button_start);
|
|
|
|
|
}
|
|
|
|
|