Using switch, first draft to use switches.
This commit is contained in:
parent
2c53334e8f
commit
87d2db2243
3 changed files with 70 additions and 2 deletions
|
|
@ -86,7 +86,6 @@ set_target_properties(LearnGtk4 spdlog_header_only PROPERTIES
|
||||||
INTERPROCEDURAL_OPTIMIZATION ON
|
INTERPROCEDURAL_OPTIMIZATION ON
|
||||||
)
|
)
|
||||||
|
|
||||||
target_compile_definitions(LearnGtk4 PUBLIC $<$<CONFIG:Debug>:_GLIBCXX_DEBUG>)
|
|
||||||
target_compile_options(LearnGtk4 PUBLIC ${COMPILE_FLAGS})
|
target_compile_options(LearnGtk4 PUBLIC ${COMPILE_FLAGS})
|
||||||
target_link_options(LearnGtk4 PUBLIC ${LINKER_OPTIONS})
|
target_link_options(LearnGtk4 PUBLIC ${LINKER_OPTIONS})
|
||||||
target_link_libraries(LearnGtk4 PkgConfig::GTKMM4 spdlog_header_only BillySheet)
|
target_link_libraries(LearnGtk4 PkgConfig::GTKMM4 spdlog_header_only BillySheet)
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
#include "app_win_2_back.hpp"
|
#include "app_win_2_back.hpp"
|
||||||
#include "hello_world.hpp"
|
#include "hello_world.hpp"
|
||||||
|
|
||||||
|
#include <billy_objects.hpp>
|
||||||
|
|
||||||
#include <glibmm/miscutils.h>
|
#include <glibmm/miscutils.h>
|
||||||
#include <gtkmm/switch.h>
|
#include <gtkmm/switch.h>
|
||||||
#include <spdlog/spdlog.h>
|
#include <spdlog/spdlog.h>
|
||||||
|
|
@ -107,6 +109,28 @@ namespace gui_to_app {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// TODO: interaction avec la CharacterSheet
|
// TODO: interaction avec la CharacterSheet
|
||||||
|
ranges::for_each(views::zip(std::array{
|
||||||
|
sword_switch,
|
||||||
|
lance_switch,
|
||||||
|
morgen_switch,
|
||||||
|
bow_switch,
|
||||||
|
chainmail_switch,
|
||||||
|
cookpot_switch,
|
||||||
|
pamphlet_switch,
|
||||||
|
medkit_switch,
|
||||||
|
fourche_switch,
|
||||||
|
dagger_switch,
|
||||||
|
rock_kit_switch,
|
||||||
|
sack_switch,
|
||||||
|
},
|
||||||
|
signal_handlers),
|
||||||
|
[](const std::tuple<Gtk::Switch *, SwitchSignalHelper &> &vals) {
|
||||||
|
const auto &[switch_val, signal_handle] = vals;
|
||||||
|
signal_handle.switch_ = switch_val;
|
||||||
|
switch_val->signal_state_set().connect(
|
||||||
|
sigc::mem_fun(signal_handle, &SwitchSignalHelper::signal_handler),
|
||||||
|
false);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void AppWin2Back::on_quit() noexcept {
|
void AppWin2Back::on_quit() noexcept {
|
||||||
|
|
@ -117,4 +141,8 @@ namespace gui_to_app {
|
||||||
});
|
});
|
||||||
quit();
|
quit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool AppWin2Back::switch_signal_handler(const bool flag, const character::billyEnums &obj) noexcept {
|
||||||
|
return flag ? gestionnaire.insert_object(sheet, obj) : !gestionnaire.erase_object(sheet, obj);
|
||||||
|
}
|
||||||
} // gui_to_app
|
} // gui_to_app
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,14 @@
|
||||||
#ifndef LEARNGTK4_APP_WIN_2_BACK_HPP
|
#ifndef LEARNGTK4_APP_WIN_2_BACK_HPP
|
||||||
#define LEARNGTK4_APP_WIN_2_BACK_HPP
|
#define LEARNGTK4_APP_WIN_2_BACK_HPP
|
||||||
|
|
||||||
#include <gtkmm/application.h>
|
#include <array>
|
||||||
|
|
||||||
#include <glibmm/refptr.h>
|
#include <glibmm/refptr.h>
|
||||||
|
#include <gtkmm/application.h>
|
||||||
|
|
||||||
|
#include <billy_objects.hpp>
|
||||||
|
#include <character_sheet.hpp>
|
||||||
|
#include <gtkmm/switch.h>
|
||||||
|
|
||||||
namespace learn_gtkmm4 {
|
namespace learn_gtkmm4 {
|
||||||
class HelloWorld;
|
class HelloWorld;
|
||||||
|
|
@ -28,8 +34,23 @@ namespace gui_to_app {
|
||||||
void on_activate() final;
|
void on_activate() final;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
struct SwitchSignalHelper {
|
||||||
|
AppWin2Back &app;
|
||||||
|
const character::billyEnums obj;
|
||||||
|
Gtk::Switch *switch_{ nullptr };
|
||||||
|
|
||||||
|
[[nodiscard]] bool signal_handler(const bool flag) const noexcept {
|
||||||
|
switch_->set_state(app.switch_signal_handler(flag, obj));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
friend struct SwitchSignalHelper;
|
||||||
|
|
||||||
void on_quit() noexcept;
|
void on_quit() noexcept;
|
||||||
|
|
||||||
|
bool switch_signal_handler(bool flag, const character::billyEnums &obj) noexcept;
|
||||||
|
|
||||||
Glib::RefPtr<Gtk::Builder> app_builder;
|
Glib::RefPtr<Gtk::Builder> app_builder;
|
||||||
learn_gtkmm4::HelloWorld *main_window{ nullptr };
|
learn_gtkmm4::HelloWorld *main_window{ nullptr };
|
||||||
Gtk::Switch *sword_switch{ nullptr };
|
Gtk::Switch *sword_switch{ nullptr };
|
||||||
|
|
@ -46,6 +67,26 @@ namespace gui_to_app {
|
||||||
Gtk::Switch *dagger_switch{ nullptr };
|
Gtk::Switch *dagger_switch{ nullptr };
|
||||||
Gtk::Switch *rock_kit_switch{ nullptr };
|
Gtk::Switch *rock_kit_switch{ nullptr };
|
||||||
Gtk::Switch *sack_switch{ nullptr };
|
Gtk::Switch *sack_switch{ nullptr };
|
||||||
|
|
||||||
|
std::array<SwitchSignalHelper, 12> signal_handlers{
|
||||||
|
SwitchSignalHelper{ .app = *this, .obj = character::weapons::Sword },
|
||||||
|
SwitchSignalHelper{ .app = *this, .obj = character::weapons::Lance },
|
||||||
|
SwitchSignalHelper{ .app = *this, .obj = character::weapons::Morgenstern },
|
||||||
|
SwitchSignalHelper{ .app = *this, .obj = character::weapons::Bow },
|
||||||
|
|
||||||
|
SwitchSignalHelper{ .app = *this, .obj = character::equipments::Chainmail },
|
||||||
|
SwitchSignalHelper{ .app = *this, .obj = character::equipments::CookingPot },
|
||||||
|
SwitchSignalHelper{ .app = *this, .obj = character::equipments::PamphletTourist },
|
||||||
|
SwitchSignalHelper{ .app = *this, .obj = character::equipments::MedicKit },
|
||||||
|
|
||||||
|
SwitchSignalHelper{ .app = *this, .obj = character::tools::Fourche },
|
||||||
|
SwitchSignalHelper{ .app = *this, .obj = character::tools::Dagger },
|
||||||
|
SwitchSignalHelper{ .app = *this, .obj = character::tools::RockClimbingKit },
|
||||||
|
SwitchSignalHelper{ .app = *this, .obj = character::tools::SackOfGrain },
|
||||||
|
};
|
||||||
|
|
||||||
|
character::BillyObjects gestionnaire{};
|
||||||
|
character::CharacterSheet sheet{};
|
||||||
};
|
};
|
||||||
} // gui_to_app
|
} // gui_to_app
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue