use std::any

This commit is contained in:
2025-05-05 13:17:38 -05:00
parent c2da1944d8
commit f35c58d3d6
9 changed files with 171 additions and 153 deletions

View File

@@ -19,9 +19,10 @@ namespace Archimedes {
public:
ResizeWindowEvent() : Event(nullptr), width(0), height(0) {}
ResizeWindowEvent() : width(0), height(0) {}
ResizeWindowEvent(int w, int h, void* userData = nullptr) : Event(userData), width(w), height(h) {}
ResizeWindowEvent(int w, int h) : width(w), height(h) {}
ResizeWindowEvent(int w, int h, std::any userData) : Event(userData), width(w), height(h) {}
~ResizeWindowEvent() {
@@ -39,7 +40,8 @@ namespace Archimedes {
CloseWindowEvent() : Event(nullptr), window(nullptr) {}
CloseWindowEvent(const Window* w, void* userData = nullptr) : Event(userData), window(w) {}
CloseWindowEvent(const Window* w) : window(w) {}
CloseWindowEvent(const Window* w, std::any userData) : Event(userData), window(w) {}
~CloseWindowEvent() {
@@ -54,9 +56,10 @@ namespace Archimedes {
public:
KeyPressedWindowEvent() : Event(nullptr), key(0), repeat(0) {}
KeyPressedWindowEvent() : key(0), repeat(0) {}
KeyPressedWindowEvent(unsigned int k, unsigned int r, void* userData = nullptr) : Event(userData), key(k), repeat(r) {}
KeyPressedWindowEvent(unsigned int k, unsigned int r) : key(k), repeat(r) {}
KeyPressedWindowEvent(unsigned int k, unsigned int r, std::any userData) : Event(userData), key(k), repeat(r) {}
~KeyPressedWindowEvent() {
@@ -74,7 +77,8 @@ namespace Archimedes {
KeyReleasedWindowEvent() : Event(nullptr), key(0) {}
KeyReleasedWindowEvent(unsigned int k, void* userData = nullptr) : Event(userData), key(k) {}
KeyReleasedWindowEvent(unsigned int k) : key(k) {}
KeyReleasedWindowEvent(unsigned int k, std::any userData) : Event(userData), key(k) {}
~KeyReleasedWindowEvent() {
@@ -89,9 +93,10 @@ namespace Archimedes {
public:
MouseButtonPressedWindowEvent() : Event(nullptr), button(0) {}
MouseButtonPressedWindowEvent() : button(0) {}
MouseButtonPressedWindowEvent(unsigned int b, void* userData = nullptr) : Event(userData), button(b) {}
MouseButtonPressedWindowEvent(unsigned int b) : button(b) {}
MouseButtonPressedWindowEvent(unsigned int b, std::any userData) : Event(userData), button(b) {}
~MouseButtonPressedWindowEvent() {
@@ -106,9 +111,9 @@ namespace Archimedes {
public:
MouseButtonReleasedWindowEvent() : Event(nullptr), button(0) {}
MouseButtonReleasedWindowEvent() : button(0) {}
MouseButtonReleasedWindowEvent(unsigned int b, void* userData = nullptr) : Event(userData), button(b) {}
MouseButtonReleasedWindowEvent(unsigned int b) : button(b) {}
~MouseButtonReleasedWindowEvent() {
@@ -123,9 +128,10 @@ namespace Archimedes {
public:
ScrollWindowEvent() : Event(nullptr), dx(0), dy(0) {}
ScrollWindowEvent() : dx(0), dy(0) {}
ScrollWindowEvent(double x, double y, void* userData = nullptr) : Event(userData), dx(x), dy(y) {}
ScrollWindowEvent(double x, double y) : dx(x), dy(y) {}
ScrollWindowEvent(double x, double y, std::any userData) : Event(userData), dx(x), dy(y) {}
~ScrollWindowEvent() {
@@ -140,9 +146,10 @@ namespace Archimedes {
public:
MouseMovedWindowEvent() : Event(nullptr), x(0), y(0) {}
MouseMovedWindowEvent() : x(0), y(0) {}
MouseMovedWindowEvent(double x, double y, void* userData = nullptr) : Event(userData), x(x), y(y) {}
MouseMovedWindowEvent(double x, double y) : x(x), y(y) {}
MouseMovedWindowEvent(double x, double y, std::any userData) : Event(userData), x(x), y(y) {}
~MouseMovedWindowEvent() {
@@ -157,9 +164,10 @@ namespace Archimedes {
public:
FocusedWindowEvent() : Event(nullptr), window(nullptr) {}
FocusedWindowEvent() : window(nullptr) {}
FocusedWindowEvent(const Window* w, void* userData = nullptr) : Event(userData), window(w) {}
FocusedWindowEvent(const Window* w) : window(w) {}
FocusedWindowEvent(const Window* w, std::any userData) : Event(userData), window(w) {}
~FocusedWindowEvent() {
@@ -174,9 +182,10 @@ namespace Archimedes {
public:
FocusLostWindowEvent() : Event(nullptr), window(nullptr) {}
FocusLostWindowEvent() : window(nullptr) {}
FocusLostWindowEvent(const Window* w, void* userData = nullptr) : Event(userData), window(w) {}
FocusLostWindowEvent(const Window* w) : window(w) {}
FocusLostWindowEvent(const Window* w, std::any userData) : Event(userData), window(w) {}
~FocusLostWindowEvent() {
@@ -191,9 +200,10 @@ namespace Archimedes {
public:
MovedWindowEvent() : Event(nullptr), x(0), y(0) {}
MovedWindowEvent() : x(0), y(0) {}
MovedWindowEvent(int x, int y, void* userData = nullptr) : Event(userData), x(x), y(y) {}
MovedWindowEvent(int x, int y) : x(x), y(y) {}
MovedWindowEvent(int x, int y, std::any userData) : Event(userData), x(x), y(y) {}
~MovedWindowEvent() {

View File

@@ -48,31 +48,6 @@ namespace Archimedes {
WindowData& data = (WindowData&) *ptr;
switch(e->type) {
}
return true;
}, &data);*/
SDL_GL_MakeCurrent(w, gl_context);
SDL_GL_SetSwapInterval(1); // Enable vsync
SDL_ShowWindow(w);
}
~WindowSDL3() {
SDL_GL_DestroyContext(gl_context);
SDL_DestroyWindow(w);
SDL_Quit();
}
bool shouldClose() { return false; }
void doFrame() { restoreContext(); SDL_GL_SwapWindow(w); }
void pollEvents() {
while(SDL_PollEvent(&e)) {
switch(e.type) {
case SDL_EVENT_WINDOW_CLOSE_REQUESTED:
@@ -117,6 +92,69 @@ namespace Archimedes {
default:
break;
}
return true;
}, &data);*/
SDL_GL_MakeCurrent(w, gl_context);
SDL_GL_SetSwapInterval(1); // Enable vsync
SDL_ShowWindow(w);
}
~WindowSDL3() {
SDL_GL_DestroyContext(gl_context);
SDL_DestroyWindow(w);
SDL_Quit();
}
bool shouldClose() { return false; }
void doFrame() { restoreContext(); SDL_GL_SwapWindow(w); }
void pollEvents() {
while(SDL_PollEvent(&e)) {
switch(e.type) {
case SDL_EVENT_WINDOW_CLOSE_REQUESTED:
case SDL_EVENT_QUIT:
data.sendEvent(new CloseWindowEvent(data.window, &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, &e));
break;
case SDL_EVENT_WINDOW_MOUSE_ENTER:
case SDL_EVENT_WINDOW_FOCUS_GAINED:
data.sendEvent(new FocusedWindowEvent(data.window, &e));
break;
case SDL_EVENT_WINDOW_MOUSE_LEAVE:
case SDL_EVENT_WINDOW_FOCUS_LOST:
data.sendEvent(new FocusLostWindowEvent(data.window, &e));
break;
case SDL_EVENT_KEY_DOWN:
data.sendEvent(new KeyPressedWindowEvent(e.key.key, e.key.repeat ? 1 : 0, &e));
break;
case SDL_EVENT_KEY_UP:
data.sendEvent(new KeyReleasedWindowEvent(e.key.key, &e));
break;
case SDL_EVENT_MOUSE_MOTION:
data.sendEvent(new MouseMovedWindowEvent(e.motion.x, e.motion.y, &e));
break;
case SDL_EVENT_MOUSE_BUTTON_DOWN:
data.sendEvent(new MouseButtonPressedWindowEvent(e.button.button, &e));
break;
case SDL_EVENT_MOUSE_BUTTON_UP:
data.sendEvent(new MouseButtonReleasedWindowEvent(e.button.button, &e));
break;
case SDL_EVENT_MOUSE_WHEEL:
data.sendEvent(new ScrollWindowEvent(e.wheel.x, e.wheel.y, &e));
break;
default:
data.sendEvent(new AnonymousEvent(&e));
break;
}
}
}