SDLFramework/src/sdlf/Window.hpp

49 lines
972 B
C++
Raw Normal View History

2020-06-15 20:03:08 +02:00
#pragma once
2020-06-15 21:36:57 +02:00
#include <string>
#include <thread>
#include <atomic>
2020-06-15 20:03:08 +02:00
#include "SDL.h"
2020-06-15 21:36:57 +02:00
#include "util/Vector2.hpp"
#define SDLF_REQUIRED_SUBSYSTEMS SDL_INIT_VIDEO
2020-06-15 20:03:08 +02:00
namespace sf
{
class IWindow
{
public:
2020-06-15 21:36:57 +02:00
void Create(Vector2u size, Vector2i position, std::string title, Uint32 flags = SDL_WINDOW_RESIZABLE);
2020-06-15 20:03:08 +02:00
2020-06-15 21:36:57 +02:00
void Launch(bool threaded = false);
void Stop();
bool IsOpen() { return m_atomWindowOpen; }
protected:
IWindow(Vector2u size, Vector2i position, std::string title, Uint32 flags = SDL_WINDOW_RESIZABLE);
virtual bool OnCreate() { return true; }
virtual void OnClose() { }
virtual bool OnUpdate(double frametime) { return true; }
protected:
2020-06-15 20:03:08 +02:00
SDL_Window* m_pWindow;
SDL_Renderer* m_pRenderer;
2020-06-15 21:36:57 +02:00
SDL_Event m_oEvent;
private:
void MessageLoop();
void Destroy();
private:
Vector2u m_oSize;
Vector2i m_oPosition;
std::string m_strTitle;
Uint32 m_uFlags;
std::thread m_oMsgLoopThread;
std::atomic_bool m_atomWindowOpen;
2020-06-15 20:03:08 +02:00
};
}