ConcaveShape.hpp
Go to the documentation of this file.
1 //
3 // Thor C++ Library
4 // Copyright (c) 2011-2015 Jan Haller
5 //
6 // This software is provided 'as-is', without any express or implied
7 // warranty. In no event will the authors be held liable for any damages
8 // arising from the use of this software.
9 //
10 // Permission is granted to anyone to use this software for any purpose,
11 // including commercial applications, and to alter it and redistribute it
12 // freely, subject to the following restrictions:
13 //
14 // 1. The origin of this software must not be misrepresented; you must not
15 // claim that you wrote the original software. If you use this software
16 // in a product, an acknowledgment in the product documentation would be
17 // appreciated but is not required.
18 //
19 // 2. Altered source versions must be plainly marked as such, and must not be
20 // misrepresented as being the original software.
21 //
22 // 3. This notice may not be removed or altered from any source distribution.
23 //
25 
28 
29 #ifndef THOR_CONCAVESHAPE_HPP
30 #define THOR_CONCAVESHAPE_HPP
31 
32 #include <Thor/Config.hpp>
33 
34 #include <SFML/Graphics/Color.hpp>
35 #include <SFML/Graphics/ConvexShape.hpp>
36 #include <SFML/Graphics/Drawable.hpp>
37 #include <SFML/Graphics/Transformable.hpp>
38 #include <SFML/Graphics/VertexArray.hpp>
39 
40 #include <vector>
41 
42 
43 namespace thor
44 {
45 
48 
52 class THOR_API ConcaveShape : public sf::Drawable, public sf::Transformable
53 {
54  // ---------------------------------------------------------------------------------------------------------------------------
55  // Public member functions
56  public:
59  ConcaveShape();
60 
63  ConcaveShape(const sf::Shape& shape);
64 
67  void setPointCount(std::size_t count);
68 
71  std::size_t getPointCount() const;
72 
76  void setPoint(std::size_t index, sf::Vector2f position);
77 
80  sf::Vector2f getPoint(std::size_t index) const;
81 
84  void setFillColor(const sf::Color& fillColor);
85 
88  void setOutlineColor(const sf::Color& outlineColor);
89 
92  sf::Color getFillColor() const;
93 
96  sf::Color getOutlineColor() const;
97 
100  void setOutlineThickness(float outlineThickness);
101 
104  float getOutlineThickness() const;
105 
108  sf::FloatRect getLocalBounds() const;
109 
114  sf::FloatRect getGlobalBounds() const;
115 
116 
117  // ---------------------------------------------------------------------------------------------------------------------------
118  // Private types
119  private:
120  struct TriangleGenerator;
121 
122 
123  // ---------------------------------------------------------------------------------------------------------------------------
124  // Private member functions
125  private:
126  // Renders the shape to target.
127  virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;
128 
129  // Computes how the shape can be split up into convex triangles.
130  void ensureDecomposed() const;
131 
132  // Forms the outline out of the given edges.
133  void ensureOutlineUpdated() const;
134 
135 
136  // ---------------------------------------------------------------------------------------------------------------------------
137  // Private variables
138  private:
139  std::vector<sf::Vector2f> mPoints;
140  sf::Color mFillColor;
141  sf::Color mOutlineColor;
142  float mOutlineThickness;
143 
144  mutable sf::VertexArray mTriangleVertices;
145  mutable std::vector<sf::ConvexShape> mOutlineShapes;
146  mutable sf::FloatRect mLocalBounds;
147  mutable bool mNeedsDecomposition;
148  mutable bool mNeedsOutlineUpdate;
149 };
150 
152 
153 } // namespace thor
154 
155 #endif // THOR_CONCAVESHAPE_HPP
Concave shape class.
Definition: ConcaveShape.hpp:52
Definition: Animator.hpp:42
Configuration header of the library.