Documentation of SFML 2.0

Warning: this page refers to an old version of SFML. Click here to switch to the latest version.
Shape.hpp
1 
2 //
3 // SFML - Simple and Fast Multimedia Library
4 // Copyright (C) 2007-2013 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_SHAPE_HPP
26 #define SFML_SHAPE_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/VertexArray.hpp>
35 #include <SFML/System/Vector2.hpp>
36 
37 
38 namespace sf
39 {
44 class SFML_GRAPHICS_API Shape : public Drawable, public Transformable
45 {
46 public :
47 
52  virtual ~Shape();
53 
74  void setTexture(const Texture* texture, bool resetRect = false);
75 
88  void setTextureRect(const IntRect& rect);
89 
105  void setFillColor(const Color& color);
106 
117  void setOutlineColor(const Color& color);
118 
132  void setOutlineThickness(float thickness);
133 
146  const Texture* getTexture() const;
147 
156  const IntRect& getTextureRect() const;
157 
166  const Color& getFillColor() const;
167 
176  const Color& getOutlineColor() const;
177 
186  float getOutlineThickness() const;
187 
196  virtual unsigned int getPointCount() const = 0;
197 
210  virtual Vector2f getPoint(unsigned int index) const = 0;
211 
224  FloatRect getLocalBounds() const;
225 
238  FloatRect getGlobalBounds() const;
239 
240 protected :
241 
246  Shape();
247 
256  void update();
257 
258 private :
259 
267  virtual void draw(RenderTarget& target, RenderStates states) const;
268 
273  void updateFillColors();
274 
279  void updateTexCoords();
280 
285  void updateOutline();
286 
291  void updateOutlineColors();
292 
293 private :
294 
296  // Member data
298  const Texture* m_texture;
299  IntRect m_textureRect;
300  Color m_fillColor;
301  Color m_outlineColor;
302  float m_outlineThickness;
303  VertexArray m_vertices;
304  VertexArray m_outlineVertices;
305  FloatRect m_insideBounds;
306  FloatRect m_bounds;
307 };
308 
309 } // namespace sf
310 
311 
312 #endif // SFML_SHAPE_HPP
313 
314