FS#126 - Add an optional parameter to Sprite::SetImage for automatic adjustment of the subrect

git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1202 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
LaurentGom 2009-08-14 09:27:00 +00:00
parent 7a8cc0c76a
commit ac0881f6a0
2 changed files with 10 additions and 5 deletions

View File

@ -66,10 +66,11 @@ public :
////////////////////////////////////////////////////////////
/// Change the image of the sprite
///
/// \param image : New image
/// \param image : New image
/// \param adjustToNewSize : If true, the SubRect of the sprite will be adjusted to the size of the new image (false by default)
///
////////////////////////////////////////////////////////////
void SetImage(const Image& image);
void SetImage(const Image& image, bool adjustToNewSize = false);
////////////////////////////////////////////////////////////
/// Set the sub-rectangle of the sprite inside the source image.

View File

@ -60,10 +60,14 @@ myIsFlippedY(false)
////////////////////////////////////////////////////////////
/// Set the image of the sprite
////////////////////////////////////////////////////////////
void Sprite::SetImage(const Image& image)
void Sprite::SetImage(const Image& image, bool adjustToNewSize)
{
// If there was no source image before and the new image is valid, adjust the source rectangle
if (!myImage && (image.GetWidth() > 0) && (image.GetHeight() > 0))
// If there was no valid image before, force adjusting to the new image size
if (!myImage)
adjustToNewSize = true;
// If we want to adjust the size and the new image is valid, we adjust the source rectangle
if (adjustToNewSize && (image.GetWidth() > 0) && (image.GetHeight() > 0))
{
SetSubRect(IntRect(0, 0, image.GetWidth(), image.GetHeight()));
}