From ae3c7d496ac8795848e81879cd3284b655b41ce8 Mon Sep 17 00:00:00 2001 From: Pcornat Date: Tue, 29 Oct 2024 20:22:28 +0100 Subject: [PATCH 01/10] Making sure it deletes the window --- app_win_2_back.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/app_win_2_back.cpp b/app_win_2_back.cpp index bd005a2..664d573 100644 --- a/app_win_2_back.cpp +++ b/app_win_2_back.cpp @@ -63,6 +63,7 @@ namespace gui_to_app { auto windows = get_windows(); for (auto *window: windows) { window->set_visible(false); + delete window; } quit(); } From 91180411ab4c59f89dfcba8f249b0b89524f6cbc Mon Sep 17 00:00:00 2001 From: Pcornat Date: Tue, 29 Oct 2024 20:23:15 +0100 Subject: [PATCH 02/10] =?UTF-8?q?Adding=20switches=20for=20mat=C3=A9riels?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app_win_2_back.cpp | 47 ++++++++++++++++++++++++++++++++++++++++++++++ app_win_2_back.hpp | 18 ++++++++++++++++++ 2 files changed, 65 insertions(+) diff --git a/app_win_2_back.cpp b/app_win_2_back.cpp index 664d573..e42fc17 100644 --- a/app_win_2_back.cpp +++ b/app_win_2_back.cpp @@ -2,6 +2,7 @@ #include "hello_world.hpp" #include #include +#include namespace gui_to_app { AppWin2Back::AppWin2Back() : Gtk::Application("org.billy_adventures.character_sheet", Flags::HANDLES_OPEN) { @@ -56,6 +57,52 @@ namespace gui_to_app { main_window->set_visible(true); } else { on_quit(); + return; + } + sword_switch = app_builder->get_widget("sword_switch"); + lance_switch = app_builder->get_widget("lance_switch"); + morgen_switch = app_builder->get_widget("morgenstern_switch"); + bow_switch = app_builder->get_widget("arc_switch"); + chainmail_switch = app_builder->get_widget("chainmail_switch"); + cookpot_switch = app_builder->get_widget("cookingpot_switch"); + pamphlet_switch = app_builder->get_widget("pamphlet_tourist_switch"); + medkit_switch = app_builder->get_widget("medkit_switch"); + fourche_switch = app_builder->get_widget("fourche_switch"); + dagger_switch = app_builder->get_widget("dagger_switch"); + rock_kit_switch = app_builder->get_widget("rock_kit_switch"); + sack_switch = app_builder->get_widget("sack_switch"); + + const auto test_result = [this]() -> std::vector { + const std::array test_ptrs{ + std::pair{ "sword_switch", sword_switch == nullptr }, + std::pair{ "lance_switch", lance_switch == nullptr }, + std::pair{ "morgen_switch", morgen_switch == nullptr }, + std::pair{ "bow_switch", bow_switch == nullptr }, + std::pair{ "chainmail_switch", chainmail_switch == nullptr }, + std::pair{ "cookpot_switch", cookpot_switch == nullptr }, + std::pair{ "pamphlet_switch", pamphlet_switch == nullptr }, + std::pair{ "medkit_switch", medkit_switch == nullptr }, + std::pair{ "fourche_switch", fourche_switch == nullptr }, + std::pair{ "dagger_switch", dagger_switch == nullptr }, + std::pair{ "rock_kit_switch", rock_kit_switch == nullptr }, + std::pair{ "sack_switch", sack_switch == nullptr }, + }; + std::vector test_result; + test_result.reserve(test_ptrs.size()); + std::for_each(test_ptrs.cbegin(), test_ptrs.cend(), [&test_result](const auto &a) { + if (a.second) { + test_result.emplace_back(a.first); + } + }); + return test_result; + }(); + if (!test_result.empty()) { + std::cerr << "Error occurred, at least one switch is not available:\n"; + for (const auto result: test_result) { + std::cerr << result << '\n'; + } + on_quit(); + return; } } diff --git a/app_win_2_back.hpp b/app_win_2_back.hpp index fbc2d67..4f2d1e2 100644 --- a/app_win_2_back.hpp +++ b/app_win_2_back.hpp @@ -8,6 +8,10 @@ namespace learn_gtkmm4 { class HelloWorld; } +namespace Gtk { + class Switch; +} + namespace gui_to_app { class AppWin2Back final : public Gtk::Application { @@ -27,6 +31,20 @@ namespace gui_to_app { void on_quit(); learn_gtkmm4::HelloWorld *main_window{ nullptr }; + Gtk::Switch *sword_switch{ nullptr }; + Gtk::Switch *lance_switch{ nullptr }; + Gtk::Switch *morgen_switch{ nullptr }; + Gtk::Switch *bow_switch{ nullptr }; + + Gtk::Switch *chainmail_switch{ nullptr }; + Gtk::Switch *cookpot_switch{ nullptr }; + Gtk::Switch *pamphlet_switch{ nullptr }; + Gtk::Switch *medkit_switch{ nullptr }; + + Gtk::Switch *fourche_switch{ nullptr }; + Gtk::Switch *dagger_switch{ nullptr }; + Gtk::Switch *rock_kit_switch{ nullptr }; + Gtk::Switch *sack_switch{ nullptr }; }; } // gui_to_app From ae19d387f68384db551a7e34ccdef4d4d90d7830 Mon Sep 17 00:00:00 2001 From: Pcornat Date: Tue, 29 Oct 2024 22:40:41 +0100 Subject: [PATCH 03/10] Adding spdlog --- .gitmodules | 3 +++ external/spdlog | 1 + 2 files changed, 4 insertions(+) create mode 160000 external/spdlog diff --git a/.gitmodules b/.gitmodules index 834c95d..654268b 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "external/assimp"] path = external/assimp url = https://github.com/assimp/assimp.git +[submodule "external/spdlog"] + path = external/spdlog + url = https://github.com/gabime/spdlog.git diff --git a/external/spdlog b/external/spdlog new file mode 160000 index 0000000..27cb4c7 --- /dev/null +++ b/external/spdlog @@ -0,0 +1 @@ +Subproject commit 27cb4c76708608465c413f6d0e6b8d99a4d84302 From 8af5d2373748ab0ac3e02c4b103d04db088f339f Mon Sep 17 00:00:00 2001 From: Pcornat Date: Tue, 29 Oct 2024 22:48:06 +0100 Subject: [PATCH 04/10] Fixing ID --- window_ui.ui | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/window_ui.ui b/window_ui.ui index 0731722..dae0b80 100644 --- a/window_ui.ui +++ b/window_ui.ui @@ -343,7 +343,7 @@ - + end 1 From 9515077e1e8070747abd06338ec77e17e33f0a8f Mon Sep 17 00:00:00 2001 From: Pcornat Date: Tue, 29 Oct 2024 22:50:13 +0100 Subject: [PATCH 05/10] Adding spdlog in CMakeLists.txt --- CMakeLists.txt | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f258d06..0979898 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -60,6 +60,14 @@ else () endif () add_subdirectory(external/assimp EXCLUDE_FROM_ALL) +option(SPDLOG_ENABLE_PCH "Build static or shared library using precompiled header to speed up compilation time" ON) +option(SPDLOG_BUILD_WARNINGS "Enable compiler warnings" ON) +option(SPDLOG_PREVENT_CHILD_FD "Prevent from child processes to inherit log file descriptors" ON) +option(SPDLOG_NO_THREAD_ID "prevent spdlog from querying the thread id on each log call if thread id is not needed" ON) +option(SPDLOG_NO_TLS "prevent spdlog from using thread local storage" ON) +option(SPDLOG_NO_ATOMIC_LEVELS "prevent spdlog from using of std::atomic log levels (use only if your code never modifies log levels concurrently" ON) +add_subdirectory(external/spdlog EXCLUDE_FROM_ALL) + add_executable(LearnGtk4 main.cpp hello_world.cpp hello_world.hpp @@ -67,7 +75,7 @@ add_executable(LearnGtk4 main.cpp app_win_2_back.hpp ) -set_target_properties(LearnGtk4 assimp PROPERTIES +set_target_properties(LearnGtk4 assimp spdlog_header_only PROPERTIES CXX_STANDARD 17 CXX_STANDARD_REQUIRED ON CXX_EXTENSIONS OFF @@ -78,4 +86,4 @@ target_compile_definitions(LearnGtk4 PUBLIC $<$:_GLIBCXX_DEBUG>) target_compile_definitions(assimp PUBLIC $<$:_GLIBCXX_DEBUG>) target_compile_options(LearnGtk4 PUBLIC ${COMPILE_FLAGS}) target_link_options(LearnGtk4 PUBLIC ${LINKER_OPTIONS}) -target_link_libraries(LearnGtk4 PkgConfig::GTKMM4 assimp) +target_link_libraries(LearnGtk4 PkgConfig::GTKMM4 assimp spdlog_header_only) From 33ba0995fdb385f4ce7e599d44c33f175438a1b8 Mon Sep 17 00:00:00 2001 From: Pcornat Date: Tue, 29 Oct 2024 22:50:42 +0100 Subject: [PATCH 06/10] Using spdlog for logs --- app_win_2_back.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/app_win_2_back.cpp b/app_win_2_back.cpp index e42fc17..0c44c12 100644 --- a/app_win_2_back.cpp +++ b/app_win_2_back.cpp @@ -1,8 +1,8 @@ #include "app_win_2_back.hpp" #include "hello_world.hpp" -#include #include #include +#include namespace gui_to_app { AppWin2Back::AppWin2Back() : Gtk::Application("org.billy_adventures.character_sheet", Flags::HANDLES_OPEN) { @@ -16,12 +16,12 @@ namespace gui_to_app { const auto builder = Gtk::Builder::create_from_file("menu_bar.ui"); return builder->get_object("menu"); } catch (const std::exception &e) { - std::cerr << e.what() << '\n'; + spdlog::error("Error occurred while loader menu bar: {}", e.what()); return nullptr; } }(); if (!menu_bar) { - std::cerr << "Error occured while loading menu bar's.\n"; + spdlog::error("Error occured while loading menu bar's."); } else { set_menubar(menu_bar); add_action("quit", sigc::mem_fun(*this, &AppWin2Back::on_quit)); @@ -40,13 +40,13 @@ namespace gui_to_app { try { return Gtk::Builder::create_from_file("window_ui.ui"); } catch (const std::exception &e) { - std::cerr << e.what() << std::endl; + spdlog::critical("Error occurred while loading Window's UI: {}", e.what()); quit(); return nullptr; } }(); if (!app_builder) { - std::cerr << "Error while loading UI.\n"; + spdlog::critical("Error while loading UI"); quit(); return; } @@ -56,6 +56,7 @@ namespace gui_to_app { main_window->set_show_menubar(true); main_window->set_visible(true); } else { + spdlog::critical("Error while getting window from builder"); on_quit(); return; } @@ -97,9 +98,9 @@ namespace gui_to_app { return test_result; }(); if (!test_result.empty()) { - std::cerr << "Error occurred, at least one switch is not available:\n"; + spdlog::critical("Error occurred, at least one switch is not available. See logs below"); for (const auto result: test_result) { - std::cerr << result << '\n'; + spdlog::critical(result); } on_quit(); return; From 14144c9ce4ef6b74cb04143b42e6a86a8a25cce1 Mon Sep 17 00:00:00 2001 From: Pcornat Date: Tue, 29 Oct 2024 22:51:14 +0100 Subject: [PATCH 07/10] on_quit to noexcept --- app_win_2_back.cpp | 2 +- app_win_2_back.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app_win_2_back.cpp b/app_win_2_back.cpp index 0c44c12..7addbd1 100644 --- a/app_win_2_back.cpp +++ b/app_win_2_back.cpp @@ -107,7 +107,7 @@ namespace gui_to_app { } } - void AppWin2Back::on_quit() { + void AppWin2Back::on_quit() noexcept { auto windows = get_windows(); for (auto *window: windows) { window->set_visible(false); diff --git a/app_win_2_back.hpp b/app_win_2_back.hpp index 4f2d1e2..f7693c6 100644 --- a/app_win_2_back.hpp +++ b/app_win_2_back.hpp @@ -28,7 +28,7 @@ namespace gui_to_app { void on_activate() final; private: - void on_quit(); + void on_quit() noexcept; learn_gtkmm4::HelloWorld *main_window{ nullptr }; Gtk::Switch *sword_switch{ nullptr }; From 031445743c930653bff2f2fa49c0f8e43846962f Mon Sep 17 00:00:00 2001 From: Pcornat Date: Wed, 18 Dec 2024 22:53:32 +0100 Subject: [PATCH 08/10] Adding a Builder as a field (app_builder) --- app_win_2_back.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app_win_2_back.hpp b/app_win_2_back.hpp index f7693c6..fdb5d21 100644 --- a/app_win_2_back.hpp +++ b/app_win_2_back.hpp @@ -9,11 +9,11 @@ namespace learn_gtkmm4 { } namespace Gtk { + class Builder; class Switch; } namespace gui_to_app { - class AppWin2Back final : public Gtk::Application { public: ~AppWin2Back() noexcept final = default; @@ -30,6 +30,7 @@ namespace gui_to_app { private: void on_quit() noexcept; + Glib::RefPtr app_builder; learn_gtkmm4::HelloWorld *main_window{ nullptr }; Gtk::Switch *sword_switch{ nullptr }; Gtk::Switch *lance_switch{ nullptr }; @@ -46,7 +47,6 @@ namespace gui_to_app { Gtk::Switch *rock_kit_switch{ nullptr }; Gtk::Switch *sack_switch{ nullptr }; }; - } // gui_to_app #endif //LEARNGTK4_APP_WIN_2_BACK_HPP From abf68d7ad36f992415a00af41848bcfa8ad7d2a2 Mon Sep 17 00:00:00 2001 From: Pcornat Date: Wed, 18 Dec 2024 22:55:31 +0100 Subject: [PATCH 09/10] Adding a Builder as a field (app_builder) --- app_win_2_back.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app_win_2_back.cpp b/app_win_2_back.cpp index 7addbd1..334ba9e 100644 --- a/app_win_2_back.cpp +++ b/app_win_2_back.cpp @@ -36,7 +36,7 @@ namespace gui_to_app { void AppWin2Back::on_activate() { Application::on_activate(); - const auto app_builder = [this]() -> Glib::RefPtr { + app_builder = [this]() -> Glib::RefPtr { try { return Gtk::Builder::create_from_file("window_ui.ui"); } catch (const std::exception &e) { From 124f15c213ef1ed15111f168ad0e9935fec0f4dd Mon Sep 17 00:00:00 2001 From: Pcornat Date: Wed, 18 Dec 2024 22:55:42 +0100 Subject: [PATCH 10/10] Reformat --- app_win_2_back.cpp | 45 +++++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/app_win_2_back.cpp b/app_win_2_back.cpp index 334ba9e..ff5dac1 100644 --- a/app_win_2_back.cpp +++ b/app_win_2_back.cpp @@ -75,27 +75,29 @@ namespace gui_to_app { const auto test_result = [this]() -> std::vector { const std::array test_ptrs{ - std::pair{ "sword_switch", sword_switch == nullptr }, - std::pair{ "lance_switch", lance_switch == nullptr }, - std::pair{ "morgen_switch", morgen_switch == nullptr }, - std::pair{ "bow_switch", bow_switch == nullptr }, - std::pair{ "chainmail_switch", chainmail_switch == nullptr }, - std::pair{ "cookpot_switch", cookpot_switch == nullptr }, - std::pair{ "pamphlet_switch", pamphlet_switch == nullptr }, - std::pair{ "medkit_switch", medkit_switch == nullptr }, - std::pair{ "fourche_switch", fourche_switch == nullptr }, - std::pair{ "dagger_switch", dagger_switch == nullptr }, - std::pair{ "rock_kit_switch", rock_kit_switch == nullptr }, - std::pair{ "sack_switch", sack_switch == nullptr }, + std::pair{ "sword_switch", sword_switch == nullptr }, + std::pair{ "lance_switch", lance_switch == nullptr }, + std::pair{ "morgen_switch", morgen_switch == nullptr }, + std::pair{ "bow_switch", bow_switch == nullptr }, + std::pair{ "chainmail_switch", chainmail_switch == nullptr }, + std::pair{ "cookpot_switch", cookpot_switch == nullptr }, + std::pair{ "pamphlet_switch", pamphlet_switch == nullptr }, + std::pair{ "medkit_switch", medkit_switch == nullptr }, + std::pair{ "fourche_switch", fourche_switch == nullptr }, + std::pair{ "dagger_switch", dagger_switch == nullptr }, + std::pair{ "rock_kit_switch", rock_kit_switch == nullptr }, + std::pair{ "sack_switch", sack_switch == nullptr }, }; - std::vector test_result; - test_result.reserve(test_ptrs.size()); - std::for_each(test_ptrs.cbegin(), test_ptrs.cend(), [&test_result](const auto &a) { - if (a.second) { - test_result.emplace_back(a.first); - } - }); - return test_result; + std::vector local_test_result; + local_test_result.reserve(test_ptrs.size()); + std::for_each(test_ptrs.cbegin(), + test_ptrs.cend(), + [&local_test_result](const auto &a) { + if (a.second) { + local_test_result.emplace_back(a.first); + } + }); + return local_test_result; }(); if (!test_result.empty()) { spdlog::critical("Error occurred, at least one switch is not available. See logs below"); @@ -115,5 +117,4 @@ namespace gui_to_app { } quit(); } - -} // gui_to_app \ No newline at end of file +} // gui_to_app