diff --git a/flake.nix b/flake.nix index 9e6dace..11452ee 100755 --- a/flake.nix +++ b/flake.nix @@ -111,11 +111,11 @@ modules/WindowModule/src/*.cpp \ -fpic -shared \ -I src -I include \ - -DRENDERER_OPENGL \ - -DWINDOW_SDL3 \ + -DRENDERER=1 \ + -DWINDOW=2 \ -DWINDOWMODULE_DYNAMIC \ -lGL -lGLEW \ - `sdl3-config --cflags --libs` \ + -lSDL3 \ -Wall \ -o $name ''; @@ -147,8 +147,8 @@ modules/WindowModule/src/*.cpp \ -fpic -shared \ -I src -I include \ - -DRENDERER_OPENGL \ - -DWINDOW_GLFW \ + -DRENDERER=1 \ + -DWINDOW=1 \ -DWINDOWMODULE_DYNAMIC \ -lGL -lglfw -lGLEW \ -Wall \ @@ -183,18 +183,18 @@ clang++ \ modules/ImguiModule/src/*.cpp \ modules/WindowModule/src/*.cpp \ - $imgui/backends/imgui_impl_sdl3.cpp \ - $imgui/backends/imgui_impl_opengl3.cpp \ - $imgui/misc/cpp/*.cpp \ - $imgui/*.cpp \ - -DRENDERER_OPENGL \ - -DWINDOW_SDL3 \ + ${imgui}/backends/imgui_impl_sdl3.cpp \ + ${imgui}/backends/imgui_impl_opengl3.cpp \ + ${imgui}/misc/cpp/*.cpp \ + ${imgui}/*.cpp \ + -DRENDERER=1 \ + -DWINDOW=2 \ -DIMGUIMODULE_DYNAMIC \ -DCUSTOMFONT=${pkgs.fira-code}/share/fonts/truetype/FiraCode-VF.ttf \ -fpic -shared \ - -I src -I include -I $imgui -I . \ + -I src -I include -I ${imgui} -I . \ -lGL -lGLEW \ - `sdl3-config --cflags --libs` \ + -lSDL3 \ -Wall \ -o $name ''; @@ -232,8 +232,8 @@ $imgui/backends/imgui_impl_opengl3.cpp \ $imgui/misc/cpp/*.cpp \ $imgui/*.cpp \ - -DRENDERER_OPENGL \ - -DWINDOW_GLFW \ + -DRENDERER=1 \ + -DWINDOW=1 \ -DIMGUIMODULE_DYNAMIC \ -DCUSTOMFONT=${pkgs.fira-code}/share/fonts/truetype/FiraCode-VF.ttf \ -fpic -shared \ @@ -276,8 +276,8 @@ $imgui/backends/imgui_impl_opengl3.cpp \ $imgui/misc/cpp/*.cpp \ $imgui/*.cpp \ - -DRENDERER_OPENGL \ - -DWINDOW_GLFW \ + -DRENDERER=1 \ + -DWINDOW=1 \ -DMAINGUI_DYNAMIC \ -fpic -shared \ -I src -I include -I $imgui -I . \ @@ -319,8 +319,8 @@ $imgui/backends/imgui_impl_opengl3.cpp \ $imgui/misc/cpp/*.cpp \ $imgui/*.cpp \ - -DRENDERER_OPENGL \ - -DWINDOW_GLFW \ + -DRENDERER=1 \ + -DWINDOW=1 \ -DTERMINAL_DYNAMIC \ -fpic -shared \ -I src -I include -I $imgui -I . \ @@ -365,8 +365,8 @@ $imgui/backends/imgui_impl_opengl3.cpp \ $imgui/misc/cpp/*.cpp \ $imgui/*.cpp \ - -DRENDERER_OPENGL \ - -DWINDOW_GLFW \ + -DRENDERER=1 \ + -DWINDOW=1 \ -DOLLAMA_DYNAMIC \ -fpic -shared \ -I src -I include -I $imgui -I . \ diff --git a/include/utils/Events/BasicEvents.h b/include/utils/Events/BasicEvents.h index 441f881..61a86da 100644 --- a/include/utils/Events/BasicEvents.h +++ b/include/utils/Events/BasicEvents.h @@ -11,9 +11,9 @@ namespace Archimedes { public: - LoadModuleEvent() {} + LoadModuleEvent() : Event(nullptr) {} - LoadModuleEvent(std::string n) : module(n) {} + LoadModuleEvent(std::string n) : Event(nullptr), module(n) {} ~LoadModuleEvent() {} @@ -27,9 +27,9 @@ namespace Archimedes { public: - DoLoadModuleEvent() {} + DoLoadModuleEvent() : Event(nullptr) {} - DoLoadModuleEvent(std::variant n) : module(n) {} + DoLoadModuleEvent(std::variant n) : Event(nullptr), module(n) {} ~DoLoadModuleEvent() {} @@ -43,9 +43,9 @@ namespace Archimedes { public: - UnloadModuleEvent() {} + UnloadModuleEvent() : Event(nullptr) {} - UnloadModuleEvent(std::string n) : module(n) {} + UnloadModuleEvent(std::string n) : Event(nullptr), module(n) {} ~UnloadModuleEvent() {} @@ -58,9 +58,9 @@ namespace Archimedes { public: - DoUnloadModuleEvent() {} + DoUnloadModuleEvent() : Event(nullptr) {} - DoUnloadModuleEvent(std::string n) : module(n) {} + DoUnloadModuleEvent(std::string n) : Event(nullptr), module(n) {} ~DoUnloadModuleEvent() {} diff --git a/include/utils/Events/Event.h b/include/utils/Events/Event.h index b98b414..3910693 100644 --- a/include/utils/Events/Event.h +++ b/include/utils/Events/Event.h @@ -9,10 +9,13 @@ namespace Archimedes { public: + Event(void* ptr) : userData(ptr) {} + virtual ~Event() {} virtual operator std::string() const = 0; + void* userData; }; } diff --git a/include/utils/Events/NetworkEvents.h b/include/utils/Events/NetworkEvents.h index 32abcc8..1438c7e 100644 --- a/include/utils/Events/NetworkEvents.h +++ b/include/utils/Events/NetworkEvents.h @@ -12,9 +12,9 @@ namespace Archimedes { public: - DataRecievedEvent() : msg(nullptr) {} + DataRecievedEvent() : Event(nullptr), msg(nullptr) {} - DataRecievedEvent(ISteamNetworkingMessage* m) : msg(m) {} + DataRecievedEvent(ISteamNetworkingMessage* m) : Event(nullptr), msg(m) {} ~DataRecievedEvent() { if(msg) @@ -31,9 +31,9 @@ namespace Archimedes { public: - DataSentEvent() : msg(nullptr) {} + DataSentEvent() : Event(nullptr), msg(nullptr) {} - DataSentEvent(const void* m, uint32 l) : msg(m), length(l) {} + DataSentEvent(const void* m, uint32 l) : Event(nullptr), msg(m), length(l) {} operator std::string() const override { return "DataSentEvent"; } @@ -45,9 +45,9 @@ namespace Archimedes { public: - ConnectionStatusChangedEvent() : info(nullptr) {} + ConnectionStatusChangedEvent() : Event(nullptr), info(nullptr) {} - ConnectionStatusChangedEvent(SteamNetConnectionStatusChangedCallback_t* i) : info(i) {} + ConnectionStatusChangedEvent(SteamNetConnectionStatusChangedCallback_t* i) : Event(nullptr), info(i) {} operator std::string() const override { return "ConnectionStatusChangedEvent"; } diff --git a/include/utils/Renderer/RendererOpenGL/RendererOpenGL.h b/include/utils/Renderer/RendererOpenGL/RendererOpenGL.h index e506104..0481cbf 100644 --- a/include/utils/Renderer/RendererOpenGL/RendererOpenGL.h +++ b/include/utils/Renderer/RendererOpenGL/RendererOpenGL.h @@ -1,5 +1,7 @@ -#ifdef RENDERER_OPENGL -#undef RENDERER_OPENGL +#if RENDERER == 1 + +#ifndef RENDERER_OPENGL +#define RENDERER_OPENGL #include "pch.hpp" @@ -38,3 +40,5 @@ namespace Archimedes { } #endif + +#endif diff --git a/include/utils/Window/WindowEvents.h b/include/utils/Window/WindowEvents.h index 80d65b5..71f7579 100644 --- a/include/utils/Window/WindowEvents.h +++ b/include/utils/Window/WindowEvents.h @@ -19,9 +19,9 @@ namespace Archimedes { public: - ResizeWindowEvent() : width(0), height(0) {} + ResizeWindowEvent() : Event(nullptr), width(0), height(0) {} - ResizeWindowEvent(int w, int h) : width(w), height(h) {} + ResizeWindowEvent(int w, int h, void* userData = nullptr) : Event(userData), width(w), height(h) {} ~ResizeWindowEvent() { @@ -37,9 +37,9 @@ namespace Archimedes { public: - CloseWindowEvent() : window(nullptr) {} + CloseWindowEvent() : Event(nullptr), window(nullptr) {} - CloseWindowEvent(const Window* w) : window(w) {} + CloseWindowEvent(const Window* w, void* userData = nullptr) : Event(userData), window(w) {} ~CloseWindowEvent() { @@ -54,9 +54,9 @@ namespace Archimedes { public: - KeyPressedWindowEvent() : key(0), repeat(0) {} + KeyPressedWindowEvent() : Event(nullptr), key(0), repeat(0) {} - KeyPressedWindowEvent(unsigned int k, unsigned int r) : key(k), repeat(r) {} + KeyPressedWindowEvent(unsigned int k, unsigned int r, void* userData = nullptr) : Event(userData), key(k), repeat(r) {} ~KeyPressedWindowEvent() { @@ -72,9 +72,9 @@ namespace Archimedes { public: - KeyReleasedWindowEvent() : key(0) {} + KeyReleasedWindowEvent() : Event(nullptr), key(0) {} - KeyReleasedWindowEvent(unsigned int k) : key(k) {} + KeyReleasedWindowEvent(unsigned int k, void* userData = nullptr) : Event(userData), key(k) {} ~KeyReleasedWindowEvent() { @@ -89,9 +89,9 @@ namespace Archimedes { public: - MouseButtonPressedWindowEvent() : button(0) {} + MouseButtonPressedWindowEvent() : Event(nullptr), button(0) {} - MouseButtonPressedWindowEvent(unsigned int b) : button(b) {} + MouseButtonPressedWindowEvent(unsigned int b, void* userData = nullptr) : Event(userData), button(b) {} ~MouseButtonPressedWindowEvent() { @@ -106,9 +106,9 @@ namespace Archimedes { public: - MouseButtonReleasedWindowEvent() : button(0) {} + MouseButtonReleasedWindowEvent() : Event(nullptr), button(0) {} - MouseButtonReleasedWindowEvent(unsigned int b) : button(b) {} + MouseButtonReleasedWindowEvent(unsigned int b, void* userData = nullptr) : Event(userData), button(b) {} ~MouseButtonReleasedWindowEvent() { @@ -123,9 +123,9 @@ namespace Archimedes { public: - ScrollWindowEvent() : dx(0), dy(0) {} + ScrollWindowEvent() : Event(nullptr), dx(0), dy(0) {} - ScrollWindowEvent(double x, double y) : dx(x), dy(y) {} + ScrollWindowEvent(double x, double y, void* userData = nullptr) : Event(userData), dx(x), dy(y) {} ~ScrollWindowEvent() { @@ -140,9 +140,9 @@ namespace Archimedes { public: - MouseMovedWindowEvent() : x(0), y(0) {} + MouseMovedWindowEvent() : Event(nullptr), x(0), y(0) {} - MouseMovedWindowEvent(double x, double y) : x(x), y(y) {} + MouseMovedWindowEvent(double x, double y, void* userData = nullptr) : Event(userData), x(x), y(y) {} ~MouseMovedWindowEvent() { @@ -157,9 +157,9 @@ namespace Archimedes { public: - FocusedWindowEvent() : window(nullptr) {} + FocusedWindowEvent() : Event(nullptr), window(nullptr) {} - FocusedWindowEvent(const Window* w) : window(w) {} + FocusedWindowEvent(const Window* w, void* userData = nullptr) : Event(userData), window(w) {} ~FocusedWindowEvent() { @@ -174,9 +174,9 @@ namespace Archimedes { public: - FocusLostWindowEvent() : window(nullptr) {} + FocusLostWindowEvent() : Event(nullptr), window(nullptr) {} - FocusLostWindowEvent(const Window* w) : window(w) {} + FocusLostWindowEvent(const Window* w, void* userData = nullptr) : Event(userData), window(w) {} ~FocusLostWindowEvent() { @@ -191,9 +191,9 @@ namespace Archimedes { public: - MovedWindowEvent() : x(0), y(0) {} + MovedWindowEvent() : Event(nullptr), x(0), y(0) {} - MovedWindowEvent(int x, int y) : x(x), y(y) {} + MovedWindowEvent(int x, int y, void* userData = nullptr) : Event(userData), x(x), y(y) {} ~MovedWindowEvent() { diff --git a/include/utils/Window/WindowGLFW/WindowGLFW.h b/include/utils/Window/WindowGLFW/WindowGLFW.h index b6cc760..db9aee8 100644 --- a/include/utils/Window/WindowGLFW/WindowGLFW.h +++ b/include/utils/Window/WindowGLFW/WindowGLFW.h @@ -1,7 +1,9 @@ -#include "pch.hpp" +#if WINDOW == 1 -#ifdef WINDOW_GLFW -#undef WINDOW_GLFW +#ifndef WINDOW_GLFW +#define WINDOW_GLFW + +#include "pch.hpp" #include "utils/Window/WindowEvents.h" @@ -127,3 +129,5 @@ namespace Archimedes { } #endif + +#endif diff --git a/include/utils/Window/WindowSDL3/WindowSDL3.h b/include/utils/Window/WindowSDL3/WindowSDL3.h index bd553a9..77ebdde 100644 --- a/include/utils/Window/WindowSDL3/WindowSDL3.h +++ b/include/utils/Window/WindowSDL3/WindowSDL3.h @@ -1,7 +1,9 @@ -#include "pch.hpp" +#if WINDOW == 2 -#ifdef WINDOW_SDL3 -#undef WINDOW_SDL3 +#ifndef WINDOW_SDL3 +#define WINDOW_SDL3 + +#include "pch.hpp" #include "utils/Window/WindowEvents.h" @@ -69,52 +71,52 @@ namespace Archimedes { void doFrame() { restoreContext(); SDL_GL_SwapWindow(w); } - void pollEvents() { - SDL_PollEvent(&e); + void pollEvents() { + while(SDL_PollEvent(&e)) { + switch(e.type) { - switch(e.type) { - - case SDL_EVENT_WINDOW_CLOSE_REQUESTED: - case SDL_EVENT_QUIT: - data.sendEvent(new CloseWindowEvent(data.window)); - break; - case SDL_EVENT_WINDOW_RESIZED: - width = e.window.data1; - height = e.window.data2; - data.sendEvent(new ResizeWindowEvent(e.window.data1, e.window.data2)); - break; - case SDL_EVENT_WINDOW_MOUSE_ENTER: - case SDL_EVENT_WINDOW_FOCUS_GAINED: - data.sendEvent(new FocusedWindowEvent(data.window)); - break; - case SDL_EVENT_WINDOW_MOUSE_LEAVE: - case SDL_EVENT_WINDOW_FOCUS_LOST: - data.sendEvent(new FocusLostWindowEvent(data.window)); - break; - case SDL_EVENT_KEY_DOWN: - data.sendEvent(new KeyPressedWindowEvent(e.key.key, e.key.repeat ? 1 : 0)); - break; - case SDL_EVENT_KEY_UP: - data.sendEvent(new KeyReleasedWindowEvent(e.key.key)); - break; - case SDL_EVENT_TEXT_EDITING: - break; - case SDL_EVENT_TEXT_INPUT: - break; - case SDL_EVENT_MOUSE_MOTION: - data.sendEvent(new MouseMovedWindowEvent(e.motion.x, e.motion.y)); - break; - case SDL_EVENT_MOUSE_BUTTON_DOWN: - data.sendEvent(new MouseButtonPressedWindowEvent(e.button.button)); - break; - case SDL_EVENT_MOUSE_BUTTON_UP: - data.sendEvent(new MouseButtonReleasedWindowEvent(e.button.button)); - break; - case SDL_EVENT_MOUSE_WHEEL: - data.sendEvent(new ScrollWindowEvent(e.wheel.x, e.wheel.y)); - break; - default: - break; + case SDL_EVENT_WINDOW_CLOSE_REQUESTED: + case SDL_EVENT_QUIT: + data.sendEvent(new CloseWindowEvent(data.window, (void*) &e)); + break; + case SDL_EVENT_WINDOW_RESIZED: + width = e.window.data1; + height = e.window.data2; + data.sendEvent(new ResizeWindowEvent(e.window.data1, e.window.data2, (void*) &e)); + break; + case SDL_EVENT_WINDOW_MOUSE_ENTER: + case SDL_EVENT_WINDOW_FOCUS_GAINED: + data.sendEvent(new FocusedWindowEvent(data.window, (void*) &e)); + break; + case SDL_EVENT_WINDOW_MOUSE_LEAVE: + case SDL_EVENT_WINDOW_FOCUS_LOST: + data.sendEvent(new FocusLostWindowEvent(data.window, (void*) &e)); + break; + case SDL_EVENT_KEY_DOWN: + data.sendEvent(new KeyPressedWindowEvent(e.key.key, e.key.repeat ? 1 : 0, (void*) &e)); + break; + case SDL_EVENT_KEY_UP: + data.sendEvent(new KeyReleasedWindowEvent(e.key.key, (void*) &e)); + break; + case SDL_EVENT_TEXT_EDITING: + break; + case SDL_EVENT_TEXT_INPUT: + break; + case SDL_EVENT_MOUSE_MOTION: + data.sendEvent(new MouseMovedWindowEvent(e.motion.x, e.motion.y, (void*) &e)); + break; + case SDL_EVENT_MOUSE_BUTTON_DOWN: + data.sendEvent(new MouseButtonPressedWindowEvent(e.button.button, (void*) &e)); + break; + case SDL_EVENT_MOUSE_BUTTON_UP: + data.sendEvent(new MouseButtonReleasedWindowEvent(e.button.button, (void*) &e)); + break; + case SDL_EVENT_MOUSE_WHEEL: + data.sendEvent(new ScrollWindowEvent(e.wheel.x, e.wheel.y, (void*) &e)); + break; + default: + break; + } } } @@ -143,3 +145,5 @@ namespace Archimedes { } #endif + +#endif diff --git a/modules/ImguiModule/src/ImguiModule.cpp b/modules/ImguiModule/src/ImguiModule.cpp index b1f3af7..8273c4b 100644 --- a/modules/ImguiModule/src/ImguiModule.cpp +++ b/modules/ImguiModule/src/ImguiModule.cpp @@ -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; } diff --git a/modules/ImguiModule/src/ImguiModule.h b/modules/ImguiModule/src/ImguiModule.h index 46a0ca1..501f474 100644 --- a/modules/ImguiModule/src/ImguiModule.h +++ b/modules/ImguiModule/src/ImguiModule.h @@ -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 -#endif - -#ifdef WINDOW_SDL3 +#elif WINDOW == 2 #include "backends/imgui_impl_sdl3.h" #include @@ -64,8 +59,10 @@ class ImguiModule : public Archimedes::Module { Archimedes::Window* window; std::list>::iterator rcmd_it; + + std::list>::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 }; diff --git a/modules/WindowModule/src/WindowModule.h b/modules/WindowModule/src/WindowModule.h index 45edc34..9fc0480 100644 --- a/modules/WindowModule/src/WindowModule.h +++ b/modules/WindowModule/src/WindowModule.h @@ -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 f : eventFuncs) + f(e); app->emitEvent(e); }); @@ -54,6 +56,10 @@ class WindowModule : public Archimedes::Module { } } } + + auto addEventFn(const std::function& fn) { eventFuncs.push_back(fn); return --eventFuncs.end()++; } + + void removeEventFn(std::list>::iterator it) { eventFuncs.erase(it); } Archimedes::Renderer* getRenderer() { return renderer; } @@ -61,6 +67,8 @@ class WindowModule : public Archimedes::Module { int windowRefs = 0; + std::list> eventFuncs; + Archimedes::Window* window = nullptr; Archimedes::Renderer* renderer = nullptr;