From e0654f045b0a751b510361f3d9f08e2415f8551d Mon Sep 17 00:00:00 2001 From: Dmitry Marakasov Date: Sat, 27 Dec 2014 00:01:09 +0300 Subject: [PATCH 01/17] Consistency with other member variable docs --- SDL2pp/Texture.hh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SDL2pp/Texture.hh b/SDL2pp/Texture.hh index 98ac8bd..f99de9d 100644 --- a/SDL2pp/Texture.hh +++ b/SDL2pp/Texture.hh @@ -49,7 +49,7 @@ class RWops; //////////////////////////////////////////////////////////// class Texture { private: - SDL_Texture* texture_; ///< SDL2 texture pointer + SDL_Texture* texture_; ///< Contained SDL_Texture structure public: //////////////////////////////////////////////////////////// From f4c2832d9008788abd3856150262a21973e82af2 Mon Sep 17 00:00:00 2001 From: Dmitry Marakasov Date: Sat, 27 Dec 2014 00:01:22 +0300 Subject: [PATCH 02/17] Add missing \see --- SDL2pp/Texture.hh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/SDL2pp/Texture.hh b/SDL2pp/Texture.hh index f99de9d..b4e72f9 100644 --- a/SDL2pp/Texture.hh +++ b/SDL2pp/Texture.hh @@ -210,6 +210,8 @@ public: //////////////////////////////////////////////////////////// /// \brief Destructor /// + /// \see http://wiki.libsdl.org/SDL_DestroyTexture + /// //////////////////////////////////////////////////////////// virtual ~Texture(); From 0007a489c347da50fd5eedb6182d0bc7e22e359c Mon Sep 17 00:00:00 2001 From: Dmitry Marakasov Date: Sat, 27 Dec 2014 00:02:08 +0300 Subject: [PATCH 03/17] Move Get to the top of memeber functions for consistency with other classes --- SDL2pp/Window.cc | 8 ++++---- SDL2pp/Window.hh | 16 ++++++++-------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/SDL2pp/Window.cc b/SDL2pp/Window.cc index 2073941..d77eb18 100644 --- a/SDL2pp/Window.cc +++ b/SDL2pp/Window.cc @@ -50,6 +50,10 @@ Window& Window::operator=(Window&& other) noexcept { return *this; } +SDL_Window* Window::Get() const { + return window_; +} + Point Window::GetSize() const { int w, h; SDL_GetWindowSize(window_, &w, &h); @@ -72,10 +76,6 @@ void Window::SetTitle(const std::string& title) { SDL_SetWindowTitle(window_, title.c_str()); } -SDL_Window* Window::Get() const { - return window_; -} - void Window::Maximize() { SDL_MaximizeWindow(window_); } diff --git a/SDL2pp/Window.hh b/SDL2pp/Window.hh index 3b06c75..e42ea00 100644 --- a/SDL2pp/Window.hh +++ b/SDL2pp/Window.hh @@ -111,6 +111,14 @@ public: Window(const Window& other) = delete; Window& operator=(const Window& other) = delete; + //////////////////////////////////////////////////////////// + /// \brief Get pointer to contained SDL_Window structure + /// + /// \returns Pointer to SDL_Window structure + /// + //////////////////////////////////////////////////////////// + SDL_Window* Get() const; + //////////////////////////////////////////////////////////// /// \brief Get dimensions of the window /// @@ -152,14 +160,6 @@ public: //////////////////////////////////////////////////////////// void SetTitle(const std::string& title); - //////////////////////////////////////////////////////////// - /// \brief Get pointer to contained SDL_Window structure - /// - /// \returns Pointer to SDL_Window structure - /// - //////////////////////////////////////////////////////////// - SDL_Window* Get() const; - //////////////////////////////////////////////////////////// /// \brief Make a window as large as possible /// From f5216c309ff27d3d51fcfcb5ee8358733498c345 Mon Sep 17 00:00:00 2001 From: Dmitry Marakasov Date: Sat, 27 Dec 2014 02:02:54 +0300 Subject: [PATCH 04/17] Add (failing) test for #22 --- tests/CMakeLists.txt | 1 + tests/test_error.cc | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 tests/test_error.cc diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index d76df00..d9b1af4 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -3,6 +3,7 @@ SET(CLI_TESTS test_pointrect test_rwops test_optional + test_error ) # tests which test graphics functionality and thus requre working diff --git a/tests/test_error.cc b/tests/test_error.cc new file mode 100644 index 0000000..46d9dd5 --- /dev/null +++ b/tests/test_error.cc @@ -0,0 +1,18 @@ +#include + +#include + +#include "testing.h" + +using namespace SDL2pp; + +BEGIN_TEST() + SDL_SetError("foo"); + + try { + throw Exception(""); + } catch (SDL2pp::Exception& e) { + SDL_SetError("bar"); + EXPECT_EQUAL((std::string)e.GetSDLError(), "foo"); + } +END_TEST() From 4bf7fbd52c1226aca81a89ad5a6eecec1306da74 Mon Sep 17 00:00:00 2001 From: Dmitry Marakasov Date: Sat, 27 Dec 2014 02:07:07 +0300 Subject: [PATCH 05/17] Store SDL error inside Exception Fixes #22 --- SDL2pp/Exception.cc | 2 +- SDL2pp/Exception.hh | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/SDL2pp/Exception.cc b/SDL2pp/Exception.cc index 546ade5..463415c 100644 --- a/SDL2pp/Exception.cc +++ b/SDL2pp/Exception.cc @@ -36,7 +36,7 @@ const char* Exception::what() const noexcept { } const char* Exception::GetSDLError() const noexcept { - return sdl_error_; + return sdl_error_.c_str(); } } // namespace SDL2pp diff --git a/SDL2pp/Exception.hh b/SDL2pp/Exception.hh index 4e6b8e4..c6fb5cf 100644 --- a/SDL2pp/Exception.hh +++ b/SDL2pp/Exception.hh @@ -22,6 +22,7 @@ #ifndef SDL2PP_EXCEPTION_HH #define SDL2PP_EXCEPTION_HH +#include #include namespace SDL2pp { @@ -29,7 +30,7 @@ namespace SDL2pp { class Exception : public std::exception { private: const char* what_; - const char* sdl_error_; + std::string sdl_error_; public: Exception(const char* what = ""); From 64952aea9a440b52631c8129f1c868f167b77017 Mon Sep 17 00:00:00 2001 From: Dmitry Marakasov Date: Sat, 27 Dec 2014 02:22:15 +0300 Subject: [PATCH 06/17] Use stock function instead of reimplementing with RWops --- SDL2pp/Texture.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/SDL2pp/Texture.cc b/SDL2pp/Texture.cc index 7a57687..9b6ceec 100644 --- a/SDL2pp/Texture.cc +++ b/SDL2pp/Texture.cc @@ -50,8 +50,7 @@ Texture::Texture(Renderer& renderer, RWops& rwops) { } Texture::Texture(Renderer& renderer, const std::string& path) { - RWops rwops = RWops::FromFile(path); - texture_ = IMG_LoadTexture_RW(renderer.Get(), rwops.Get(), 0); + texture_ = IMG_LoadTexture(renderer.Get(), path.c_str()); } #endif From f4fdd893909a9813b67928db7b807f82fca1c1bd Mon Sep 17 00:00:00 2001 From: Dmitry Marakasov Date: Sat, 27 Dec 2014 02:30:29 +0300 Subject: [PATCH 07/17] Bump version to 0.5.1 --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3dd5887..b408e24 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,7 @@ SET(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake) SET(SDL2PP_MAJOR_VERSION 0) SET(SDL2PP_MINOR_VERSION 5) -SET(SDL2PP_PATCH_VERSION 0) +SET(SDL2PP_PATCH_VERSION 1) SET(SDL2PP_VERSION "${SDL2PP_MAJOR_VERSION}.${SDL2PP_MINOR_VERSION}.${SDL2PP_PATCH_VERSION}") From 7bb9c57cb439a6977108a8b158e67a5dd23bd317 Mon Sep 17 00:00:00 2001 From: Dmitry Marakasov Date: Sat, 27 Dec 2014 02:36:53 +0300 Subject: [PATCH 08/17] Bump soversion after abi-incompatible change --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b408e24..7c1d630 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -116,7 +116,7 @@ IF(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR) # library ADD_LIBRARY(SDL2pp SHARED ${LIBRARY_SOURCES} ${LIBRARY_HEADERS}) TARGET_LINK_LIBRARIES(SDL2pp ${SDL2_ALL_LIBRARIES}) - SET_TARGET_PROPERTIES(SDL2pp PROPERTIES VERSION 2.0.0 SOVERSION 2) + SET_TARGET_PROPERTIES(SDL2pp PROPERTIES VERSION 3.0.0 SOVERSION 3) # examples and tests OPTION(SDL2PP_WITH_EXAMPLES "Build examples" ON) From 69d93bc6e41f551ff1feaacbe86b044f60d25c7d Mon Sep 17 00:00:00 2001 From: Dmitry Marakasov Date: Sat, 27 Dec 2014 02:36:53 +0300 Subject: [PATCH 09/17] Bump soversion after abi-incompatible change --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f417ab5..b912810 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -128,7 +128,7 @@ IF(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR) # library ADD_LIBRARY(SDL2pp SHARED ${LIBRARY_SOURCES} ${LIBRARY_HEADERS}) TARGET_LINK_LIBRARIES(SDL2pp ${SDL2_ALL_LIBRARIES}) - SET_TARGET_PROPERTIES(SDL2pp PROPERTIES VERSION 2.0.0 SOVERSION 2) + SET_TARGET_PROPERTIES(SDL2pp PROPERTIES VERSION 3.0.0 SOVERSION 3) # examples and tests OPTION(SDL2PP_WITH_EXAMPLES "Build examples" ON) From ad1e6879dfef2a9a77c2d6af4c8a2677b04df62c Mon Sep 17 00:00:00 2001 From: Dmitry Marakasov Date: Sat, 27 Dec 2014 05:17:01 +0300 Subject: [PATCH 10/17] Check for errors after calling SDL_image functions Fixes #20 --- SDL2pp/Texture.cc | 6 ++++-- SDL2pp/Texture.hh | 4 ++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/SDL2pp/Texture.cc b/SDL2pp/Texture.cc index 9b6ceec..0750ca3 100644 --- a/SDL2pp/Texture.cc +++ b/SDL2pp/Texture.cc @@ -46,11 +46,13 @@ Texture::Texture(Renderer& renderer, Uint32 format, int access, int w, int h) { #ifdef SDL2PP_WITH_IMAGE Texture::Texture(Renderer& renderer, RWops& rwops) { - texture_ = IMG_LoadTexture_RW(renderer.Get(), rwops.Get(), 0); + if ((texture_ = IMG_LoadTexture_RW(renderer.Get(), rwops.Get(), 0)) == nullptr) + throw Exception("IMG_LoadTexture_RW failed"); } Texture::Texture(Renderer& renderer, const std::string& path) { - texture_ = IMG_LoadTexture(renderer.Get(), path.c_str()); + if ((texture_ = IMG_LoadTexture(renderer.Get(), path.c_str())) == nullptr) + throw Exception("IMG_LoadTexture failed"); } #endif diff --git a/SDL2pp/Texture.hh b/SDL2pp/Texture.hh index b4e72f9..17ff1dd 100644 --- a/SDL2pp/Texture.hh +++ b/SDL2pp/Texture.hh @@ -194,6 +194,8 @@ public: /// \param renderer Rendering context to create texture for /// \param rwops RWops used to access an image file /// + /// \throws SDL2pp::Exception + /// //////////////////////////////////////////////////////////// Texture(Renderer& renderer, RWops& rwops); @@ -203,6 +205,8 @@ public: /// \param renderer Rendering context to create texture for /// \param filename Path to an image file /// + /// \throws SDL2pp::Exception + /// //////////////////////////////////////////////////////////// Texture(Renderer& renderer, const std::string& filename); #endif From e0032de44713e32cc9bd17812550f7f1c28cb315 Mon Sep 17 00:00:00 2001 From: Dmitry Marakasov Date: Sat, 27 Dec 2014 05:22:12 +0300 Subject: [PATCH 11/17] Implement wrapper for SDL_image init/deinit Fixes #21 --- CMakeLists.txt | 2 + SDL2pp/Exception.hh | 7 +++ SDL2pp/SDL2pp.hh | 8 ++++ SDL2pp/SDLImage.cc | 49 ++++++++++++++++++++ SDL2pp/SDLImage.hh | 106 ++++++++++++++++++++++++++++++++++++++++++++ examples/image.cc | 3 ++ 6 files changed, 175 insertions(+) create mode 100644 SDL2pp/SDLImage.cc create mode 100644 SDL2pp/SDLImage.hh diff --git a/CMakeLists.txt b/CMakeLists.txt index b912810..ee4bc9f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -98,6 +98,7 @@ SET(LIBRARY_SOURCES SDL2pp/Rect.cc SDL2pp/Renderer.cc SDL2pp/SDL.cc + SDL2pp/SDLImage.cc SDL2pp/Texture.cc SDL2pp/TextureLock.cc SDL2pp/Wav.cc @@ -116,6 +117,7 @@ SET(LIBRARY_HEADERS SDL2pp/Renderer.hh SDL2pp/SDL.hh SDL2pp/SDL2pp.hh + SDL2pp/SDLImage.hh SDL2pp/StreamRWops.hh SDL2pp/Texture.hh SDL2pp/Wav.hh diff --git a/SDL2pp/Exception.hh b/SDL2pp/Exception.hh index 4418c09..5151f1a 100644 --- a/SDL2pp/Exception.hh +++ b/SDL2pp/Exception.hh @@ -43,6 +43,13 @@ namespace SDL2pp { /// what() usually contains a name of SDL2 function which failed, /// e.g. "SDL_Init() failed" /// +/// Note: this Exception object is used to report errors from +/// SDL2 satellite libraries (SDL_image, SDL_mixer, SDL_ttf) +/// as well. Though they use their own error handling functions +/// (IMG_GetError, Mix_GetError, TTF_GetError), those are (currently) +/// just macros pointing to SDL_GetError. We currently rely on that. +/// If that changes, we'll need a hierarchy of specific exceptions. +/// /// Usage example: /// \code /// { diff --git a/SDL2pp/SDL2pp.hh b/SDL2pp/SDL2pp.hh index b3e8588..3bc6059 100644 --- a/SDL2pp/SDL2pp.hh +++ b/SDL2pp/SDL2pp.hh @@ -95,4 +95,12 @@ #include #include +//////////////////////////////////////////////////////////// +/// \defgroup image SDL_image +/// +/// \brief Functions that are specific to SDL_image library +/// +//////////////////////////////////////////////////////////// +#include + #endif diff --git a/SDL2pp/SDLImage.cc b/SDL2pp/SDLImage.cc new file mode 100644 index 0000000..f2e9c66 --- /dev/null +++ b/SDL2pp/SDLImage.cc @@ -0,0 +1,49 @@ +/* + libSDL2pp - C++11 bindings/wrapper for SDL2 + Copyright (C) 2014 Dmitry Marakasov + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ + +#include + +#include +#include + +namespace SDL2pp { + +SDLImage::SDLImage(int flags) { + if ((IMG_Init(flags) & flags) != flags) + throw Exception("IMG_Init failed"); +} + +SDLImage::~SDLImage() { + IMG_Quit(); +} + +int SDLImage::InitMore(int flags) { + int ret; + if (((ret = IMG_Init(flags)) & flags) != flags) + throw Exception("IMG_Init failed"); + return ret; +} + +int SDLImage::GetInitFlags() { + return IMG_Init(0); +} + +} diff --git a/SDL2pp/SDLImage.hh b/SDL2pp/SDLImage.hh new file mode 100644 index 0000000..1d8e3cc --- /dev/null +++ b/SDL2pp/SDLImage.hh @@ -0,0 +1,106 @@ +/* + libSDL2pp - C++11 bindings/wrapper for SDL2 + Copyright (C) 2014 Dmitry Marakasov + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ + +#ifndef SDL2PP_SDLIMAGE_HH +#define SDL2PP_SDLIMAGE_HH + +namespace SDL2pp { + +//////////////////////////////////////////////////////////// +/// \brief Object taking care of SDL_image library (de-)initialization +/// +/// \ingroup image +/// +/// \headerfile SDL2pp/SDLImage.hh +/// +/// Though it's possible to use SDL_image without initializing it, +/// library provide initialization/deinitialization functions to +/// be able to preload libraries for specific file format support +/// (png, jpeg or tiff) beforehand. In SDL2pp, this is handled by +/// this class. +/// +/// Usage example: +/// \code +/// int main() { +/// SDL2pp::SDL sdl(SDL_INIT_VIDEO); +/// SDL2pp::SDLImage image(IMG_INIT_PNG); +/// +/// // use SDL_image functions +/// SDL2pp::Texture t("/path/to/file.png"); +/// +/// // SDL_image library is automatically deinitialized before exit +/// return 0; +/// } +/// \endcode +/// +//////////////////////////////////////////////////////////// +class SDLImage { +public: + //////////////////////////////////////////////////////////// + /// \brief Initializes SDL_image library + /// + /// \param flags Flags to pass to IMG_Init() + /// + /// \throws SDL2pp::Exception + /// + /// \see https://www.libsdl.org/projects/SDL_image/docs/SDL_image.html#SEC8 + /// + //////////////////////////////////////////////////////////// + SDLImage(int flags); + + //////////////////////////////////////////////////////////// + /// \brief Destructor, deinitializes SDL_image library + /// + /// \see https://www.libsdl.org/projects/SDL_image/docs/SDL_image.html#SEC9 + /// + //////////////////////////////////////////////////////////// + virtual ~SDLImage(); + + //////////////////////////////////////////////////////////// + /// \brief Try to init more SDL_image formats + /// + /// \param flags Flags to pass to IMG_Init() + /// + /// \throws SDL2pp::Exception + /// + /// \see https://www.libsdl.org/projects/SDL_image/docs/SDL_image.html#SEC8 + /// + //////////////////////////////////////////////////////////// + int InitMore(int flags); + + //////////////////////////////////////////////////////////// + /// \brief Get mask of initialized SDL_image formats + /// + /// \see https://www.libsdl.org/projects/SDL_image/docs/SDL_image.html#SEC8 + /// + //////////////////////////////////////////////////////////// + int GetInitFlags(); + + // Deleted copy/move constructors and assignments + SDLImage(const SDLImage& other) = delete; + SDLImage(SDLImage&& other) = delete; + SDLImage& operator=(const SDLImage& other) = delete; + SDLImage& operator=(SDLImage&& other) = delete; +}; + +} + +#endif diff --git a/examples/image.cc b/examples/image.cc index 0aa8007..a243e1e 100644 --- a/examples/image.cc +++ b/examples/image.cc @@ -22,8 +22,10 @@ #include #include +#include #include +#include #include #include #include @@ -33,6 +35,7 @@ using namespace SDL2pp; int Run() { SDL sdl(SDL_INIT_VIDEO); + SDLImage image(IMG_INIT_PNG); // optional Window window("libSDL2pp demo: loading", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, SDL_WINDOW_RESIZABLE); Renderer render(window, -1, SDL_RENDERER_ACCELERATED); From 53308e04f7f2027d6f3ca89c05cb7d97f1a0f9af Mon Sep 17 00:00:00 2001 From: Dmitry Marakasov Date: Sat, 27 Dec 2014 05:23:33 +0300 Subject: [PATCH 12/17] Display library version during the build --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b912810..d6a330a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -123,7 +123,7 @@ SET(LIBRARY_HEADERS ) IF(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR) - MESSAGE(STATUS "libSDL2pp standalone build") + MESSAGE(STATUS "libSDL2pp ${SDL2PP_VERSION} standalone build") # library ADD_LIBRARY(SDL2pp SHARED ${LIBRARY_SOURCES} ${LIBRARY_HEADERS}) @@ -166,7 +166,7 @@ IF(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR) INSTALL(TARGETS SDL2pp LIBRARY DESTINATION lib) INSTALL(FILES ${PROJECT_BINARY_DIR}/sdl2pp.pc DESTINATION ${PKGCONFIGDIR}) ELSE(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR) - MESSAGE(STATUS "libSDL2pp bundled build") + MESSAGE(STATUS "libSDL2pp ${SDL2PP_VERSION} bundled build") # library ADD_LIBRARY(SDL2pp STATIC ${LIBRARY_SOURCES} ${LIBRARY_HEADERS}) From 63065bc820a50ccb5b60859be8570e488011a78b Mon Sep 17 00:00:00 2001 From: Dmitry Marakasov Date: Sat, 27 Dec 2014 05:23:46 +0300 Subject: [PATCH 13/17] Add note on minimal compiler versions --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 0ade3d4..27c20e5 100644 --- a/README.md +++ b/README.md @@ -77,6 +77,9 @@ methods. These classes also support: ## Building ## +To build libSDL2pp, you need a compiler with C++11 support, for +example clang 3.4+ or gcc 4.8+. + Dependencies: * cmake * SDL2 From 60f8e7febc1c0cfcd4dbf355e88339625246563e Mon Sep 17 00:00:00 2001 From: Dmitry Marakasov Date: Sat, 27 Dec 2014 19:00:03 +0300 Subject: [PATCH 14/17] Fix copypasta in documentation --- SDL2pp/Texture.hh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/SDL2pp/Texture.hh b/SDL2pp/Texture.hh index 17ff1dd..e9f58cb 100644 --- a/SDL2pp/Texture.hh +++ b/SDL2pp/Texture.hh @@ -103,7 +103,7 @@ public: /// /// \throws STL2pp::Exception /// - /// \see http://wiki.libsdl.org/SDL_LockAudioDevice + /// \see http://wiki.libsdl.org/SDL_LockTexture /// //////////////////////////////////////////////////////////// LockHandle(Texture* texture, const Optional& rect); @@ -125,7 +125,7 @@ public: /// \details /// Releases the lock /// - /// \see http://wiki.libsdl.org/SDL_UnlockAudioDevice + /// \see http://wiki.libsdl.org/SDL_UnlockTexture /// //////////////////////////////////////////////////////////// ~LockHandle(); @@ -133,7 +133,7 @@ public: //////////////////////////////////////////////////////////// /// \brief Move constructor /// - /// \param other SDL2pp::AudioDevice::LockHandle to move data from + /// \param other SDL2pp::Texture::LockHandle to move data from /// //////////////////////////////////////////////////////////// LockHandle(LockHandle&& other) noexcept; @@ -141,7 +141,7 @@ public: //////////////////////////////////////////////////////////// /// \brief Move assignment operator /// - /// \param other SDL2pp::AudioDevice::LockHandle to move data from + /// \param other SDL2pp::Texture::LockHandle to move data from /// /// \returns Reference to self /// From 25bbd97b3e4c93e2e4c7ec4c50de0cc3bff431c0 Mon Sep 17 00:00:00 2001 From: Dmitry Marakasov Date: Sun, 28 Dec 2014 06:06:22 +0300 Subject: [PATCH 15/17] Add constructors from existing SDL2 objects --- SDL2pp/Renderer.cc | 3 +++ SDL2pp/Renderer.hh | 8 ++++++++ SDL2pp/Surface.hh | 7 +++---- SDL2pp/Texture.cc | 3 +++ SDL2pp/Texture.hh | 8 ++++++++ SDL2pp/Window.cc | 3 +++ SDL2pp/Window.hh | 8 ++++++++ 7 files changed, 36 insertions(+), 4 deletions(-) diff --git a/SDL2pp/Renderer.cc b/SDL2pp/Renderer.cc index 7c2ccef..5e14cac 100644 --- a/SDL2pp/Renderer.cc +++ b/SDL2pp/Renderer.cc @@ -30,6 +30,9 @@ namespace SDL2pp { +Renderer::Renderer(SDL_Renderer* renderer) : renderer_(renderer) { +} + Renderer::Renderer(Window& window, int index, Uint32 flags) { if ((renderer_ = SDL_CreateRenderer(window.Get(), index, flags)) == nullptr) throw Exception("SDL_CreateRenderer failed"); diff --git a/SDL2pp/Renderer.hh b/SDL2pp/Renderer.hh index 80bfd9a..1d0b9bc 100644 --- a/SDL2pp/Renderer.hh +++ b/SDL2pp/Renderer.hh @@ -51,6 +51,14 @@ private: SDL_Renderer* renderer_; ///< Contained SDL_Renderer structure public: + //////////////////////////////////////////////////////////// + /// \brief Construct from existing SDL_Renderer structure + /// + /// \param renderer Existing SDL_Renderer to manage + /// + //////////////////////////////////////////////////////////// + Renderer(SDL_Renderer* renderer); + //////////////////////////////////////////////////////////// /// \brief Create renderer /// diff --git a/SDL2pp/Surface.hh b/SDL2pp/Surface.hh index 80851bf..5cdcb89 100644 --- a/SDL2pp/Surface.hh +++ b/SDL2pp/Surface.hh @@ -148,16 +148,15 @@ public: const SDL_PixelFormat& GetFormat() const; }; -private: +public: //////////////////////////////////////////////////////////// - /// \brief Create surface taking existing SDL_surface structure + /// \brief Construct from existing SDL_Surface structure /// - /// \param surface Existing SDL_surface to manage + /// \param surface Existing SDL_Surface to manage /// //////////////////////////////////////////////////////////// Surface(SDL_Surface* surface); -public: //////////////////////////////////////////////////////////// /// \brief Create RGB surface /// diff --git a/SDL2pp/Texture.cc b/SDL2pp/Texture.cc index 5308756..2a5912e 100644 --- a/SDL2pp/Texture.cc +++ b/SDL2pp/Texture.cc @@ -40,6 +40,9 @@ namespace SDL2pp { +Texture::Texture(SDL_Texture* texture) : texture_(texture) { +} + Texture::Texture(Renderer& renderer, Uint32 format, int access, int w, int h) { if ((texture_ = SDL_CreateTexture(renderer.Get(), format, access, w, h)) == nullptr) throw Exception("SDL_CreateTexture failed"); diff --git a/SDL2pp/Texture.hh b/SDL2pp/Texture.hh index e80fb9c..84b32d2 100644 --- a/SDL2pp/Texture.hh +++ b/SDL2pp/Texture.hh @@ -172,6 +172,14 @@ public: }; public: + //////////////////////////////////////////////////////////// + /// \brief Construct from existing SDL_Texture structure + /// + /// \param texture Existing SDL_Texture to manage + /// + //////////////////////////////////////////////////////////// + Texture(SDL_Texture* texture); + //////////////////////////////////////////////////////////// /// \brief Create empty texture /// diff --git a/SDL2pp/Window.cc b/SDL2pp/Window.cc index d77eb18..71ef909 100644 --- a/SDL2pp/Window.cc +++ b/SDL2pp/Window.cc @@ -26,6 +26,9 @@ namespace SDL2pp { +Window::Window(SDL_Window* window) : window_(window) { +} + Window::Window(const std::string& title, int x, int y, int w, int h, Uint32 flags) { if ((window_ = SDL_CreateWindow(title.c_str(), x, y, w, h, flags)) == nullptr) throw Exception("SDL_CreateWindow failed"); diff --git a/SDL2pp/Window.hh b/SDL2pp/Window.hh index e42ea00..d1a9a79 100644 --- a/SDL2pp/Window.hh +++ b/SDL2pp/Window.hh @@ -64,6 +64,14 @@ private: SDL_Window* window_; ///< Contained SDL2_Window structure public: + //////////////////////////////////////////////////////////// + /// \brief Construct from existing SDL_Window structure + /// + /// \param window Existing SDL_Window to manage + /// + //////////////////////////////////////////////////////////// + Window(SDL_Window* window); + //////////////////////////////////////////////////////////// /// \brief Create window with specified title and fimensions /// From 0c0a7aad15c2bd99a6e13c314ed42ed5ab0b6900 Mon Sep 17 00:00:00 2001 From: Dmitry Marakasov Date: Sun, 28 Dec 2014 06:09:47 +0300 Subject: [PATCH 16/17] Only add image-related sources to the project if SDL_image support is enabled --- CMakeLists.txt | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 83a23c5..435273e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -98,7 +98,6 @@ SET(LIBRARY_SOURCES SDL2pp/Rect.cc SDL2pp/Renderer.cc SDL2pp/SDL.cc - SDL2pp/SDLImage.cc SDL2pp/Surface.cc SDL2pp/SurfaceLock.cc SDL2pp/Texture.cc @@ -107,6 +106,13 @@ SET(LIBRARY_SOURCES SDL2pp/Window.cc ) +IF(SDL2PP_WITH_IMAGE) + SET(LIBRARY_SOURCES + ${LIBRARY_SOURCES} + SDL2pp/SDLImage.cc + ) +ENDIF(SDL2PP_WITH_IMAGE) + SET(LIBRARY_HEADERS SDL2pp/AudioDevice.hh SDL2pp/AudioSpec.hh @@ -119,7 +125,6 @@ SET(LIBRARY_HEADERS SDL2pp/Renderer.hh SDL2pp/SDL.hh SDL2pp/SDL2pp.hh - SDL2pp/SDLImage.hh SDL2pp/StreamRWops.hh SDL2pp/Surface.hh SDL2pp/Texture.hh @@ -127,6 +132,13 @@ SET(LIBRARY_HEADERS SDL2pp/Window.hh ) +IF(SDL2PP_WITH_IMAGE) + SET(LIBRARY_HEADERS + ${LIBRARY_HEADERS} + SDL2pp/SDLImage.hh + ) +ENDIF(SDL2PP_WITH_IMAGE) + IF(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR) MESSAGE(STATUS "libSDL2pp ${SDL2PP_VERSION} standalone build") From 835ce5d7c03e3cbcad8733491cd30724cc9f79ef Mon Sep 17 00:00:00 2001 From: Dmitry Marakasov Date: Sun, 28 Dec 2014 06:09:59 +0300 Subject: [PATCH 17/17] Include SDLImage conditionally --- SDL2pp/SDL2pp.hh | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/SDL2pp/SDL2pp.hh b/SDL2pp/SDL2pp.hh index 3bc6059..85f9b65 100644 --- a/SDL2pp/SDL2pp.hh +++ b/SDL2pp/SDL2pp.hh @@ -95,12 +95,14 @@ #include #include -//////////////////////////////////////////////////////////// -/// \defgroup image SDL_image -/// -/// \brief Functions that are specific to SDL_image library -/// -//////////////////////////////////////////////////////////// -#include +#ifdef SDL2PP_WITH_IMAGE + //////////////////////////////////////////////////////////// + /// \defgroup image SDL_image + /// + /// \brief Functions that are specific to SDL_image library + /// + //////////////////////////////////////////////////////////// +# include +#endif #endif