|
|
|
@ -1,5 +1,6 @@
|
|
|
|
|
#include "bpmcalculatorwidget.h"
|
|
|
|
|
#include "tools/bpmcalculator.h"
|
|
|
|
|
#include "core/editor.h"
|
|
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
|
@ -70,6 +71,7 @@ void BPMCalculatorWidget::draw(sf::RenderTarget& target, sf::RenderStates states
|
|
|
|
|
_slider->draw(target, states);
|
|
|
|
|
_button_start->draw(target, states);
|
|
|
|
|
_button_stop->draw(target, states);
|
|
|
|
|
_button_apply->draw(target, states);
|
|
|
|
|
target.draw(_bpm_value, states);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -89,6 +91,10 @@ void BPMCalculatorWidget::setRect(const sf::FloatRect& rect)
|
|
|
|
|
_button_stop->setPosition({_window_content.getGlobalBounds().left + rect.width / 7,
|
|
|
|
|
_window_content.getGlobalBounds().top + _window_content.getGlobalBounds().height - 40});
|
|
|
|
|
|
|
|
|
|
_button_apply->setRect(sf::FloatRect{0, 0, rect.width / 10 * 3, 30});
|
|
|
|
|
_button_apply->setPosition({_window_content.getGlobalBounds().left + 20 + (2 * (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 });
|
|
|
|
|
}
|
|
|
|
@ -105,12 +111,13 @@ void BPMCalculatorWidget::setPosition(const sf::Vector2f &position)
|
|
|
|
|
Window::setPosition(position);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BPMCalculatorWidget::init()
|
|
|
|
|
void BPMCalculatorWidget::init(const std::unique_ptr<Editor>& _editor)
|
|
|
|
|
{
|
|
|
|
|
auto& bpm_calculator = _bpm_calculator;
|
|
|
|
|
|
|
|
|
|
_button_start = std::make_shared<PushButton>("Start", _font);
|
|
|
|
|
_button_stop = std::make_shared<PushButton>("Stop", _font);
|
|
|
|
|
_button_apply = std::make_shared<PushButton>("Apply", _font);
|
|
|
|
|
|
|
|
|
|
_button_start->setCallback([bpm_calculator, button_start=_button_start, button_stop=_button_stop]()
|
|
|
|
|
{
|
|
|
|
@ -128,8 +135,19 @@ void BPMCalculatorWidget::init()
|
|
|
|
|
button_stop->setVisibility(false);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
_button_apply->setCallback([&_editor, bpm_calculator]()
|
|
|
|
|
{
|
|
|
|
|
BPMSection section;
|
|
|
|
|
section.bpm = bpm_calculator->fetchApproximatedInfo().BPM;
|
|
|
|
|
section.fraction = 2;
|
|
|
|
|
section.offset_start = bpm_calculator->getStartingOffset();
|
|
|
|
|
|
|
|
|
|
_editor->insertBPMSection(std::move(section));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
addChild(_button_start);
|
|
|
|
|
addChild(_button_stop);
|
|
|
|
|
addChild(_button_apply);
|
|
|
|
|
|
|
|
|
|
_button_stop->setVisibility(false);
|
|
|
|
|
}
|
|
|
|
@ -139,6 +157,6 @@ void BPMCalculatorWidget::setVisibility(bool is_visible)
|
|
|
|
|
Window::setVisibility(is_visible);
|
|
|
|
|
|
|
|
|
|
bool can_stop = _bpm_calculator->calculating();
|
|
|
|
|
_button_stop->setVisibility(can_stop);
|
|
|
|
|
_button_start->setVisibility(!can_stop);
|
|
|
|
|
_button_stop->setVisibility(can_stop && is_visible);
|
|
|
|
|
_button_start->setVisibility(!can_stop && is_visible);
|
|
|
|
|
}
|
|
|
|
|