diff options
author | MacDue <macdue@dueutil.tech> | 2022-08-24 21:27:17 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-08-25 13:42:17 +0200 |
commit | b609dd73482278b6ad80eef4f81a7f8d3d6ba650 (patch) | |
tree | b6858bda9a953b0db3ac5246aa4ea0603ba0bf6b | |
parent | 21358d8a5f7daf14b71e0f53a54c7e65db6d373e (diff) | |
download | serenity-b609dd73482278b6ad80eef4f81a7f8d3d6ba650.zip |
Eyes: Add an option to show/hide the window frame
This works the same as in the Cube demo, and now allows enjoying
the eyes without any obstructions :^)
The window frame can now be disabled with the -h/--hide-window
command-line option, or via toggle in the GUI.
-rw-r--r-- | Userland/Demos/Eyes/EyesWidget.h | 9 | ||||
-rw-r--r-- | Userland/Demos/Eyes/main.cpp | 25 |
2 files changed, 33 insertions, 1 deletions
diff --git a/Userland/Demos/Eyes/EyesWidget.h b/Userland/Demos/Eyes/EyesWidget.h index 6f64c2fa12..62792298eb 100644 --- a/Userland/Demos/Eyes/EyesWidget.h +++ b/Userland/Demos/Eyes/EyesWidget.h @@ -18,6 +18,15 @@ class EyesWidget final : public GUI::Widget public: virtual ~EyesWidget() override = default; + Function<void(GUI::ContextMenuEvent&)> on_context_menu_request; + +protected: + virtual void context_menu_event(GUI::ContextMenuEvent& event) override + { + if (on_context_menu_request) + on_context_menu_request(event); + } + private: EyesWidget(int num_eyes, int full_rows, int extra) : m_full_rows(full_rows) diff --git a/Userland/Demos/Eyes/main.cpp b/Userland/Demos/Eyes/main.cpp index 72b8a47109..44e5e55683 100644 --- a/Userland/Demos/Eyes/main.cpp +++ b/Userland/Demos/Eyes/main.cpp @@ -26,11 +26,14 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) int grid_rows = -1; int grid_columns = -1; + bool hide_window_frame = false; + Core::ArgsParser args_parser; args_parser.add_option(num_eyes, "Number of eyes", "num-eyes", 'n', "number"); args_parser.add_option(max_in_row, "Maximum number of eyes in a row", "max-in-row", 'm', "number"); args_parser.add_option(grid_rows, "Number of rows in grid (incompatible with --number)", "grid-rows", 'r', "number"); args_parser.add_option(grid_columns, "Number of columns in grid (incompatible with --number)", "grid-cols", 'c', "number"); + args_parser.add_option(hide_window_frame, "Hide window frame", "hide-window", 'h'); args_parser.parse(arguments); TRY(Core::System::pledge("stdio recvfd sendfd rpath unix cpath wpath thread")); @@ -66,9 +69,24 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) window->resize(75 * (full_rows > 0 ? max_in_row : extra_columns), 100 * (full_rows + (extra_columns > 0 ? 1 : 0))); window->set_has_alpha_channel(true); - (void)TRY(window->try_set_main_widget<EyesWidget>(num_eyes, full_rows, extra_columns)); + bool window_frame_enabled = true; + auto set_window_frame_enabled = [&](bool enable) { + if (enable == window_frame_enabled) + return; + window_frame_enabled = enable; + window->set_frameless(!window_frame_enabled); + window->set_alpha_hit_threshold(window_frame_enabled ? 0 : 1); + }; + + auto show_window_frame_action = GUI::Action::create_checkable("Show Window &Frame", [&](auto& action) { + set_window_frame_enabled(action.is_checked()); + }); + set_window_frame_enabled(!hide_window_frame); + show_window_frame_action->set_checked(window_frame_enabled); auto file_menu = TRY(window->try_add_menu("&File")); + TRY(file_menu->try_add_action(move(show_window_frame_action))); + TRY(file_menu->try_add_separator()); TRY(file_menu->try_add_action(GUI::CommonActions::make_quit_action([&](auto&) { app->quit(); }))); auto help_menu = TRY(window->try_add_menu("&Help")); @@ -77,6 +95,11 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) }))); TRY(help_menu->try_add_action(GUI::CommonActions::make_about_action("Eyes Demo", app_icon, window))); + auto eyes_widget = TRY(window->try_set_main_widget<EyesWidget>(num_eyes, full_rows, extra_columns)); + eyes_widget->on_context_menu_request = [&](auto& event) { + file_menu->popup(event.screen_position()); + }; + window->show(); return app->exec(); |