]> git.sesse.net Git - casparcg/blob - SFML-1.6/include/SFML/Graphics/Sprite.hpp
(no commit message)
[casparcg] / SFML-1.6 / include / SFML / Graphics / Sprite.hpp
1 ////////////////////////////////////////////////////////////\r
2 //\r
3 // SFML - Simple and Fast Multimedia Library\r
4 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)\r
5 //\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
8 //\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
12 //\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
17 //\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
20 //\r
21 // 3. This notice may not be removed or altered from any source distribution.\r
22 //\r
23 ////////////////////////////////////////////////////////////\r
24 \r
25 #ifndef SFML_SPRITE_HPP\r
26 #define SFML_SPRITE_HPP\r
27 \r
28 ////////////////////////////////////////////////////////////\r
29 // Headers\r
30 ////////////////////////////////////////////////////////////\r
31 #include <SFML/System/Resource.hpp>\r
32 #include <SFML/Graphics/Drawable.hpp>\r
33 #include <SFML/Graphics/Rect.hpp>\r
34 \r
35 \r
36 namespace sf\r
37 {\r
38 class Image;\r
39 \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
45 {\r
46 public :\r
47 \r
48     ////////////////////////////////////////////////////////////\r
49     /// Default constructor\r
50     ///\r
51     ////////////////////////////////////////////////////////////\r
52     Sprite();\r
53 \r
54     ////////////////////////////////////////////////////////////\r
55     /// Construct the sprite from a source image\r
56     ///\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
62     ///\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
65 \r
66     ////////////////////////////////////////////////////////////\r
67     /// Change the image of the sprite\r
68     ///\r
69     /// \param Img : New image\r
70     ///\r
71     ////////////////////////////////////////////////////////////\r
72     void SetImage(const Image& Img);\r
73 \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
77     ///\r
78     /// \param SubRect : New sub-rectangle\r
79     ///\r
80     ////////////////////////////////////////////////////////////\r
81     void SetSubRect(const IntRect& SubRect);\r
82 \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
86     ///\r
87     /// \param Width :  New width (must be strictly positive)\r
88     /// \param Height : New height (must be strictly positive)\r
89     ///\r
90     ////////////////////////////////////////////////////////////\r
91     void Resize(float Width, float Height);\r
92 \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
96     ///\r
97     /// \param Size : New size (both coordinates must be strictly positive)\r
98     ///\r
99     ////////////////////////////////////////////////////////////\r
100     void Resize(const Vector2f& Size);\r
101 \r
102     ////////////////////////////////////////////////////////////\r
103     /// Flip the sprite horizontally\r
104     ///\r
105     /// \param Flipped : True to flip the sprite\r
106     ///\r
107     ////////////////////////////////////////////////////////////\r
108     void FlipX(bool Flipped);\r
109 \r
110     ////////////////////////////////////////////////////////////\r
111     /// Flip the sprite vertically\r
112     ///\r
113     /// \param Flipped : True to flip the sprite\r
114     ///\r
115     ////////////////////////////////////////////////////////////\r
116     void FlipY(bool Flipped);\r
117 \r
118     ////////////////////////////////////////////////////////////\r
119     /// Get the source image of the sprite\r
120     ///\r
121     /// \return Pointer to the image (can be NULL)\r
122     ///\r
123     ////////////////////////////////////////////////////////////\r
124     const Image* GetImage() const;\r
125 \r
126     ////////////////////////////////////////////////////////////\r
127     /// Get the sub-rectangle of the sprite inside the source image\r
128     ///\r
129     /// \return Sub-rectangle\r
130     ///\r
131     ////////////////////////////////////////////////////////////\r
132     const IntRect& GetSubRect() const;\r
133 \r
134     ////////////////////////////////////////////////////////////\r
135     /// Get the sprite size\r
136     ///\r
137     /// \return Size of the sprite\r
138     ///\r
139     ////////////////////////////////////////////////////////////\r
140     Vector2f GetSize() const;\r
141 \r
142     ////////////////////////////////////////////////////////////\r
143     /// Get the color of a given pixel in the sprite\r
144     /// (point is in local coordinates)\r
145     ///\r
146     /// \param X : X coordinate of the pixel to get\r
147     /// \param Y : Y coordinate of the pixel to get\r
148     ///\r
149     /// \return Color of pixel (X, Y)\r
150     ///\r
151     ////////////////////////////////////////////////////////////\r
152     Color GetPixel(unsigned int X, unsigned int Y) const;\r
153 \r
154 protected :\r
155 \r
156     ////////////////////////////////////////////////////////////\r
157     /// /see Drawable::Render\r
158     ///\r
159     ////////////////////////////////////////////////////////////\r
160     virtual void Render(RenderTarget& Target) const;\r
161 \r
162 private :\r
163 \r
164     ////////////////////////////////////////////////////////////\r
165     // Member data\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
171 };\r
172 \r
173 } // namespace sf\r
174 \r
175 \r
176 #endif // SFML_SPRITE_HPP\r