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/application/mainmenu.cpp

51 lines
1.4 KiB
C++

#include "mainmenu.h"
#include "widgets/pushbutton.h"
#include "widgets/group.h"
MainMenu::MainMenu(Callbacks&& callbacks, const FontHolder& font_holder) :
_font(font_holder.get(Fonts::Id::GUI)),
_callbacks(std::move(callbacks)),
_buttons(std::make_shared<Group>())
{
}
void MainMenu::input(const sf::Event& event)
{
_buttons->input(event);
}
void MainMenu::update(const sf::Time& dt)
{
_buttons->update(dt);
}
void MainMenu::draw(sf::RenderTarget &target, sf::RenderStates states) const
{
target.draw(*_buttons, states);
}
void MainMenu::enter(sf::Vector2u&& render_size)
{
const float window_width = render_size.x;
const float window_height = render_size.y;
auto button_start = std::make_shared<PushButton>("Start", _font, 48);
button_start->setRect(sf::FloatRect(window_width / 3., window_height / 7., window_width / 3., window_height / 7.));
button_start->setCallback(_callbacks.onAppendGameState);
auto button_editor = std::make_shared<PushButton>("Editor", _font, 48);
button_editor->setRect(sf::FloatRect(window_width / 3., window_height / 7. * 3, window_width / 3., window_height / 7.));
button_editor->setCallback(_callbacks.onAppendEditorState);
_buttons->addChild(button_start);
_buttons->addChild(button_editor);
_buttons->setVisibility();
}
void MainMenu::leave()
{
_buttons->setVisibility(false);
}