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/editor.cpp

62 lines
1.4 KiB
C++

#include "editor.h"
#include "widgets/button.h"
#include "widgets/group.h"
#include "tools/bpmcalculator.h"
#include <iostream>
Editor::Editor(sf::RenderWindow& game_window, Callbacks&& callbacks, std::unique_ptr<Music>&& music) :
_buttons(std::make_shared<Group>()),
_game_window(game_window),
_music(std::move(music)),
_bpm_calculator(std::make_unique<BPMCalculator>(_music))
{
(void)callbacks;
const float window_width = game_window.getSize().x;
const float window_height = game_window.getSize().y;
_music->openFromFile("Uta-test.flac");
_music->setVolume(20);
std::shared_ptr<Button> button_start = std::make_shared<Button>("Start");
button_start->setRect(sf::FloatRect(window_width / 3., window_height / 7. * 2, window_width / 3., window_height / 7.));
button_start->setCallback([&]()
{
_bpm_calculator->startListening(0);
});
_buttons->addChild(button_start);
}
void Editor::input(const sf::Event& event)
{
_buttons->input(event);
if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Space)
{
_bpm_calculator->click();
std::cout << _bpm_calculator->getCurrentApproximation() << '\n';
}
}
void Editor::update()
{
_buttons->update();
}
void Editor::draw() const
{
_game_window.draw(*_buttons);
}
void Editor::enter()
{
_buttons->setVisibility();
}
void Editor::leave()
{
_buttons->setVisibility(false);
}