From be69a4ede6f5f5d6dc12e650cf04e3c47f5722de Mon Sep 17 00:00:00 2001 From: Dmitry Marakasov Date: Mon, 16 Feb 2015 21:19:31 +0300 Subject: [PATCH] Add Renderer::Copy overloads which take target Point instead of a Rect --- SDL2pp/Renderer.cc | 20 ++++++++++++++++++++ SDL2pp/Renderer.hh | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) diff --git a/SDL2pp/Renderer.cc b/SDL2pp/Renderer.cc index cbccf8f..a062731 100644 --- a/SDL2pp/Renderer.cc +++ b/SDL2pp/Renderer.cc @@ -88,12 +88,32 @@ Renderer& Renderer::Copy(Texture& texture, const Optional& srcrect, const return *this; } +Renderer& Renderer::Copy(Texture& texture, const Optional& srcrect, const Point& dstpoint) { + Rect dstrect( + dstpoint.x, + dstpoint.y, + srcrect ? srcrect->w : texture.GetWidth(), + srcrect ? srcrect->h : texture.GetHeight() + ); + return Copy(texture, srcrect, dstrect); +} + Renderer& Renderer::Copy(Texture& texture, const Optional& srcrect, const Optional& dstrect, double angle, const Optional& center, int flip) { if (SDL_RenderCopyEx(renderer_, texture.Get(), srcrect ? &*srcrect : nullptr, dstrect ? &*dstrect : nullptr, angle, center ? &*center : nullptr, static_cast(flip)) != 0) throw Exception("SDL_RenderCopyEx"); return *this; } +Renderer& Renderer::Copy(Texture& texture, const Optional& srcrect, const Point& dstpoint, double angle, const Optional& center, int flip) { + Rect dstrect( + dstpoint.x, + dstpoint.y, + srcrect ? srcrect->w : texture.GetWidth(), + srcrect ? srcrect->h : texture.GetHeight() + ); + return Copy(texture, srcrect, dstrect, angle, center, flip); +} + Renderer& Renderer::SetDrawColor(Uint8 r, Uint8 g, Uint8 b, Uint8 a) { if (SDL_SetRenderDrawColor(renderer_, r, g, b, a) != 0) throw Exception("SDL_SetRenderDrawColor"); diff --git a/SDL2pp/Renderer.hh b/SDL2pp/Renderer.hh index 1f95e69..ab9ee30 100644 --- a/SDL2pp/Renderer.hh +++ b/SDL2pp/Renderer.hh @@ -206,6 +206,23 @@ public: //////////////////////////////////////////////////////////// Renderer& Copy(Texture& texture, const Optional& srcrect = NullOpt, const Optional& dstrect = NullOpt); + //////////////////////////////////////////////////////////// + /// \brief Copy a portion of the texture to the current rendering + /// target (preserve texture dimensions) + /// + /// \param[in] texture Source texture + /// \param[in] srcrect Source rectangle, NullOpt for the entire texture + /// \param[in] dstpoint Target point for source top left corner + /// + /// \returns Reference to self + /// + /// \throws SDL2pp::Exception + /// + /// \see http://wiki.libsdl.org/SDL_RenderCopy + /// + //////////////////////////////////////////////////////////// + Renderer& Copy(Texture& texture, const Optional& srcrect, const Point& dstpoint); + //////////////////////////////////////////////////////////// /// \brief Copy a portion of the texture to the current rendering /// target with optional rotating or flipping @@ -232,6 +249,32 @@ public: //////////////////////////////////////////////////////////// Renderer& Copy(Texture& texture, const Optional& srcrect, const Optional& dstrect, double angle, const Optional& center = NullOpt, int flip = 0); + //////////////////////////////////////////////////////////// + /// \brief Copy a portion of the texture to the current rendering + /// target with optional rotating or flipping (preserve texture + /// dimensions) + /// + /// \param[in] texture Source texture + /// \param[in] srcrect Source rectangle, NullOpt for the entire texture + /// \param[in] dstpoint Target point for source top left corner + /// \param[in] angle Angle in degrees that indicates the rotation that + /// will be applied to dstrect + /// \param[in] center Point indicating the point around which dstrect + /// will be rotated (NullOpt to rotate around dstrect + /// center) + /// \param[in] flip SDL_RendererFlip value stating which flipping + /// actions should be performed on the texture + /// + /// \returns Reference to self + /// + /// \throws SDL2pp::Exception + /// + /// \see http://wiki.libsdl.org/SDL_RendererFlip + /// \see http://wiki.libsdl.org/SDL_RenderCopyEx + /// + //////////////////////////////////////////////////////////// + Renderer& Copy(Texture& texture, const Optional& srcrect, const SDL2pp::Point& dstpoint, double angle, const Optional& center = NullOpt, int flip = 0); + //////////////////////////////////////////////////////////// /// \brief Set color user for drawing operations ///