You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
project-kyoku/src/gui/widgets/bpmcalculatorwidget.cpp

63 lines
1.7 KiB
C++

#include "bpmcalculatorwidget.h"
#include "tools/bpmcalculator.h"
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))
{
_widget_window.setFillColor(sf::Color(88, 57, 107));
//addChild(_slider);
}
void BPMCalculatorWidget::input(const sf::Event& event)
{
switch (event.type)
{
default:
break;
case sf::Event::KeyPressed:
if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Space)
{
_bpm_calculator->click();
}
break;
}
Widget::input(event);
}
void BPMCalculatorWidget::update(const sf::Time& dt)
{
Widget::update(dt);
}
void BPMCalculatorWidget::draw(sf::RenderTarget& target, sf::RenderStates states) const
{
if (_is_visible)
{
target.draw(_widget_window, states);
Widget::draw(target, states);
}
}
void BPMCalculatorWidget::setRect(const sf::FloatRect& rect)
{
_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});
}
void BPMCalculatorWidget::setPosition(const sf::Vector2f &position)
{
_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});
}
bool BPMCalculatorWidget::isUnderMouse(int mouse_x, int mouse_y) const
{
return _is_visible && _widget_window.getGlobalBounds().contains(mouse_x, mouse_y);
}