diff options
| author | Felix Morgner <felix.morgner@gmail.com> | 2025-05-24 11:58:39 +0200 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@gmail.com> | 2025-05-24 11:58:39 +0200 |
| commit | 72ab1fb4c1bf363f46470816d8b914a78ac493c4 (patch) | |
| tree | 27349a1bacbab4ea698be35d2d3d9b5184b15ca1 /gui/include | |
| parent | b7f2ff4d991ae068f7834bf8e565f6261bf7fff1 (diff) | |
| download | turns-72ab1fb4c1bf363f46470816d8b914a78ac493c4.tar.xz turns-72ab1fb4c1bf363f46470816d8b914a78ac493c4.zip | |
gui: restructure file layout and apply licenses
Diffstat (limited to 'gui/include')
| -rw-r--r-- | gui/include/messages.hpp | 54 | ||||
| -rw-r--r-- | gui/include/participant_editor.hpp | 87 | ||||
| -rw-r--r-- | gui/include/participant_row.hpp | 55 | ||||
| -rw-r--r-- | gui/include/preferences.hpp | 58 | ||||
| -rw-r--r-- | gui/include/settings.hpp | 26 | ||||
| -rw-r--r-- | gui/include/template_widget.hpp | 72 | ||||
| -rw-r--r-- | gui/include/tracker.hpp | 109 | ||||
| -rw-r--r-- | gui/include/turn_order_view.hpp | 45 |
8 files changed, 506 insertions, 0 deletions
diff --git a/gui/include/messages.hpp b/gui/include/messages.hpp new file mode 100644 index 0000000..e29580b --- /dev/null +++ b/gui/include/messages.hpp @@ -0,0 +1,54 @@ +/* + * SPDX-FileCopyrightText: 2025 Felix Morgner <felix.morgner@gmail.com> + * SPDX-License-Identifier: LGPL-2.1-only + */ + +#ifndef TURNS_LANG_MESSAGES_HPP +#define TURNS_LANG_MESSAGES_HPP + +namespace turns::lang +{ + auto constexpr static add_participant = "Add participant"; + auto constexpr static cancel = "Cancel"; + auto constexpr static clear = "_Clear"; + auto constexpr static delete_participant = "Delete participant"; + auto constexpr static disposition = "Disposition"; + auto constexpr static disposition_colors = "Disposition Colors"; + auto constexpr static edit_participant = "Edit participant"; + auto constexpr static end_turn_order = "End turn order"; + auto constexpr static finish = "Finish"; + auto constexpr static flow = "Flow"; + auto constexpr static friendly = "Friendly"; + auto constexpr static hostile = "Hostile"; + auto constexpr static main_menu = "Main Menu"; + auto constexpr static mark_as_defeated = "Mark as defeated"; + auto constexpr static name = "Name"; + auto constexpr static new_turn_order_file_name = "New turn order.trns"; + auto constexpr static next_participant = "Next participant"; + auto constexpr static no_active_turn_order = "No active turn order"; + auto constexpr static open = "_Open..."; + auto constexpr static preferences = "Preferences"; + auto constexpr static preferences_mnemonic = "_Preferences"; + auto constexpr static previous_participant = "Previous participant"; + auto constexpr static priority = "Priority"; + auto constexpr static priority_number = "Priority {}"; + auto constexpr static question_clear_turn_order = "Do you want to clear the turn order?"; + auto constexpr static quit = "_Quit"; + auto constexpr static reset = "Reset"; + auto constexpr static round_number = "Round {}"; + auto constexpr static save = "_Save"; + auto constexpr static save_as = "Save as..."; + auto constexpr static saving_failed_format = "Saving failed: {}"; + auto constexpr static secret = "Secret"; + auto constexpr static skip_defeated = "Skip defeated"; + auto constexpr static start_turn_order = "Start turn order"; + auto constexpr static stop = "Stop"; + auto constexpr static stop_and_clear = "Stop and clear"; + auto constexpr static stop_turn_order = "Stop turn order"; + auto constexpr static successfully_opened_format = "Successfully opened '{}'"; + auto constexpr static successfully_saved_format = "Successfully saved '{}'"; + auto constexpr static turns = "Turns"; + auto constexpr static turns_files = "Turns Files"; +} // namespace turns::lang + +#endif
\ No newline at end of file diff --git a/gui/include/participant_editor.hpp b/gui/include/participant_editor.hpp new file mode 100644 index 0000000..39b721c --- /dev/null +++ b/gui/include/participant_editor.hpp @@ -0,0 +1,87 @@ +/* + * SPDX-FileCopyrightText: 2025 Felix Morgner <felix.morgner@gmail.com> + * SPDX-License-Identifier: LGPL-2.1-only + */ + +#ifndef TURNS_UI_PARTICIPANT_EDITOR_HPP +#define TURNS_UI_PARTICIPANT_EDITOR_HPP + +#include "turns/core/disposition.hpp" +#include "turns/core/fwd.hpp" +#include "turns/core/participant.hpp" +#include "turns/ui/template_widget.hpp" + +#include <sigc++/signal.h> + +#include <glibmm/property.h> +#include <glibmm/propertyproxy.h> +#include <glibmm/refptr.h> +#include <glibmm/ustring.h> + +#include <gtkmm/builder.h> +#include <gtkmm/button.h> +#include <gtkmm/listitem.h> +#include <gtkmm/signallistitemfactory.h> +#include <gtkmm/stringlist.h> +#include <gtkmm/widget.h> + +#include <adwaitamm/comborow.hpp> +#include <adwaitamm/dialog.hpp> +#include <adwaitamm/entryrow.hpp> +#include <adwaitamm/spinrow.hpp> + +#include <array> + +namespace turns::ui +{ + + struct ParticipantEditor : template_widget<ParticipantEditor, Adwaita::Dialog> + { + using SignalFinishedType = sigc::signal<void(Glib::ustring, float, core::Disposition)>; + + auto constexpr inline static children = std::array{ + "disposition", + "finish", + "name", + "priority", + }; + + explicit ParticipantEditor(Glib::RefPtr<core::Participant> participant); + + [[nodiscard]] auto get_disposition() const -> core::Disposition; + [[nodiscard]] auto get_name() const -> Glib::ustring; + [[nodiscard]] auto get_participant() const -> Glib::RefPtr<core::Participant>; + [[nodiscard]] auto get_priority() const -> double; + + auto set_disposition(core::Disposition value) -> void; + auto set_name(Glib::ustring const & value) -> void; + auto set_participant(Glib::RefPtr<core::Participant> const & value) -> void; + auto set_priority(double value) -> void; + + [[nodiscard]] auto property_participant() -> Glib::PropertyProxy<Glib::RefPtr<core::Participant>>; + [[nodiscard]] auto property_participant() const -> Glib::PropertyProxy_ReadOnly<Glib::RefPtr<core::Participant>>; + + auto signal_finished() -> SignalFinishedType; + + private: + auto handle_finish_clicked() -> void; + auto handle_item_bind(Glib::RefPtr<Gtk::ListItem> item) -> void; + auto handle_item_setup(Glib::RefPtr<Gtk::ListItem> item) -> void; + auto handle_participant_changed() -> void; + + Adwaita::ComboRow * m_disposition; + Gtk::Button * m_finish; + Adwaita::EntryRow * m_name; + Adwaita::SpinRow * m_priority; + + Glib::RefPtr<Gtk::SignalListItemFactory> m_disposition_factory; + Glib::RefPtr<Gtk::StringList> m_disposition_model; + + Glib::Property<Glib::RefPtr<core::Participant>> m_participant; + + SignalFinishedType m_signal_finished{}; + }; + +} // namespace turns::ui + +#endif
\ No newline at end of file diff --git a/gui/include/participant_row.hpp b/gui/include/participant_row.hpp new file mode 100644 index 0000000..81b3610 --- /dev/null +++ b/gui/include/participant_row.hpp @@ -0,0 +1,55 @@ +/* + * SPDX-FileCopyrightText: 2025 Felix Morgner <felix.morgner@gmail.com> + * SPDX-License-Identifier: LGPL-2.1-only + */ + +#ifndef TURNS_UI_PARTICIPANT_ROW_HPP +#define TURNS_UI_PARTICIPANT_ROW_HPP + +#include "turns/core/fwd.hpp" +#include "turns/ui/template_widget.hpp" + +#include <glibmm/property.h> +#include <glibmm/propertyproxy.h> +#include <glibmm/refptr.h> + +#include <gtkmm/button.h> +#include <gtkmm/label.h> +#include <gtkmm/listboxrow.h> +#include <gtkmm/togglebutton.h> + +#include <array> + +namespace turns::ui +{ + struct ParticipantRow : template_widget<ParticipantRow, Gtk::ListBoxRow> + { + auto constexpr inline static children = std::array{ + "delete", + "edit", + "subtitle", + "title", + "toggle_defeated", + }; + + ParticipantRow(Glib::RefPtr<core::Participant> participant); + + auto delete_enabled() -> Glib::PropertyProxy<bool>; + auto edit_enabled() -> Glib::PropertyProxy<bool>; + + private: + auto handle_delete() -> void; + auto handle_edit() -> void; + + Gtk::Button * m_delete; + Gtk::Button * m_edit; + Gtk::Label * m_subtitle; + Gtk::Label * m_title; + Gtk::ToggleButton * m_toggle_defeated; + + Glib::Property<bool> m_delete_enabled; + Glib::Property<bool> m_edit_enabled; + }; +} // namespace turns::ui::widgets + +#endif
\ No newline at end of file diff --git a/gui/include/preferences.hpp b/gui/include/preferences.hpp new file mode 100644 index 0000000..c5bace3 --- /dev/null +++ b/gui/include/preferences.hpp @@ -0,0 +1,58 @@ +/* + * SPDX-FileCopyrightText: 2025 Felix Morgner <felix.morgner@gmail.com> + * SPDX-License-Identifier: LGPL-2.1-only + */ + +#ifndef TURNS_UI_PREFERENCES_HPP +#define TURNS_UI_PREFERENCES_HPP + +#include "turns/ui/template_widget.hpp" + +#include <glibmm/refptr.h> +#include <glibmm/ustring.h> + +#include <giomm/settings.h> + +#include <gtkmm/button.h> +#include <gtkmm/colordialogbutton.h> + +#include <adwaitamm/preferencespage.hpp> +#include <adwaitamm/switchrow.hpp> + +#include <array> + +namespace turns::ui +{ + struct Preferences : template_widget<Preferences, Adwaita::PreferencesPage> + { + + auto constexpr inline static children = std::array{ + "friendly_reset_button", + "hostile_reset_button", + "secret_reset_button", + "friendly_color_button", + "hostile_color_button", + "secret_color_button", + "skip_defeated", + }; + + explicit Preferences(Glib::RefPtr<Gio::Settings> settings = {}); + + private: + auto bind_reset(Glib::ustring const & key, Gtk::Button * button) -> void; + auto bind_setting(Glib::ustring const & key, Gtk::ColorDialogButton * button) -> void; + auto update_sensitive(Glib::ustring const & key, Gtk::Button * button) -> void; + + Glib::RefPtr<Gio::Settings> m_settings; + + Gtk::Button * m_friendly_reset_button{}; + Gtk::Button * m_hostile_reset_button{}; + Gtk::Button * m_secret_reset_button{}; + Gtk::ColorDialogButton * m_friendly_color_button{}; + Gtk::ColorDialogButton * m_hostile_color_button{}; + Gtk::ColorDialogButton * m_secret_color_button{}; + Adwaita::SwitchRow * m_skip_defeated{}; + }; +} // namespace turns::ui::widgets + +#endif
\ No newline at end of file diff --git a/gui/include/settings.hpp b/gui/include/settings.hpp new file mode 100644 index 0000000..70e429a --- /dev/null +++ b/gui/include/settings.hpp @@ -0,0 +1,26 @@ +/* + * SPDX-FileCopyrightText: 2025 Felix Morgner <felix.morgner@gmail.com> + * SPDX-License-Identifier: LGPL-2.1-only + */ + +#ifndef TURNS_CORE_SETTINGS_HPP +#define TURNS_CORE_SETTINGS_HPP + +#include <glibmm/refptr.h> + +#include <giomm/settings.h> + +namespace turns::core +{ + namespace settings::key + { + auto constexpr disposition_friendly_color = "disposition-color-friendly"; + auto constexpr disposition_hostile_color = "disposition-color-hostile"; + auto constexpr disposition_secret_color = "disposition-color-secret"; + auto constexpr skip_defeated = "skip-defeated"; + } // namespace settings::key + + auto get_settings() -> Glib::RefPtr<Gio::Settings>; +} // namespace turns::core + +#endif
\ No newline at end of file diff --git a/gui/include/template_widget.hpp b/gui/include/template_widget.hpp new file mode 100644 index 0000000..f90b473 --- /dev/null +++ b/gui/include/template_widget.hpp @@ -0,0 +1,72 @@ +/* + * SPDX-FileCopyrightText: 2025 Felix Morgner <felix.morgner@gmail.com> + * SPDX-License-Identifier: LGPL-2.1-only + */ + +#ifndef TURNS_UI_TEMPLATE_WIDGET_HPP +#define TURNS_UI_TEMPLATE_WIDGET_HPP + +#include <glibmm/extraclassinit.h> +#include <glibmm/ustring.h> +#include <glibmm/wrap.h> + +#include <gtkmm/widget.h> + +#include <glib-object.h> +#include <glib.h> +#include <gtk/gtk.h> + +#include <algorithm> +#include <utility> + +namespace turns::ui +{ + + template<typename CustomWidgetType, typename BaseWidgetType> + struct template_widget : Glib::ExtraClassInit, + BaseWidgetType + { + template<typename... BaseWidgetCtorArgTypes> + template_widget(Glib::ustring && resource_path, BaseWidgetCtorArgTypes &&... base_widget_ctor_args) + : Glib::ExtraClassInit{class_init, &resource_path, instance_init} + , BaseWidgetType{std::forward<BaseWidgetCtorArgTypes>(base_widget_ctor_args)...} + { + } + + protected: + template<typename WidgetType = Gtk::Widget> + auto get_widget(char const * name) -> WidgetType * + { + auto self = static_cast<CustomWidgetType *>(this); + auto widget = GTK_WIDGET(Glib::unwrap(self)); + auto type = G_OBJECT_TYPE(Glib::unwrap(self)); + auto child = GTK_WIDGET(gtk_widget_get_template_child(widget, type, name)); + g_assert_nonnull(child); + return dynamic_cast<WidgetType *>(Glib::wrap(child)); + } + + private: + auto static class_init(void * g_class, void * g_class_data) -> void + { + g_return_if_fail(GTK_IS_WIDGET_CLASS(g_class)); + + auto resource_path = static_cast<Glib::ustring const *>(g_class_data); + + gtk_widget_class_set_template_from_resource(GTK_WIDGET_CLASS(g_class), resource_path->c_str()); + + std::ranges::for_each(CustomWidgetType::children, [g_class](auto const & child) { + gtk_widget_class_bind_template_child_full(GTK_WIDGET_CLASS(g_class), child, false, 0); + }); + } + + auto static instance_init(GTypeInstance * instance, void * /* type_class */) -> void + { + g_return_if_fail(GTK_IS_WIDGET(instance)); + + gtk_widget_init_template(GTK_WIDGET(instance)); + } + }; + +} // namespace turns::ui::widgets + +#endif
\ No newline at end of file diff --git a/gui/include/tracker.hpp b/gui/include/tracker.hpp new file mode 100644 index 0000000..d639aee --- /dev/null +++ b/gui/include/tracker.hpp @@ -0,0 +1,109 @@ +/* + * SPDX-FileCopyrightText: 2025 Felix Morgner <felix.morgner@gmail.com> + * SPDX-License-Identifier: LGPL-2.1-only + */ + +#ifndef TURNS_UI_TRACKER_HPP +#define TURNS_UI_TRACKER_HPP + +#include "turns/core/turn_order_model.hpp" +#include "turns/ui/template_widget.hpp" +#include "turns/ui/turn_order_view.hpp" + +#include <glibmm/propertyproxy.h> +#include <glibmm/refptr.h> +#include <glibmm/ustring.h> +#include <glibmm/variant.h> + +#include <giomm/asyncresult.h> +#include <giomm/file.h> +#include <giomm/settings.h> + +#include <gtkmm/applicationwindow.h> +#include <gtkmm/builder.h> +#include <gtkmm/button.h> +#include <gtkmm/cssprovider.h> +#include <gtkmm/filedialog.h> +#include <gtkmm/revealer.h> +#include <gtkmm/stack.h> +#include <gtkmm/widget.h> + +#include <adwaitamm/application.hpp> +#include <adwaitamm/applicationwindow.hpp> +#include <adwaitamm/toastoverlay.hpp> +#include <adwaitamm/windowtitle.hpp> + +#include <array> +#include <exception> +#include <string> + +namespace turns::ui +{ + + struct Tracker : template_widget<Tracker, Adwaita::ApplicationWindow> + { + auto constexpr inline static children = std::array{ + "controls", + "empty", + "overlay", + "stack", + "start", + "title", + }; + + Tracker(Glib::RefPtr<Adwaita::Application> const & app, Glib::RefPtr<Gio::Settings> const & settings); + + auto load(Glib::RefPtr<Gio::File> file) -> void; + + private: + friend auto register_types() -> void; + Tracker(); + + /** Setup */ + auto setup_actions() -> void; + auto setup_colors() -> void; + + /** Actions */ + auto add_participant() -> void; + auto delete_participant(Glib::VariantBase param) -> void; + auto edit_participant(Glib::VariantBase param) -> void; + auto open() -> void; + auto preferences() -> void; + auto save(bool force_ask) -> void; + auto stop() -> void; + + /** Event Handlers */ + auto on_open_response(Glib::RefPtr<Gio::AsyncResult> result, Glib::RefPtr<Gtk::FileDialog> dialog) -> void; + auto on_save_response(Glib::RefPtr<Gio::AsyncResult> result, Glib::RefPtr<Gtk::FileDialog> dialog) -> void; + auto on_load_content_done(Glib::RefPtr<Gio::AsyncResult> result) -> void; + auto on_replace_content_done(Glib::RefPtr<Gio::AsyncResult> result) -> void; + auto on_settings_changed(Glib::ustring key) -> void; + + /** Helpers */ + auto show_error(std::exception const & e) -> void; + auto show_toast(std::string const & message) -> void; + auto start_replace_content() -> void; + auto update_colors() -> void; + auto update_subtitle() -> void; + + Gtk::Revealer * m_controls; + Gtk::Widget * m_empty; + Adwaita::ToastOverlay * m_overlay; + Gtk::Stack * m_stack; + Gtk::Button * m_start; + Adwaita::WindowTitle * m_title; + Glib::RefPtr<core::TurnOderModel> m_turn_order; + TurnOrderView * m_turn_order_view; + Glib::RefPtr<Gio::Settings> m_settings{}; + Glib::PropertyProxy<Glib::ustring> m_subtitle; + + Glib::RefPtr<Gio::File> m_file{}; + std::string m_file_etag{}; + std::string m_file_buffer{}; + + Glib::RefPtr<Gtk::CssProvider> m_css{}; + }; + +} // namespace turns::ui + +#endif
\ No newline at end of file diff --git a/gui/include/turn_order_view.hpp b/gui/include/turn_order_view.hpp new file mode 100644 index 0000000..9a7ede6 --- /dev/null +++ b/gui/include/turn_order_view.hpp @@ -0,0 +1,45 @@ +/* + * SPDX-FileCopyrightText: 2025 Felix Morgner <felix.morgner@gmail.com> + * SPDX-License-Identifier: LGPL-2.1-only + */ + +#ifndef TURNS_UI_TURN_ORDER_VIEW_HPP +#define TURNS_UI_TURN_ORDER_VIEW_HPP + +#include "turns/core/fwd.hpp" +#include "turns/core/turn_order_model.hpp" +#include "turns/ui/template_widget.hpp" + +#include <glibmm/object.h> +#include <glibmm/refptr.h> + +#include <gtkmm/box.h> +#include <gtkmm/listbox.h> +#include <gtkmm/progressbar.h> +#include <gtkmm/widget.h> + +#include <array> + +namespace turns::ui +{ + struct TurnOrderView : template_widget<TurnOrderView, Gtk::Box> + { + using model_type = core::TurnOderModel; + + auto constexpr inline static children = std::array{ + "progress", + "view", + }; + + explicit TurnOrderView(Glib::RefPtr<model_type> model = {}); + + private: + auto handle_create_row(Glib::RefPtr<Glib::Object> const item) -> Gtk::Widget *; + + Glib::RefPtr<model_type> m_model; + Gtk::ProgressBar * m_progress; + Gtk::ListBox * m_view; + }; +} // namespace turns::ui::widgets + +#endif
\ No newline at end of file |
