Documentation de SFML 1.6

Attention: cette page se réfère à une ancienne version de SFML. Cliquez ici pour passer à la dernière version.
Image.hpp
1 
2 //
3 // SFML - Simple and Fast Multimedia Library
4 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
5 //
6 // This software is provided 'as-is', without any express or implied warranty.
7 // In no event will the authors be held liable for any damages arising from the use of this software.
8 //
9 // Permission is granted to anyone to use this software for any purpose,
10 // including commercial applications, and to alter it and redistribute it freely,
11 // subject to the following restrictions:
12 //
13 // 1. The origin of this software must not be misrepresented;
14 // you must not claim that you wrote the original software.
15 // If you use this software in a product, an acknowledgment
16 // in the product documentation would be appreciated but is not required.
17 //
18 // 2. Altered source versions must be plainly marked as such,
19 // and must not be misrepresented as being the original software.
20 //
21 // 3. This notice may not be removed or altered from any source distribution.
22 //
24 
25 #ifndef SFML_IMAGE_HPP
26 #define SFML_IMAGE_HPP
27 
29 // Headers
31 #include <SFML/System/Resource.hpp>
32 #include <SFML/Graphics/Color.hpp>
33 #include <SFML/Graphics/Rect.hpp>
34 #include <string>
35 #include <vector>
36 
37 
38 namespace sf
39 {
40 class RenderWindow;
41 
46 class SFML_API Image : public Resource<Image>
47 {
48 public :
49 
54  Image();
55 
62  Image(const Image& Copy);
63 
72  Image(unsigned int Width, unsigned int Height, const Color& Col = Color(0, 0, 0, 255));
73 
82  Image(unsigned int Width, unsigned int Height, const Uint8* Data);
83 
88  ~Image();
89 
98  bool LoadFromFile(const std::string& Filename);
99 
109  bool LoadFromMemory(const char* Data, std::size_t SizeInBytes);
110 
121  bool LoadFromPixels(unsigned int Width, unsigned int Height, const Uint8* Data);
122 
131  bool SaveToFile(const std::string& Filename) const;
132 
143  bool Create(unsigned int Width, unsigned int Height, Color Col = Color(0, 0, 0, 255));
144 
152  void CreateMaskFromColor(Color ColorKey, Uint8 Alpha = 0);
153 
166  void Copy(const Image& Source, unsigned int DestX, unsigned int DestY, const IntRect& SourceRect = IntRect(0, 0, 0, 0), bool ApplyAlpha = false);
167 
178  bool CopyScreen(RenderWindow& Window, const IntRect& SourceRect = IntRect(0, 0, 0, 0));
179 
188  void SetPixel(unsigned int X, unsigned int Y, const Color& Col);
189 
199  const Color& GetPixel(unsigned int X, unsigned int Y) const;
200 
209  const Uint8* GetPixelsPtr() const;
210 
215  void Bind() const;
216 
224  void SetSmooth(bool Smooth);
225 
232  unsigned int GetWidth() const;
233 
240  unsigned int GetHeight() const;
241 
248  bool IsSmooth() const;
249 
259  FloatRect GetTexCoords(const IntRect& Rect) const;
260 
269  static unsigned int GetValidTextureSize(unsigned int Size);
270 
279  Image& operator =(const Image& Other);
280 
281 private :
282 
289  bool CreateTexture();
290 
295  void EnsureTextureUpdate() const;
296 
301  void EnsureArrayUpdate() const;
302 
307  void Reset();
308 
313  void DestroyTexture();
314 
316  // Member data
318  unsigned int myWidth;
319  unsigned int myHeight;
320  unsigned int myTextureWidth;
321  unsigned int myTextureHeight;
322  unsigned int myTexture;
323  bool myIsSmooth;
324  mutable std::vector<Color> myPixels;
325  mutable bool myNeedTextureUpdate;
326  mutable bool myNeedArrayUpdate;
327 };
328 
329 } // namespace sf
330 
331 
332 #endif // SFML_IMAGE_HPP