sdl event stuff

This commit is contained in:
2025-05-05 11:08:07 -05:00
parent 2820387851
commit c2da1944d8
11 changed files with 195 additions and 134 deletions

View File

@@ -111,11 +111,11 @@
modules/WindowModule/src/*.cpp \ modules/WindowModule/src/*.cpp \
-fpic -shared \ -fpic -shared \
-I src -I include \ -I src -I include \
-DRENDERER_OPENGL \ -DRENDERER=1 \
-DWINDOW_SDL3 \ -DWINDOW=2 \
-DWINDOWMODULE_DYNAMIC \ -DWINDOWMODULE_DYNAMIC \
-lGL -lGLEW \ -lGL -lGLEW \
`sdl3-config --cflags --libs` \ -lSDL3 \
-Wall \ -Wall \
-o $name -o $name
''; '';
@@ -147,8 +147,8 @@
modules/WindowModule/src/*.cpp \ modules/WindowModule/src/*.cpp \
-fpic -shared \ -fpic -shared \
-I src -I include \ -I src -I include \
-DRENDERER_OPENGL \ -DRENDERER=1 \
-DWINDOW_GLFW \ -DWINDOW=1 \
-DWINDOWMODULE_DYNAMIC \ -DWINDOWMODULE_DYNAMIC \
-lGL -lglfw -lGLEW \ -lGL -lglfw -lGLEW \
-Wall \ -Wall \
@@ -183,18 +183,18 @@
clang++ \ clang++ \
modules/ImguiModule/src/*.cpp \ modules/ImguiModule/src/*.cpp \
modules/WindowModule/src/*.cpp \ modules/WindowModule/src/*.cpp \
$imgui/backends/imgui_impl_sdl3.cpp \ ${imgui}/backends/imgui_impl_sdl3.cpp \
$imgui/backends/imgui_impl_opengl3.cpp \ ${imgui}/backends/imgui_impl_opengl3.cpp \
$imgui/misc/cpp/*.cpp \ ${imgui}/misc/cpp/*.cpp \
$imgui/*.cpp \ ${imgui}/*.cpp \
-DRENDERER_OPENGL \ -DRENDERER=1 \
-DWINDOW_SDL3 \ -DWINDOW=2 \
-DIMGUIMODULE_DYNAMIC \ -DIMGUIMODULE_DYNAMIC \
-DCUSTOMFONT=${pkgs.fira-code}/share/fonts/truetype/FiraCode-VF.ttf \ -DCUSTOMFONT=${pkgs.fira-code}/share/fonts/truetype/FiraCode-VF.ttf \
-fpic -shared \ -fpic -shared \
-I src -I include -I $imgui -I . \ -I src -I include -I ${imgui} -I . \
-lGL -lGLEW \ -lGL -lGLEW \
`sdl3-config --cflags --libs` \ -lSDL3 \
-Wall \ -Wall \
-o $name -o $name
''; '';
@@ -232,8 +232,8 @@
$imgui/backends/imgui_impl_opengl3.cpp \ $imgui/backends/imgui_impl_opengl3.cpp \
$imgui/misc/cpp/*.cpp \ $imgui/misc/cpp/*.cpp \
$imgui/*.cpp \ $imgui/*.cpp \
-DRENDERER_OPENGL \ -DRENDERER=1 \
-DWINDOW_GLFW \ -DWINDOW=1 \
-DIMGUIMODULE_DYNAMIC \ -DIMGUIMODULE_DYNAMIC \
-DCUSTOMFONT=${pkgs.fira-code}/share/fonts/truetype/FiraCode-VF.ttf \ -DCUSTOMFONT=${pkgs.fira-code}/share/fonts/truetype/FiraCode-VF.ttf \
-fpic -shared \ -fpic -shared \
@@ -276,8 +276,8 @@
$imgui/backends/imgui_impl_opengl3.cpp \ $imgui/backends/imgui_impl_opengl3.cpp \
$imgui/misc/cpp/*.cpp \ $imgui/misc/cpp/*.cpp \
$imgui/*.cpp \ $imgui/*.cpp \
-DRENDERER_OPENGL \ -DRENDERER=1 \
-DWINDOW_GLFW \ -DWINDOW=1 \
-DMAINGUI_DYNAMIC \ -DMAINGUI_DYNAMIC \
-fpic -shared \ -fpic -shared \
-I src -I include -I $imgui -I . \ -I src -I include -I $imgui -I . \
@@ -319,8 +319,8 @@
$imgui/backends/imgui_impl_opengl3.cpp \ $imgui/backends/imgui_impl_opengl3.cpp \
$imgui/misc/cpp/*.cpp \ $imgui/misc/cpp/*.cpp \
$imgui/*.cpp \ $imgui/*.cpp \
-DRENDERER_OPENGL \ -DRENDERER=1 \
-DWINDOW_GLFW \ -DWINDOW=1 \
-DTERMINAL_DYNAMIC \ -DTERMINAL_DYNAMIC \
-fpic -shared \ -fpic -shared \
-I src -I include -I $imgui -I . \ -I src -I include -I $imgui -I . \
@@ -365,8 +365,8 @@
$imgui/backends/imgui_impl_opengl3.cpp \ $imgui/backends/imgui_impl_opengl3.cpp \
$imgui/misc/cpp/*.cpp \ $imgui/misc/cpp/*.cpp \
$imgui/*.cpp \ $imgui/*.cpp \
-DRENDERER_OPENGL \ -DRENDERER=1 \
-DWINDOW_GLFW \ -DWINDOW=1 \
-DOLLAMA_DYNAMIC \ -DOLLAMA_DYNAMIC \
-fpic -shared \ -fpic -shared \
-I src -I include -I $imgui -I . \ -I src -I include -I $imgui -I . \

View File

@@ -11,9 +11,9 @@ namespace Archimedes {
public: public:
LoadModuleEvent() {} LoadModuleEvent() : Event(nullptr) {}
LoadModuleEvent(std::string n) : module(n) {} LoadModuleEvent(std::string n) : Event(nullptr), module(n) {}
~LoadModuleEvent() {} ~LoadModuleEvent() {}
@@ -27,9 +27,9 @@ namespace Archimedes {
public: public:
DoLoadModuleEvent() {} DoLoadModuleEvent() : Event(nullptr) {}
DoLoadModuleEvent(std::variant<std::string, Module*> n) : module(n) {} DoLoadModuleEvent(std::variant<std::string, Module*> n) : Event(nullptr), module(n) {}
~DoLoadModuleEvent() {} ~DoLoadModuleEvent() {}
@@ -43,9 +43,9 @@ namespace Archimedes {
public: public:
UnloadModuleEvent() {} UnloadModuleEvent() : Event(nullptr) {}
UnloadModuleEvent(std::string n) : module(n) {} UnloadModuleEvent(std::string n) : Event(nullptr), module(n) {}
~UnloadModuleEvent() {} ~UnloadModuleEvent() {}
@@ -58,9 +58,9 @@ namespace Archimedes {
public: public:
DoUnloadModuleEvent() {} DoUnloadModuleEvent() : Event(nullptr) {}
DoUnloadModuleEvent(std::string n) : module(n) {} DoUnloadModuleEvent(std::string n) : Event(nullptr), module(n) {}
~DoUnloadModuleEvent() {} ~DoUnloadModuleEvent() {}

View File

@@ -9,10 +9,13 @@ namespace Archimedes {
public: public:
Event(void* ptr) : userData(ptr) {}
virtual ~Event() {} virtual ~Event() {}
virtual operator std::string() const = 0; virtual operator std::string() const = 0;
void* userData;
}; };
} }

View File

@@ -12,9 +12,9 @@ namespace Archimedes {
public: public:
DataRecievedEvent() : msg(nullptr) {} DataRecievedEvent() : Event(nullptr), msg(nullptr) {}
DataRecievedEvent(ISteamNetworkingMessage* m) : msg(m) {} DataRecievedEvent(ISteamNetworkingMessage* m) : Event(nullptr), msg(m) {}
~DataRecievedEvent() { ~DataRecievedEvent() {
if(msg) if(msg)
@@ -31,9 +31,9 @@ namespace Archimedes {
public: 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"; } operator std::string() const override { return "DataSentEvent"; }
@@ -45,9 +45,9 @@ namespace Archimedes {
public: 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"; } operator std::string() const override { return "ConnectionStatusChangedEvent"; }

View File

@@ -1,5 +1,7 @@
#ifdef RENDERER_OPENGL #if RENDERER == 1
#undef RENDERER_OPENGL
#ifndef RENDERER_OPENGL
#define RENDERER_OPENGL
#include "pch.hpp" #include "pch.hpp"
@@ -38,3 +40,5 @@ namespace Archimedes {
} }
#endif #endif
#endif

View File

@@ -19,9 +19,9 @@ namespace Archimedes {
public: 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() { ~ResizeWindowEvent() {
@@ -37,9 +37,9 @@ namespace Archimedes {
public: 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() { ~CloseWindowEvent() {
@@ -54,9 +54,9 @@ namespace Archimedes {
public: 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() { ~KeyPressedWindowEvent() {
@@ -72,9 +72,9 @@ namespace Archimedes {
public: 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() { ~KeyReleasedWindowEvent() {
@@ -89,9 +89,9 @@ namespace Archimedes {
public: 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() { ~MouseButtonPressedWindowEvent() {
@@ -106,9 +106,9 @@ namespace Archimedes {
public: 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() { ~MouseButtonReleasedWindowEvent() {
@@ -123,9 +123,9 @@ namespace Archimedes {
public: 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() { ~ScrollWindowEvent() {
@@ -140,9 +140,9 @@ namespace Archimedes {
public: 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() { ~MouseMovedWindowEvent() {
@@ -157,9 +157,9 @@ namespace Archimedes {
public: 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() { ~FocusedWindowEvent() {
@@ -174,9 +174,9 @@ namespace Archimedes {
public: 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() { ~FocusLostWindowEvent() {
@@ -191,9 +191,9 @@ namespace Archimedes {
public: 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() { ~MovedWindowEvent() {

View File

@@ -1,7 +1,9 @@
#include "pch.hpp" #if WINDOW == 1
#ifdef WINDOW_GLFW #ifndef WINDOW_GLFW
#undef WINDOW_GLFW #define WINDOW_GLFW
#include "pch.hpp"
#include "utils/Window/WindowEvents.h" #include "utils/Window/WindowEvents.h"
@@ -127,3 +129,5 @@ namespace Archimedes {
} }
#endif #endif
#endif

View File

@@ -1,7 +1,9 @@
#include "pch.hpp" #if WINDOW == 2
#ifdef WINDOW_SDL3 #ifndef WINDOW_SDL3
#undef WINDOW_SDL3 #define WINDOW_SDL3
#include "pch.hpp"
#include "utils/Window/WindowEvents.h" #include "utils/Window/WindowEvents.h"
@@ -70,53 +72,53 @@ namespace Archimedes {
void doFrame() { restoreContext(); SDL_GL_SwapWindow(w); } void doFrame() { restoreContext(); SDL_GL_SwapWindow(w); }
void pollEvents() { void pollEvents() {
SDL_PollEvent(&e); while(SDL_PollEvent(&e)) {
switch(e.type) { switch(e.type) {
case SDL_EVENT_WINDOW_CLOSE_REQUESTED: case SDL_EVENT_WINDOW_CLOSE_REQUESTED:
case SDL_EVENT_QUIT: case SDL_EVENT_QUIT:
data.sendEvent(new CloseWindowEvent(data.window)); data.sendEvent(new CloseWindowEvent(data.window, (void*) &e));
break; break;
case SDL_EVENT_WINDOW_RESIZED: case SDL_EVENT_WINDOW_RESIZED:
width = e.window.data1; width = e.window.data1;
height = e.window.data2; height = e.window.data2;
data.sendEvent(new ResizeWindowEvent(e.window.data1, e.window.data2)); data.sendEvent(new ResizeWindowEvent(e.window.data1, e.window.data2, (void*) &e));
break; break;
case SDL_EVENT_WINDOW_MOUSE_ENTER: case SDL_EVENT_WINDOW_MOUSE_ENTER:
case SDL_EVENT_WINDOW_FOCUS_GAINED: case SDL_EVENT_WINDOW_FOCUS_GAINED:
data.sendEvent(new FocusedWindowEvent(data.window)); data.sendEvent(new FocusedWindowEvent(data.window, (void*) &e));
break; break;
case SDL_EVENT_WINDOW_MOUSE_LEAVE: case SDL_EVENT_WINDOW_MOUSE_LEAVE:
case SDL_EVENT_WINDOW_FOCUS_LOST: case SDL_EVENT_WINDOW_FOCUS_LOST:
data.sendEvent(new FocusLostWindowEvent(data.window)); data.sendEvent(new FocusLostWindowEvent(data.window, (void*) &e));
break; break;
case SDL_EVENT_KEY_DOWN: case SDL_EVENT_KEY_DOWN:
data.sendEvent(new KeyPressedWindowEvent(e.key.key, e.key.repeat ? 1 : 0)); data.sendEvent(new KeyPressedWindowEvent(e.key.key, e.key.repeat ? 1 : 0, (void*) &e));
break; break;
case SDL_EVENT_KEY_UP: case SDL_EVENT_KEY_UP:
data.sendEvent(new KeyReleasedWindowEvent(e.key.key)); data.sendEvent(new KeyReleasedWindowEvent(e.key.key, (void*) &e));
break; break;
case SDL_EVENT_TEXT_EDITING: case SDL_EVENT_TEXT_EDITING:
break; break;
case SDL_EVENT_TEXT_INPUT: case SDL_EVENT_TEXT_INPUT:
break; break;
case SDL_EVENT_MOUSE_MOTION: case SDL_EVENT_MOUSE_MOTION:
data.sendEvent(new MouseMovedWindowEvent(e.motion.x, e.motion.y)); data.sendEvent(new MouseMovedWindowEvent(e.motion.x, e.motion.y, (void*) &e));
break; break;
case SDL_EVENT_MOUSE_BUTTON_DOWN: case SDL_EVENT_MOUSE_BUTTON_DOWN:
data.sendEvent(new MouseButtonPressedWindowEvent(e.button.button)); data.sendEvent(new MouseButtonPressedWindowEvent(e.button.button, (void*) &e));
break; break;
case SDL_EVENT_MOUSE_BUTTON_UP: case SDL_EVENT_MOUSE_BUTTON_UP:
data.sendEvent(new MouseButtonReleasedWindowEvent(e.button.button)); data.sendEvent(new MouseButtonReleasedWindowEvent(e.button.button, (void*) &e));
break; break;
case SDL_EVENT_MOUSE_WHEEL: case SDL_EVENT_MOUSE_WHEEL:
data.sendEvent(new ScrollWindowEvent(e.wheel.x, e.wheel.y)); data.sendEvent(new ScrollWindowEvent(e.wheel.x, e.wheel.y, (void*) &e));
break; break;
default: default:
break; break;
} }
} }
}
void restoreContext() { SDL_GL_MakeCurrent(w, gl_context); } void restoreContext() { SDL_GL_MakeCurrent(w, gl_context); }
@@ -143,3 +145,5 @@ namespace Archimedes {
} }
#endif #endif
#endif

View File

@@ -17,6 +17,10 @@ ImguiModule::~ImguiModule() {
wm->getRenderer()->getCmdList().erase(rcmd_it); wm->getRenderer()->getCmdList().erase(rcmd_it);
#if WINDOW == 2
wm->removeEventFn(ecmd_it);
#endif
rendererShutdown(); rendererShutdown();
windowShutdown(); windowShutdown();
ImGui::DestroyContext(); ImGui::DestroyContext();
@@ -60,7 +64,7 @@ void ImguiModule::onLoad() {
std::cout << "rendererInit failed!\n" << std::endl; std::cout << "rendererInit failed!\n" << std::endl;
} }
wm->getRenderer()->getCmdList().push_back([](){ wm->getRenderer()->getCmdList().push_back([this](){
ImGui::Render(); ImGui::Render();
rendererRenderDrawData(); rendererRenderDrawData();
@@ -72,6 +76,28 @@ void ImguiModule::onLoad() {
rcmd_it = --wm->getRenderer()->getCmdList().end()++; 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() //Compute first frame ahead of first WindowModule->run()
rendererNewFrame(); rendererNewFrame();
windowNewFrame(); 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; return false;
} }

View File

@@ -1,6 +1,3 @@
#ifndef GUIMODULE
#define GUIMODULE
#endif
#include "Archimedes.h" #include "Archimedes.h"
@@ -9,20 +6,18 @@
#include "modules/WindowModule/src/WindowModule.h" #include "modules/WindowModule/src/WindowModule.h"
#ifdef RENDERER_OPENGL #if RENDERER == 1
#include "backends/imgui_impl_opengl3.h" #include "backends/imgui_impl_opengl3.h"
#endif #endif
#ifdef WINDOW_GLFW #if WINDOW == 1
#include "backends/imgui_impl_glfw.h" #include "backends/imgui_impl_glfw.h"
#include <GLFW/glfw3.h> #include <GLFW/glfw3.h>
#endif #elif WINDOW == 2
#ifdef WINDOW_SDL3
#include "backends/imgui_impl_sdl3.h" #include "backends/imgui_impl_sdl3.h"
#include <SDL3/SDL.h> #include <SDL3/SDL.h>
@@ -65,7 +60,9 @@ class ImguiModule : public Archimedes::Module {
std::list<std::function<void()>>::iterator rcmd_it; std::list<std::function<void()>>::iterator rcmd_it;
#ifdef RENDERER_OPENGL std::list<std::function<void(Archimedes::Event*)>>::iterator ecmd_it;
#if RENDERER == 1
auto rendererInit() { return ImGui_ImplOpenGL3_Init("#version 330"); } auto rendererInit() { return ImGui_ImplOpenGL3_Init("#version 330"); }
void rendererShutdown() { ImGui_ImplOpenGL3_Shutdown(); } void rendererShutdown() { ImGui_ImplOpenGL3_Shutdown(); }
@@ -74,30 +71,24 @@ class ImguiModule : public Archimedes::Module {
#endif #endif
#ifdef WINDOW_GLFW #if WINDOW == 1
#ifdef RENDERER_OPENGL #if RENDERER == 1
auto windowInit(Archimedes::Window* window) { return ImGui_ImplGlfw_InitForOpenGL(window->getWindowImpl().getWindow(), true); } auto windowInit() { return ImGui_ImplGlfw_InitForOpenGL(window->getWindowImpl().getWindow(), true); }
#endif #endif
void windowShutdown() { ImGui_ImplGlfw_Shutdown(); } void windowShutdown() { ImGui_ImplGlfw_Shutdown(); }
void windowNewFrame() { ImGui_ImplGlfw_NewFrame(); } void windowNewFrame() { ImGui_ImplGlfw_NewFrame(); }
#elif WINDOW == 2
#if RENDERER == 1
auto windowInit() { return ImGui_ImplSDL3_InitForOpenGL(window->getWindowImpl().getWindow(), window->getWindowImpl().getContext()); }
#endif #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(); } void windowShutdown() { ImGui_ImplSDL3_Shutdown(); }
#define windowNewFrame() ImGui_ImplSDL3_NewFrame()
void windowNewFrame() { ImGui_ImplSDL3_NewFrame(); } void windowNewFrame() { ImGui_ImplSDL3_NewFrame(); }
void windowProcessEvent(SDL_Event e) { ImGui_ImplSDL3_ProcessEvent(&e); }
#endif #endif
}; };

View File

@@ -28,7 +28,9 @@ class WindowModule : public Archimedes::Module {
Archimedes::Window* aquireWindow() { Archimedes::Window* aquireWindow() {
if(!window) { 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); app->emitEvent(e);
}); });
@@ -55,12 +57,18 @@ 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; } Archimedes::Renderer* getRenderer() { return renderer; }
private: private:
int windowRefs = 0; int windowRefs = 0;
std::list<std::function<void(Archimedes::Event*)>> eventFuncs;
Archimedes::Window* window = nullptr; Archimedes::Window* window = nullptr;
Archimedes::Renderer* renderer = nullptr; Archimedes::Renderer* renderer = nullptr;