mirror of
https://github.com/SFML/SFML.git
synced 2024-11-28 22:31:09 +08:00
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:
parent
7a8cc0c76a
commit
ac0881f6a0
@ -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.
|
||||
|
@ -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()));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user