diff --git a/CMakeLists.txt b/CMakeLists.txt index 73d5617..8a67ac1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,12 +1,10 @@ cmake_minimum_required(VERSION 3.30) -project(BillyGui LANGUAGES C CXX) +project(BillyGui LANGUAGES CXX) include(FetchContent) find_package(PkgConfig REQUIRED) pkg_check_modules(GTKMM4 REQUIRED IMPORTED_TARGET gtkmm-4.0) -find_program(GLIB_COMPILE_RESOURCES NAMES glib-compile-resources REQUIRED) - fetchcontent_declare(BillySheet GIT_REPOSITORY https://gitea.pcornatcloud.fr/Pcornat/BillySheet.git GIT_TAG main @@ -75,41 +73,13 @@ set(SPDLOG_NO_TLS ON) set(SPDLOG_NO_ATOMIC_LEVELS ON) fetchcontent_makeavailable(spdlog) -set(GRESOURCE_C resources.c) -set(GRESOURCE_XML billy_gui.gresource.xml) - -# Step 2: -add_custom_command( - OUTPUT ${GRESOURCE_C} - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - COMMAND ${GLIB_COMPILE_RESOURCES} - ARGS - --target=${CMAKE_CURRENT_BINARY_DIR}/${GRESOURCE_C} ${GRESOURCE_XML} --generate-source - VERBATIM - MAIN_DEPENDENCY ${GRESOURCE_XML} - DEPENDS window_ui.ui menu_bar.ui -) - -# Step 3: -add_custom_target( - dummy-resource - DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${GRESOURCE_C} -) - add_executable(${PROJECT_NAME} main.cpp hello_world.cpp hello_world.hpp app_win_2_back.cpp app_win_2_back.hpp - ${CMAKE_CURRENT_BINARY_DIR}/${GRESOURCE_C} ) -set_source_files_properties( - ${CMAKE_CURRENT_BINARY_DIR}/${GRESOURCE_C} - PROPERTIES GENERATED TRUE -) -add_dependencies(${PROJECT_NAME} dummy-resource) - set_target_properties(${PROJECT_NAME} spdlog_header_only PROPERTIES CXX_STANDARD 23 CXX_STANDARD_REQUIRED ON diff --git a/app_win_2_back.cpp b/app_win_2_back.cpp index 0138856..b51ea15 100644 --- a/app_win_2_back.cpp +++ b/app_win_2_back.cpp @@ -16,22 +16,16 @@ namespace gui_to_app { namespace views = std::views; AppWin2Back::AppWin2Back() : Gtk::Application("org.billy_adventures.character_sheet", Flags::HANDLES_OPEN) { - signal_window_removed().connect([](const Gtk::Window *window) { delete window; }); Glib::set_application_name("Billy's character sheet"); selection_buttons.reserve(signal_handlers.size()); } void AppWin2Back::on_startup() { Application::on_startup(); - const auto menu_bar = [this]() -> Glib::RefPtr { + const auto menu_bar = []() -> Glib::RefPtr { try { - menu_builder = Gtk::Builder::create_from_resource("/org/gtkmm/billy_gui/menu_bar.ui"); - if (menu_builder != nullptr) { - return menu_builder->get_object("menu"); - } else { - spdlog::error("Error while loading menu bar UI"); - return nullptr; - } + const auto builder = Gtk::Builder::create_from_file("menu_bar.ui"); + return builder->get_object("menu"); } catch (const std::exception &e) { spdlog::error("Error occurred while loader menu bar: {}", e.what()); return nullptr; @@ -78,18 +72,18 @@ namespace gui_to_app { } bool AppWin2Back::switches_procedure() { - sword_switch = window_builder->get_widget("sword_button"); - lance_switch = window_builder->get_widget("lance_button"); - morgen_switch = window_builder->get_widget("morgenstern_button"); - bow_switch = window_builder->get_widget("arc_button"); - chainmail_switch = window_builder->get_widget("chainmail_button"); - cookpot_switch = window_builder->get_widget("cookingpot_button"); - pamphlet_switch = window_builder->get_widget("pamphlet_tourist_button"); - medkit_switch = window_builder->get_widget("medkit_button"); - fourche_switch = window_builder->get_widget("fourche_button"); - dagger_switch = window_builder->get_widget("dagger_button"); - rock_kit_switch = window_builder->get_widget("rock_kit_button"); - sack_switch = window_builder->get_widget("sack_button"); + sword_switch = app_builder->get_widget("sword_button"); + lance_switch = app_builder->get_widget("lance_button"); + morgen_switch = app_builder->get_widget("morgenstern_button"); + bow_switch = app_builder->get_widget("arc_button"); + chainmail_switch = app_builder->get_widget("chainmail_button"); + cookpot_switch = app_builder->get_widget("cookingpot_button"); + pamphlet_switch = app_builder->get_widget("pamphlet_tourist_button"); + medkit_switch = app_builder->get_widget("medkit_button"); + fourche_switch = app_builder->get_widget("fourche_button"); + dagger_switch = app_builder->get_widget("dagger_button"); + rock_kit_switch = app_builder->get_widget("rock_kit_button"); + sack_switch = app_builder->get_widget("sack_button"); const auto test_result = ranges::to >( std::array{ @@ -148,24 +142,24 @@ namespace gui_to_app { void AppWin2Back::on_activate() { Application::on_activate(); - window_builder = [] -> Glib::RefPtr { + app_builder = [] -> Glib::RefPtr { try { - return Gtk::Builder::create_from_resource("/org/gtkmm/billy_gui/window_ui.ui"); + return Gtk::Builder::create_from_file("window_ui.ui"); } catch (const std::exception &e) { spdlog::critical("Error occurred while loading Window's UI: {}", e.what()); return nullptr; } }(); - if (!window_builder) { + if (!app_builder) { spdlog::critical("Error while loading UI"); quit(); return; } - main_window = Gtk::Builder::get_widget_derived(window_builder, "main_window"); + main_window = Gtk::Builder::get_widget_derived(app_builder, "main_window"); if (main_window != nullptr) { add_window(*main_window); main_window->set_show_menubar(true); - main_window->present(); + main_window->set_visible(true); } else { spdlog::critical("Error while getting window from builder"); on_quit(); @@ -174,7 +168,7 @@ namespace gui_to_app { if (switches_procedure()) { return; } - debug_button = window_builder->get_widget("debug_button"); + debug_button = app_builder->get_widget("debug_button"); hab_labels = CaracInterface{ { "habilete_label_base", @@ -182,7 +176,7 @@ namespace gui_to_app { "habilete_label_materiel", "habilete_label_total" }, - window_builder + app_builder }; endu_labels = CaracInterface{ { @@ -191,7 +185,7 @@ namespace gui_to_app { "endurance_label_materiel", "endurance_label_total" }, - window_builder + app_builder }; addr_labels = CaracInterface{ { @@ -200,7 +194,7 @@ namespace gui_to_app { "adresse_label_materiel", "adresse_label_total" }, - window_builder + app_builder }; luck_labels = CaracInterface{ { @@ -209,20 +203,21 @@ namespace gui_to_app { "chance_label_materiel", "chance_label_total" }, - window_builder + app_builder }; - damage_label = window_builder->get_widget("label_degat"); - armor_label = window_builder->get_widget("label_armure"); - critic_label = window_builder->get_widget("label_critique"); + damage_label = app_builder->get_widget("label_degat"); + armor_label = app_builder->get_widget("label_armure"); + critic_label = app_builder->get_widget("label_critique"); debug_button->signal_clicked().connect(sigc::mem_fun(*this, &AppWin2Back::debug_button_clicked), false); } void AppWin2Back::on_quit() noexcept { ranges::for_each(get_windows() | views::filter([](const auto windows) { return windows != nullptr; }), - [this](auto *window) { - remove_window(*window); + [](auto *window) { + window->set_visible(false); + delete window; }); quit(); } diff --git a/app_win_2_back.hpp b/app_win_2_back.hpp index 1c35836..2865b72 100644 --- a/app_win_2_back.hpp +++ b/app_win_2_back.hpp @@ -83,8 +83,7 @@ namespace gui_to_app { bool erase_obj(const character::billyEnums &obj) noexcept; - Glib::RefPtr window_builder; - Glib::RefPtr menu_builder; + Glib::RefPtr app_builder; learn_gtkmm4::HelloWorld *main_window{ nullptr }; selection_button *sword_switch{ nullptr }; selection_button *lance_switch{ nullptr }; diff --git a/billy_gui.gresource.xml b/billy_gui.gresource.xml deleted file mode 100644 index 0d1fb18..0000000 --- a/billy_gui.gresource.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - window_ui.ui - menu_bar.ui - - \ No newline at end of file diff --git a/menu_bar.ui b/menu_bar.ui index 43842b8..b2aa985 100644 --- a/menu_bar.ui +++ b/menu_bar.ui @@ -1,7 +1,5 @@ - - + -