SFML

- Main Page
- Modules
- Classes
- Files

- File List

Sprite.hpp
1 //
3 // SFML - Simple and Fast Multimedia Library
4 // Copyright (C) 2007-2014 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_SPRITE_HPP
26 #define SFML_SPRITE_HPP
27
29 // Headers
31 #include <SFML/Graphics/Export.hpp>
32 #include <SFML/Graphics/Drawable.hpp>
33 #include <SFML/Graphics/Transformable.hpp>
34 #include <SFML/Graphics/Vertex.hpp>
35 #include <SFML/Graphics/Rect.hpp>
36
37
38 namespace sf
39 {
40 class Texture;
41
47 class SFML_GRAPHICS_API Sprite : public Drawable, public Transformable
48 {
49 public:
50
57 Sprite();
58
67 explicit Sprite(const Texture& texture);
68
78 Sprite(const Texture& texture, const IntRect& rectangle);
79
99 void setTexture(const Texture& texture, bool resetRect = false);
100
113 void setTextureRect(const IntRect& rectangle);
114
128 void setColor(const Color& color);
129
142 const Texture* getTexture() const;
143
152 const IntRect& getTextureRect() const;
153
162 const Color& getColor() const;
163
176 FloatRect getLocalBounds() const;
177
190 FloatRect getGlobalBounds() const;
191
192 private:
193
201 virtual void draw(RenderTarget& target, RenderStates states) const;
202
207 void updatePositions();
208
213 void updateTexCoords();
214
216 // Member data
218 Vertex m_vertices[4];
219 const Texture* m_texture;
220 IntRect m_textureRect;
221 };
222
223 } // namespace sf
224
225
226 #endif // SFML_SPRITE_HPP
227
228
sf::Rect< int >
sf
Definition: Listener.hpp:35
sf::Drawable
Abstract base class for objects that can be drawn to a render target.
Definition: Drawable.hpp:44
sf::Transformable
Decomposed transform defined by a position, a rotation and a scale.
Definition: Transformable.hpp:41
sf::RenderStates
Define the states used for drawing to a RenderTarget.
Definition: RenderStates.hpp:45
sf::Vertex
Define a point with color and texture coordinates.
Definition: Vertex.hpp:42
sf::Texture
Image living on the graphics card that can be used for drawing.
Definition: Texture.hpp:47
sf::Color
Utility class for manipulating RGBA colors.
Definition: Color.hpp:40
sf::Sprite
Drawable representation of a texture, with its own transformations, color, etc.
Definition: Sprite.hpp:47
sf::RenderTarget
Base class for all render targets (window, texture, ...)
Definition: RenderTarget.hpp:51