Added events
This commit is contained in:
parent
9ce9cd3432
commit
fd43b8917c
3 changed files with 21 additions and 1 deletions
|
@ -62,6 +62,11 @@ namespace sf
|
|||
|
||||
}
|
||||
|
||||
void IWindow::AddEventCallback(EventCallback callback, void* userdata)
|
||||
{
|
||||
SDL_AddEventWatch(*(callback.target<SDL_EventFilter>()), userdata);
|
||||
}
|
||||
|
||||
IWindow::IWindow(Vector2u size, Vector2i position, std::string title,
|
||||
Uint32 flags /*= SDL_WINDOW_RESIZABLE*/) :
|
||||
m_pWindow(nullptr), m_pRenderer(nullptr), m_oEvent(),
|
||||
|
@ -83,6 +88,8 @@ namespace sf
|
|||
{
|
||||
while (SDL_PollEvent(&m_oEvent))
|
||||
{
|
||||
OnEvent(m_oEvent);
|
||||
|
||||
if (m_oEvent.type == SDL_QUIT)
|
||||
{
|
||||
m_atomWindowOpen = false;
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include <string>
|
||||
#include <thread>
|
||||
#include <atomic>
|
||||
#include <functional>
|
||||
|
||||
#include "SDL.h"
|
||||
#include "util/Vector2.hpp"
|
||||
|
@ -11,6 +12,8 @@
|
|||
|
||||
namespace sf
|
||||
{
|
||||
typedef std::function<int(void*, SDL_Event*)> EventCallback;
|
||||
|
||||
class IWindow
|
||||
{
|
||||
public:
|
||||
|
@ -21,11 +24,14 @@ namespace sf
|
|||
|
||||
bool IsOpen() { return m_atomWindowOpen; }
|
||||
|
||||
void AddEventCallback(EventCallback callback, void* userdata);
|
||||
|
||||
protected:
|
||||
IWindow(Vector2u size, Vector2i position, std::string title, Uint32 flags = SDL_WINDOW_RESIZABLE);
|
||||
|
||||
virtual bool OnCreate() { return true; }
|
||||
virtual void OnClose() { }
|
||||
virtual void OnEvent(const SDL_Event& event) { }
|
||||
virtual bool OnUpdate(double frametime) { return true; }
|
||||
|
||||
protected:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue