Add constructors from existing SDL2 objects

This commit is contained in:
Dmitry Marakasov 2014-12-28 06:06:22 +03:00
parent 0557464b56
commit 25bbd97b3e
7 changed files with 36 additions and 4 deletions

View File

@ -30,6 +30,9 @@
namespace SDL2pp { namespace SDL2pp {
Renderer::Renderer(SDL_Renderer* renderer) : renderer_(renderer) {
}
Renderer::Renderer(Window& window, int index, Uint32 flags) { Renderer::Renderer(Window& window, int index, Uint32 flags) {
if ((renderer_ = SDL_CreateRenderer(window.Get(), index, flags)) == nullptr) if ((renderer_ = SDL_CreateRenderer(window.Get(), index, flags)) == nullptr)
throw Exception("SDL_CreateRenderer failed"); throw Exception("SDL_CreateRenderer failed");

View File

@ -51,6 +51,14 @@ private:
SDL_Renderer* renderer_; ///< Contained SDL_Renderer structure SDL_Renderer* renderer_; ///< Contained SDL_Renderer structure
public: public:
////////////////////////////////////////////////////////////
/// \brief Construct from existing SDL_Renderer structure
///
/// \param renderer Existing SDL_Renderer to manage
///
////////////////////////////////////////////////////////////
Renderer(SDL_Renderer* renderer);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Create renderer /// \brief Create renderer
/// ///

View File

@ -148,16 +148,15 @@ public:
const SDL_PixelFormat& GetFormat() const; 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); Surface(SDL_Surface* surface);
public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Create RGB surface /// \brief Create RGB surface
/// ///

View File

@ -40,6 +40,9 @@
namespace SDL2pp { namespace SDL2pp {
Texture::Texture(SDL_Texture* texture) : texture_(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) {
if ((texture_ = SDL_CreateTexture(renderer.Get(), format, access, w, h)) == nullptr) if ((texture_ = SDL_CreateTexture(renderer.Get(), format, access, w, h)) == nullptr)
throw Exception("SDL_CreateTexture failed"); throw Exception("SDL_CreateTexture failed");

View File

@ -172,6 +172,14 @@ public:
}; };
public: public:
////////////////////////////////////////////////////////////
/// \brief Construct from existing SDL_Texture structure
///
/// \param texture Existing SDL_Texture to manage
///
////////////////////////////////////////////////////////////
Texture(SDL_Texture* texture);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Create empty texture /// \brief Create empty texture
/// ///

View File

@ -26,6 +26,9 @@
namespace SDL2pp { 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) { 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) if ((window_ = SDL_CreateWindow(title.c_str(), x, y, w, h, flags)) == nullptr)
throw Exception("SDL_CreateWindow failed"); throw Exception("SDL_CreateWindow failed");

View File

@ -64,6 +64,14 @@ private:
SDL_Window* window_; ///< Contained SDL2_Window structure SDL_Window* window_; ///< Contained SDL2_Window structure
public: 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 /// \brief Create window with specified title and fimensions
/// ///