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 CPP3DS_SPRITE_HPP
26 #define CPP3DS_SPRITE_HPP
27 
29 // Headers
31 #include <cpp3ds/Graphics/Drawable.hpp>
32 #include <cpp3ds/Graphics/Transformable.hpp>
33 #include <cpp3ds/Graphics/Vertex.hpp>
34 #include <cpp3ds/Graphics/Rect.hpp>
35 
36 
37 namespace cpp3ds
38 {
39 class Texture;
40 
46 class Sprite : public Drawable, public Transformable
47 {
48 public :
49 
56  Sprite();
57 
66  explicit Sprite(const Texture& texture);
67 
77  Sprite(const Texture& texture, const IntRect& rectangle);
78 
79  ~Sprite();
80 
100  void setTexture(const Texture& texture, bool resetRect = false);
101 
114  void setTextureRect(const IntRect& rectangle);
115 
129  void setColor(const Color& color);
130 
143  const Texture* getTexture() const;
144 
153  const IntRect& getTextureRect() const;
154 
163  const Color& getColor() const;
164 
177  FloatRect getLocalBounds() const;
178 
191  FloatRect getGlobalBounds() const;
192 
193 private :
194 
202  virtual void draw(RenderTarget& target, RenderStates states) const;
203 
208  void updatePositions();
209 
214  void updateTexCoords();
215 
217  // Member data
219  Vertex* m_vertices;
220  const Texture* m_texture;
221  IntRect m_textureRect;
222 };
223 
224 }
225 
226 
227 #endif
228 
229 
FloatRect getGlobalBounds() const
Get the global bounding rectangle of the entity.
Decomposed transform defined by a position, a rotation and a scale.
void setTexture(const Texture &texture, bool resetRect=false)
Change the source texture of the sprite.
Utility class for manpulating RGBA colors.
Definition: Color.hpp:36
void setColor(const Color &color)
Set the global color of the sprite.
void setTextureRect(const IntRect &rectangle)
Set the sub-rectangle of the texture that the sprite will display.
Drawable representation of a texture, with its own transformations, color, etc.
Definition: Sprite.hpp:46
Define a point with color and texture coordinates.
Definition: Vertex.hpp:41
const Color & getColor() const
Get the global color of the sprite.
const Texture * getTexture() const
Get the source texture of the sprite.
Abstract base class for objects that can be drawn to a render target.
Definition: Drawable.hpp:43
const IntRect & getTextureRect() const
Get the sub-rectangle of the texture displayed by the sprite.
Base class for all render targets (window, texture, ...)
Define the states used for drawing to a RenderTarget.
Sprite()
Default constructor.
FloatRect getLocalBounds() const
Get the local bounding rectangle of the entity.
some things could easily be broken///////
Definition: Texture.hpp:47