Implemented SDL event listener class and HUD toggle key (#4)

* Implemented SDL event listener class

* Add HUD toggle.

* frontend_listener: clean-up

* window: invoke all listener callbacks at once

* window: use raw pointers for listeners

* Rename WindowListener to SDLEventListener, reduce virtual functions

---------

Co-authored-by: RadiantDerg <jayvier13@gmail.com>
This commit is contained in:
Hyper
2024-11-10 18:23:36 +00:00
committed by GitHub
parent 21fc80798e
commit f157b21d67
6 changed files with 71 additions and 1 deletions
+21
View File
@@ -0,0 +1,21 @@
#pragma once
#include "ui/window.h"
class ISDLEventListener
{
public:
virtual ~ISDLEventListener() = default;
virtual void OnSDLEvent(SDL_Event* event) = 0;
};
class SDLEventListener : public ISDLEventListener
{
public:
SDLEventListener()
{
Window::s_eventListeners.emplace_back(this);
}
void OnSDLEvent(SDL_Event* event) override {}
};
+4
View File
@@ -1,4 +1,5 @@
#include "window.h"
#include "sdl_listener.h"
#include <config.h>
#include <kernel/function.h>
#include <SDL_syswm.h>
@@ -107,6 +108,9 @@ int Window_OnSDLEvent(void*, SDL_Event* event)
}
}
for (auto listener : Window::s_eventListeners)
listener->OnSDLEvent(event);
return 0;
}
+5 -1
View File
@@ -7,7 +7,9 @@
#define DEFAULT_WIDTH 1280
#define DEFAULT_HEIGHT 720
struct Window
class SDLEventListener;
class Window
{
public:
inline static SDL_Window* s_pWindow;
@@ -20,6 +22,8 @@ public:
inline static bool s_isFocused;
inline static std::vector<SDLEventListener*> s_eventListeners;
static SDL_Surface* GetIconSurface(void* pIconBmp = nullptr, size_t iconSize = 0)
{
auto rw = SDL_RWFromMem(pIconBmp ? pIconBmp : (void*)g_icon, pIconBmp ? iconSize : g_icon_size);