42 lines
1009 B
C++
42 lines
1009 B
C++
|
#include "mainmenu.h"
|
||
|
#include "widgets/button.h"
|
||
|
#include "widgets/group.h"
|
||
|
|
||
|
MainMenu::MainMenu(sf::RenderWindow& game_window) :
|
||
|
_buttons(std::make_shared<Group>()),
|
||
|
_game_window(game_window)
|
||
|
{
|
||
|
std::shared_ptr<Button> button_start = std::make_shared<Button>("Start");
|
||
|
button_start->setRect(sf::FloatRect(140, 140, 500, 100));
|
||
|
button_start->setCallback([&]()
|
||
|
{
|
||
|
_game_window.close();
|
||
|
});
|
||
|
|
||
|
std::shared_ptr<Button> button_exit = std::make_shared<Button>("Exit");
|
||
|
button_exit->setRect(sf::FloatRect(140, 140, 400, 100));
|
||
|
button_exit->setPosition({240, 340});
|
||
|
button_exit->setCallback([&]()
|
||
|
{
|
||
|
_game_window.close();
|
||
|
});
|
||
|
|
||
|
_buttons->addChild(button_start);
|
||
|
_buttons->addChild(button_exit);
|
||
|
}
|
||
|
|
||
|
void MainMenu::input(const sf::Event& event)
|
||
|
{
|
||
|
_buttons->input(event);
|
||
|
}
|
||
|
|
||
|
void MainMenu::update()
|
||
|
{
|
||
|
_buttons->update();
|
||
|
}
|
||
|
|
||
|
void MainMenu::draw(sf::RenderTarget& target, sf::RenderStates states) const
|
||
|
{
|
||
|
target.draw(*_buttons, states);
|
||
|
}
|