mirror of
https://github.com/libSDL2pp/libSDL2pp.git
synced 2025-08-03 02:45:57 -04:00
Merge branch 'master' of github.com:libSDL2pp/libSDL2pp
This commit is contained in:
commit
970cd74dd9
@ -102,7 +102,7 @@ public:
|
||||
/// \see http://wiki.libsdl.org/SDL_LockAudioDevice
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
LockHandle(AudioDevice* device);
|
||||
explicit LockHandle(AudioDevice* device);
|
||||
|
||||
public:
|
||||
////////////////////////////////////////////////////////////
|
||||
|
@ -19,6 +19,8 @@
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#include <cassert>
|
||||
|
||||
#include <SDL2pp/Chunk.hh>
|
||||
#include <SDL2pp/RWops.hh>
|
||||
#include <SDL2pp/Exception.hh>
|
||||
@ -26,6 +28,7 @@
|
||||
namespace SDL2pp {
|
||||
|
||||
Chunk::Chunk(Mix_Chunk* chunk) : chunk_(chunk) {
|
||||
assert(chunk);
|
||||
}
|
||||
|
||||
Chunk::Chunk(const std::string& file) {
|
||||
|
@ -51,7 +51,7 @@ public:
|
||||
/// \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
|
||||
@ -63,7 +63,7 @@ public:
|
||||
/// \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
|
||||
@ -75,7 +75,7 @@ public:
|
||||
/// \see https://www.libsdl.org/projects/SDL_mixer/docs/SDL_mixer.html#SEC20
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Chunk(RWops& rwops);
|
||||
explicit Chunk(RWops& rwops);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Destructor
|
||||
|
@ -83,7 +83,7 @@ public:
|
||||
/// \param[in] function Name of SDL function which generated an error
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Exception(const char* function);
|
||||
explicit Exception(const char* function);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Copy constructor
|
||||
|
@ -19,6 +19,7 @@
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#include <cassert>
|
||||
#include <vector>
|
||||
|
||||
#include <SDL_ttf.h>
|
||||
@ -29,8 +30,8 @@
|
||||
|
||||
namespace SDL2pp {
|
||||
|
||||
Font::Font(TTF_Font* font) {
|
||||
font_ = font;
|
||||
Font::Font(TTF_Font* font) : font_(font) {
|
||||
assert(font);
|
||||
}
|
||||
|
||||
Font::Font(const std::string& file, int ptsize, long index) {
|
||||
|
@ -60,7 +60,7 @@ public:
|
||||
/// \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
|
||||
|
@ -19,12 +19,15 @@
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#include <cassert>
|
||||
|
||||
#include <SDL2pp/Music.hh>
|
||||
#include <SDL2pp/Exception.hh>
|
||||
|
||||
namespace SDL2pp {
|
||||
|
||||
Music::Music(Mix_Music* music) : music_(music) {
|
||||
assert(music);
|
||||
}
|
||||
|
||||
Music::Music(const std::string& file) {
|
||||
|
@ -49,7 +49,7 @@ public:
|
||||
/// \param[in] music Existing Mix_Music to manage
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Music(Mix_Music* music);
|
||||
explicit Music(Mix_Music* music);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Load music file
|
||||
@ -61,7 +61,7 @@ public:
|
||||
/// \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
|
||||
|
@ -130,6 +130,8 @@ RWops RWops::FromFile(const std::string& file, const std::string& mode) {
|
||||
}
|
||||
|
||||
RWops::RWops(SDL_RWops* rwops) {
|
||||
assert(rwops);
|
||||
|
||||
rwops_ = SDL_AllocRW();
|
||||
if (rwops_ == nullptr)
|
||||
throw Exception("SDL_AllocRW");
|
||||
|
@ -220,7 +220,7 @@ public:
|
||||
/// \param[in] rwops Pointer to SDL_RWops to use
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
RWops(SDL_RWops* rwops);
|
||||
explicit RWops(SDL_RWops* rwops);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Move constructor
|
||||
@ -267,7 +267,7 @@ public:
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template<class C>
|
||||
RWops(C&& custom_rwops) {
|
||||
explicit RWops(C&& custom_rwops) {
|
||||
rwops_ = SDL_AllocRW();
|
||||
if (rwops_ == nullptr)
|
||||
throw Exception("SDL_AllocRW");
|
||||
|
@ -20,6 +20,7 @@
|
||||
*/
|
||||
|
||||
#include <vector>
|
||||
#include <cassert>
|
||||
|
||||
#include <SDL.h>
|
||||
|
||||
@ -31,6 +32,7 @@
|
||||
namespace SDL2pp {
|
||||
|
||||
Renderer::Renderer(SDL_Renderer* renderer) : renderer_(renderer) {
|
||||
assert(renderer);
|
||||
}
|
||||
|
||||
Renderer::Renderer(Window& window, int index, Uint32 flags) {
|
||||
|
@ -59,7 +59,7 @@ public:
|
||||
/// \param[in] renderer Existing SDL_Renderer to manage
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Renderer(SDL_Renderer* renderer);
|
||||
explicit Renderer(SDL_Renderer* renderer);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Create renderer
|
||||
|
@ -67,7 +67,7 @@ public:
|
||||
/// \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
|
||||
|
@ -58,7 +58,7 @@ public:
|
||||
/// \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
|
||||
|
@ -20,6 +20,7 @@
|
||||
*/
|
||||
|
||||
#include <vector>
|
||||
#include <cassert>
|
||||
|
||||
#include <SDL2pp/Config.hh>
|
||||
|
||||
@ -37,6 +38,7 @@
|
||||
namespace SDL2pp {
|
||||
|
||||
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) {
|
||||
@ -88,14 +90,14 @@ Surface Surface::Convert(const SDL_PixelFormat& format) {
|
||||
SDL_Surface* surface = SDL_ConvertSurface(surface_, &format, 0);
|
||||
if (surface == nullptr)
|
||||
throw Exception("SDL_ConvertSurface");
|
||||
return surface;
|
||||
return SDL2pp::Surface(surface);
|
||||
}
|
||||
|
||||
Surface Surface::Convert(Uint32 pixel_format) {
|
||||
SDL_Surface* surface = SDL_ConvertSurfaceFormat(surface_, pixel_format, 0);
|
||||
if (surface == nullptr)
|
||||
throw Exception("SDL_ConvertSurfaceFormat");
|
||||
return surface;
|
||||
return SDL2pp::Surface(surface);
|
||||
}
|
||||
|
||||
void Surface::Blit(const Optional<Rect>& srcrect, Surface& dst, const Rect& dstrect) {
|
||||
|
@ -80,7 +80,7 @@ public:
|
||||
/// \see http://wiki.libsdl.org/SDL_LockSurface
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
LockHandle(Surface* surface);
|
||||
explicit LockHandle(Surface* surface);
|
||||
|
||||
public:
|
||||
////////////////////////////////////////////////////////////
|
||||
@ -169,7 +169,7 @@ public:
|
||||
/// \param[in] surface Existing SDL_Surface to manage
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Surface(SDL_Surface* surface);
|
||||
explicit Surface(SDL_Surface* surface);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Create RGB surface
|
||||
@ -217,7 +217,7 @@ public:
|
||||
/// \param[in] rwops RWops used to access an image file
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Surface(RWops& rwops);
|
||||
explicit Surface(RWops& rwops);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Create surface loading it from file
|
||||
@ -225,7 +225,7 @@ public:
|
||||
/// \param[in] filename Path to an image file
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Surface(const std::string& filename);
|
||||
explicit Surface(const std::string& filename);
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
|
@ -21,6 +21,7 @@
|
||||
|
||||
#include <utility>
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
|
||||
#include <SDL2pp/Config.hh>
|
||||
|
||||
@ -42,6 +43,7 @@
|
||||
namespace SDL2pp {
|
||||
|
||||
Texture::Texture(SDL_Texture* texture) : texture_(texture) {
|
||||
assert(texture);
|
||||
}
|
||||
|
||||
Texture::Texture(Renderer& renderer, Uint32 format, int access, int w, int h) {
|
||||
|
@ -191,7 +191,7 @@ public:
|
||||
/// \param[in] texture Existing SDL_Texture to manage
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Texture(SDL_Texture* texture);
|
||||
explicit Texture(SDL_Texture* texture);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Create empty texture
|
||||
|
@ -67,7 +67,7 @@ public:
|
||||
/// \see http://wiki.libsdl.org/SDL_LoadWAV
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Wav(const std::string& file);
|
||||
explicit Wav(const std::string& file);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Load audio using RWops
|
||||
@ -79,7 +79,7 @@ public:
|
||||
/// \see http://wiki.libsdl.org/SDL_LoadWAV_RW
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Wav(RWops& rwops);
|
||||
explicit Wav(RWops& rwops);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Destructor
|
||||
|
@ -19,6 +19,8 @@
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#include <cassert>
|
||||
|
||||
#include <SDL.h>
|
||||
|
||||
#include <SDL2pp/Window.hh>
|
||||
@ -28,6 +30,7 @@
|
||||
namespace SDL2pp {
|
||||
|
||||
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) {
|
||||
@ -244,17 +247,17 @@ Window& Window::SetBordered(bool bordered) {
|
||||
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 5)
|
||||
Window& Window::SetOpacity(float opacity) {
|
||||
if (SDL_SetWindowOpacity(window_, opacity))
|
||||
if (SDL_SetWindowOpacity(window_, opacity))
|
||||
throw SDL2pp::Exception("SDL_SetWindowOpacity");
|
||||
return *this;
|
||||
return *this;
|
||||
}
|
||||
|
||||
float Window::GetOpacity() const {
|
||||
float opacity;
|
||||
if (SDL_GetWindowOpacity(window_, &opacity) == -1)
|
||||
float opacity;
|
||||
if (SDL_GetWindowOpacity(window_, &opacity) == -1)
|
||||
throw SDL2pp::Exception("SDL_GetWindowOpacity");
|
||||
|
||||
return opacity;
|
||||
return opacity;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -75,7 +75,7 @@ public:
|
||||
/// \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
|
||||
|
@ -194,23 +194,23 @@ BEGIN_TEST(int, char*[])
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 5)
|
||||
{
|
||||
// Opacity
|
||||
bool has_opacity = true;
|
||||
try {
|
||||
window.SetOpacity(0.5f);
|
||||
} catch (...) {
|
||||
has_opacity = false;
|
||||
std::cerr << "Setting window opacity is not supported on this platform" << std::endl;
|
||||
}
|
||||
bool has_opacity = true;
|
||||
try {
|
||||
window.SetOpacity(0.5f);
|
||||
} catch (...) {
|
||||
has_opacity = false;
|
||||
std::cerr << "Setting window opacity is not supported on this platform" << std::endl;
|
||||
}
|
||||
|
||||
if (has_opacity) {
|
||||
EXPECT_TRUE(window.GetOpacity() > 0.49f);
|
||||
EXPECT_TRUE(window.GetOpacity() < 0.51f);
|
||||
EventSleep(1000);
|
||||
if (has_opacity) {
|
||||
EXPECT_TRUE(window.GetOpacity() > 0.49f);
|
||||
EXPECT_TRUE(window.GetOpacity() < 0.51f);
|
||||
EventSleep(1000);
|
||||
|
||||
window.SetOpacity();
|
||||
EXPECT_TRUE(window.GetOpacity() > 0.99f);
|
||||
EventSleep(1000);
|
||||
}
|
||||
window.SetOpacity();
|
||||
EXPECT_TRUE(window.GetOpacity() > 0.99f);
|
||||
EventSleep(1000);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user