diff options
-rw-r--r-- | debug.hpp | 2 | ||||
-rw-r--r-- | include/input.hpp | 0 | ||||
-rw-r--r-- | include/video.hpp | 14 | ||||
-rw-r--r-- | include/wrapsdl2.hpp | 16 | ||||
-rw-r--r-- | test/makefile | 2 | ||||
-rw-r--r-- | test/window_test.cpp | 20 | ||||
-rw-r--r-- | video.cpp | 12 | ||||
-rw-r--r-- | wrapsdl2.cpp | 9 |
8 files changed, 63 insertions, 12 deletions
@@ -4,8 +4,6 @@ #include <sstream> #ifdef DEBUG - - #warning building in debug mode! #ifdef __builtin_strrchr #define __FILENAME__ (\ __builtin_strrchr(__FILE__, '/') ? \ diff --git a/include/input.hpp b/include/input.hpp deleted file mode 100644 index e69de29..0000000 --- a/include/input.hpp +++ /dev/null diff --git a/include/video.hpp b/include/video.hpp index 1b6e022..45b1fc5 100644 --- a/include/video.hpp +++ b/include/video.hpp @@ -1,11 +1,16 @@ #pragma once #include <string> +#include <array> -class SDL_Window; -class SDL_Surface; +extern "C" { +#include <SDL2/SDL_video.h> +} namespace wrapsdl2 { + typedef SDL_Point point; + typedef SDL_Rect rect; + class window { public: window() = delete; @@ -14,11 +19,14 @@ namespace wrapsdl2 { window(const std::string& title, std::size_t width, std::size_t height); ~window(); - // manipulation + // setters void show(); void hide(); void raise(); + // getters + bool visible(); + // rendering void update(); diff --git a/include/wrapsdl2.hpp b/include/wrapsdl2.hpp index 993a704..847ed99 100644 --- a/include/wrapsdl2.hpp +++ b/include/wrapsdl2.hpp @@ -1,9 +1,23 @@ #pragma once +extern "C" { +#include <SDL2/SDL.h> +} + namespace wrapsdl2 { bool initialize(void); void quit(void); + + namespace util { + constexpr bool sdl_bool(SDL_bool b) { + return b == SDL_TRUE; + } + + constexpr SDL_bool sdl_bool(bool b) { + return (b) ? SDL_TRUE : SDL_FALSE; + } + } // tool functions - void delay() + void delay(unsigned ms); }
\ No newline at end of file diff --git a/test/makefile b/test/makefile index 11df431..ee8569a 100644 --- a/test/makefile +++ b/test/makefile @@ -1,7 +1,7 @@ # Compiler CPP := c++ CFLAGS := -Wall -pedantic -std=c++17 -fPIC -I ../include -DDEBUG -LFLAGS := ../build/libwrapsdl2.so -lSDL2 +LFLAGS := ../build/libwrapsdl2.so -lSDL2 -lpthread SRCS := $(wildcard *.cpp) OBJS := $(patsubst %.cpp,build/%.o,$(SRCS)) diff --git a/test/window_test.cpp b/test/window_test.cpp index 70fcb1a..2136488 100644 --- a/test/window_test.cpp +++ b/test/window_test.cpp @@ -2,21 +2,37 @@ #include "video.hpp" #include <iostream> +#include <thread> +#include <mutex> int main(int argc, char *argv[]) { wrapsdl2::initialize(); { - wrapsdl2::window win("Window Test", 800, 600); + using namespace wrapsdl2; + + window win("Window Test", 800, 600); + std::mutex win_mutex; std::cout << "press ENTER to show the window" << std::endl; std::cin.get(); win.show(); - win.update(); + + std::thread win_update([&]() { + std::lock_guard<std::mutex> lock(win_mutex); + while (win.is_open()) { + win.update(); + wrapsdl2::delay(200); + + + } + }); std::cout << "press ENTER to quit" << std::endl; std::cin.get(); + + win_update.join(); } wrapsdl2::quit(); @@ -1,13 +1,13 @@ #include "video.hpp" #include "debug.hpp" +#include <exception> +#include <cstdint> + 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) { @@ -39,6 +39,12 @@ void window::show() { SDL_ShowWindow(m_window); } void window::hide() { SDL_HideWindow(m_window); } void window::raise() { SDL_RaiseWindow(m_window); } +bool window::visible() { + std::uint32_t flags = SDL_GetWindowFlags(m_window); + + return flags & SDL_WINDOW_SHOWN; +} + void window::update() { SDL_UpdateWindowSurface(m_window); }
\ No newline at end of file diff --git a/wrapsdl2.cpp b/wrapsdl2.cpp index 6c7896f..f9f346b 100644 --- a/wrapsdl2.cpp +++ b/wrapsdl2.cpp @@ -15,5 +15,14 @@ bool wrapsdl2::initialize(void) { } void wrapsdl2::quit(void) { + if (SDL_WasInit(SDL_INIT_VIDEO)) + SDL_QuitSubSystem(SDL_INIT_VIDEO); + SDL_Quit(); } + + + +void wrapsdl2::delay(unsigned ms) { + SDL_Delay(ms); +}
\ No newline at end of file |