summaryrefslogtreecommitdiff
path: root/include/SFML/Graphics/Image.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'include/SFML/Graphics/Image.hpp')
-rw-r--r--[-rwxr-xr-x]include/SFML/Graphics/Image.hpp74
1 files changed, 49 insertions, 25 deletions
diff --git a/include/SFML/Graphics/Image.hpp b/include/SFML/Graphics/Image.hpp
index 200d3a7..e950ec3 100755..100644
--- a/include/SFML/Graphics/Image.hpp
+++ b/include/SFML/Graphics/Image.hpp
@@ -28,8 +28,8 @@
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
+#include <SFML/System/Resource.hpp>
#include <SFML/Graphics/Color.hpp>
-#include <SFML/Graphics/VideoResource.hpp>
#include <SFML/Graphics/Rect.hpp>
#include <string>
#include <vector>
@@ -37,11 +37,14 @@
namespace sf
{
+class RenderImage;
+class RenderWindow;
+
////////////////////////////////////////////////////////////
/// Image is the low-level class for loading and
/// manipulating images
////////////////////////////////////////////////////////////
-class SFML_API Image : public VideoResource
+class SFML_API Image : public Resource<Image>
{
public :
@@ -150,17 +153,29 @@ public :
void CreateMaskFromColor(Color ColorKey, Uint8 Alpha = 0);
////////////////////////////////////////////////////////////
- /// Resize the image - warning : this function does not scale the image,
- /// it just adjusts its size (add padding or remove pixels)
+ /// Copy pixels from another image onto this one.
+ /// This function does a slow pixel copy and should only
+ /// be used at initialization time
///
- /// \param Width : New width
- /// \param Height : New height
- /// \param Col : Color to assign to new pixels (black by default)
+ /// \param Source : Source image to copy
+ /// \param DestX : X coordinate of the destination position
+ /// \param DestY : Y coordinate of the destination position
+ /// \param SourceRect : Sub-rectangle of the source image to copy (empty by default - entire image)
///
- /// \return True if resize has been successful
+ ////////////////////////////////////////////////////////////
+ void Copy(const Image& Source, unsigned int DestX, unsigned int DestY, const IntRect& SourceRect = IntRect(0, 0, 0, 0));
+
+ ////////////////////////////////////////////////////////////
+ /// Create the image from the current contents of the
+ /// given window
+ ///
+ /// \param Window : Window to capture
+ /// \param SourceRect : Sub-rectangle of the screen to copy (empty by default - entire image)
+ ///
+ /// \return True if copy was successful
///
////////////////////////////////////////////////////////////
- bool Resize(unsigned int Width, unsigned int Height, Color Col = Color(0, 0, 0, 255));
+ bool CopyScreen(RenderWindow& Window, const IntRect& SourceRect = IntRect(0, 0, 0, 0));
////////////////////////////////////////////////////////////
/// Change the color of a pixel
@@ -175,10 +190,10 @@ public :
////////////////////////////////////////////////////////////
/// Get a pixel from the image
///
- /// \param X : X coordinate of pixel in the image
- /// \param Y : Y coordinate of pixel in the image
+ /// \param X : X coordinate of pixel in the image
+ /// \param Y : Y coordinate of pixel in the image
///
- /// \return Color of pixel (x, y)
+ /// \return Color of pixel (X, Y)
///
////////////////////////////////////////////////////////////
const Color& GetPixel(unsigned int X, unsigned int Y) const;
@@ -266,6 +281,8 @@ public :
private :
+ friend class RenderImage;
+
////////////////////////////////////////////////////////////
/// Create the OpenGL texture
///
@@ -275,10 +292,16 @@ private :
bool CreateTexture();
////////////////////////////////////////////////////////////
- /// Update the internal texture in video memory
- ///
+ /// Make sure the texture in video memory is updated with the
+ /// array of pixels
+ ////////////////////////////////////////////////////////////
+ void EnsureTextureUpdate() const;
+
+ ////////////////////////////////////////////////////////////
+ /// Make sure the array of pixels is updated with the
+ /// texture in video memory
////////////////////////////////////////////////////////////
- void Update();
+ void EnsureArrayUpdate() const;
////////////////////////////////////////////////////////////
/// Reset the image attributes
@@ -287,22 +310,23 @@ private :
void Reset();
////////////////////////////////////////////////////////////
- /// /see VideoResource::DestroyVideoResources
+ /// Destroy the OpenGL texture
///
////////////////////////////////////////////////////////////
- virtual void DestroyVideoResources();
+ void DestroyTexture();
////////////////////////////////////////////////////////////
// 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)
- std::vector<Color> myPixels; ///< Pixels of the image
- unsigned int myTexture; ///< Internal texture identifier
- bool myIsSmooth; ///< Status if the smooth filter
- mutable bool myUpdated; ///< Tells if the internal texture needs to be updated
+ 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 std::vector<Color> myPixels; ///< Pixels of the image
+ mutable bool myNeedTextureUpdate; ///< Status of synchronization between pixels in central memory and the internal texture un video memory
+ mutable bool myNeedArrayUpdate; ///< Status of synchronization between pixels in central memory and the internal texture un video memory
};
} // namespace sf