TestImgui

This commit is contained in:
2025-04-09 21:32:29 -05:00
parent 6a89659a0a
commit 6d7a05d409
3 changed files with 9 additions and 85 deletions

View File

@@ -9,7 +9,7 @@
class ImguiModule : public Archimedes::GuiModule {
public:
ImguiModule(Archimedes::App*, void*);
ImguiModule(Archimedes::App* a, void* h = nullptr);
~ImguiModule();

View File

@@ -6,9 +6,14 @@
#include <GLFW/glfw3.h>
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; }

View File

@@ -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