#include "ImguiModule.h" #include "pch.hpp" ImguiModule::ImguiModule(Archimedes::App* a, void* h = nullptr) : Archimedes::Module(a, h) { name = "ImguiModule"; WindowModule* wm = new WindowModule(a, h); deps[*wm] = wm; } ImguiModule::~ImguiModule() { if(app) { WindowModule* wm; { wm = (WindowModule*) moduleInstances[WindowModule()]; } wm->getRenderer()->getCmdList().erase(rcmd_it); #if WINDOW == 2 wm->removeEventFn(ecmd_it); #endif rendererShutdown(); windowShutdown(); ImGui::DestroyContext(); wm->releaseWindow(window); } } void ImguiModule::onLoad() { WindowModule* wm; { wm = (WindowModule*) moduleInstances[WindowModule()]; } if(!wm) { std::cout << "No WindowModule for ImguiModule!\n"; std::abort(); } window = wm->aquireWindow(); #if RENDERER == 2 renderer = window->getRenderer()->getRendererImpl().renderer; #endif IMGUI_CHECKVERSION(); context = ImGui::CreateContext(); ImGuiIO& io = ImGui::GetIO(); (void)io; io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; // Enable Docking io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; // Enable Multi-Viewport / Platform Windows #ifdef CUSTOMFONT io.Fonts->AddFontFromFileTTF(STRINGIZE_VALUE_OF(CUSTOMFONT), 13.0f); #endif // Setup Dear ImGui style ImGui::StyleColorsDark(); //ImGui::StyleColorsLight(); // Setup scaling ImGuiStyle& style = ImGui::GetStyle(); io.ConfigDpiScaleFonts = true; // [Experimental] Automatically overwrite style.FontScaleDpi in Begin() when Monitor DPI changes. This will scale fonts but _NOT_ scale sizes/padding for now. io.ConfigDpiScaleViewports = true; // [Experimental] Scale Dear ImGui and Platform Windows when Monitor DPI changes. // When viewports are enabled we tweak WindowRounding/WindowBg so platform windows can look identical to regular ones. if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) { style.WindowRounding = 0.0f; style.Colors[ImGuiCol_WindowBg].w = 1.0f; } // Setup Platform/Renderer backends if(!windowInit()) std::cout << "windowInit failed\n"; if(!rendererInit()) { std::cout << "rendererInit failed!\n" << std::endl; } wm->getRenderer()->getCmdList().push_back([this](){ ImGui::Render(); rendererRenderDrawData(); if(ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_ViewportsEnable) { ImGui::UpdatePlatformWindows(); ImGui::RenderPlatformWindowsDefault(); window->getWindowImpl().restoreContext(); } }); rcmd_it = --wm->getRenderer()->getCmdList().end()++; #if WINDOW == 2 ecmd_it = wm->addEventFn([](Archimedes::Event* e){ if(e->userData.type() == typeid(SDL_Event*)) { ImGui_ImplSDL3_ProcessEvent(std::any_cast(e->userData)); } }); #endif //Compute first frame ahead of first WindowModule->run() rendererNewFrame(); windowNewFrame(); ImGui::NewFrame(); } void ImguiModule::run() { rendererNewFrame(); windowNewFrame(); ImGui::NewFrame(); }; bool ImguiModule::onEvent(const Archimedes::Event &e) { return false; }