Always functional.
Design : the controller controls data of the character sheet and also saving and reading data.
This commit is contained in:
parent
84450d25af
commit
b759836989
16 changed files with 8011 additions and 23 deletions
|
@ -1 +1,10 @@
|
|||
#include "controller.hpp"
|
||||
#include "gui/menu/menu_data.hpp"
|
||||
|
||||
void Controller::control() noexcept {
|
||||
if (menu_data.is_edit_mode()) {
|
||||
// TODO
|
||||
} else {
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
#include "gui/gui.hpp"
|
||||
#include "gui/gui_data.hpp"
|
||||
#include "imgui.h"
|
||||
#include "imgui_stdlib.h"
|
||||
#include "imgui_impl_glfw.h"
|
||||
#include "imgui_impl_opengl3.h"
|
||||
#include "imgui_impl_opengl3_loader.h"
|
||||
#include "gui/window.hpp"
|
||||
#include "gui/gui_data.hpp"
|
||||
#include "character_sheet.hpp"
|
||||
|
||||
gui::Gui::Gui(GuiData &data, menu::MenuData &menuData) : data(data), menu(menuData), font("font/DejaVuSans.ttf") {
|
||||
SPDLOG_DEBUG("Creating GUI");
|
||||
|
@ -13,7 +13,7 @@ gui::Gui::Gui(GuiData &data, menu::MenuData &menuData) : data(data), menu(menuDa
|
|||
ImGui::StyleColorsDark();
|
||||
(void) ImGui::GetIO().Fonts->AddFontFromFileTTF(font.c_str(), 18.0f);
|
||||
(void) ImGui_ImplGlfw_InitForOpenGL(data.get_window().get_window().get(), true);
|
||||
initialized = ImGui_ImplOpenGL3_Init();
|
||||
initialized = ImGui_ImplOpenGL3_Init("#version 130");
|
||||
SPDLOG_DEBUG("Initialized: {}", initialized);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,24 +1,52 @@
|
|||
#include "gui/menu/menu.hpp"
|
||||
#include "imgui.h"
|
||||
#include "gui/menu/menu_data.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;
|
||||
|
||||
glGenTextures(1, &tex);
|
||||
glBindTexture(GL_TEXTURE_2D, tex);
|
||||
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);
|
||||
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")) {
|
||||
|
||||
// TODO
|
||||
}
|
||||
|
||||
if (ImGui::MenuItem("Save")) {
|
||||
std::ofstream file{ data.save_path / data.filename };
|
||||
nlohmann::json j;
|
||||
j.emplace("character_sheet", data)
|
||||
j.emplace("character_sheet", data.character_sheet);
|
||||
}
|
||||
|
||||
if (ImGui::MenuItem("Save as...")) {
|
||||
|
||||
// TODO
|
||||
}
|
||||
|
||||
ImGui::EndMenu();
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include "gui/window.hpp"
|
||||
#include <stdexcept>
|
||||
#include "spdlog/spdlog.h"
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
static void glfwErrorCallback(int error, const char *message) {
|
||||
SPDLOG_CRITICAL("Error code{}: {}", error, message);
|
||||
|
@ -27,6 +27,13 @@ gui::Window::Window() {
|
|||
throw std::runtime_error("GLFW failed. See log.");
|
||||
}
|
||||
glfwMakeContextCurrent(wwindow.get());
|
||||
glewExperimental = true;
|
||||
if (glewInit() != GLEW_OK) {
|
||||
wwindow.reset(nullptr);
|
||||
glfwTerminate();
|
||||
SPDLOG_CRITICAL("GLEW loader failed.");
|
||||
throw std::runtime_error("GLEW failed. See log.");
|
||||
}
|
||||
glfwSwapInterval(1); // VSync on
|
||||
|
||||
glfwSetFramebufferSizeCallback(wwindow.get(), framebufferCallback);
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
#include "gui/menu/menu_data.hpp"
|
||||
#include "gui/gui_data.hpp"
|
||||
#include "gui/gui.hpp"
|
||||
#include "controller.hpp"
|
||||
#include "character_sheet.hpp"
|
||||
|
||||
int main() {
|
||||
std::ios::sync_with_stdio(false);
|
||||
|
@ -11,12 +13,15 @@ int main() {
|
|||
|
||||
try {
|
||||
gui::Window window;
|
||||
gui::GuiData gui_data(window);
|
||||
gui::menu::MenuData menu_data;
|
||||
character::CharacterSheet billy;
|
||||
gui::GuiData gui_data(window, billy);
|
||||
gui::menu::MenuData menu_data(billy);
|
||||
Controller controller(billy, menu_data);
|
||||
gui::Gui gui(gui_data, menu_data);
|
||||
|
||||
while (!window.should_close()) {
|
||||
glfwPollEvents();
|
||||
controller.control();
|
||||
|
||||
gui.render_gui();
|
||||
gui.render_gpu();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue