From 6d7a05d409d33bad91907528d96ec25b45a785f6 Mon Sep 17 00:00:00 2001 From: Nathan Date: Wed, 9 Apr 2025 21:32:29 -0500 Subject: [PATCH] TestImgui --- modules/ImguiModule/src/ImguiModule.h | 2 +- .../GuiModules/TestImgui/src/TestImgui.cpp | 67 ++----------------- .../GuiModules/TestImgui/src/TestImgui.h | 25 +------ 3 files changed, 9 insertions(+), 85 deletions(-) diff --git a/modules/ImguiModule/src/ImguiModule.h b/modules/ImguiModule/src/ImguiModule.h index d336b45..3d1f005 100644 --- a/modules/ImguiModule/src/ImguiModule.h +++ b/modules/ImguiModule/src/ImguiModule.h @@ -9,7 +9,7 @@ class ImguiModule : public Archimedes::GuiModule { public: - ImguiModule(Archimedes::App*, void*); + ImguiModule(Archimedes::App* a, void* h = nullptr); ~ImguiModule(); diff --git a/modules/examples/GuiModules/TestImgui/src/TestImgui.cpp b/modules/examples/GuiModules/TestImgui/src/TestImgui.cpp index ddfc007..155f628 100644 --- a/modules/examples/GuiModules/TestImgui/src/TestImgui.cpp +++ b/modules/examples/GuiModules/TestImgui/src/TestImgui.cpp @@ -6,9 +6,14 @@ #include -TestImgui::TestImgui(void* h, Archimedes::App* a) : Archimedes::GuiModule(h, a) { +#include "modules/ImguiModule/src/ImguiModule.h" + +TestImgui::TestImgui(Archimedes::App* a, void* h) : Archimedes::GuiModule(a, h) { name = "TestImgui"; + + ImguiModule* im = new ImguiModule(a); + deps[im->getName()] = im; } TestImgui::~TestImgui() { @@ -17,21 +22,15 @@ TestImgui::~TestImgui() { void TestImgui::onLoad() { - WindowModule* wm = (WindowModule*) depsInstances["WindowModule"]; + WindowModule* wm = (WindowModule*) moduleInstances["WindowModule"]; if(!wm) { std::cout << "No WindowModule for TestImgui!\n"; std::abort(); } - - wm->getLayerstack()->push(&layer); } void TestImgui::run() { - ImGui_ImplOpenGL3_NewFrame(); - ImGui_ImplGlfw_NewFrame(); - ImGui::NewFrame(); - if(demo) ImGui::ShowDemoWindow(&this->demo); else @@ -56,56 +55,4 @@ void TestImgui::run() { ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / io.Framerate, io.Framerate); ImGui::End(); } - ImGui::Render(); } - - -TestImgui::TILayer::~TILayer() {} - -void TestImgui::TILayer::onAttach() { - WindowModule* wm = (WindowModule*) ti->depsInstances["WindowModule"]; - - if(!wm) { - std::cout << "No WindowModule for TestImgui!\n"; - std::abort(); - } - - IMGUI_CHECKVERSION(); - 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 - - // Setup Dear ImGui style - ImGui::StyleColorsDark(); - //ImGui::StyleColorsLight(); - - // Setup Platform/Renderer backends - if(!ImGui_ImplGlfw_InitForOpenGL(wm->getWindow()->getWindowImpl().getWindow(), true)) - std::cout << "GLFWImpl failed\n"; - if(!ImGui_ImplOpenGL3_Init("#version 330")) { - std::cout << "ImGui_ImplOpenGL3_Init failed!\n" << std::endl; - } - - //Compute first frame ahead of first WindowModule->run() - ImGui_ImplOpenGL3_NewFrame(); - ImGui_ImplGlfw_NewFrame(); - ImGui::NewFrame(); - - ImGui::Render(); -} - -void TestImgui::TILayer::onRender() { - ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); -} - -void TestImgui::TILayer::onDetach() { - ImGui_ImplOpenGL3_Shutdown(); - ImGui_ImplGlfw_Shutdown(); - ImGui::DestroyContext(); -} - -bool TestImgui::TILayer::onEvent(const Archimedes::Event&) { return false; } diff --git a/modules/examples/GuiModules/TestImgui/src/TestImgui.h b/modules/examples/GuiModules/TestImgui/src/TestImgui.h index 345b661..d232f4b 100644 --- a/modules/examples/GuiModules/TestImgui/src/TestImgui.h +++ b/modules/examples/GuiModules/TestImgui/src/TestImgui.h @@ -9,7 +9,7 @@ class TestImgui : public Archimedes::GuiModule { public: - TestImgui(void*, Archimedes::App*); + TestImgui(Archimedes::App*, void*); ~TestImgui(); @@ -20,29 +20,6 @@ class TestImgui : public Archimedes::GuiModule { private: bool demo = true; - - Archimedes::Window* window; - - class TILayer : public Archimedes::Layer { - public: - - TILayer(TestImgui* _ti) : ti(_ti) {} - - ~TILayer(); - - void onRender(); - - void onAttach(); - - void onDetach(); - - bool onEvent(const Archimedes::Event&); - - private: - - TestImgui* ti; - - } layer = TILayer(this); }; #ifdef TESTIMGUI_DYNAMIC