1 ////////////////////////////////////////////////////////////
\r
3 // SFML - Simple and Fast Multimedia Library
\r
4 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
\r
6 // This software is provided 'as-is', without any express or implied warranty.
\r
7 // In no event will the authors be held liable for any damages arising from the use of this software.
\r
9 // Permission is granted to anyone to use this software for any purpose,
\r
10 // including commercial applications, and to alter it and redistribute it freely,
\r
11 // subject to the following restrictions:
\r
13 // 1. The origin of this software must not be misrepresented;
\r
14 // you must not claim that you wrote the original software.
\r
15 // If you use this software in a product, an acknowledgment
\r
16 // in the product documentation would be appreciated but is not required.
\r
18 // 2. Altered source versions must be plainly marked as such,
\r
19 // and must not be misrepresented as being the original software.
\r
21 // 3. This notice may not be removed or altered from any source distribution.
\r
23 ////////////////////////////////////////////////////////////
\r
25 #ifndef SFML_SPRITE_HPP
\r
26 #define SFML_SPRITE_HPP
\r
28 ////////////////////////////////////////////////////////////
\r
30 ////////////////////////////////////////////////////////////
\r
31 #include <SFML/System/Resource.hpp>
\r
32 #include <SFML/Graphics/Drawable.hpp>
\r
33 #include <SFML/Graphics/Rect.hpp>
\r
40 ////////////////////////////////////////////////////////////
\r
41 /// Sprite defines a sprite : texture, transformations,
\r
42 /// color, and draw on screen
\r
43 ////////////////////////////////////////////////////////////
\r
44 class SFML_API Sprite : public Drawable
\r
48 ////////////////////////////////////////////////////////////
\r
49 /// Default constructor
\r
51 ////////////////////////////////////////////////////////////
\r
54 ////////////////////////////////////////////////////////////
\r
55 /// Construct the sprite from a source image
\r
57 /// \param Img : Image of the sprite
\r
58 /// \param Position : Position of the sprite (0, 0 by default)
\r
59 /// \param Scale : Scale factor (1, 1 by default)
\r
60 /// \param Rotation : Orientation, in degrees (0 by default)
\r
61 /// \param Col : Color of the sprite (white by default)
\r
63 ////////////////////////////////////////////////////////////
\r
64 explicit Sprite(const Image& Img, const Vector2f& Position = Vector2f(0, 0), const Vector2f& Scale = Vector2f(1, 1), float Rotation = 0.f, const Color& Col = Color(255, 255, 255, 255));
\r
66 ////////////////////////////////////////////////////////////
\r
67 /// Change the image of the sprite
\r
69 /// \param Img : New image
\r
71 ////////////////////////////////////////////////////////////
\r
72 void SetImage(const Image& Img);
\r
74 ////////////////////////////////////////////////////////////
\r
75 /// Set the sub-rectangle of the sprite inside the source image.
\r
76 /// By default, the subrect covers the entire source image
\r
78 /// \param SubRect : New sub-rectangle
\r
80 ////////////////////////////////////////////////////////////
\r
81 void SetSubRect(const IntRect& SubRect);
\r
83 ////////////////////////////////////////////////////////////
\r
84 /// Resize the sprite (by changing its scale factors) (take 2 values).
\r
85 /// The default size is defined by the subrect
\r
87 /// \param Width : New width (must be strictly positive)
\r
88 /// \param Height : New height (must be strictly positive)
\r
90 ////////////////////////////////////////////////////////////
\r
91 void Resize(float Width, float Height);
\r
93 ////////////////////////////////////////////////////////////
\r
94 /// Resize the sprite (by changing its scale factors) (take a 2D vector).
\r
95 /// The default size is defined by the subrect
\r
97 /// \param Size : New size (both coordinates must be strictly positive)
\r
99 ////////////////////////////////////////////////////////////
\r
100 void Resize(const Vector2f& Size);
\r
102 ////////////////////////////////////////////////////////////
\r
103 /// Flip the sprite horizontally
\r
105 /// \param Flipped : True to flip the sprite
\r
107 ////////////////////////////////////////////////////////////
\r
108 void FlipX(bool Flipped);
\r
110 ////////////////////////////////////////////////////////////
\r
111 /// Flip the sprite vertically
\r
113 /// \param Flipped : True to flip the sprite
\r
115 ////////////////////////////////////////////////////////////
\r
116 void FlipY(bool Flipped);
\r
118 ////////////////////////////////////////////////////////////
\r
119 /// Get the source image of the sprite
\r
121 /// \return Pointer to the image (can be NULL)
\r
123 ////////////////////////////////////////////////////////////
\r
124 const Image* GetImage() const;
\r
126 ////////////////////////////////////////////////////////////
\r
127 /// Get the sub-rectangle of the sprite inside the source image
\r
129 /// \return Sub-rectangle
\r
131 ////////////////////////////////////////////////////////////
\r
132 const IntRect& GetSubRect() const;
\r
134 ////////////////////////////////////////////////////////////
\r
135 /// Get the sprite size
\r
137 /// \return Size of the sprite
\r
139 ////////////////////////////////////////////////////////////
\r
140 Vector2f GetSize() const;
\r
142 ////////////////////////////////////////////////////////////
\r
143 /// Get the color of a given pixel in the sprite
\r
144 /// (point is in local coordinates)
\r
146 /// \param X : X coordinate of the pixel to get
\r
147 /// \param Y : Y coordinate of the pixel to get
\r
149 /// \return Color of pixel (X, Y)
\r
151 ////////////////////////////////////////////////////////////
\r
152 Color GetPixel(unsigned int X, unsigned int Y) const;
\r
156 ////////////////////////////////////////////////////////////
\r
157 /// /see Drawable::Render
\r
159 ////////////////////////////////////////////////////////////
\r
160 virtual void Render(RenderTarget& Target) const;
\r
164 ////////////////////////////////////////////////////////////
\r
166 ////////////////////////////////////////////////////////////
\r
167 ResourcePtr<Image> myImage; ///< Image used to draw the sprite
\r
168 IntRect mySubRect; ///< Sub-rectangle of source image to assign to the sprite
\r
169 bool myIsFlippedX; ///< Is the sprite flipped on the X axis ?
\r
170 bool myIsFlippedY; ///< Is the sprite flipped on the Y axis ?
\r
176 #endif // SFML_SPRITE_HPP
\r