BillySheet/src/gui/gui.cpp

102 lines
2.8 KiB
C++
Raw Normal View History

2022-01-11 22:33:29 +01:00
#include "gui/gui.hpp"
#include "gui/gui_data.hpp"
2022-01-09 00:43:33 +01:00
#include "imgui.h"
2022-01-17 19:57:00 +01:00
#include "imgui_stdlib.h"
2022-01-09 00:43:33 +01:00
#include "imgui_impl_glfw.h"
#include "imgui_impl_opengl3.h"
#include "imgui_impl_opengl3_loader.h"
2022-01-11 22:33:29 +01:00
#include "gui/window.hpp"
2022-01-09 00:43:33 +01:00
gui::Gui::Gui(GuiData &data, menu::MenuData &menuData) : data(data), menu(menuData), font("font/DejaVuSans.ttf") {
2022-01-10 21:16:05 +01:00
SPDLOG_DEBUG("Creating GUI");
2022-01-11 22:06:21 +01:00
(void) ImGui::CreateContext();
2022-01-09 00:43:33 +01:00
ImGui::StyleColorsDark();
2022-01-11 22:06:21 +01:00
(void) ImGui::GetIO().Fonts->AddFontFromFileTTF(font.c_str(), 18.0f);
(void) ImGui_ImplGlfw_InitForOpenGL(data.get_window().get_window().get(), true);
2022-01-09 00:43:33 +01:00
initialized = ImGui_ImplOpenGL3_Init();
2022-01-10 21:16:05 +01:00
SPDLOG_DEBUG("Initialized: {}", initialized);
2022-01-09 00:43:33 +01:00
}
gui::Gui::~Gui() noexcept {
2022-01-09 00:43:33 +01:00
ImGui_ImplOpenGL3_Shutdown();
ImGui_ImplGlfw_Shutdown();
ImGui::DestroyContext();
}
void gui::Gui::render_gui() {
if (initialized) {
2022-01-14 19:21:42 +01:00
constexpr ImGuiWindowFlags flags = ImGuiWindowFlags_MenuBar |
ImGuiWindowFlags_NoMove |
2022-01-11 22:01:57 +01:00
ImGuiWindowFlags_NoResize |
ImGuiWindowFlags_NoCollapse |
ImGuiWindowFlags_NoTitleBar;
2022-01-09 00:43:33 +01:00
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame();
//TODO GUI
2022-01-11 22:01:57 +01:00
{
const ImGuiViewport &viewport = *ImGui::GetMainViewport();
ImGui::SetNextWindowPos(viewport.Pos);
ImGui::SetNextWindowSize(viewport.Size);
2022-01-09 00:43:33 +01:00
}
2022-01-11 22:01:57 +01:00
// Never collapsed.
2022-01-11 22:06:21 +01:00
(void) ImGui::Begin("Billy", nullptr, flags);
2022-01-14 19:21:42 +01:00
menu.gui();
2022-01-11 22:01:57 +01:00
2022-01-09 00:43:33 +01:00
ImGui::Text("Hello world!");
ImGui::Text("Average framerate: %.3f ms/frame (%.1f FPS)", 1000.f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
2022-01-17 19:57:00 +01:00
{
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();
}
2022-01-09 00:43:33 +01:00
ImGui::End();
ImGui::Render();
}
}
2022-01-09 00:43:33 +01:00
void gui::Gui::render_gpu() const {
if (initialized) {
glClear(GL_COLOR_BUFFER_BIT);
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
}
}