Compare commits

..

4 commits

5 changed files with 79 additions and 34 deletions

View file

@ -1,10 +1,12 @@
cmake_minimum_required(VERSION 3.30)
project(BillyGui LANGUAGES CXX)
project(BillyGui LANGUAGES C 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
@ -73,13 +75,41 @@ 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

View file

@ -16,16 +16,22 @@ 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 = []() -> Glib::RefPtr<Gio::Menu> {
const auto menu_bar = [this]() -> Glib::RefPtr<Gio::Menu> {
try {
const auto builder = Gtk::Builder::create_from_file("menu_bar.ui");
return builder->get_object<Gio::Menu>("menu");
menu_builder = Gtk::Builder::create_from_resource("/org/gtkmm/billy_gui/menu_bar.ui");
if (menu_builder != nullptr) {
return menu_builder->get_object<Gio::Menu>("menu");
} else {
spdlog::error("Error while loading menu bar UI");
return nullptr;
}
} catch (const std::exception &e) {
spdlog::error("Error occurred while loader menu bar: {}", e.what());
return nullptr;
@ -72,18 +78,18 @@ namespace gui_to_app {
}
bool AppWin2Back::switches_procedure() {
sword_switch = app_builder->get_widget<selection_button>("sword_button");
lance_switch = app_builder->get_widget<selection_button>("lance_button");
morgen_switch = app_builder->get_widget<selection_button>("morgenstern_button");
bow_switch = app_builder->get_widget<selection_button>("arc_button");
chainmail_switch = app_builder->get_widget<selection_button>("chainmail_button");
cookpot_switch = app_builder->get_widget<selection_button>("cookingpot_button");
pamphlet_switch = app_builder->get_widget<selection_button>("pamphlet_tourist_button");
medkit_switch = app_builder->get_widget<selection_button>("medkit_button");
fourche_switch = app_builder->get_widget<selection_button>("fourche_button");
dagger_switch = app_builder->get_widget<selection_button>("dagger_button");
rock_kit_switch = app_builder->get_widget<selection_button>("rock_kit_button");
sack_switch = app_builder->get_widget<selection_button>("sack_button");
sword_switch = window_builder->get_widget<selection_button>("sword_button");
lance_switch = window_builder->get_widget<selection_button>("lance_button");
morgen_switch = window_builder->get_widget<selection_button>("morgenstern_button");
bow_switch = window_builder->get_widget<selection_button>("arc_button");
chainmail_switch = window_builder->get_widget<selection_button>("chainmail_button");
cookpot_switch = window_builder->get_widget<selection_button>("cookingpot_button");
pamphlet_switch = window_builder->get_widget<selection_button>("pamphlet_tourist_button");
medkit_switch = window_builder->get_widget<selection_button>("medkit_button");
fourche_switch = window_builder->get_widget<selection_button>("fourche_button");
dagger_switch = window_builder->get_widget<selection_button>("dagger_button");
rock_kit_switch = window_builder->get_widget<selection_button>("rock_kit_button");
sack_switch = window_builder->get_widget<selection_button>("sack_button");
const auto test_result = ranges::to<std::vector<const char *> >(
std::array{
@ -142,24 +148,24 @@ namespace gui_to_app {
void AppWin2Back::on_activate() {
Application::on_activate();
app_builder = [] -> Glib::RefPtr<Gtk::Builder> {
window_builder = [] -> Glib::RefPtr<Gtk::Builder> {
try {
return Gtk::Builder::create_from_file("window_ui.ui");
return Gtk::Builder::create_from_resource("/org/gtkmm/billy_gui/window_ui.ui");
} catch (const std::exception &e) {
spdlog::critical("Error occurred while loading Window's UI: {}", e.what());
return nullptr;
}
}();
if (!app_builder) {
if (!window_builder) {
spdlog::critical("Error while loading UI");
quit();
return;
}
main_window = Gtk::Builder::get_widget_derived<learn_gtkmm4::HelloWorld>(app_builder, "main_window");
main_window = Gtk::Builder::get_widget_derived<learn_gtkmm4::HelloWorld>(window_builder, "main_window");
if (main_window != nullptr) {
add_window(*main_window);
main_window->set_show_menubar(true);
main_window->set_visible(true);
main_window->present();
} else {
spdlog::critical("Error while getting window from builder");
on_quit();
@ -168,7 +174,7 @@ namespace gui_to_app {
if (switches_procedure()) {
return;
}
debug_button = app_builder->get_widget<Gtk::Button>("debug_button");
debug_button = window_builder->get_widget<Gtk::Button>("debug_button");
hab_labels = CaracInterface<Gtk::Label>{
{
"habilete_label_base",
@ -176,7 +182,7 @@ namespace gui_to_app {
"habilete_label_materiel",
"habilete_label_total"
},
app_builder
window_builder
};
endu_labels = CaracInterface<Gtk::Label>{
{
@ -185,7 +191,7 @@ namespace gui_to_app {
"endurance_label_materiel",
"endurance_label_total"
},
app_builder
window_builder
};
addr_labels = CaracInterface<Gtk::Label>{
{
@ -194,7 +200,7 @@ namespace gui_to_app {
"adresse_label_materiel",
"adresse_label_total"
},
app_builder
window_builder
};
luck_labels = CaracInterface<Gtk::Label>{
{
@ -203,21 +209,20 @@ namespace gui_to_app {
"chance_label_materiel",
"chance_label_total"
},
app_builder
window_builder
};
damage_label = app_builder->get_widget<Gtk::Label>("label_degat");
armor_label = app_builder->get_widget<Gtk::Label>("label_armure");
critic_label = app_builder->get_widget<Gtk::Label>("label_critique");
damage_label = window_builder->get_widget<Gtk::Label>("label_degat");
armor_label = window_builder->get_widget<Gtk::Label>("label_armure");
critic_label = window_builder->get_widget<Gtk::Label>("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; }),
[](auto *window) {
window->set_visible(false);
delete window;
[this](auto *window) {
remove_window(*window);
});
quit();
}

View file

@ -83,7 +83,8 @@ namespace gui_to_app {
bool erase_obj(const character::billyEnums &obj) noexcept;
Glib::RefPtr<Gtk::Builder> app_builder;
Glib::RefPtr<Gtk::Builder> window_builder;
Glib::RefPtr<Gtk::Builder> menu_builder;
learn_gtkmm4::HelloWorld *main_window{ nullptr };
selection_button *sword_switch{ nullptr };
selection_button *lance_switch{ nullptr };

7
billy_gui.gresource.xml Normal file
View file

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
<gresource prefix="/org/gtkmm/billy_gui">
<file preprocess="xml-stripblanks">window_ui.ui</file>
<file preprocess="xml-stripblanks">menu_bar.ui</file>
</gresource>
</gresources>

View file

@ -1,5 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml version='1.0' encoding='UTF-8'?>
<!-- Created with Cambalache 0.96.3 -->
<interface>
<!-- interface-name menu_bar.ui -->
<requires lib="gio" version="2.0"/>
<menu id="menu">
<submenu id="file_submenu">