#include "Archimedes.h" #include "imgui.h" #include "misc/cpp/imgui_stdlib.h" #include "modules/WindowModule/WindowModule.h" #if RENDERER == 1 #include "backends/imgui_impl_opengl3.h" #elif RENDERER == 2 #include "backends/imgui_impl_sdlrenderer3.h" #endif #if WINDOW == 1 #include "backends/imgui_impl_glfw.h" #include #elif WINDOW == 2 #include "backends/imgui_impl_sdl3.h" #include #endif class ImguiModule : public Archimedes::Module { public: ImguiModule(Archimedes::App*, void*); ImguiModule() { name = "ImguiModule"; } ~ImguiModule(); void onLoad() override; bool onEvent(const Archimedes::Event&) override; ImGuiContext* aquireContext() { contextRefs++; return context; } void releaseContext(ImGuiContext* ctxt) { if(ctxt == context && context != nullptr) { if(--contextRefs == 0) { app->emitEvent(new Archimedes::DoUnloadModuleEvent(name)); } } } private: int contextRefs = 0; ImGuiContext* context; Archimedes::Window* window; std::list>::iterator rcmd_it; std::list>::iterator ecmd_it; #if RENDERER == 1 auto rendererInit() { return ImGui_ImplOpenGL3_Init("#version 330"); } void rendererShutdown() { ImGui_ImplOpenGL3_Shutdown(); } void rendererNewFrame() { ImGui_ImplOpenGL3_NewFrame(); } void rendererRenderDrawData() { ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); } #elif RENDERER == 2 SDL_Renderer* renderer; auto rendererInit() { return ImGui_ImplSDLRenderer3_Init(renderer); } void rendererShutdown() { ImGui_ImplSDLRenderer3_Shutdown(); } void rendererNewFrame() { ImGui_ImplSDLRenderer3_NewFrame(); } void rendererRenderDrawData() { ImGui_ImplSDLRenderer3_RenderDrawData(ImGui::GetDrawData(), renderer); } #endif #if WINDOW == 1 #if RENDERER == 1 auto windowInit() { return ImGui_ImplGlfw_InitForOpenGL(window->getWindowImpl().getWindow(), true); } #endif void windowShutdown() { ImGui_ImplGlfw_Shutdown(); } void windowNewFrame() { ImGui_ImplGlfw_NewFrame(); } #elif WINDOW == 2 #if RENDERER == 1 auto windowInit() { return ImGui_ImplSDL3_InitForOpenGL(window->getWindowImpl().getWindow(), window->getWindowImpl().getContext()); } #elif RENDERER == 2 auto windowInit() { return ImGui_ImplSDL3_InitForSDLRenderer(window->getWindowImpl().getWindow(), renderer); } #endif void windowShutdown() { ImGui_ImplSDL3_Shutdown(); } void windowNewFrame() { ImGui_ImplSDL3_NewFrame(); } #endif }; #ifdef IMGUIMODULE_DYNAMIC #define MODULE_TYPE ImguiModule #include "endModule.h" #endif