From 467a6990b0ee9ba568008697ba2f31b26951dbeb Mon Sep 17 00:00:00 2001 From: Nao Pross Date: Wed, 23 Jan 2019 01:12:09 +0100 Subject: Separate renderer from window --- include/video.hpp | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/video.hpp b/include/video.hpp index a00f77e..23c1c6e 100644 --- a/include/video.hpp +++ b/include/video.hpp @@ -12,13 +12,37 @@ namespace wsdl2 { typedef SDL_Point point; typedef SDL_Rect rect; + class window; + + class renderer { + public: + friend class window; + + renderer(window& w); + virtual ~renderer(); + + inline void clear() { SDL_RenderClear(safe()); } + inline void present() { SDL_RenderPresent(safe()); } + + // dirty C code + inline SDL_Renderer* sdl() { return m_renderer; } + + private: + renderer(); + + SDL_Renderer* safe(); + void create_sdl_renderer(SDL_Window *win); + + SDL_Renderer *m_renderer; + }; + class window { public: window() = delete; window(const window& other) = delete; window(const std::string& title, std::size_t width, std::size_t height); - ~window(); + virtual ~window(); // setters void open(); @@ -35,9 +59,15 @@ namespace wsdl2 { // rendering void update(); + // dirty C code + inline SDL_Window* sdl() { return m_window; } + private: bool m_open; + renderer m_renderer; SDL_Window *m_window; - SDL_Renderer *m_renderer; }; + + + } \ No newline at end of file -- cgit v1.2.1