/
Kotopeska
/
RiseUpGame
Обзор
Документация
Войти
/
Kotopeska
/
RiseUpGame
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
view/MenuView.cpp
99 строк
3 KB
Kotopeska
init
18 май 2025, 19:03
18 май 2025, 19:03
668dfef
Код
Авторство
О чём код?
#include "MenuView.h" #include <FL/fl_draw.H> #include <FL/Fl.H> namespace View { MenuView::MenuView(int x, int y, int w, int h, Model::GameModel &model) : ViewBase(x, y, w, h, model), titleBox(std::make_unique<Fl_Box>(x + w / 2 - 150, y + h / 4, 300, 50, "RISE UP")), startButton(std::make_unique<Fl_Button>(x + w / 2 - 100, y + h / 2, 200, 40, "New Game")), aboutButton(std::make_unique<Fl_Button>(x + w / 2 - 100, y + h / 2 + 50, 200, 40, "About")), exitButton(std::make_unique<Fl_Button>(x + w / 2 - 100, y + h / 2 + 100, 200, 40, "Exit")) { titleBox->box(FL_NO_BOX); titleBox->labelsize(40); titleBox->labelfont(FL_HELVETICA_BOLD); titleBox->labelcolor(FL_WHITE); startButton->callback(startCallback, &model); startButton->color(fl_rgb_color(64, 156, 255)); startButton->labelcolor(FL_WHITE); startButton->labelfont(FL_HELVETICA_BOLD); aboutButton->callback(aboutCallback, &model); aboutButton->color(fl_rgb_color(64, 156, 255)); aboutButton->labelcolor(FL_WHITE); aboutButton->labelfont(FL_HELVETICA_BOLD); exitButton->callback(exitCallback, nullptr); exitButton->color(fl_rgb_color(255, 64, 64)); exitButton->labelcolor(FL_WHITE); exitButton->labelfont(FL_HELVETICA_BOLD); add(titleBox.get()); add(startButton.get()); add(aboutButton.get()); add(exitButton.get()); } MenuView::~MenuView() { } void MenuView::update() { redraw(); } void MenuView::draw() { ViewBase::drawBackground(); draw_children(); } int MenuView::handle(int event) { switch (event) { case FL_KEYDOWN: if (Fl::event_key() == ' ' || Fl::event_key() == 32) { model.startGame(); return 1; } break; } return ViewBase::handle(event); } void MenuView::startCallback(Fl_Widget *widget, void *data) { Model::GameModel *model = static_cast<Model::GameModel *>(data); model->startGame(); } void MenuView::aboutCallback(Fl_Widget *widget, void *data) { Model::GameModel *model = static_cast<Model::GameModel *>(data); model->showAbout(); } void MenuView::exitCallback(Fl_Widget *widget, void *data) { exit(0); } void MenuView::fullscreenCallback(Fl_Widget *widget, void *data) { Fl::e_keysym = FL_F + 11; Fl::handle(FL_KEYDOWN, nullptr); } } // namespace View