flake parts

This commit is contained in:
2026-02-14 13:12:52 -06:00
parent f9f311c82b
commit 874de65dba
75 changed files with 495 additions and 341 deletions

View File

@@ -0,0 +1,116 @@
#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()]; }
#ifdef WINDOW_SDL3
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 = (Archimedes::WindowGLFW*) wm->aquireWindow();
#ifdef RENDERER_SDL3
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;
}
#ifdef WINDOW_SDL3
ecmd_it = wm->addEventFn([](Archimedes::Event* e){
if(e->userData.type() == typeid(SDL_Event*)) {
ImGui_ImplSDL3_ProcessEvent(std::any_cast<SDL_Event*>(e->userData));
}
});
#endif
//Compute first frame ahead of first WindowModule->run()
rendererNewFrame();
windowNewFrame();
ImGui::NewFrame();
}
void ImguiModule::run() {
ImGui::Render();
rendererRenderDrawData();
if(ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_ViewportsEnable) {
ImGui::UpdatePlatformWindows();
ImGui::RenderPlatformWindowsDefault();
window->getWindowImpl()->restoreContext();
}
rendererNewFrame();
windowNewFrame();
ImGui::NewFrame();
};
bool ImguiModule::onEvent(const Archimedes::Event &e) {
return false;
}

View File

@@ -0,0 +1,120 @@
#include "Archimedes.h"
#include "imgui.h"
#include "misc/cpp/imgui_stdlib.h"
#include "modules/WindowModule/WindowModule.h"
#ifdef RENDERER_OPENGL
#include "backends/imgui_impl_opengl3.h"
#endif
#ifdef RENDERER_SDL3
#include "backends/imgui_impl_sdlrenderer3.h"
#endif
#ifdef WINDOW_GLFW
#include "backends/imgui_impl_glfw.h"
#include <GLFW/glfw3.h>
#endif
#ifdef WINDOW_SDL3
#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;
void run() 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::WindowGLFW* window;
std::list<std::function<void()>>::iterator rcmd_it;
std::list<std::function<void(Archimedes::Event*)>>::iterator ecmd_it;
#ifdef RENDERER_OPENGL
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()); }
#endif
#ifdef RENDERER_SDL3
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
#ifdef WINDOW_GLFW
#ifdef RENDERER_OPENGL
auto windowInit() { return ImGui_ImplGlfw_InitForOpenGL(window->getWindowImpl()->getWindow(), true); }
#endif
void windowShutdown() { ImGui_ImplGlfw_Shutdown(); }
void windowNewFrame() { ImGui_ImplGlfw_NewFrame(); }
#endif
#ifdef WINDOW_SDL3
#ifdef RENDERER_OPENGL
auto windowInit() { return ImGui_ImplSDL3_InitForOpenGL(window->getWindowImpl()->getWindow(), window->getWindowImpl()->getContext()); }
#endif
#ifdef RENDERER_SDL3
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