Merge branch 'copy-to-point'

This commit is contained in:
Dmitry Marakasov 2015-06-10 00:08:41 +03:00
commit fdbca27e73
2 changed files with 63 additions and 0 deletions

View File

@ -88,12 +88,32 @@ Renderer& Renderer::Copy(Texture& texture, const Optional<Rect>& srcrect, const
return *this; return *this;
} }
Renderer& Renderer::Copy(Texture& texture, const Optional<Rect>& 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<Rect>& srcrect, const Optional<Rect>& dstrect, double angle, const Optional<Point>& center, int flip) { Renderer& Renderer::Copy(Texture& texture, const Optional<Rect>& srcrect, const Optional<Rect>& dstrect, double angle, const Optional<Point>& center, int flip) {
if (SDL_RenderCopyEx(renderer_, texture.Get(), srcrect ? &*srcrect : nullptr, dstrect ? &*dstrect : nullptr, angle, center ? &*center : nullptr, static_cast<SDL_RendererFlip>(flip)) != 0) if (SDL_RenderCopyEx(renderer_, texture.Get(), srcrect ? &*srcrect : nullptr, dstrect ? &*dstrect : nullptr, angle, center ? &*center : nullptr, static_cast<SDL_RendererFlip>(flip)) != 0)
throw Exception("SDL_RenderCopyEx"); throw Exception("SDL_RenderCopyEx");
return *this; return *this;
} }
Renderer& Renderer::Copy(Texture& texture, const Optional<Rect>& srcrect, const Point& dstpoint, double angle, const Optional<Point>& 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) { Renderer& Renderer::SetDrawColor(Uint8 r, Uint8 g, Uint8 b, Uint8 a) {
if (SDL_SetRenderDrawColor(renderer_, r, g, b, a) != 0) if (SDL_SetRenderDrawColor(renderer_, r, g, b, a) != 0)
throw Exception("SDL_SetRenderDrawColor"); throw Exception("SDL_SetRenderDrawColor");

View File

@ -206,6 +206,23 @@ public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Renderer& Copy(Texture& texture, const Optional<Rect>& srcrect = NullOpt, const Optional<Rect>& dstrect = NullOpt); Renderer& Copy(Texture& texture, const Optional<Rect>& srcrect = NullOpt, const Optional<Rect>& 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<Rect>& srcrect, const Point& dstpoint);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Copy a portion of the texture to the current rendering /// \brief Copy a portion of the texture to the current rendering
/// target with optional rotating or flipping /// target with optional rotating or flipping
@ -232,6 +249,32 @@ public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Renderer& Copy(Texture& texture, const Optional<Rect>& srcrect, const Optional<Rect>& dstrect, double angle, const Optional<Point>& center = NullOpt, int flip = 0); Renderer& Copy(Texture& texture, const Optional<Rect>& srcrect, const Optional<Rect>& dstrect, double angle, const Optional<Point>& 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<Rect>& srcrect, const SDL2pp::Point& dstpoint, double angle, const Optional<Point>& center = NullOpt, int flip = 0);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Set color user for drawing operations /// \brief Set color user for drawing operations
/// ///