diff options
author | Nao Pross <naopross@thearcway.org> | 2019-01-21 04:48:02 +0100 |
---|---|---|
committer | Nao Pross <naopross@thearcway.org> | 2019-01-21 04:48:02 +0100 |
commit | ca091e358a8b02423ba304bfca055712b3a70881 (patch) | |
tree | 71252ee4f0316387fd2c335fe299313b5b313167 | |
parent | Initial commit, add makefile, .gitignore and debug header (diff) | |
download | libwsdl2-ca091e358a8b02423ba304bfca055712b3a70881.tar.gz libwsdl2-ca091e358a8b02423ba304bfca055712b3a70881.zip |
Add basic window wrapper
Diffstat (limited to '')
-rw-r--r-- | include/input.hpp | 0 | ||||
-rw-r--r-- | include/video.hpp | 29 | ||||
-rw-r--r-- | include/wrapsdl.hpp | 6 | ||||
-rw-r--r-- | include/wrapsdl2.hpp | 9 | ||||
-rw-r--r-- | video.cpp | 44 | ||||
-rw-r--r-- | wrapsdl.cpp | 19 | ||||
-rw-r--r-- | wrapsdl2.cpp | 19 |
7 files changed, 101 insertions, 25 deletions
diff --git a/include/input.hpp b/include/input.hpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/include/input.hpp diff --git a/include/video.hpp b/include/video.hpp new file mode 100644 index 0000000..1b6e022 --- /dev/null +++ b/include/video.hpp @@ -0,0 +1,29 @@ +#pragma once + +#include <string> + +class SDL_Window; +class SDL_Surface; + +namespace wrapsdl2 { + class window { + public: + window() = delete; + window(const window& other) = delete; + + window(const std::string& title, std::size_t width, std::size_t height); + ~window(); + + // manipulation + void show(); + void hide(); + void raise(); + + // rendering + void update(); + + private: + SDL_Window *m_window; + SDL_Surface *m_surface; + }; +}
\ No newline at end of file diff --git a/include/wrapsdl.hpp b/include/wrapsdl.hpp deleted file mode 100644 index 9b9a72c..0000000 --- a/include/wrapsdl.hpp +++ /dev/null @@ -1,6 +0,0 @@ -#pragma once - -namespace wrapsdl { - bool initialize(void); - void quit(void); -}
\ No newline at end of file diff --git a/include/wrapsdl2.hpp b/include/wrapsdl2.hpp new file mode 100644 index 0000000..993a704 --- /dev/null +++ b/include/wrapsdl2.hpp @@ -0,0 +1,9 @@ +#pragma once + +namespace wrapsdl2 { + bool initialize(void); + void quit(void); + + // tool functions + void delay() +}
\ No newline at end of file diff --git a/video.cpp b/video.cpp new file mode 100644 index 0000000..8413cb4 --- /dev/null +++ b/video.cpp @@ -0,0 +1,44 @@ +#include "video.hpp" +#include "debug.hpp" + +extern "C" { +#include <SDL2/SDL.h> +} + +#include <exception> + + +using namespace wrapsdl2; + +window::window(const std::string& title, std::size_t width, std::size_t height) { + // create (hidden) window + m_window = SDL_CreateWindow( + title.c_str(), + SDL_WINDOWPOS_CENTERED, + SDL_WINDOWPOS_CENTERED, + static_cast<int>(width), + static_cast<int>(height), + SDL_WINDOW_OPENGL | SDL_WINDOW_HIDDEN + ); + + if (m_window == NULL) { + throw std::runtime_error("failed to create SDL window"); + } + + // create surface + m_surface = SDL_GetWindowSurface(m_window); +} + +window::~window() { + SDL_FreeSurface(m_surface); + SDL_DestroyWindow(m_window); +} + + +void window::show() { SDL_ShowWindow(m_window); } +void window::hide() { SDL_HideWindow(m_window); } +void window::raise() { SDL_RaiseWindow(m_window); } + +void window::update() { + SDL_UpdateWindowSurface(m_window); +}
\ No newline at end of file diff --git a/wrapsdl.cpp b/wrapsdl.cpp deleted file mode 100644 index e91ec8c..0000000 --- a/wrapsdl.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#include "wrapsdl.hpp" -#include "debug.hpp" - -extern "C" { -#include <SDL2/SDL.h> -} - -bool wrapsdl::initialize(void) { - if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0) { - npdebug("failed to initialize sdl video subsystem"); - return false; - } - - return true; -} - -void wrapsdl::quit(void) { - SDL_Quit(); -} diff --git a/wrapsdl2.cpp b/wrapsdl2.cpp new file mode 100644 index 0000000..6c7896f --- /dev/null +++ b/wrapsdl2.cpp @@ -0,0 +1,19 @@ +#include "wrapsdl2.hpp" +#include "debug.hpp" + +extern "C" { +#include <SDL2/SDL.h> +} + +bool wrapsdl2::initialize(void) { + if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0) { + npdebug("failed to initialize sdl video subsystem"); + return false; + } + + return true; +} + +void wrapsdl2::quit(void) { + SDL_Quit(); +} |