From 25bbd97b3e4c93e2e4c7ec4c50de0cc3bff431c0 Mon Sep 17 00:00:00 2001 From: Dmitry Marakasov Date: Sun, 28 Dec 2014 06:06:22 +0300 Subject: [PATCH] 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 ///