2020-11-09 07:40:35 -03:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
|
*
|
2021-04-22 05:24:48 -03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-11-09 07:40:35 -03:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "Game.h"
|
|
|
|
|
#include <LibGUI/Application.h>
|
2020-11-10 10:25:45 -03:00
|
|
|
#include <LibGUI/Icon.h>
|
2020-11-10 10:31:14 -03:00
|
|
|
#include <LibGUI/Menu.h>
|
2021-04-13 11:18:20 -03:00
|
|
|
#include <LibGUI/Menubar.h>
|
2020-11-09 07:40:35 -03:00
|
|
|
#include <LibGUI/Window.h>
|
2020-11-10 10:25:45 -03:00
|
|
|
#include <LibGfx/Bitmap.h>
|
2021-03-12 13:29:37 -03:00
|
|
|
#include <unistd.h>
|
2020-11-09 07:40:35 -03:00
|
|
|
|
|
|
|
|
int main(int argc, char** argv)
|
|
|
|
|
{
|
2021-05-13 18:20:26 -03:00
|
|
|
if (pledge("stdio recvfd sendfd rpath unix", nullptr) < 0) {
|
2020-12-15 08:16:33 -03:00
|
|
|
perror("pledge");
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-09 07:40:35 -03:00
|
|
|
auto app = GUI::Application::construct(argc, argv);
|
2020-12-15 08:16:33 -03:00
|
|
|
|
2021-01-16 13:42:31 -03:00
|
|
|
if (pledge("stdio recvfd sendfd rpath", nullptr) < 0) {
|
2020-12-15 08:16:33 -03:00
|
|
|
perror("pledge");
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (unveil("/res", "r") < 0) {
|
|
|
|
|
perror("unveil");
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (unveil(nullptr, nullptr) < 0) {
|
|
|
|
|
perror("unveil");
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-09 07:40:35 -03:00
|
|
|
auto window = GUI::Window::construct();
|
|
|
|
|
window->resize(Breakout::Game::game_width, Breakout::Game::game_height);
|
2020-12-19 18:50:48 -03:00
|
|
|
window->set_resizable(false);
|
|
|
|
|
window->set_double_buffering_enabled(false);
|
|
|
|
|
window->set_title("Breakout");
|
2020-11-10 10:25:45 -03:00
|
|
|
auto app_icon = GUI::Icon::default_icon("app-breakout");
|
|
|
|
|
window->set_icon(app_icon.bitmap_for_size(16));
|
2020-12-19 18:50:48 -03:00
|
|
|
auto& game = window->set_main_widget<Breakout::Game>();
|
2020-11-10 10:31:14 -03:00
|
|
|
|
2021-07-21 16:21:03 -03:00
|
|
|
auto& game_menu = window->add_menu("&Game");
|
2021-05-01 05:45:39 -03:00
|
|
|
game_menu.add_action(GUI::Action::create_checkable("&Pause", { {}, Key_P }, [&](auto& action) {
|
2020-12-19 18:50:48 -03:00
|
|
|
game.set_paused(action.is_checked());
|
|
|
|
|
}));
|
|
|
|
|
|
2021-05-01 05:45:39 -03:00
|
|
|
game_menu.add_separator();
|
2020-12-19 18:50:48 -03:00
|
|
|
|
2021-05-01 05:45:39 -03:00
|
|
|
game_menu.add_action(GUI::CommonActions::make_quit_action([](auto&) {
|
2020-11-10 10:31:14 -03:00
|
|
|
GUI::Application::the()->quit();
|
|
|
|
|
}));
|
|
|
|
|
|
2021-07-21 16:21:03 -03:00
|
|
|
auto& help_menu = window->add_menu("&Help");
|
2021-01-04 19:51:49 -03:00
|
|
|
help_menu.add_action(GUI::CommonActions::make_about_action("Breakout", app_icon, window));
|
2020-11-10 10:31:14 -03:00
|
|
|
|
2021-07-28 06:38:04 -03:00
|
|
|
window->show();
|
|
|
|
|
|
2020-11-09 07:40:35 -03:00
|
|
|
return app->exec();
|
|
|
|
|
}
|