Working with file dialog, yay ! :D

This commit is contained in:
Pcornat 2022-01-20 22:30:14 +01:00
parent 1266628646
commit 546c935cf2
Signed by: Pcornat
GPG Key ID: 2F3932FF46D9ECA0
8 changed files with 25 additions and 31 deletions

View File

@ -115,15 +115,15 @@ set(COMPILE_FLAGS
-Wpedantic
# -Wpadded
-pedantic
-ffunction-sections
-fdata-sections
# -ffunction-sections
# -fdata-sections
-fuse-ld=gold
-funroll-loops
-fdevirtualize-at-ltrans
-fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free
)
set(LINKER_OPTIONS
-Wl,--sort-common,--as-needed,--gc-sections,--strip-all
-Wl,--sort-common,--as-needed#[[,--gc-sections,--strip-all]]
-fuse-ld=gold
-fdevirtualize-at-ltrans
)

View File

@ -21,7 +21,9 @@ public:
~Controller() noexcept = default;
void control() noexcept;
void control_menu() const noexcept;
void control_sheet()const noexcept;
};

View File

@ -3,6 +3,7 @@
#include <filesystem>
#include "gui/menu/menu.hpp"
#include "controller.hpp"
namespace fs = std::filesystem;
@ -28,7 +29,7 @@ namespace gui {
~Gui() noexcept;
void render_gui();
void render_gui(const Controller &controller);
void render_gpu() const;
};

View File

@ -14,9 +14,9 @@ namespace character {
namespace gui::menu {
class MenuData final {
public:
static constexpr const char *const open_character_key{ "CharacterSheetOpen" };
const std::string open_character_key{ "CharacterSheetOpen" };
static constexpr const char *const save_character_key{ "CharacterSheetSaveAs" };
const std::string save_character_key{ "CharacterSheetSaveAs" };
private:
friend class Menu;

View File

@ -3,27 +3,24 @@
#include "ImFileDialog.h"
#include <spdlog/spdlog.h>
void Controller::control() noexcept {
SPDLOG_DEBUG("Check \"open character\" task");
if (ifd::FileDialog::Instance().IsDone(gui::menu::MenuData::open_character_key)) {
SPDLOG_DEBUG("Task done");
void Controller::control_menu() const noexcept {
if (ifd::FileDialog::Instance().IsDone(menu_data.open_character_key)) {
if (ifd::FileDialog::Instance().HasResult()) {
SPDLOG_DEBUG("Has Result");
fs::path str = ifd::FileDialog::Instance().GetResult();
SPDLOG_DEBUG("path opening: {}", str.string());
}
ifd::FileDialog::Instance().Close();
}
SPDLOG_DEBUG("Check \"saving character\" task");
if (ifd::FileDialog::Instance().IsDone(gui::menu::MenuData::save_character_key)) {
SPDLOG_DEBUG("Task done");
if (ifd::FileDialog::Instance().IsDone(menu_data.save_character_key)) {
if (ifd::FileDialog::Instance().HasResult()) {
SPDLOG_DEBUG("Has Result");
const fs::path str = ifd::FileDialog::Instance().GetResult();
SPDLOG_DEBUG("path saving: {}", str.string());
}
ifd::FileDialog::Instance().Close();
}
}
void Controller::control_sheet() const noexcept {
if (menu_data.is_edit_mode()) {
// TODO
} else {

View File

@ -6,6 +6,7 @@
#include "gui/window.hpp"
#include "gui/gui_data.hpp"
#include "character_sheet.hpp"
#include "controller.hpp"
gui::Gui::Gui(GuiData &data, menu::MenuData &menuData) : data(data), menu(menuData), font("font/DejaVuSans.ttf") {
SPDLOG_DEBUG("Creating GUI");
@ -23,7 +24,7 @@ gui::Gui::~Gui() noexcept {
ImGui::DestroyContext();
}
void gui::Gui::render_gui() {
void gui::Gui::render_gui(const Controller &controller) {
if (initialized) {
constexpr ImGuiWindowFlags flags = ImGuiWindowFlags_MenuBar |
ImGuiWindowFlags_NoMove |
@ -88,6 +89,8 @@ void gui::Gui::render_gui() {
ImGui::End();
controller.control_menu();
ImGui::Render();
}
}

View File

@ -40,7 +40,7 @@ void gui::menu::Menu::gui() const noexcept {
if (ImGui::BeginMenu("File")) {
if (ImGui::MenuItem("Open file")) {
SPDLOG_DEBUG("Opening file");
ifd::FileDialog::Instance().Open(MenuData::open_character_key, "Open a character sheet", "Character sheet (*.json){.json},.*");
ifd::FileDialog::Instance().Open(data.open_character_key, "Open a character sheet", "Character sheet (*.json){.json},.*");
SPDLOG_DEBUG("File opened");
}
@ -49,12 +49,12 @@ void gui::menu::Menu::gui() const noexcept {
std::ofstream file{ data.save_path / data.filename };
nlohmann::json j;
j.emplace("character_sheet", data.character_sheet);
file << j;
file << j.dump(4);
}
if (ImGui::MenuItem("Save as...")) {
SPDLOG_DEBUG("Saving with file dialog");
ifd::FileDialog::Instance().Save(MenuData::save_character_key, "Save character sheet as...", "*.json {.json}");
ifd::FileDialog::Instance().Save(data.save_character_key, "Save character sheet as...", "*.json {.json}");
SPDLOG_DEBUG("File saved with dialog");
}

View File

@ -1,4 +1,3 @@
#include <boost/stacktrace.hpp>
#include <spdlog/spdlog.h>
#include <spdlog/sinks/stdout_color_sinks.h>
#include "gui/window.hpp"
@ -8,15 +7,7 @@
#include "controller.hpp"
#include "character_sheet.hpp"
void myTerminateHandler() {
try {
SPDLOG_CRITICAL(to_string(boost::stacktrace::stacktrace()));
} catch (...) {}
std::abort();
}
int main() {
std::set_terminate(myTerminateHandler);
std::ios::sync_with_stdio(false);
spdlog::set_default_logger(spdlog::stdout_color_st("console"));
@ -30,9 +21,9 @@ int main() {
while (!window.should_close()) {
glfwPollEvents();
controller.control();
// controller.control();
gui.render_gui();
gui.render_gui(controller);
gui.render_gpu();
window.swap_buffers();