SFML - Simple and Fast Multimedia Library

SMFL 2.3.2

Sprite.hpp
1 //
3 // SFML - Simple and Fast Multimedia Library
4 // Copyright (C) 2007-2015 Laurent Gomila ([email protected])
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 
Image living on the graphics card that can be used for drawing.
Definition: Texture.hpp:47
Define the states used for drawing to a RenderTarget.
Utility class for manipulating RGBA colors.
Definition: Color.hpp:40
Define a point with color and texture coordinates.
Definition: Vertex.hpp:42
Base class for all render targets (window, texture, ...)
Abstract base class for objects that can be drawn to a render target.
Definition: Drawable.hpp:44
Drawable representation of a texture, with its own transformations, color, etc.
Definition: Sprite.hpp:47
Decomposed transform defined by a position, a rotation and a scale.