project-kyoku/src/gui/editor.cpp

53 lines
1.1 KiB
C++
Raw Normal View History

2021-08-12 15:10:52 -04:00
#include "editor.h"
#include "widgets/button.h"
#include "widgets/group.h"
2021-08-16 14:54:03 -04:00
#include "widgets/menubar.h"
2021-08-12 15:10:52 -04:00
#include "tools/bpmcalculator.h"
#include <iostream>
Editor::Editor(sf::RenderWindow& game_window, Callbacks&& callbacks, std::unique_ptr<Music>&& music) :
2021-08-16 14:54:03 -04:00
_menu_bar(std::make_shared<MenuBar>()),
2021-08-12 15:10:52 -04: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 14:54:03 -04:00
//const float window_height = game_window.getSize().y;
2021-08-12 15:10:52 -04:00
2021-08-16 14:54:03 -04:00
_menu_bar->setRect(sf::FloatRect(0, 0, window_width, 27));
2021-08-12 15:10:52 -04:00
}
void Editor::input(const sf::Event& event)
{
2021-08-16 14:54:03 -04:00
_menu_bar->input(event);
2021-08-12 15:10:52 -04: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 14:54:03 -04:00
_menu_bar->update();
2021-08-12 15:10:52 -04:00
}
void Editor::draw() const
{
2021-08-16 14:54:03 -04:00
_game_window.draw(*_menu_bar);
2021-08-12 15:10:52 -04:00
}
void Editor::enter()
{
2021-08-16 14:54:03 -04:00
_menu_bar->setVisibility();
2021-08-12 15:10:52 -04:00
}
void Editor::leave()
{
2021-08-16 14:54:03 -04:00
_menu_bar->setVisibility(false);
2021-08-12 15:10:52 -04:00
}