project-kyoku/src/gui/widgets/bpmcalculatorwidget.cpp

61 lines
1.5 KiB
C++
Raw Normal View History

2021-08-21 14:29:58 +02:00
#include "bpmcalculatorwidget.h"
#include "tools/bpmcalculator.h"
2021-08-16 20:54:03 +02:00
BPMCalculatorWidget::BPMCalculatorWidget(const std::shared_ptr<BPMCalculator>& bpm_calculator, const std::shared_ptr<sf::Font>& font) :
Window("BPM Calculation", font),
_bpm_calculator(bpm_calculator),
_slider(std::make_shared<BPMSlider>())
2021-08-16 20:54:03 +02:00
{
}
2021-08-21 14:29:58 +02:00
void BPMCalculatorWidget::input(const sf::Event& event)
2021-08-16 20:54:03 +02:00
{
switch (event.type)
{
default:
break;
case sf::Event::KeyPressed:
if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Space)
2021-08-16 20:54:03 +02:00
{
_bpm_calculator->click();
2021-08-16 20:54:03 +02:00
}
break;
}
Window::input(event);
2021-08-16 20:54:03 +02:00
}
void BPMCalculatorWidget::update(const sf::Time& dt)
2021-08-16 20:54:03 +02:00
{
Window::update(dt);
2021-08-16 20:54:03 +02:00
}
2021-08-21 14:29:58 +02:00
void BPMCalculatorWidget::draw(sf::RenderTarget& target, sf::RenderStates states) const
2021-08-16 20:54:03 +02:00
{
Window::draw(target, states);
if (_is_visible)
_slider->draw(target, states);
2021-08-16 20:54:03 +02:00
}
2021-08-21 14:29:58 +02:00
void BPMCalculatorWidget::setRect(const sf::FloatRect& rect)
2021-08-16 20:54:03 +02:00
{
Window::setRect(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});
2021-08-16 20:54:03 +02:00
}
void BPMCalculatorWidget::move(const sf::Vector2f &delta)
2021-08-16 20:54:03 +02:00
{
Window::move(delta);
_slider->move(delta);
2021-08-16 20:54:03 +02:00
}
void BPMCalculatorWidget::setPosition(const sf::Vector2f &position)
2021-08-16 20:54:03 +02:00
{
Window::setPosition(position);
_slider->setPosition(position);
2021-08-16 20:54:03 +02:00
}