03af57f6868537d6aa000c220d427dc4e6a137ab
[TDDC76_proj.git] /
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 //
23 ////////////////////////////////////////////////////////////
24
25 #ifndef SFML_CONVEXSHAPE_HPP
26 #define SFML_CONVEXSHAPE_HPP
27
28 ////////////////////////////////////////////////////////////
29 // Headers
30 ////////////////////////////////////////////////////////////
31 #include <SFML/Graphics/Export.hpp>
32 #include <SFML/Graphics/Shape.hpp>
33 #include <vector>
34
35
36 namespace sf
37 {
38 ////////////////////////////////////////////////////////////
39 /// \brief Specialized shape representing a convex polygon
40 ///
41 ////////////////////////////////////////////////////////////
42 class SFML_GRAPHICS_API ConvexShape : public Shape
43 {
44 public :
45
46 ////////////////////////////////////////////////////////////
47 /// \brief Default constructor
48 ///
49 /// \param pointCount Number of points of the polygon
50 ///
51 ////////////////////////////////////////////////////////////
52 explicit ConvexShape(unsigned int pointCount = 0);
53
54 ////////////////////////////////////////////////////////////
55 /// \brief Set the number of points of the polygon
56 ///
57 /// \a count must be greater than 2 to define a valid shape.
58 ///
59 /// \param count New number of points of the polygon
60 ///
61 /// \see getPointCount
62 ///
63 ////////////////////////////////////////////////////////////
64 void setPointCount(unsigned int count);
65
66 ////////////////////////////////////////////////////////////
67 /// \brief Get the number of points of the polygon
68 ///
69 /// \return Number of points of the polygon
70 ///
71 /// \see setPointCount
72 ///
73 ////////////////////////////////////////////////////////////
74 virtual unsigned int getPointCount() const;
75
76 ////////////////////////////////////////////////////////////
77 /// \brief Set the position of a point
78 ///
79 /// Don't forget that the polygon must remain convex, and
80 /// the points need to stay ordered!
81 /// setPointCount must be called first in order to set the total
82 /// number of points. The result is undefined if \a index is out
83 /// of the valid range.
84 ///
85 /// \param index Index of the point to change, in range [0 .. getPointCount() - 1]
86 /// \param point New position of the point
87 ///
88 /// \see getPoint
89 ///
90 ////////////////////////////////////////////////////////////
91 void setPoint(unsigned int index, const Vector2f& point);
92
93 ////////////////////////////////////////////////////////////
94 /// \brief Get the position of a point
95 ///
96 /// The result is undefined if \a index is out of the valid range.
97 ///
98 /// \param index Index of the point to get, in range [0 .. getPointCount() - 1]
99 ///
100 /// \return Position of the index-th point of the polygon
101 ///
102 /// \see setPoint
103 ///
104 ////////////////////////////////////////////////////////////
105 virtual Vector2f getPoint(unsigned int index) const;
106
107 private :
108
109 ////////////////////////////////////////////////////////////
110 // Member data
111 ////////////////////////////////////////////////////////////
112 std::vector<Vector2f> m_points; ///< Points composing the convex polygon
113 };
114
115 } // namespace sf
116
117
118 #endif // SFML_CONVEXSHAPE_HPP
119
120
121 ////////////////////////////////////////////////////////////
122 /// \class sf::ConvexShape
123 /// \ingroup graphics
124 ///
125 /// This class inherits all the functions of sf::Transformable
126 /// (position, rotation, scale, bounds, ...) as well as the
127 /// functions of sf::Shape (outline, color, texture, ...).
128 ///
129 /// It is important to keep in mind that a convex shape must
130 /// always be... convex, otherwise it may not be drawn correctly.
131 /// Moreover, the points must be defined in order; using a random
132 /// order would result in an incorrect shape.
133 ///
134 /// Usage example:
135 /// \code
136 /// sf::ConvexShape polygon;
137 /// polygon.setPointCount(3);
138 /// polygon.setPoint(0, sf::Vector2f(0, 0));
139 /// polygon.setPoint(1, sf::Vector2f(0, 10));
140 /// polygon.setPoint(2, sf::Vector2f(25, 5));
141 /// polygon.setOutlineColor(sf::Color::Red);
142 /// polygon.setOutlineThickness(5);
143 /// polygon.setPosition(10, 20);
144 /// ...
145 /// window.draw(polygon);
146 /// \endcode
147 ///
148 /// \see sf::Shape, sf::RectangleShape, sf::CircleShape
149 ///
150 ////////////////////////////////////////////////////////////