#include "imgui_context.hpp" #include #include namespace bookmouse { ImguiContext::ImguiContext(GlContext& glContext, SdlContext& sdlContext, SdlMainWindow& mainWindow) : m_mainWindow(mainWindow) { IMGUI_CHECKVERSION(); ImGui::CreateContext(); setIOFlag(ImGuiConfigFlags_NavEnableKeyboard); setIOFlag(ImGuiConfigFlags_NavEnableGamepad); ImGui::StyleColorsDark(); // ImGui::StyleColorsLight(); ImGui_ImplSDL2_InitForOpenGL(mainWindow.window(), glContext.context()); ImGui_ImplOpenGL3_Init(sdlContext.glslVersion()); } ImguiContext::~ImguiContext() { ImGui_ImplOpenGL3_Shutdown(); ImGui_ImplSDL2_Shutdown(); ImGui::DestroyContext(); } void ImguiContext::setIOFlag(ImGuiConfigFlags_ flag) const { ImGui::GetIO().ConfigFlags |= flag; } const ImGuiIO& ImguiContext::getIO() const { return ImGui::GetIO(); } bool ImguiContext::processEvent(SDL_Event& event) const { return ImGui_ImplSDL2_ProcessEvent(&event); } void ImguiContext::startFrame() const { ImGui_ImplOpenGL3_NewFrame(); ImGui_ImplSDL2_NewFrame(); ImGui::NewFrame(); } void ImguiContext::render() const { ImGui::Render(); ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); SDL_GL_SwapWindow(m_mainWindow.window()); } } // namespace bookmouse