sdl event stuff
This commit is contained in:
@@ -17,6 +17,10 @@ ImguiModule::~ImguiModule() {
|
||||
|
||||
wm->getRenderer()->getCmdList().erase(rcmd_it);
|
||||
|
||||
#if WINDOW == 2
|
||||
wm->removeEventFn(ecmd_it);
|
||||
#endif
|
||||
|
||||
rendererShutdown();
|
||||
windowShutdown();
|
||||
ImGui::DestroyContext();
|
||||
@@ -60,7 +64,7 @@ void ImguiModule::onLoad() {
|
||||
std::cout << "rendererInit failed!\n" << std::endl;
|
||||
}
|
||||
|
||||
wm->getRenderer()->getCmdList().push_back([](){
|
||||
wm->getRenderer()->getCmdList().push_back([this](){
|
||||
ImGui::Render();
|
||||
|
||||
rendererRenderDrawData();
|
||||
@@ -72,6 +76,28 @@ void ImguiModule::onLoad() {
|
||||
|
||||
rcmd_it = --wm->getRenderer()->getCmdList().end()++;
|
||||
|
||||
#if WINDOW == 2
|
||||
ecmd_it = wm->addEventFn([this](Archimedes::Event* e){
|
||||
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
|
||||
|
||||
//Compute first frame ahead of first WindowModule->run()
|
||||
rendererNewFrame();
|
||||
windowNewFrame();
|
||||
@@ -79,6 +105,27 @@ void ImguiModule::onLoad() {
|
||||
|
||||
}
|
||||
|
||||
bool ImguiModule::onEvent(const Archimedes::Event &event) {
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
#ifndef GUIMODULE
|
||||
#define GUIMODULE
|
||||
#endif
|
||||
|
||||
#include "Archimedes.h"
|
||||
|
||||
@@ -9,20 +6,18 @@
|
||||
|
||||
#include "modules/WindowModule/src/WindowModule.h"
|
||||
|
||||
#ifdef RENDERER_OPENGL
|
||||
#if RENDERER == 1
|
||||
|
||||
#include "backends/imgui_impl_opengl3.h"
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef WINDOW_GLFW
|
||||
#if WINDOW == 1
|
||||
|
||||
#include "backends/imgui_impl_glfw.h"
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef WINDOW_SDL3
|
||||
#elif WINDOW == 2
|
||||
|
||||
#include "backends/imgui_impl_sdl3.h"
|
||||
#include <SDL3/SDL.h>
|
||||
@@ -64,8 +59,10 @@ class ImguiModule : public Archimedes::Module {
|
||||
Archimedes::Window* window;
|
||||
|
||||
std::list<std::function<void()>>::iterator rcmd_it;
|
||||
|
||||
std::list<std::function<void(Archimedes::Event*)>>::iterator ecmd_it;
|
||||
|
||||
#ifdef RENDERER_OPENGL
|
||||
#if RENDERER == 1
|
||||
auto rendererInit() { return ImGui_ImplOpenGL3_Init("#version 330"); }
|
||||
void rendererShutdown() { ImGui_ImplOpenGL3_Shutdown(); }
|
||||
|
||||
@@ -74,30 +71,24 @@ class ImguiModule : public Archimedes::Module {
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef WINDOW_GLFW
|
||||
#ifdef RENDERER_OPENGL
|
||||
auto windowInit(Archimedes::Window* window) { return ImGui_ImplGlfw_InitForOpenGL(window->getWindowImpl().getWindow(), true); }
|
||||
#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()); }
|
||||
#endif
|
||||
|
||||
#ifdef WINDOW_SDL3
|
||||
#ifdef RENDERER_OPENGL
|
||||
auto windowInit(Archimedes::Window* window) { return ImGui_ImplSDL3_InitForOpenGL(window->getWindowImpl().getWindow(), window->getWindowImpl().getContext()); }
|
||||
#endif
|
||||
|
||||
#define windowShutdown() ImGui_ImplSDL3_Shutdown()
|
||||
void windowShutdown() { ImGui_ImplSDL3_Shutdown(); }
|
||||
|
||||
#define windowNewFrame() ImGui_ImplSDL3_NewFrame()
|
||||
void windowNewFrame() { ImGui_ImplSDL3_NewFrame(); }
|
||||
|
||||
void windowProcessEvent(SDL_Event e) { ImGui_ImplSDL3_ProcessEvent(&e); }
|
||||
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
@@ -28,7 +28,9 @@ class WindowModule : public Archimedes::Module {
|
||||
Archimedes::Window* aquireWindow() {
|
||||
if(!window) {
|
||||
|
||||
window = new Archimedes::Window([this](Archimedes::Event* e){
|
||||
window = new Archimedes::Window([this](Archimedes::Event* e) {
|
||||
for(std::function<void(Archimedes::Event*)> f : eventFuncs)
|
||||
f(e);
|
||||
app->emitEvent(e);
|
||||
});
|
||||
|
||||
@@ -54,6 +56,10 @@ class WindowModule : public Archimedes::Module {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
auto addEventFn(const std::function<void(Archimedes::Event*)>& fn) { eventFuncs.push_back(fn); return --eventFuncs.end()++; }
|
||||
|
||||
void removeEventFn(std::list<std::function<void(Archimedes::Event*)>>::iterator it) { eventFuncs.erase(it); }
|
||||
|
||||
Archimedes::Renderer* getRenderer() { return renderer; }
|
||||
|
||||
@@ -61,6 +67,8 @@ class WindowModule : public Archimedes::Module {
|
||||
|
||||
int windowRefs = 0;
|
||||
|
||||
std::list<std::function<void(Archimedes::Event*)>> eventFuncs;
|
||||
|
||||
Archimedes::Window* window = nullptr;
|
||||
Archimedes::Renderer* renderer = nullptr;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user