mirror of
https://github.com/hedge-dev/UnleashedRecomp
synced 2026-09-04 02:49:35 -04:00
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:
@@ -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 {}
|
||||
};
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user