BillySheet/src/gui/gui.cpp

63 lines
1.7 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"
#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);
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());
}
}