summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNao Pross <naopross@thearcway.org>2019-01-21 15:26:43 +0100
committerNao Pross <naopross@thearcway.org>2019-01-21 15:27:10 +0100
commit46a28a711fd730828ae5596f68ef3510a20b7b31 (patch)
tree95e1d89c6213fbb140e9b9c767eccdabab2eb369
parentAdd window test (diff)
downloadlibwsdl2-46a28a711fd730828ae5596f68ef3510a20b7b31.tar.gz
libwsdl2-46a28a711fd730828ae5596f68ef3510a20b7b31.zip
Make window_test threaded
Diffstat (limited to '')
-rw-r--r--debug.hpp2
-rw-r--r--include/input.hpp0
-rw-r--r--include/video.hpp14
-rw-r--r--include/wrapsdl2.hpp16
-rw-r--r--test/makefile2
-rw-r--r--test/window_test.cpp20
-rw-r--r--video.cpp12
-rw-r--r--wrapsdl2.cpp9
8 files changed, 63 insertions, 12 deletions
diff --git a/debug.hpp b/debug.hpp
index 16dc5a8..c53fc45 100644
--- a/debug.hpp
+++ b/debug.hpp
@@ -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();
diff --git a/video.cpp b/video.cpp
index 8413cb4..d6ae6cb 100644
--- a/video.cpp
+++ b/video.cpp
@@ -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