2020-03-09 18:09:22 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2020, Till Mayer <till.mayer@web.de>
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
|
|
* list of conditions and the following disclaimer.
|
|
|
|
*
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer in the documentation
|
|
|
|
* and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
|
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
|
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "SolitaireWidget.h"
|
|
|
|
#include <LibGUI/Action.h>
|
|
|
|
#include <LibGUI/Application.h>
|
2020-11-01 00:58:52 +03:00
|
|
|
#include <LibGUI/Icon.h>
|
2020-03-09 18:09:22 +03:00
|
|
|
#include <LibGUI/Menu.h>
|
|
|
|
#include <LibGUI/MenuBar.h>
|
|
|
|
#include <LibGUI/Window.h>
|
|
|
|
#include <stdio.h>
|
2020-10-15 13:26:33 +03:00
|
|
|
#include <unistd.h>
|
2020-03-09 18:09:22 +03:00
|
|
|
|
|
|
|
int main(int argc, char** argv)
|
|
|
|
{
|
2020-07-04 15:05:19 +03:00
|
|
|
auto app = GUI::Application::construct(argc, argv);
|
2020-11-01 00:58:52 +03:00
|
|
|
auto app_icon = GUI::Icon::default_icon("app-solitaire");
|
2020-03-09 18:09:22 +03:00
|
|
|
|
2021-01-16 19:42:31 +03:00
|
|
|
if (pledge("stdio recvfd sendfd rpath", nullptr) < 0) {
|
2020-03-09 18:09:22 +03:00
|
|
|
perror("pledge");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2020-11-01 23:16:45 +03:00
|
|
|
if (unveil("/res", "r") < 0) {
|
|
|
|
perror("unveil");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (unveil(nullptr, nullptr) < 0) {
|
|
|
|
perror("unveil");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2020-03-09 18:09:22 +03:00
|
|
|
auto window = GUI::Window::construct();
|
|
|
|
|
|
|
|
window->set_resizable(false);
|
Misc: Use automatic window positioning in more applications
This is a follow up to #2936 / d3e3b4ae56aa79d9bde12ca1f143dcf116f89a4c.
Affected programs:
- Applications: Browser (Download, View source, Inspect DOM tree, JS
console), Terminal (Settings)
- Demos: Cube, Eyes, Fire, HelloWorld, LibGfxDemo, WebView,
WidgetGallery
- DevTools: HackStudio, Inspector, Profiler
- Games: 2048, Minesweeper, Snake, Solitaire
- Userland: test-web
A few have been left out where manual positioning is done on purpose,
e.g. ClipboardManager (to be close to the menu bar) or VisualBuilder (to
preserve alignment of the multiple application windows).
2020-08-15 18:24:05 +03:00
|
|
|
window->resize(SolitaireWidget::width, SolitaireWidget::height);
|
2020-03-09 18:09:22 +03:00
|
|
|
|
|
|
|
auto widget = SolitaireWidget::construct(window, [&](uint32_t score) {
|
2020-10-15 13:26:33 +03:00
|
|
|
window->set_title(String::formatted("Score: {} - Solitaire", score));
|
2020-03-09 18:09:22 +03:00
|
|
|
});
|
|
|
|
|
2020-04-21 17:01:00 +03:00
|
|
|
auto menubar = GUI::MenuBar::construct();
|
2021-03-25 23:41:39 +03:00
|
|
|
auto& app_menu = menubar->add_menu("Game");
|
2020-03-09 18:09:22 +03:00
|
|
|
|
2020-08-17 14:26:38 +03:00
|
|
|
app_menu.add_action(GUI::Action::create("New game", { Mod_None, Key_F2 }, [&](auto&) {
|
|
|
|
widget->setup();
|
|
|
|
}));
|
2020-04-04 13:18:40 +03:00
|
|
|
app_menu.add_separator();
|
2020-07-04 15:05:19 +03:00
|
|
|
app_menu.add_action(GUI::CommonActions::make_quit_action([&](auto&) { app->quit(); }));
|
2020-03-13 00:53:37 +03:00
|
|
|
|
2020-04-04 13:18:40 +03:00
|
|
|
auto& help_menu = menubar->add_menu("Help");
|
2021-01-05 01:51:49 +03:00
|
|
|
help_menu.add_action(GUI::CommonActions::make_about_action("Solitaire", app_icon, window));
|
2020-03-13 00:53:37 +03:00
|
|
|
|
2021-03-25 23:41:39 +03:00
|
|
|
window->set_menubar(move(menubar));
|
2020-03-09 18:09:22 +03:00
|
|
|
window->set_main_widget(widget);
|
2020-11-01 00:58:52 +03:00
|
|
|
window->set_icon(app_icon.bitmap_for_size(16));
|
2020-03-09 18:09:22 +03:00
|
|
|
window->show();
|
|
|
|
widget->setup();
|
|
|
|
|
2020-07-04 15:05:19 +03:00
|
|
|
return app->exec();
|
2020-03-09 18:09:22 +03:00
|
|
|
}
|