2021-08-21 14:29:58 +02:00
|
|
|
#include "bpmcalculatorwidget.h"
|
2021-08-27 19:40:48 +02:00
|
|
|
#include "tools/bpmcalculator.h"
|
2021-08-16 20:54:03 +02:00
|
|
|
|
2021-08-27 19:40:48 +02:00
|
|
|
BPMCalculatorWidget::BPMCalculatorWidget(const std::shared_ptr<BPMCalculator>& bpm_calculator, const std::shared_ptr<sf::Font>& font) :
|
|
|
|
_bpm_calculator(bpm_calculator),
|
|
|
|
_slider(std::make_shared<BPMSlider>(font))
|
2021-08-16 20:54:03 +02:00
|
|
|
{
|
2021-08-27 19:40:48 +02:00
|
|
|
_widget_window.setFillColor(sf::Color(88, 57, 107));
|
|
|
|
//addChild(_slider);
|
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;
|
|
|
|
|
2021-08-27 19:40:48 +02:00
|
|
|
case sf::Event::KeyPressed:
|
|
|
|
if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Space)
|
2021-08-16 20:54:03 +02:00
|
|
|
{
|
2021-08-27 19:40:48 +02:00
|
|
|
_bpm_calculator->click();
|
2021-08-16 20:54:03 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget::input(event);
|
|
|
|
}
|
|
|
|
|
2021-08-27 19:40:48 +02:00
|
|
|
void BPMCalculatorWidget::update(const sf::Time& dt)
|
2021-08-16 20:54:03 +02:00
|
|
|
{
|
2021-08-27 19:40:48 +02:00
|
|
|
Widget::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
|
|
|
{
|
2021-08-27 19:40:48 +02:00
|
|
|
if (_is_visible)
|
|
|
|
{
|
|
|
|
target.draw(_widget_window, states);
|
|
|
|
Widget::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
|
|
|
{
|
2021-08-27 19:40:48 +02:00
|
|
|
_widget_window.setPosition(rect.left, rect.top);
|
|
|
|
_widget_window.setSize({rect.width, rect.height});
|
|
|
|
_slider->setRect(sf::FloatRect{rect.width / 3, rect.height / 2 - 50, rect.width / 3, 100});
|
2021-08-16 20:54:03 +02:00
|
|
|
}
|
|
|
|
|
2021-08-21 14:29:58 +02:00
|
|
|
void BPMCalculatorWidget::setPosition(const sf::Vector2f &position)
|
2021-08-16 20:54:03 +02:00
|
|
|
{
|
2021-08-27 19:40:48 +02:00
|
|
|
_widget_window.setPosition(position);
|
|
|
|
_slider->setRect(sf::FloatRect{_widget_window.getSize().x / 3,
|
|
|
|
_widget_window.getSize().y / 2 - 50,
|
|
|
|
_widget_window.getSize().x / 3, 100});
|
2021-08-16 20:54:03 +02:00
|
|
|
}
|
|
|
|
|
2021-08-21 14:29:58 +02:00
|
|
|
bool BPMCalculatorWidget::isUnderMouse(int mouse_x, int mouse_y) const
|
2021-08-16 20:54:03 +02:00
|
|
|
{
|
2021-08-27 19:40:48 +02:00
|
|
|
return _is_visible && _widget_window.getGlobalBounds().contains(mouse_x, mouse_y);
|
2021-08-16 20:54:03 +02:00
|
|
|
}
|