74 lines
2.7 KiB
C++
74 lines
2.7 KiB
C++
#include "gui/menu/menu.hpp"
|
|
#include <GL/glew.h>
|
|
#include <GL/gl.h>
|
|
#include <fstream>
|
|
#include <nlohmann/json.hpp>
|
|
#include "imgui.h"
|
|
#include "gui/menu/menu_data.hpp"
|
|
#include "character_sheet.hpp"
|
|
#include "ImFileDialog.h"
|
|
|
|
gui::menu::Menu::Menu(gui::menu::MenuData &data) noexcept: data(data) {
|
|
SPDLOG_DEBUG("Creating Menu");
|
|
ifd::FileDialog::Instance().CreateTexture = [](uint8_t *data, int w, int h, char fmt) -> void * {
|
|
GLuint tex;
|
|
SPDLOG_DEBUG("Inside CreateTexture for file dialog.");
|
|
glGenTextures(1, &tex);
|
|
SPDLOG_DEBUG("texture generated");
|
|
glBindTexture(GL_TEXTURE_2D, tex);
|
|
SPDLOG_DEBUG("Texture binded");
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, (fmt == 0) ? GL_BGRA : GL_RGBA, GL_UNSIGNED_BYTE, data);
|
|
SPDLOG_DEBUG("Before mipmap");
|
|
glGenerateMipmap(GL_TEXTURE_2D);
|
|
glBindTexture(GL_TEXTURE_2D, 0);
|
|
|
|
return (void *) tex;
|
|
};
|
|
|
|
ifd::FileDialog::Instance().DeleteTexture = [](void *tex) -> void {
|
|
auto texID = (GLuint) ((std::uintptr_t) tex);
|
|
glDeleteTextures(1, &texID);
|
|
};
|
|
}
|
|
|
|
void gui::menu::Menu::gui() const noexcept {
|
|
if (ImGui::BeginMenuBar()) {
|
|
if (ImGui::BeginMenu("File")) {
|
|
if (ImGui::MenuItem("Open file")) {
|
|
SPDLOG_DEBUG("Opening file");
|
|
ifd::FileDialog::Instance().Open(data.open_character_key,
|
|
"Open a character sheet",
|
|
"Character sheet (*.json){.json},.*");
|
|
SPDLOG_DEBUG("File opened");
|
|
}
|
|
|
|
if (ImGui::MenuItem("Save")) {
|
|
SPDLOG_DEBUG("Saving file with know path");
|
|
std::ofstream file{ data.save_path / data.filename };
|
|
nlohmann::json j;
|
|
j.emplace("character_sheet", data.character_sheet);
|
|
file << j.dump(4);
|
|
}
|
|
|
|
if (ImGui::MenuItem("Save as...")) {
|
|
SPDLOG_DEBUG("Saving with file dialog");
|
|
ifd::FileDialog::Instance().Save(data.save_character_key,
|
|
"Save character sheet as...",
|
|
"*.json {.json}");
|
|
SPDLOG_DEBUG("File saved with dialog");
|
|
}
|
|
|
|
ImGui::EndMenu();
|
|
}
|
|
if (ImGui::BeginMenu("Editor")) {
|
|
ImGui::MenuItem("Edit mode", nullptr, &data.edit_mode);
|
|
ImGui::EndMenu();
|
|
}
|
|
ImGui::EndMenuBar();
|
|
}
|
|
}
|