Merge branch 'master' of github.com:libSDL2pp/libSDL2pp

This commit is contained in:
Dmitry Marakasov 2017-02-20 16:31:51 +03:00
commit 970cd74dd9
22 changed files with 63 additions and 45 deletions

View File

@ -102,7 +102,7 @@ public:
/// \see http://wiki.libsdl.org/SDL_LockAudioDevice /// \see http://wiki.libsdl.org/SDL_LockAudioDevice
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
LockHandle(AudioDevice* device); explicit LockHandle(AudioDevice* device);
public: public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////

View File

@ -19,6 +19,8 @@
3. This notice may not be removed or altered from any source distribution. 3. This notice may not be removed or altered from any source distribution.
*/ */
#include <cassert>
#include <SDL2pp/Chunk.hh> #include <SDL2pp/Chunk.hh>
#include <SDL2pp/RWops.hh> #include <SDL2pp/RWops.hh>
#include <SDL2pp/Exception.hh> #include <SDL2pp/Exception.hh>
@ -26,6 +28,7 @@
namespace SDL2pp { namespace SDL2pp {
Chunk::Chunk(Mix_Chunk* chunk) : chunk_(chunk) { Chunk::Chunk(Mix_Chunk* chunk) : chunk_(chunk) {
assert(chunk);
} }
Chunk::Chunk(const std::string& file) { Chunk::Chunk(const std::string& file) {

View File

@ -51,7 +51,7 @@ public:
/// \param[in] chunk Existing Mix_Chunk to manage /// \param[in] chunk Existing Mix_Chunk to manage
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Chunk(Mix_Chunk* chunk); explicit Chunk(Mix_Chunk* chunk);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Load file for use as a sample /// \brief Load file for use as a sample
@ -63,7 +63,7 @@ public:
/// \see https://www.libsdl.org/projects/SDL_mixer/docs/SDL_mixer.html#SEC19 /// \see https://www.libsdl.org/projects/SDL_mixer/docs/SDL_mixer.html#SEC19
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Chunk(const std::string& file); explicit Chunk(const std::string& file);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Load sample using RWops /// \brief Load sample using RWops
@ -75,7 +75,7 @@ public:
/// \see https://www.libsdl.org/projects/SDL_mixer/docs/SDL_mixer.html#SEC20 /// \see https://www.libsdl.org/projects/SDL_mixer/docs/SDL_mixer.html#SEC20
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Chunk(RWops& rwops); explicit Chunk(RWops& rwops);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Destructor /// \brief Destructor

View File

@ -83,7 +83,7 @@ public:
/// \param[in] function Name of SDL function which generated an error /// \param[in] function Name of SDL function which generated an error
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Exception(const char* function); explicit Exception(const char* function);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Copy constructor /// \brief Copy constructor

View File

@ -19,6 +19,7 @@
3. This notice may not be removed or altered from any source distribution. 3. This notice may not be removed or altered from any source distribution.
*/ */
#include <cassert>
#include <vector> #include <vector>
#include <SDL_ttf.h> #include <SDL_ttf.h>
@ -29,8 +30,8 @@
namespace SDL2pp { namespace SDL2pp {
Font::Font(TTF_Font* font) { Font::Font(TTF_Font* font) : font_(font) {
font_ = font; assert(font);
} }
Font::Font(const std::string& file, int ptsize, long index) { Font::Font(const std::string& file, int ptsize, long index) {

View File

@ -60,7 +60,7 @@ public:
/// \param[in] font Existing TTF_Font to manage /// \param[in] font Existing TTF_Font to manage
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Font(TTF_Font* font); explicit Font(TTF_Font* font);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Loads font from .ttf or .fon file /// \brief Loads font from .ttf or .fon file

View File

@ -19,12 +19,15 @@
3. This notice may not be removed or altered from any source distribution. 3. This notice may not be removed or altered from any source distribution.
*/ */
#include <cassert>
#include <SDL2pp/Music.hh> #include <SDL2pp/Music.hh>
#include <SDL2pp/Exception.hh> #include <SDL2pp/Exception.hh>
namespace SDL2pp { namespace SDL2pp {
Music::Music(Mix_Music* music) : music_(music) { Music::Music(Mix_Music* music) : music_(music) {
assert(music);
} }
Music::Music(const std::string& file) { Music::Music(const std::string& file) {

View File

@ -49,7 +49,7 @@ public:
/// \param[in] music Existing Mix_Music to manage /// \param[in] music Existing Mix_Music to manage
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Music(Mix_Music* music); explicit Music(Mix_Music* music);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Load music file /// \brief Load music file
@ -61,7 +61,7 @@ public:
/// \see https://www.libsdl.org/projects/SDL_mixer/docs/SDL_mixer.html#SEC55 /// \see https://www.libsdl.org/projects/SDL_mixer/docs/SDL_mixer.html#SEC55
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Music(const std::string& file); explicit Music(const std::string& file);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Destructor /// \brief Destructor

View File

@ -130,6 +130,8 @@ RWops RWops::FromFile(const std::string& file, const std::string& mode) {
} }
RWops::RWops(SDL_RWops* rwops) { RWops::RWops(SDL_RWops* rwops) {
assert(rwops);
rwops_ = SDL_AllocRW(); rwops_ = SDL_AllocRW();
if (rwops_ == nullptr) if (rwops_ == nullptr)
throw Exception("SDL_AllocRW"); throw Exception("SDL_AllocRW");

View File

@ -220,7 +220,7 @@ public:
/// \param[in] rwops Pointer to SDL_RWops to use /// \param[in] rwops Pointer to SDL_RWops to use
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
RWops(SDL_RWops* rwops); explicit RWops(SDL_RWops* rwops);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Move constructor /// \brief Move constructor
@ -267,7 +267,7 @@ public:
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
template<class C> template<class C>
RWops(C&& custom_rwops) { explicit RWops(C&& custom_rwops) {
rwops_ = SDL_AllocRW(); rwops_ = SDL_AllocRW();
if (rwops_ == nullptr) if (rwops_ == nullptr)
throw Exception("SDL_AllocRW"); throw Exception("SDL_AllocRW");

View File

@ -20,6 +20,7 @@
*/ */
#include <vector> #include <vector>
#include <cassert>
#include <SDL.h> #include <SDL.h>
@ -31,6 +32,7 @@
namespace SDL2pp { namespace SDL2pp {
Renderer::Renderer(SDL_Renderer* renderer) : renderer_(renderer) { Renderer::Renderer(SDL_Renderer* renderer) : renderer_(renderer) {
assert(renderer);
} }
Renderer::Renderer(Window& window, int index, Uint32 flags) { Renderer::Renderer(Window& window, int index, Uint32 flags) {

View File

@ -59,7 +59,7 @@ public:
/// \param[in] renderer Existing SDL_Renderer to manage /// \param[in] renderer Existing SDL_Renderer to manage
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Renderer(SDL_Renderer* renderer); explicit Renderer(SDL_Renderer* renderer);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Create renderer /// \brief Create renderer

View File

@ -67,7 +67,7 @@ public:
/// \see https://www.libsdl.org/projects/SDL_image/docs/SDL_image.html#SEC8 /// \see https://www.libsdl.org/projects/SDL_image/docs/SDL_image.html#SEC8
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
SDLImage(int flags = 0); explicit SDLImage(int flags = 0);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Destructor, deinitializes SDL_image library /// \brief Destructor, deinitializes SDL_image library

View File

@ -58,7 +58,7 @@ public:
/// \see https://www.libsdl.org/projects/SDL_mixer/docs/SDL_mixer.html#SEC9 /// \see https://www.libsdl.org/projects/SDL_mixer/docs/SDL_mixer.html#SEC9
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
SDLMixer(int flags = 0); explicit SDLMixer(int flags = 0);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Destructor, deinitializes SDL_mixer library /// \brief Destructor, deinitializes SDL_mixer library

View File

@ -20,6 +20,7 @@
*/ */
#include <vector> #include <vector>
#include <cassert>
#include <SDL2pp/Config.hh> #include <SDL2pp/Config.hh>
@ -37,6 +38,7 @@
namespace SDL2pp { namespace SDL2pp {
Surface::Surface(SDL_Surface* surface) : surface_(surface) { Surface::Surface(SDL_Surface* surface) : surface_(surface) {
assert(surface);
} }
Surface::Surface(Uint32 flags, int width, int height, int depth, Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask) { Surface::Surface(Uint32 flags, int width, int height, int depth, Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask) {
@ -88,14 +90,14 @@ Surface Surface::Convert(const SDL_PixelFormat& format) {
SDL_Surface* surface = SDL_ConvertSurface(surface_, &format, 0); SDL_Surface* surface = SDL_ConvertSurface(surface_, &format, 0);
if (surface == nullptr) if (surface == nullptr)
throw Exception("SDL_ConvertSurface"); throw Exception("SDL_ConvertSurface");
return surface; return SDL2pp::Surface(surface);
} }
Surface Surface::Convert(Uint32 pixel_format) { Surface Surface::Convert(Uint32 pixel_format) {
SDL_Surface* surface = SDL_ConvertSurfaceFormat(surface_, pixel_format, 0); SDL_Surface* surface = SDL_ConvertSurfaceFormat(surface_, pixel_format, 0);
if (surface == nullptr) if (surface == nullptr)
throw Exception("SDL_ConvertSurfaceFormat"); throw Exception("SDL_ConvertSurfaceFormat");
return surface; return SDL2pp::Surface(surface);
} }
void Surface::Blit(const Optional<Rect>& srcrect, Surface& dst, const Rect& dstrect) { void Surface::Blit(const Optional<Rect>& srcrect, Surface& dst, const Rect& dstrect) {

View File

@ -80,7 +80,7 @@ public:
/// \see http://wiki.libsdl.org/SDL_LockSurface /// \see http://wiki.libsdl.org/SDL_LockSurface
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
LockHandle(Surface* surface); explicit LockHandle(Surface* surface);
public: public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
@ -169,7 +169,7 @@ public:
/// \param[in] surface Existing SDL_Surface to manage /// \param[in] surface Existing SDL_Surface to manage
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Surface(SDL_Surface* surface); explicit Surface(SDL_Surface* surface);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Create RGB surface /// \brief Create RGB surface
@ -217,7 +217,7 @@ public:
/// \param[in] rwops RWops used to access an image file /// \param[in] rwops RWops used to access an image file
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Surface(RWops& rwops); explicit Surface(RWops& rwops);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Create surface loading it from file /// \brief Create surface loading it from file
@ -225,7 +225,7 @@ public:
/// \param[in] filename Path to an image file /// \param[in] filename Path to an image file
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Surface(const std::string& filename); explicit Surface(const std::string& filename);
#endif #endif
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////

View File

@ -21,6 +21,7 @@
#include <utility> #include <utility>
#include <algorithm> #include <algorithm>
#include <cassert>
#include <SDL2pp/Config.hh> #include <SDL2pp/Config.hh>
@ -42,6 +43,7 @@
namespace SDL2pp { namespace SDL2pp {
Texture::Texture(SDL_Texture* texture) : texture_(texture) { Texture::Texture(SDL_Texture* texture) : texture_(texture) {
assert(texture);
} }
Texture::Texture(Renderer& renderer, Uint32 format, int access, int w, int h) { Texture::Texture(Renderer& renderer, Uint32 format, int access, int w, int h) {

View File

@ -191,7 +191,7 @@ public:
/// \param[in] texture Existing SDL_Texture to manage /// \param[in] texture Existing SDL_Texture to manage
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Texture(SDL_Texture* texture); explicit Texture(SDL_Texture* texture);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Create empty texture /// \brief Create empty texture

View File

@ -67,7 +67,7 @@ public:
/// \see http://wiki.libsdl.org/SDL_LoadWAV /// \see http://wiki.libsdl.org/SDL_LoadWAV
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Wav(const std::string& file); explicit Wav(const std::string& file);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Load audio using RWops /// \brief Load audio using RWops
@ -79,7 +79,7 @@ public:
/// \see http://wiki.libsdl.org/SDL_LoadWAV_RW /// \see http://wiki.libsdl.org/SDL_LoadWAV_RW
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Wav(RWops& rwops); explicit Wav(RWops& rwops);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Destructor /// \brief Destructor

View File

@ -19,6 +19,8 @@
3. This notice may not be removed or altered from any source distribution. 3. This notice may not be removed or altered from any source distribution.
*/ */
#include <cassert>
#include <SDL.h> #include <SDL.h>
#include <SDL2pp/Window.hh> #include <SDL2pp/Window.hh>
@ -28,6 +30,7 @@
namespace SDL2pp { namespace SDL2pp {
Window::Window(SDL_Window* window) : window_(window) { Window::Window(SDL_Window* window) : window_(window) {
assert(window);
} }
Window::Window(const std::string& title, int x, int y, int w, int h, Uint32 flags) { Window::Window(const std::string& title, int x, int y, int w, int h, Uint32 flags) {
@ -244,17 +247,17 @@ Window& Window::SetBordered(bool bordered) {
#if SDL_VERSION_ATLEAST(2, 0, 5) #if SDL_VERSION_ATLEAST(2, 0, 5)
Window& Window::SetOpacity(float opacity) { Window& Window::SetOpacity(float opacity) {
if (SDL_SetWindowOpacity(window_, opacity)) if (SDL_SetWindowOpacity(window_, opacity))
throw SDL2pp::Exception("SDL_SetWindowOpacity"); throw SDL2pp::Exception("SDL_SetWindowOpacity");
return *this; return *this;
} }
float Window::GetOpacity() const { float Window::GetOpacity() const {
float opacity; float opacity;
if (SDL_GetWindowOpacity(window_, &opacity) == -1) if (SDL_GetWindowOpacity(window_, &opacity) == -1)
throw SDL2pp::Exception("SDL_GetWindowOpacity"); throw SDL2pp::Exception("SDL_GetWindowOpacity");
return opacity; return opacity;
} }
#endif #endif

View File

@ -75,7 +75,7 @@ public:
/// \param[in] window Existing SDL_Window to manage /// \param[in] window Existing SDL_Window to manage
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Window(SDL_Window* window); explicit Window(SDL_Window* window);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Create window with specified title and dimensions /// \brief Create window with specified title and dimensions

View File

@ -194,23 +194,23 @@ BEGIN_TEST(int, char*[])
#if SDL_VERSION_ATLEAST(2, 0, 5) #if SDL_VERSION_ATLEAST(2, 0, 5)
{ {
// Opacity // Opacity
bool has_opacity = true; bool has_opacity = true;
try { try {
window.SetOpacity(0.5f); window.SetOpacity(0.5f);
} catch (...) { } catch (...) {
has_opacity = false; has_opacity = false;
std::cerr << "Setting window opacity is not supported on this platform" << std::endl; std::cerr << "Setting window opacity is not supported on this platform" << std::endl;
} }
if (has_opacity) { if (has_opacity) {
EXPECT_TRUE(window.GetOpacity() > 0.49f); EXPECT_TRUE(window.GetOpacity() > 0.49f);
EXPECT_TRUE(window.GetOpacity() < 0.51f); EXPECT_TRUE(window.GetOpacity() < 0.51f);
EventSleep(1000); EventSleep(1000);
window.SetOpacity(); window.SetOpacity();
EXPECT_TRUE(window.GetOpacity() > 0.99f); EXPECT_TRUE(window.GetOpacity() > 0.99f);
EventSleep(1000); EventSleep(1000);
} }
} }
#endif #endif