summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--include/video.hpp11
-rw-r--r--video.cpp37
2 files changed, 40 insertions, 8 deletions
diff --git a/include/video.hpp b/include/video.hpp
index 45b1fc5..3c2a238 100644
--- a/include/video.hpp
+++ b/include/video.hpp
@@ -5,6 +5,7 @@
extern "C" {
#include <SDL2/SDL_video.h>
+#include <SDL2/SDL_render.h>
}
namespace wrapsdl2 {
@@ -20,18 +21,24 @@ namespace wrapsdl2 {
~window();
// setters
+ void open();
+ void close();
+
+
void show();
void hide();
void raise();
// getters
- bool visible();
+ bool is_open();
+ bool is_visible();
// rendering
void update();
private:
+ bool m_open;
SDL_Window *m_window;
- SDL_Surface *m_surface;
+ SDL_Renderer *m_renderer;
};
} \ No newline at end of file
diff --git a/video.cpp b/video.cpp
index d6ae6cb..f58b171 100644
--- a/video.cpp
+++ b/video.cpp
@@ -10,6 +10,8 @@ extern "C" {
using namespace wrapsdl2;
+/* class window */
+
window::window(const std::string& title, std::size_t width, std::size_t height) {
// create (hidden) window
m_window = SDL_CreateWindow(
@@ -25,26 +27,49 @@ window::window(const std::string& title, std::size_t width, std::size_t height)
throw std::runtime_error("failed to create SDL window");
}
- // create surface
- m_surface = SDL_GetWindowSurface(m_window);
+ // create a rendering contest
+ m_renderer = SDL_CreateRenderer(
+ m_window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC
+ );
+
+ // other attributes
+ m_open = false;
}
window::~window() {
- SDL_FreeSurface(m_surface);
- SDL_DestroyWindow(m_window);
+ if (m_renderer != NULL)
+ SDL_DestroyRenderer(m_renderer);
+
+ if (m_window != NULL)
+ SDL_DestroyWindow(m_window);
+}
+
+
+void window::open() {
+ show();
+ m_open = true;
}
+void window::close() {
+ hide();
+ m_open = false;
+}
void window::show() { SDL_ShowWindow(m_window); }
void window::hide() { SDL_HideWindow(m_window); }
void window::raise() { SDL_RaiseWindow(m_window); }
-bool window::visible() {
+bool window::is_open() {
+ return m_open;
+}
+
+bool window::is_visible() {
std::uint32_t flags = SDL_GetWindowFlags(m_window);
return flags & SDL_WINDOW_SHOWN;
}
void window::update() {
- SDL_UpdateWindowSurface(m_window);
+ SDL_RenderClear(m_renderer);
+ SDL_RenderPresent(m_renderer);
} \ No newline at end of file