no src
This commit is contained in:
121
modules/ImguiModule/ImguiModule.cpp
Normal file
121
modules/ImguiModule/ImguiModule.cpp
Normal file
@@ -0,0 +1,121 @@
|
||||
#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()]; }
|
||||
|
||||
wm->getRenderer()->getCmdList().erase(rcmd_it);
|
||||
|
||||
#if WINDOW == 2
|
||||
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 = wm->aquireWindow();
|
||||
|
||||
#if RENDERER == 2
|
||||
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 Platform/Renderer backends
|
||||
if(!windowInit())
|
||||
std::cout << "windowInit failed\n";
|
||||
|
||||
if(!rendererInit()) {
|
||||
std::cout << "rendererInit failed!\n" << std::endl;
|
||||
}
|
||||
|
||||
wm->getRenderer()->getCmdList().push_back([this](){
|
||||
ImGui::Render();
|
||||
|
||||
rendererRenderDrawData();
|
||||
|
||||
rendererNewFrame();
|
||||
windowNewFrame();
|
||||
ImGui::NewFrame();
|
||||
});
|
||||
|
||||
rcmd_it = --wm->getRenderer()->getCmdList().end()++;
|
||||
|
||||
#if WINDOW == 2
|
||||
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();
|
||||
|
||||
}
|
||||
|
||||
bool ImguiModule::onEvent(const Archimedes::Event &e) {
|
||||
/*
|
||||
#if WINDOW == 2
|
||||
if(e.userData != nullptr) {
|
||||
unsigned int type = app->getEventType(e);
|
||||
|
||||
if(type == app->getEventType(Archimedes::ResizeWindowEvent())
|
||||
|| type == app->getEventType(Archimedes::CloseWindowEvent())
|
||||
|| type == app->getEventType(Archimedes::KeyPressedWindowEvent())
|
||||
|| type == app->getEventType(Archimedes::KeyReleasedWindowEvent())
|
||||
|| type == app->getEventType(Archimedes::MouseButtonPressedWindowEvent())
|
||||
|| type == app->getEventType(Archimedes::MouseButtonReleasedWindowEvent())
|
||||
|| type == app->getEventType(Archimedes::ScrollWindowEvent())
|
||||
|| type == app->getEventType(Archimedes::MouseMovedWindowEvent())
|
||||
|| type == app->getEventType(Archimedes::FocusedWindowEvent())
|
||||
|| type == app->getEventType(Archimedes::FocusLostWindowEvent())
|
||||
|| type == app->getEventType(Archimedes::MovedWindowEvent())) {
|
||||
ImGui_ImplSDL3_ProcessEvent((SDL_Event*) e.userData);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
*/
|
||||
return false;
|
||||
}
|
||||
Reference in New Issue
Block a user