114 lines
2.8 KiB
C++
114 lines
2.8 KiB
C++
|
|
#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 <GLFW/glfw3.h>
|
|
|
|
#elif WINDOW == 2
|
|
|
|
#include "backends/imgui_impl_sdl3.h"
|
|
#include <SDL3/SDL.h>
|
|
|
|
#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<std::function<void()>>::iterator rcmd_it;
|
|
|
|
std::list<std::function<void(Archimedes::Event*)>>::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
|
|
typedef ImguiModule mtype;
|
|
#include "endModule.h"
|
|
#endif
|
|
|
|
|