diff --git a/dotnet/extlibs/csfml-audio.dll b/dotnet/extlibs/csfml-audio.dll index cf6f6a30..48d1badd 100644 Binary files a/dotnet/extlibs/csfml-audio.dll and b/dotnet/extlibs/csfml-audio.dll differ diff --git a/dotnet/extlibs/csfml-graphics.dll b/dotnet/extlibs/csfml-graphics.dll index 6dc38ae0..bc4c4a69 100644 Binary files a/dotnet/extlibs/csfml-graphics.dll and b/dotnet/extlibs/csfml-graphics.dll differ diff --git a/dotnet/extlibs/csfml-window.dll b/dotnet/extlibs/csfml-window.dll index 2fa646bf..2cf6c872 100644 Binary files a/dotnet/extlibs/csfml-window.dll and b/dotnet/extlibs/csfml-window.dll differ diff --git a/include/SFML/Graphics/Drawable.hpp b/include/SFML/Graphics/Drawable.hpp index 8bfe3780..7140f803 100644 --- a/include/SFML/Graphics/Drawable.hpp +++ b/include/SFML/Graphics/Drawable.hpp @@ -346,16 +346,16 @@ private : //////////////////////////////////////////////////////////// // Member data //////////////////////////////////////////////////////////// - Vector2f myPosition; ///< Position of the object on screen - Vector2f myScale; ///< Scale of the object - Vector2f myOrigin; ///< Origin of translation / rotation / scaling of the object - float myRotation; ///< Orientation of the object, in degrees - Color myColor; ///< Overlay color of the object - Blend::Mode myBlendMode; ///< Blending mode - mutable bool myNeedUpdate; ///< Do we need to recompute the transform matrix ? - mutable bool myInvNeedUpdate; ///< Do we need to recompute the inverse transform matrix ? - mutable Matrix3 myMatrix; ///< Precomputed transform matrix gathering the translation / rotation / scale / center - mutable Matrix3 myInvMatrix; ///< Precomputed inverse transform matrix gathering the translation / rotation / scale / center + Vector2f myPosition; ///< Position of the object on screen + Vector2f myScale; ///< Scale of the object + Vector2f myOrigin; ///< Origin of translation / rotation / scaling of the object + float myRotation; ///< Orientation of the object, in degrees + Color myColor; ///< Overlay color of the object + Blend::Mode myBlendMode; ///< Blending mode + mutable Matrix3 myMatrix; ///< Precomputed transform matrix gathering the translation / rotation / scale / center + mutable Matrix3 myInvMatrix; ///< Precomputed inverse transform matrix gathering the translation / rotation / scale / center + mutable bool myMatrixUpdated; ///< Do we need to recompute the transform matrix ? + mutable bool myInvMatrixUpdated; ///< Do we need to recompute the inverse transform matrix ? }; } // namespace sf diff --git a/include/SFML/Graphics/Image.hpp b/include/SFML/Graphics/Image.hpp index 907fdf13..17d7257d 100644 --- a/include/SFML/Graphics/Image.hpp +++ b/include/SFML/Graphics/Image.hpp @@ -306,14 +306,14 @@ private : /// array of pixels /// //////////////////////////////////////////////////////////// - void EnsureTextureUpdate(); + void EnsureTextureUpdate() const; //////////////////////////////////////////////////////////// /// Make sure the array of pixels is updated with the /// texture in video memory /// //////////////////////////////////////////////////////////// - void EnsureArrayUpdate(); + void EnsureArrayUpdate() const; //////////////////////////////////////////////////////////// /// Reset the image attributes @@ -327,19 +327,24 @@ private : //////////////////////////////////////////////////////////// void DestroyTexture(); + //////////////////////////////////////////////////////////// + // Types + //////////////////////////////////////////////////////////// + typedef std::vector ColorArray; ///< Array of colors + //////////////////////////////////////////////////////////// // Member data //////////////////////////////////////////////////////////// - unsigned int myWidth; ///< Image width - unsigned int myHeight; ///< Image Height - unsigned int myTextureWidth; ///< Actual texture width (can be greater than image width because of padding) - unsigned int myTextureHeight; ///< Actual texture height (can be greater than image height because of padding) - unsigned int myTexture; ///< Internal texture identifier - bool myIsSmooth; ///< Status of the smooth filter - std::vector myPixels; ///< Pixels of the image - bool myNeedTextureUpdate; ///< Status of synchronization between pixels in central memory and the internal texture un video memory - bool myNeedArrayUpdate; ///< Status of synchronization between pixels in central memory and the internal texture un video memory - bool myPixelsFlipped; ///< To work around the inconsistency in Y orientation + unsigned int myWidth; ///< Image width + unsigned int myHeight; ///< Image Height + unsigned int myTextureWidth; ///< Actual texture width (can be greater than image width because of padding) + unsigned int myTextureHeight; ///< Actual texture height (can be greater than image height because of padding) + unsigned int myTexture; ///< Internal texture identifier + bool myIsSmooth; ///< Status of the smooth filter + mutable ColorArray myPixels; ///< Pixels of the image + mutable bool myTextureUpdated; ///< Status of synchronization between pixels in central memory and the internal texture un video memory + mutable bool myArrayUpdated; ///< Status of synchronization between pixels in central memory and the internal texture un video memory + mutable bool myPixelsFlipped; ///< To work around the inconsistency in Y orientation }; } // namespace sf diff --git a/include/SFML/Graphics/Text.hpp b/include/SFML/Graphics/Text.hpp index 5524428f..9f0f4d54 100644 --- a/include/SFML/Graphics/Text.hpp +++ b/include/SFML/Graphics/Text.hpp @@ -172,17 +172,17 @@ private : /// Recompute the bounding rectangle of the text /// //////////////////////////////////////////////////////////// - void RecomputeRect(); + void UpdateRect() const; //////////////////////////////////////////////////////////// // Member data //////////////////////////////////////////////////////////// - String myString; ///< String to display - ResourcePtr myFont; ///< Font used to display the string - unsigned int myCharacterSize; ///< Base size of characters, in pixels - unsigned long myStyle; ///< Text style (see Style enum) - FloatRect myBaseRect; ///< Bounding rectangle of the text in object coordinates - bool myNeedRectUpdate; ///< Does the bounding rect need an update ? + String myString; ///< String to display + ResourcePtr myFont; ///< Font used to display the string + unsigned int myCharacterSize; ///< Base size of characters, in pixels + unsigned long myStyle; ///< Text style (see Style enum) + mutable FloatRect myBaseRect; ///< Bounding rectangle of the text in object coordinates + mutable bool myRectUpdated; ///< Is the bounding rectangle up-to-date ? }; } // namespace sf diff --git a/include/SFML/Graphics/View.hpp b/include/SFML/Graphics/View.hpp index b7592a58..dd9c5130 100644 --- a/include/SFML/Graphics/View.hpp +++ b/include/SFML/Graphics/View.hpp @@ -276,14 +276,14 @@ private : //////////////////////////////////////////////////////////// // Member data //////////////////////////////////////////////////////////// - Vector2f myCenter; ///< Center of the view, in scene coordinates - Vector2f mySize; ///< Size of the view, in scene coordinates - float myRotation; ///< Angle of rotation of the view rectangle, in degrees - FloatRect myViewport; ///< Viewport rectangle, expressed as a factor of the render-target's size - mutable Matrix3 myMatrix; ///< Precomputed projection matrix corresponding to the view - mutable Matrix3 myInverseMatrix; ///< Precomputed inverse projection matrix corresponding to the view - mutable bool myNeedUpdate; ///< Internal state telling if the matrix needs to be updated - mutable bool myNeedInvUpdate; ///< Internal state telling if the matrix needs to be updated + Vector2f myCenter; ///< Center of the view, in scene coordinates + Vector2f mySize; ///< Size of the view, in scene coordinates + float myRotation; ///< Angle of rotation of the view rectangle, in degrees + FloatRect myViewport; ///< Viewport rectangle, expressed as a factor of the render-target's size + mutable Matrix3 myMatrix; ///< Precomputed projection matrix corresponding to the view + mutable Matrix3 myInverseMatrix; ///< Precomputed inverse projection matrix corresponding to the view + mutable bool myMatrixUpdated; ///< Internal state telling if the matrix needs to be updated + mutable bool myInvMatrixUpdated; ///< Internal state telling if the matrix needs to be updated }; } // namespace sf diff --git a/src/SFML/Graphics/Drawable.cpp b/src/SFML/Graphics/Drawable.cpp index 7ea56722..ba3a9954 100644 --- a/src/SFML/Graphics/Drawable.cpp +++ b/src/SFML/Graphics/Drawable.cpp @@ -37,14 +37,14 @@ namespace sf /// Default constructor //////////////////////////////////////////////////////////// Drawable::Drawable(const Vector2f& position, const Vector2f& scale, float rotation, const Color& color) : -myPosition (position), -myScale (scale), -myOrigin (0, 0), -myRotation (rotation), -myColor (color), -myBlendMode (Blend::Alpha), -myNeedUpdate (true), -myInvNeedUpdate(true) +myPosition (position), +myScale (scale), +myOrigin (0, 0), +myRotation (rotation), +myColor (color), +myBlendMode (Blend::Alpha), +myMatrixUpdated (false), +myInvMatrixUpdated(false) { } @@ -83,9 +83,10 @@ void Drawable::SetPosition(const Vector2f& position) //////////////////////////////////////////////////////////// void Drawable::SetX(float x) { - myPosition.x = x; - myNeedUpdate = true; - myInvNeedUpdate = true; + myPosition.x = x; + + myMatrixUpdated = false; + myInvMatrixUpdated = false; } @@ -94,9 +95,10 @@ void Drawable::SetX(float x) //////////////////////////////////////////////////////////// void Drawable::SetY(float y) { - myPosition.y = y; - myNeedUpdate = true; - myInvNeedUpdate = true; + myPosition.y = y; + + myMatrixUpdated = false; + myInvMatrixUpdated = false; } @@ -127,9 +129,10 @@ void Drawable::SetScaleX(float factor) { if (factor > 0) { - myScale.x = factor; - myNeedUpdate = true; - myInvNeedUpdate = true; + myScale.x = factor; + + myMatrixUpdated = false; + myInvMatrixUpdated = false; } } @@ -141,9 +144,10 @@ void Drawable::SetScaleY(float factor) { if (factor > 0) { - myScale.y = factor; - myNeedUpdate = true; - myInvNeedUpdate = true; + myScale.y = factor; + + myMatrixUpdated = false; + myInvMatrixUpdated = false; } } @@ -155,10 +159,11 @@ void Drawable::SetScaleY(float factor) //////////////////////////////////////////////////////////// void Drawable::SetOrigin(float x, float y) { - myOrigin.x = x; - myOrigin.y = y; - myNeedUpdate = true; - myInvNeedUpdate = true; + myOrigin.x = x; + myOrigin.y = y; + + myMatrixUpdated = false; + myInvMatrixUpdated = false; } @@ -181,8 +186,9 @@ void Drawable::SetRotation(float angle) myRotation = static_cast(fmod(angle, 360)); if (myRotation < 0) myRotation += 360.f; - myNeedUpdate = true; - myInvNeedUpdate = true; + + myMatrixUpdated = false; + myInvMatrixUpdated = false; } @@ -331,10 +337,10 @@ sf::Vector2f Drawable::TransformToGlobal(const sf::Vector2f& point) const const Matrix3& Drawable::GetMatrix() const { // First recompute it if needed - if (myNeedUpdate) + if (!myMatrixUpdated) { myMatrix.SetFromTransformations(myOrigin, myPosition, myRotation, myScale); - myNeedUpdate = false; + myMatrixUpdated = true; } return myMatrix; @@ -347,10 +353,10 @@ const Matrix3& Drawable::GetMatrix() const const Matrix3& Drawable::GetInverseMatrix() const { // First recompute it if needed - if (myInvNeedUpdate) + if (!myInvMatrixUpdated) { - myInvMatrix = GetMatrix().GetInverse(); - myInvNeedUpdate = false; + myInvMatrix = GetMatrix().GetInverse(); + myInvMatrixUpdated = true; } return myInvMatrix; diff --git a/src/SFML/Graphics/Image.cpp b/src/SFML/Graphics/Image.cpp index 29d5126b..c453d3a6 100644 --- a/src/SFML/Graphics/Image.cpp +++ b/src/SFML/Graphics/Image.cpp @@ -48,8 +48,8 @@ myTextureWidth (0), myTextureHeight (0), myTexture (0), myIsSmooth (true), -myNeedTextureUpdate(false), -myNeedArrayUpdate (false), +myTextureUpdated (true), +myArrayUpdated (true), myPixelsFlipped (false) { @@ -63,19 +63,19 @@ Image::Image(const Image& copy) : Resource(copy) { // First make sure that the source image is up-to-date - const_cast(copy).EnsureArrayUpdate(); + copy.EnsureArrayUpdate(); // Copy all its members - myWidth = copy.myWidth; - myHeight = copy.myHeight; - myTextureWidth = copy.myTextureWidth; - myTextureHeight = copy.myTextureHeight; - myTexture = 0; - myIsSmooth = copy.myIsSmooth; - myPixels = copy.myPixels; - myNeedTextureUpdate = false; - myNeedArrayUpdate = false; - myPixelsFlipped = copy.myPixelsFlipped; + myWidth = copy.myWidth; + myHeight = copy.myHeight; + myTextureWidth = copy.myTextureWidth; + myTextureHeight = copy.myTextureHeight; + myTexture = 0; + myIsSmooth = copy.myIsSmooth; + myPixels = copy.myPixels; + myTextureUpdated = true; + myArrayUpdated = true; + myPixelsFlipped = copy.myPixelsFlipped; // Create the texture CreateTexture(); @@ -184,7 +184,7 @@ bool Image::LoadFromPixels(unsigned int width, unsigned int height, const Uint8* bool Image::SaveToFile(const std::string& filename) const { // Check if the array of pixels needs to be updated - const_cast(this)->EnsureArrayUpdate(); + EnsureArrayUpdate(); // Let the image loader save our pixel array into the image return priv::ImageLoader::GetInstance().SaveImageToFile(filename, myPixels, myWidth, myHeight); @@ -233,7 +233,7 @@ void Image::CreateMaskFromColor(const Color& transparentColor, Uint8 alpha) std::replace(myPixels.begin(), myPixels.end(), transparentColor, newColor); // The texture will need to be updated - myNeedTextureUpdate = true; + myTextureUpdated = false; } @@ -250,7 +250,7 @@ void Image::Copy(const Image& source, unsigned int destX, unsigned int destY, co // Make sure both images have up-to-date arrays EnsureArrayUpdate(); - const_cast(source).EnsureArrayUpdate(); + source.EnsureArrayUpdate(); // Adjust the source rectangle IntRect srcRect = sourceRect; @@ -323,7 +323,7 @@ void Image::Copy(const Image& source, unsigned int destX, unsigned int destY, co } // The texture will need an update - myNeedTextureUpdate = true; + myTextureUpdated = false; } @@ -368,9 +368,9 @@ bool Image::CopyScreen(RenderWindow& window, const IntRect& sourceRect) GLCheck(glBindTexture(GL_TEXTURE_2D, previous)); - myNeedTextureUpdate = false; - myNeedArrayUpdate = true; - myPixelsFlipped = true; + myTextureUpdated = true; + myArrayUpdated = false; + myPixelsFlipped = true; return true; } @@ -401,7 +401,7 @@ void Image::SetPixel(unsigned int x, unsigned int y, const Color& color) myPixels[x + y * myWidth] = color; // The texture will need to be updated - myNeedTextureUpdate = true; + myTextureUpdated = false; } @@ -411,7 +411,7 @@ void Image::SetPixel(unsigned int x, unsigned int y, const Color& color) const Color& Image::GetPixel(unsigned int x, unsigned int y) const { // First check if the array of pixels needs to be updated - const_cast(this)->EnsureArrayUpdate(); + EnsureArrayUpdate(); // Check if pixel is whithin the image bounds if ((x >= myWidth) || (y >= myHeight)) @@ -433,7 +433,7 @@ const Color& Image::GetPixel(unsigned int x, unsigned int y) const const Uint8* Image::GetPixelsPtr() const { // First check if the array of pixels needs to be updated - const_cast(this)->EnsureArrayUpdate(); + EnsureArrayUpdate(); if (!myPixels.empty()) { @@ -461,8 +461,8 @@ void Image::UpdatePixels(const Uint8* pixels) GLCheck(glBindTexture(GL_TEXTURE_2D, previous)); - myNeedArrayUpdate = true; - myNeedTextureUpdate = false; + myArrayUpdated = false; + myTextureUpdated = true; } @@ -484,7 +484,7 @@ void Image::UpdatePixels(const Uint8* pixels, const IntRect& rectangle) GLCheck(glBindTexture(GL_TEXTURE_2D, previous)); // The pixel cache is no longer up-to-date - myNeedArrayUpdate = true; + myArrayUpdated = false; } @@ -494,7 +494,7 @@ void Image::UpdatePixels(const Uint8* pixels, const IntRect& rectangle) void Image::Bind() const { // First check if the texture needs to be updated - const_cast(this)->EnsureTextureUpdate(); + EnsureTextureUpdate(); // Bind it if (myTexture) @@ -562,22 +562,29 @@ bool Image::IsSmooth() const //////////////////////////////////////////////////////////// FloatRect Image::GetTexCoords(const IntRect& rect) const { - float width = static_cast(myTextureWidth); - float height = static_cast(myTextureHeight); - - if (myPixelsFlipped) + if ((myTextureWidth != 0) && (myTextureHeight != 0)) { - return FloatRect(rect.Left / width, - rect.Bottom / height, - rect.Right / width, - rect.Top / height); + float width = static_cast(myTextureWidth); + float height = static_cast(myTextureHeight); + + if (myPixelsFlipped) + { + return FloatRect(rect.Left / width, + rect.Bottom / height, + rect.Right / width, + rect.Top / height); + } + else + { + return FloatRect(rect.Left / width, + rect.Top / height, + rect.Right / width, + rect.Bottom / height); + } } else { - return FloatRect(rect.Left / width, - rect.Top / height, - rect.Right / width, - rect.Bottom / height); + return FloatRect(0, 0, 0, 0); } } @@ -626,15 +633,15 @@ Image& Image::operator =(const Image& other) { Image temp(other); - std::swap(myWidth, temp.myWidth); - std::swap(myHeight, temp.myHeight); - std::swap(myTextureWidth, temp.myTextureWidth); - std::swap(myTextureHeight, temp.myTextureHeight); - std::swap(myTexture, temp.myTexture); - std::swap(myIsSmooth, temp.myIsSmooth); - std::swap(myNeedArrayUpdate, temp.myNeedArrayUpdate); - std::swap(myNeedTextureUpdate, temp.myNeedTextureUpdate); - std::swap(myPixelsFlipped, temp.myPixelsFlipped); + std::swap(myWidth, temp.myWidth); + std::swap(myHeight, temp.myHeight); + std::swap(myTextureWidth, temp.myTextureWidth); + std::swap(myTextureHeight, temp.myTextureHeight); + std::swap(myTexture, temp.myTexture); + std::swap(myIsSmooth, temp.myIsSmooth); + std::swap(myArrayUpdated, temp.myArrayUpdated); + std::swap(myTextureUpdated, temp.myTextureUpdated); + std::swap(myPixelsFlipped, temp.myPixelsFlipped); myPixels.swap(temp.myPixels); return *this; @@ -692,7 +699,7 @@ bool Image::CreateTexture() GLCheck(glBindTexture(GL_TEXTURE_2D, previous)); } - myNeedTextureUpdate = true; + myTextureUpdated = false; return true; } @@ -702,9 +709,9 @@ bool Image::CreateTexture() /// Make sure the texture in video memory is updated with the /// array of pixels //////////////////////////////////////////////////////////// -void Image::EnsureTextureUpdate() +void Image::EnsureTextureUpdate() const { - if (myNeedTextureUpdate) + if (!myTextureUpdated) { if (myTexture && !myPixels.empty()) { @@ -719,7 +726,7 @@ void Image::EnsureTextureUpdate() GLCheck(glBindTexture(GL_TEXTURE_2D, previous)); } - myNeedTextureUpdate = false; + myTextureUpdated = true; } } @@ -728,9 +735,9 @@ void Image::EnsureTextureUpdate() /// Make sure the array of pixels is updated with the /// texture in video memory //////////////////////////////////////////////////////////// -void Image::EnsureArrayUpdate() +void Image::EnsureArrayUpdate() const { - if (myNeedArrayUpdate) + if (!myArrayUpdated) { // First make sure the texture is up-to-date // (may not be the case if an external update has been scheduled) @@ -756,7 +763,7 @@ void Image::EnsureArrayUpdate() // Texture and array don't have the same size, we have to use a slower algorithm // All the pixels will first be copied to a temporary array - std::vector allPixels(myTextureWidth * myTextureHeight); + ColorArray allPixels(myTextureWidth * myTextureHeight); GLCheck(glBindTexture(GL_TEXTURE_2D, myTexture)); GLCheck(glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, &allPixels[0])); @@ -783,7 +790,7 @@ void Image::EnsureArrayUpdate() // Restore the previous texture GLCheck(glBindTexture(GL_TEXTURE_2D, previous)); - myNeedArrayUpdate = false; + myArrayUpdated = true; } } @@ -795,15 +802,15 @@ void Image::Reset() { DestroyTexture(); - myWidth = 0; - myHeight = 0; - myTextureWidth = 0; - myTextureHeight = 0; - myTexture = 0; - myIsSmooth = true; - myNeedTextureUpdate = false; - myNeedArrayUpdate = false; - myPixelsFlipped = false; + myWidth = 0; + myHeight = 0; + myTextureWidth = 0; + myTextureHeight = 0; + myTexture = 0; + myIsSmooth = true; + myTextureUpdated = true; + myArrayUpdated = true; + myPixelsFlipped = false; myPixels.clear(); } @@ -818,9 +825,9 @@ void Image::DestroyTexture() { GLuint Texture = static_cast(myTexture); GLCheck(glDeleteTextures(1, &Texture)); - myTexture = 0; - myNeedTextureUpdate = false; - myNeedArrayUpdate = false; + myTexture = 0; + myTextureUpdated = true; + myArrayUpdated = true; } } diff --git a/src/SFML/Graphics/RenderImage.cpp b/src/SFML/Graphics/RenderImage.cpp index 7d9d349a..87613f54 100644 --- a/src/SFML/Graphics/RenderImage.cpp +++ b/src/SFML/Graphics/RenderImage.cpp @@ -140,8 +140,8 @@ void RenderImage::Display() { bool pixelsFlipped = myRenderImage->UpdateTexture(myImage.myTexture); myImage.myPixelsFlipped = pixelsFlipped; - myImage.myNeedArrayUpdate = true; - myImage.myNeedTextureUpdate = false; + myImage.myArrayUpdated = false; + myImage.myTextureUpdated = true; } } diff --git a/src/SFML/Graphics/RenderTarget.cpp b/src/SFML/Graphics/RenderTarget.cpp index 89a90b02..ac3a5652 100644 --- a/src/SFML/Graphics/RenderTarget.cpp +++ b/src/SFML/Graphics/RenderTarget.cpp @@ -165,7 +165,7 @@ IntRect RenderTarget::GetViewport(const View& view) const rect.Top = static_cast(0.5f + height * (1.f - viewport.Bottom)); rect.Right = static_cast(0.5f + width * viewport.Right); rect.Bottom = static_cast(0.5f + height * (1.f - viewport.Top)); - + return rect; } diff --git a/src/SFML/Graphics/Sprite.cpp b/src/SFML/Graphics/Sprite.cpp index 99ee50f2..36feb981 100644 --- a/src/SFML/Graphics/Sprite.cpp +++ b/src/SFML/Graphics/Sprite.cpp @@ -190,7 +190,7 @@ void Sprite::Render(RenderTarget&, RenderQueue& queue) const // Check if the image is valid, and calculate the texture coordinates FloatRect coords; - if (myImage && (myImage->GetWidth() > 0) && (myImage->GetHeight() > 0)) + if (myImage) { coords = myImage->GetTexCoords(mySubRect); if (myIsFlippedX) std::swap(coords.Left, coords.Right); diff --git a/src/SFML/Graphics/Text.cpp b/src/SFML/Graphics/Text.cpp index ad3ce352..7e284438 100644 --- a/src/SFML/Graphics/Text.cpp +++ b/src/SFML/Graphics/Text.cpp @@ -36,10 +36,10 @@ namespace sf /// Default constructor //////////////////////////////////////////////////////////// Text::Text() : -myFont (&Font::GetDefaultFont()), -myCharacterSize (30), -myStyle (Regular), -myNeedRectUpdate(true) +myFont (&Font::GetDefaultFont()), +myCharacterSize(30), +myStyle (Regular), +myRectUpdated (true) { } @@ -49,10 +49,10 @@ myNeedRectUpdate(true) /// Construct the string from any kind of text //////////////////////////////////////////////////////////// Text::Text(const String& string, const Font& font, unsigned int characterSize) : -myFont (&font), -myCharacterSize (characterSize), -myStyle (Regular), -myNeedRectUpdate(true) +myFont (&font), +myCharacterSize(characterSize), +myStyle (Regular), +myRectUpdated (true) { SetString(string); } @@ -63,8 +63,8 @@ myNeedRectUpdate(true) //////////////////////////////////////////////////////////// void Text::SetString(const String& string) { - myNeedRectUpdate = true; myString = string; + myRectUpdated = false; } @@ -75,8 +75,8 @@ void Text::SetFont(const Font& font) { if (myFont != &font) { - myNeedRectUpdate = true; myFont = &font; + myRectUpdated = false; } } @@ -88,8 +88,8 @@ void Text::SetCharacterSize(unsigned int size) { if (myCharacterSize != size) { - myNeedRectUpdate = true; myCharacterSize = size; + myRectUpdated = false; } } @@ -102,8 +102,8 @@ void Text::SetStyle(unsigned long style) { if (myStyle != style) { - myNeedRectUpdate = true; myStyle = style; + myRectUpdated = false; } } @@ -197,8 +197,7 @@ Vector2f Text::GetCharacterPos(std::size_t index) const //////////////////////////////////////////////////////////// FloatRect Text::GetRect() const { - if (myNeedRectUpdate) - const_cast(this)->RecomputeRect(); + UpdateRect(); FloatRect rect; rect.Left = (myBaseRect.Left - GetOrigin().x) * GetScale().x + GetPosition().x; @@ -312,10 +311,13 @@ void Text::Render(RenderTarget&, RenderQueue& queue) const //////////////////////////////////////////////////////////// /// Recompute the bounding rectangle of the text //////////////////////////////////////////////////////////// -void Text::RecomputeRect() +void Text::UpdateRect() const { + if (myRectUpdated) + return; + // Reset the previous states - myNeedRectUpdate = false; + myRectUpdated = true; myBaseRect = FloatRect(0, 0, 0, 0); // No text or not font: empty box diff --git a/src/SFML/Graphics/View.cpp b/src/SFML/Graphics/View.cpp index efdfddad..fcfd4fdc 100644 --- a/src/SFML/Graphics/View.cpp +++ b/src/SFML/Graphics/View.cpp @@ -32,12 +32,12 @@ namespace sf { //////////////////////////////////////////////////////////// View::View() : -myCenter (), -mySize (), -myRotation (0), -myViewport (0, 0, 1, 1), -myNeedUpdate (true), -myNeedInvUpdate(true) +myCenter (), +mySize (), +myRotation (0), +myViewport (0, 0, 1, 1), +myMatrixUpdated (false), +myInvMatrixUpdated(false) { Reset(FloatRect(0, 0, 1000, 1000)); } @@ -45,12 +45,12 @@ myNeedInvUpdate(true) //////////////////////////////////////////////////////////// View::View(const FloatRect& rectangle) : -myCenter (), -mySize (), -myRotation (0), -myViewport (0, 0, 1, 1), -myNeedUpdate (true), -myNeedInvUpdate(true) +myCenter (), +mySize (), +myRotation (0), +myViewport (0, 0, 1, 1), +myMatrixUpdated (false), +myInvMatrixUpdated(false) { Reset(rectangle); } @@ -58,12 +58,12 @@ myNeedInvUpdate(true) //////////////////////////////////////////////////////////// View::View(const Vector2f& center, const Vector2f& size) : -myCenter (center), -mySize (size), -myRotation (0), -myViewport (0, 0, 1, 1), -myNeedUpdate (true), -myNeedInvUpdate(true) +myCenter (center), +mySize (size), +myRotation (0), +myViewport (0, 0, 1, 1), +myMatrixUpdated (false), +myInvMatrixUpdated(false) { } @@ -71,10 +71,11 @@ myNeedInvUpdate(true) //////////////////////////////////////////////////////////// void View::SetCenter(float x, float y) { - myCenter.x = x; - myCenter.y = y; - myNeedUpdate = true; - myNeedInvUpdate = true; + myCenter.x = x; + myCenter.y = y; + + myMatrixUpdated = false; + myInvMatrixUpdated = false; } @@ -88,10 +89,11 @@ void View::SetCenter(const Vector2f& center) //////////////////////////////////////////////////////////// void View::SetSize(float width, float height) { - mySize.x = width; - mySize.y = height; - myNeedUpdate = true; - myNeedInvUpdate = true; + mySize.x = width; + mySize.y = height; + + myMatrixUpdated = false; + myInvMatrixUpdated = false; } @@ -108,8 +110,9 @@ void View::SetRotation(float angle) myRotation = static_cast(fmod(angle, 360)); if (myRotation < 0) myRotation += 360.f; - myNeedUpdate = true; - myNeedInvUpdate = true; + + myMatrixUpdated = false; + myInvMatrixUpdated = false; } @@ -123,11 +126,12 @@ void View::SetViewport(const FloatRect& viewport) //////////////////////////////////////////////////////////// void View::Reset(const FloatRect& rectangle) { - myCenter = rectangle.GetCenter(); - mySize = rectangle.GetSize(); - myRotation = 0; - myNeedUpdate = true; - myNeedInvUpdate = true; + myCenter = rectangle.GetCenter(); + mySize = rectangle.GetSize(); + myRotation = 0; + + myMatrixUpdated = false; + myInvMatrixUpdated = false; } @@ -191,10 +195,10 @@ void View::Zoom(float factor) const Matrix3& View::GetMatrix() const { // Recompute the matrix if needed - if (myNeedUpdate) + if (!myMatrixUpdated) { myMatrix.SetFromProjection(myCenter, mySize, myRotation); - myNeedUpdate = false; + myMatrixUpdated = true; } return myMatrix; @@ -205,10 +209,10 @@ const Matrix3& View::GetMatrix() const const Matrix3& View::GetInverseMatrix() const { // Recompute the matrix if needed - if (myNeedInvUpdate) + if (!myInvMatrixUpdated) { myInverseMatrix = GetMatrix().GetInverse(); - myNeedInvUpdate = false; + myInvMatrixUpdated = true; } return myInverseMatrix;