Shape.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_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 
213  virtual Vector2f getPoint(unsigned int index) const = 0;
214 
227  FloatRect getLocalBounds() const;
228 
241  FloatRect getGlobalBounds() const;
242 
243 protected:
244 
249  Shape();
250 
259  void update();
260 
261 private:
262 
270  virtual void draw(RenderTarget& target, RenderStates states) const;
271 
276  void updateFillColors();
277 
282  void updateTexCoords();
283 
288  void updateOutline();
289 
294  void updateOutlineColors();
295 
296 private:
297 
299  // Member data
301  const Texture* m_texture;
302  IntRect m_textureRect;
303  Color m_fillColor;
304  Color m_outlineColor;
305  float m_outlineThickness;
306  VertexArray m_vertices;
307  VertexArray m_outlineVertices;
308  FloatRect m_insideBounds;
309  FloatRect m_bounds;
310 };
311 
312 } // namespace sf
313 
314 
315 #endif // SFML_SHAPE_HPP
316 
317 
Base class for textured shapes with outline.
Definition: Shape.hpp:44
Definition: Listener.hpp:35
Abstract base class for objects that can be drawn to a render target.
Definition: Drawable.hpp:44
Decomposed transform defined by a position, a rotation and a scale.
Define the states used for drawing to a RenderTarget.
Image living on the graphics card that can be used for drawing.
Definition: Texture.hpp:47
Utility class for manipulating RGBA colors.
Definition: Color.hpp:40
Base class for all render targets (window, texture, ...)
Define a set of one or more 2D primitives.
Definition: VertexArray.hpp:45