BillySheet/src/gui/gui.cpp
Pcornat b759836989
Always functional.
Design : the controller controls data of the character sheet and also saving and reading data.
2022-01-17 22:00:26 +01:00

102 lines
2.8 KiB
C++

#include "gui/gui.hpp"
#include "imgui.h"
#include "imgui_stdlib.h"
#include "imgui_impl_glfw.h"
#include "imgui_impl_opengl3.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");
(void) ImGui::CreateContext();
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("#version 130");
SPDLOG_DEBUG("Initialized: {}", initialized);
}
gui::Gui::~Gui() noexcept {
ImGui_ImplOpenGL3_Shutdown();
ImGui_ImplGlfw_Shutdown();
ImGui::DestroyContext();
}
void gui::Gui::render_gui() {
if (initialized) {
constexpr ImGuiWindowFlags flags = ImGuiWindowFlags_MenuBar |
ImGuiWindowFlags_NoMove |
ImGuiWindowFlags_NoResize |
ImGuiWindowFlags_NoCollapse |
ImGuiWindowFlags_NoTitleBar;
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame();
//TODO GUI
{
const ImGuiViewport &viewport = *ImGui::GetMainViewport();
ImGui::SetNextWindowPos(viewport.Pos);
ImGui::SetNextWindowSize(viewport.Size);
}
// Never collapsed.
(void) ImGui::Begin("Billy", nullptr, flags);
menu.gui();
ImGui::Text("Hello world!");
ImGui::Text("Average framerate: %.3f ms/frame (%.1f FPS)", 1000.f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
{
ImGui::BeginChild("left pane",
ImVec2(ImGui::GetWindowWidth() / 2, -ImGui::GetFrameHeightWithSpacing() -
ImGui::GetStyle().ItemSpacing.y * 4 -
ImGui::GetStyle().ChildBorderSize -
ImGui::GetStyle().FrameBorderSize),
true);
ImGui::Text("Caractère");
// Remove label
ImGui::PushItemWidth(-1);
ImGui::InputTextMultiline("Caractère", &data.billy.caractere);
ImGui::PopItemWidth();
ImGui::TreePop();
ImGui::EndChild();
}
ImGui::SameLine();
{
ImGui::BeginChild("Right Pane",
ImVec2(0,
-ImGui::GetFrameHeightWithSpacing() -
ImGui::GetStyle().ItemSpacing.y * 4 -
ImGui::GetStyle().ChildBorderSize -
ImGui::GetStyle().FrameBorderSize),
true);
ImGui::Text("Hello");
ImGui::EndChild();
}
{
ImGui::BeginChild("Bottom pane", ImVec2(0, 0), true);
ImGui::Text("Bottom pane");
ImGui::Text("Bottom pane1");
ImGui::Text("Bottom pane2");
ImGui::Text("Bottom pane3");
ImGui::Text("Bottom pane4");
ImGui::EndChild();
}
ImGui::End();
ImGui::Render();
}
}
void gui::Gui::render_gpu() const {
if (initialized) {
glClear(GL_COLOR_BUFFER_BIT);
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
}
}