00001 00002 // 00003 // SFML - Simple and Fast Multimedia Library 00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) 00005 // 00006 // This software is provided 'as-is', without any express or implied warranty. 00007 // In no event will the authors be held liable for any damages arising from the use of this software. 00008 // 00009 // Permission is granted to anyone to use this software for any purpose, 00010 // including commercial applications, and to alter it and redistribute it freely, 00011 // subject to the following restrictions: 00012 // 00013 // 1. The origin of this software must not be misrepresented; 00014 // you must not claim that you wrote the original software. 00015 // If you use this software in a product, an acknowledgment 00016 // in the product documentation would be appreciated but is not required. 00017 // 00018 // 2. Altered source versions must be plainly marked as such, 00019 // and must not be misrepresented as being the original software. 00020 // 00021 // 3. This notice may not be removed or altered from any source distribution. 00022 // 00024 00025 #ifndef SFML_IMAGE_HPP 00026 #define SFML_IMAGE_HPP 00027 00029 // Headers 00031 #include <SFML/System/Resource.hpp> 00032 #include <SFML/Graphics/Color.hpp> 00033 #include <SFML/Graphics/Rect.hpp> 00034 #include <string> 00035 #include <vector> 00036 00037 00038 namespace sf 00039 { 00040 class Renderer; 00041 class RenderImage; 00042 class RenderWindow; 00043 00048 class SFML_API Image : public Resource<Image> 00049 { 00050 public : 00051 00056 Image(); 00057 00064 Image(const Image& copy); 00065 00070 ~Image(); 00071 00080 bool LoadFromFile(const std::string& filename); 00081 00091 bool LoadFromMemory(const void* data, std::size_t sizeInBytes); 00092 00103 bool LoadFromPixels(unsigned int width, unsigned int height, const Uint8* pixels); 00104 00113 bool SaveToFile(const std::string& filename) const; 00114 00125 bool Create(unsigned int width, unsigned int height, const Color& color = Color(0, 0, 0)); 00126 00134 void CreateMaskFromColor(const Color& transparentColor, Uint8 alpha = 0); 00135 00148 void Copy(const Image& source, unsigned int destX, unsigned int destY, const IntRect& sourceRect = IntRect(0, 0, 0, 0), bool applyAlpha = false); 00149 00160 bool CopyScreen(RenderWindow& window, const IntRect& sourceRect = IntRect(0, 0, 0, 0)); 00161 00170 void SetPixel(unsigned int x, unsigned int y, const Color& color); 00171 00181 const Color& GetPixel(unsigned int x, unsigned int y) const; 00182 00191 const Uint8* GetPixelsPtr() const; 00192 00199 void UpdatePixels(const Uint8* pixels); 00200 00213 void UpdatePixels(const Uint8* pixels, const IntRect& rectangle); 00214 00219 void Bind() const; 00220 00228 void SetSmooth(bool smooth); 00229 00236 unsigned int GetWidth() const; 00237 00244 unsigned int GetHeight() const; 00245 00252 bool IsSmooth() const; 00253 00263 FloatRect GetTexCoords(const IntRect& rectangle) const; 00264 00271 static unsigned int GetMaximumSize(); 00272 00281 static unsigned int GetValidSize(unsigned int size); 00282 00291 Image& operator =(const Image& other); 00292 00293 private : 00294 00295 friend class Renderer; 00296 friend class RenderImage; 00297 00304 bool CreateTexture(); 00305 00311 void EnsureTextureUpdate() const; 00312 00318 void EnsureArrayUpdate() const; 00319 00324 void Use() const; 00325 00330 void Reset(); 00331 00336 void DestroyTexture(); 00337 00339 // Types 00341 typedef std::vector<Color> ColorArray; 00342 00344 // Member data 00346 unsigned int myWidth; 00347 unsigned int myHeight; 00348 unsigned int myTextureWidth; 00349 unsigned int myTextureHeight; 00350 unsigned int myTexture; 00351 bool myIsSmooth; 00352 mutable ColorArray myPixels; 00353 mutable bool myTextureUpdated; 00354 mutable bool myArrayUpdated; 00355 mutable bool myPixelsFlipped; 00356 }; 00357 00358 } // namespace sf 00359 00360 00361 #endif // SFML_IMAGE_HPP
:: Copyright © 2007-2008 Laurent Gomila, all rights reserved :: Documentation generated by doxygen 1.5.2 ::