project-kyoku/src/gui/editor.cpp

72 lines
1.8 KiB
C++
Raw Normal View History

2021-08-12 21:10:52 +02:00
#include "editor.h"
#include "widgets/button.h"
#include "widgets/group.h"
2021-08-16 20:54:03 +02:00
#include "widgets/menubar.h"
2021-08-12 21:10:52 +02:00
#include "tools/bpmcalculator.h"
#include <iostream>
Editor::Editor(sf::RenderWindow& game_window, Callbacks&& callbacks, std::unique_ptr<Music>&& music) :
2021-08-16 20:54:03 +02:00
_menu_bar(std::make_shared<MenuBar>()),
2021-08-12 21:10:52 +02:00
_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;
2021-08-16 20:54:03 +02:00
//const float window_height = game_window.getSize().y;
2021-08-12 21:10:52 +02:00
auto bpm_button = std::make_shared<PushButton>("Calculate BPM");
bpm_button->setCallback([&]()
{
_bpm_calculator->startListening(0);
});
auto quit_button = std::make_shared<PushButton>("Quit");
quit_button->setCallback(callbacks.onLeaveEditorState);
auto test_menu = std::make_shared<MenuDrop>();
test_menu->setRect(sf::FloatRect{0, 0, 200, 27});
2021-08-16 20:54:03 +02:00
_menu_bar->setRect(sf::FloatRect(0, 0, window_width, 27));
_menu_bar->addSubMenu("test", test_menu);
test_menu->addPushButton(bpm_button);
test_menu->addPushButton(quit_button);
_music->openFromFile("Uta-test.flac");
_music->setVolume(5);
2021-08-12 21:10:52 +02:00
}
void Editor::input(const sf::Event& event)
{
2021-08-16 20:54:03 +02:00
_menu_bar->input(event);
2021-08-12 21:10:52 +02:00
if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Space)
{
_bpm_calculator->click();
std::cout << _bpm_calculator->getCurrentApproximation() << '\n';
}
}
void Editor::update()
{
2021-08-16 20:54:03 +02:00
_menu_bar->update();
2021-08-12 21:10:52 +02:00
}
void Editor::draw() const
{
2021-08-16 20:54:03 +02:00
_game_window.draw(*_menu_bar);
2021-08-12 21:10:52 +02:00
}
void Editor::enter()
{
2021-08-16 20:54:03 +02:00
_menu_bar->setVisibility();
2021-08-12 21:10:52 +02:00
}
void Editor::leave()
{
2021-08-16 20:54:03 +02:00
_menu_bar->setVisibility(false);
2021-08-12 21:10:52 +02:00
}