Working with file dialog, yay ! :D
This commit is contained in:
parent
1266628646
commit
546c935cf2
@ -115,15 +115,15 @@ set(COMPILE_FLAGS
|
|||||||
-Wpedantic
|
-Wpedantic
|
||||||
# -Wpadded
|
# -Wpadded
|
||||||
-pedantic
|
-pedantic
|
||||||
-ffunction-sections
|
# -ffunction-sections
|
||||||
-fdata-sections
|
# -fdata-sections
|
||||||
-fuse-ld=gold
|
-fuse-ld=gold
|
||||||
-funroll-loops
|
-funroll-loops
|
||||||
-fdevirtualize-at-ltrans
|
-fdevirtualize-at-ltrans
|
||||||
-fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free
|
-fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free
|
||||||
)
|
)
|
||||||
set(LINKER_OPTIONS
|
set(LINKER_OPTIONS
|
||||||
-Wl,--sort-common,--as-needed,--gc-sections,--strip-all
|
-Wl,--sort-common,--as-needed#[[,--gc-sections,--strip-all]]
|
||||||
-fuse-ld=gold
|
-fuse-ld=gold
|
||||||
-fdevirtualize-at-ltrans
|
-fdevirtualize-at-ltrans
|
||||||
)
|
)
|
||||||
|
@ -21,7 +21,9 @@ public:
|
|||||||
|
|
||||||
~Controller() noexcept = default;
|
~Controller() noexcept = default;
|
||||||
|
|
||||||
void control() noexcept;
|
void control_menu() const noexcept;
|
||||||
|
|
||||||
|
void control_sheet()const noexcept;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include "gui/menu/menu.hpp"
|
#include "gui/menu/menu.hpp"
|
||||||
|
#include "controller.hpp"
|
||||||
|
|
||||||
namespace fs = std::filesystem;
|
namespace fs = std::filesystem;
|
||||||
|
|
||||||
@ -28,7 +29,7 @@ namespace gui {
|
|||||||
|
|
||||||
~Gui() noexcept;
|
~Gui() noexcept;
|
||||||
|
|
||||||
void render_gui();
|
void render_gui(const Controller &controller);
|
||||||
|
|
||||||
void render_gpu() const;
|
void render_gpu() const;
|
||||||
};
|
};
|
||||||
|
@ -14,9 +14,9 @@ namespace character {
|
|||||||
namespace gui::menu {
|
namespace gui::menu {
|
||||||
class MenuData final {
|
class MenuData final {
|
||||||
public:
|
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:
|
private:
|
||||||
friend class Menu;
|
friend class Menu;
|
||||||
|
|
||||||
|
@ -3,27 +3,24 @@
|
|||||||
#include "ImFileDialog.h"
|
#include "ImFileDialog.h"
|
||||||
#include <spdlog/spdlog.h>
|
#include <spdlog/spdlog.h>
|
||||||
|
|
||||||
void Controller::control() noexcept {
|
void Controller::control_menu() const noexcept {
|
||||||
SPDLOG_DEBUG("Check \"open character\" task");
|
if (ifd::FileDialog::Instance().IsDone(menu_data.open_character_key)) {
|
||||||
if (ifd::FileDialog::Instance().IsDone(gui::menu::MenuData::open_character_key)) {
|
|
||||||
SPDLOG_DEBUG("Task done");
|
|
||||||
if (ifd::FileDialog::Instance().HasResult()) {
|
if (ifd::FileDialog::Instance().HasResult()) {
|
||||||
SPDLOG_DEBUG("Has Result");
|
|
||||||
fs::path str = ifd::FileDialog::Instance().GetResult();
|
fs::path str = ifd::FileDialog::Instance().GetResult();
|
||||||
SPDLOG_DEBUG("path opening: {}", str.string());
|
SPDLOG_DEBUG("path opening: {}", str.string());
|
||||||
}
|
}
|
||||||
ifd::FileDialog::Instance().Close();
|
ifd::FileDialog::Instance().Close();
|
||||||
}
|
}
|
||||||
SPDLOG_DEBUG("Check \"saving character\" task");
|
if (ifd::FileDialog::Instance().IsDone(menu_data.save_character_key)) {
|
||||||
if (ifd::FileDialog::Instance().IsDone(gui::menu::MenuData::save_character_key)) {
|
|
||||||
SPDLOG_DEBUG("Task done");
|
|
||||||
if (ifd::FileDialog::Instance().HasResult()) {
|
if (ifd::FileDialog::Instance().HasResult()) {
|
||||||
SPDLOG_DEBUG("Has Result");
|
|
||||||
const fs::path str = ifd::FileDialog::Instance().GetResult();
|
const fs::path str = ifd::FileDialog::Instance().GetResult();
|
||||||
SPDLOG_DEBUG("path saving: {}", str.string());
|
SPDLOG_DEBUG("path saving: {}", str.string());
|
||||||
}
|
}
|
||||||
ifd::FileDialog::Instance().Close();
|
ifd::FileDialog::Instance().Close();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Controller::control_sheet() const noexcept {
|
||||||
if (menu_data.is_edit_mode()) {
|
if (menu_data.is_edit_mode()) {
|
||||||
// TODO
|
// TODO
|
||||||
} else {
|
} else {
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
#include "gui/window.hpp"
|
#include "gui/window.hpp"
|
||||||
#include "gui/gui_data.hpp"
|
#include "gui/gui_data.hpp"
|
||||||
#include "character_sheet.hpp"
|
#include "character_sheet.hpp"
|
||||||
|
#include "controller.hpp"
|
||||||
|
|
||||||
gui::Gui::Gui(GuiData &data, menu::MenuData &menuData) : data(data), menu(menuData), font("font/DejaVuSans.ttf") {
|
gui::Gui::Gui(GuiData &data, menu::MenuData &menuData) : data(data), menu(menuData), font("font/DejaVuSans.ttf") {
|
||||||
SPDLOG_DEBUG("Creating GUI");
|
SPDLOG_DEBUG("Creating GUI");
|
||||||
@ -23,7 +24,7 @@ gui::Gui::~Gui() noexcept {
|
|||||||
ImGui::DestroyContext();
|
ImGui::DestroyContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
void gui::Gui::render_gui() {
|
void gui::Gui::render_gui(const Controller &controller) {
|
||||||
if (initialized) {
|
if (initialized) {
|
||||||
constexpr ImGuiWindowFlags flags = ImGuiWindowFlags_MenuBar |
|
constexpr ImGuiWindowFlags flags = ImGuiWindowFlags_MenuBar |
|
||||||
ImGuiWindowFlags_NoMove |
|
ImGuiWindowFlags_NoMove |
|
||||||
@ -88,6 +89,8 @@ void gui::Gui::render_gui() {
|
|||||||
|
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
|
|
||||||
|
controller.control_menu();
|
||||||
|
|
||||||
ImGui::Render();
|
ImGui::Render();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ void gui::menu::Menu::gui() const noexcept {
|
|||||||
if (ImGui::BeginMenu("File")) {
|
if (ImGui::BeginMenu("File")) {
|
||||||
if (ImGui::MenuItem("Open file")) {
|
if (ImGui::MenuItem("Open file")) {
|
||||||
SPDLOG_DEBUG("Opening 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");
|
SPDLOG_DEBUG("File opened");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,12 +49,12 @@ void gui::menu::Menu::gui() const noexcept {
|
|||||||
std::ofstream file{ data.save_path / data.filename };
|
std::ofstream file{ data.save_path / data.filename };
|
||||||
nlohmann::json j;
|
nlohmann::json j;
|
||||||
j.emplace("character_sheet", data.character_sheet);
|
j.emplace("character_sheet", data.character_sheet);
|
||||||
file << j;
|
file << j.dump(4);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ImGui::MenuItem("Save as...")) {
|
if (ImGui::MenuItem("Save as...")) {
|
||||||
SPDLOG_DEBUG("Saving with file dialog");
|
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");
|
SPDLOG_DEBUG("File saved with dialog");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
13
src/main.cpp
13
src/main.cpp
@ -1,4 +1,3 @@
|
|||||||
#include <boost/stacktrace.hpp>
|
|
||||||
#include <spdlog/spdlog.h>
|
#include <spdlog/spdlog.h>
|
||||||
#include <spdlog/sinks/stdout_color_sinks.h>
|
#include <spdlog/sinks/stdout_color_sinks.h>
|
||||||
#include "gui/window.hpp"
|
#include "gui/window.hpp"
|
||||||
@ -8,15 +7,7 @@
|
|||||||
#include "controller.hpp"
|
#include "controller.hpp"
|
||||||
#include "character_sheet.hpp"
|
#include "character_sheet.hpp"
|
||||||
|
|
||||||
void myTerminateHandler() {
|
|
||||||
try {
|
|
||||||
SPDLOG_CRITICAL(to_string(boost::stacktrace::stacktrace()));
|
|
||||||
} catch (...) {}
|
|
||||||
std::abort();
|
|
||||||
}
|
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
std::set_terminate(myTerminateHandler);
|
|
||||||
std::ios::sync_with_stdio(false);
|
std::ios::sync_with_stdio(false);
|
||||||
spdlog::set_default_logger(spdlog::stdout_color_st("console"));
|
spdlog::set_default_logger(spdlog::stdout_color_st("console"));
|
||||||
|
|
||||||
@ -30,9 +21,9 @@ int main() {
|
|||||||
|
|
||||||
while (!window.should_close()) {
|
while (!window.should_close()) {
|
||||||
glfwPollEvents();
|
glfwPollEvents();
|
||||||
controller.control();
|
// controller.control();
|
||||||
|
|
||||||
gui.render_gui();
|
gui.render_gui(controller);
|
||||||
gui.render_gpu();
|
gui.render_gpu();
|
||||||
|
|
||||||
window.swap_buffers();
|
window.swap_buffers();
|
||||||
|
Loading…
Reference in New Issue
Block a user