Updated README
This commit is contained in:
parent
802e725db2
commit
27b459c85e
6 changed files with 87 additions and 21 deletions
|
@ -1,21 +1,20 @@
|
|||
#pragma once
|
||||
|
||||
#include "SDL.h"
|
||||
#include "util/Callback.hpp"
|
||||
|
||||
namespace sf
|
||||
{
|
||||
class IScreen
|
||||
class IScreen : public ICallback
|
||||
{
|
||||
public:
|
||||
virtual void OnFocus() {} // Called when the screen is being switched to
|
||||
virtual void OnDefocus() {} // Called when the screen is being switched from
|
||||
virtual bool OnUpdate(double frametime) { return true; } // Called every frame
|
||||
virtual void OnEvent(const SDL_Event& event) {} // Called after an event occurs
|
||||
virtual void OnRender(SDL_Renderer* renderer) {} // Called for rendering
|
||||
virtual void OnFocus(IWindow* parent) { }
|
||||
virtual void OnDefocus() { }
|
||||
virtual bool OnUpdate(double frametime) override { return true; }
|
||||
virtual bool OnEvent(const SDL_Event& event) override { return true; }
|
||||
virtual void OnRender(SDL_Renderer* renderer) override {}
|
||||
|
||||
protected:
|
||||
IScreen() = default;
|
||||
|
||||
private:
|
||||
};
|
||||
}
|
|
@ -87,7 +87,7 @@ namespace sf
|
|||
m_oUpdateFunction = std::bind<bool>(&IScreen::OnUpdate, m_pCurrentScreen, std::placeholders::_1);
|
||||
m_oRenderFunction = std::bind(&IScreen::OnRender, m_pCurrentScreen, std::placeholders::_1);
|
||||
|
||||
m_pCurrentScreen->OnFocus();
|
||||
m_pCurrentScreen->OnFocus(this);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -120,11 +120,13 @@ namespace sf
|
|||
{
|
||||
while (SDL_PollEvent(&m_oEvent))
|
||||
{
|
||||
m_oEventFunction(m_oEvent);
|
||||
|
||||
if (m_oEvent.type == SDL_QUIT)
|
||||
if (m_oEventFunction(m_oEvent))
|
||||
{
|
||||
m_atomWindowOpen = false;
|
||||
|
||||
if (m_oEvent.type == SDL_QUIT)
|
||||
{
|
||||
m_atomWindowOpen = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
#include <atomic>
|
||||
#include <functional>
|
||||
|
||||
#include "SDL.h"
|
||||
#include "util/Vector2.hpp"
|
||||
#include "util/Callback.hpp"
|
||||
#include "Screen.hpp"
|
||||
|
||||
#define SDLF_REQUIRED_SUBSYSTEMS SDL_INIT_VIDEO
|
||||
|
@ -15,7 +15,7 @@ namespace sf
|
|||
{
|
||||
typedef std::function<int(void*, SDL_Event*)> EventCallback;
|
||||
|
||||
class IWindow
|
||||
class IWindow : public ICallback
|
||||
{
|
||||
public:
|
||||
void Create(Vector2u size, Vector2i position, std::string title, Uint32 flags = SDL_WINDOW_RESIZABLE);
|
||||
|
@ -34,9 +34,9 @@ namespace sf
|
|||
|
||||
virtual bool OnCreate() { return true; }
|
||||
virtual void OnClose() { }
|
||||
virtual void OnEvent(const SDL_Event& event) { }
|
||||
virtual bool OnUpdate(double frametime) { return true; }
|
||||
virtual void OnRender(SDL_Renderer* renderer) { }
|
||||
virtual bool OnEvent(const SDL_Event& event) override { return true; }
|
||||
virtual bool OnUpdate(double frametime) override { return true; }
|
||||
virtual void OnRender(SDL_Renderer* renderer) override { }
|
||||
|
||||
protected:
|
||||
SDL_Window* m_pWindow;
|
||||
|
@ -58,7 +58,7 @@ namespace sf
|
|||
std::thread m_oMsgLoopThread;
|
||||
std::atomic_bool m_atomWindowOpen;
|
||||
|
||||
std::function<void( SDL_Event& )> m_oEventFunction;
|
||||
std::function<bool( SDL_Event& )> m_oEventFunction;
|
||||
std::function<bool( double )> m_oUpdateFunction;
|
||||
std::function<void( SDL_Renderer* )> m_oRenderFunction;
|
||||
};
|
||||
|
|
19
src/sdlf/util/Callback.hpp
Normal file
19
src/sdlf/util/Callback.hpp
Normal file
|
@ -0,0 +1,19 @@
|
|||
#pragma once
|
||||
|
||||
namespace sf
|
||||
{
|
||||
#include <SDL.h>
|
||||
|
||||
class ICallback
|
||||
{
|
||||
protected:
|
||||
virtual bool OnEvent(const SDL_Event& event) = 0;
|
||||
virtual bool OnUpdate(double frametime) = 0;
|
||||
virtual void OnRender(SDL_Renderer* renderer) = 0;
|
||||
|
||||
protected:
|
||||
ICallback() = default;
|
||||
ICallback(const ICallback& other) = delete;
|
||||
ICallback& operator=(const ICallback& other) = delete;
|
||||
};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue