1 ////////////////////////////////////////////////////////////
 
   3 // SFML - Simple and Fast Multimedia Library
 
   4 // Copyright (C) 2007-2013 Laurent Gomila (laurent.gom@gmail.com)
 
   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.
 
   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:
 
  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.
 
  18 // 2. Altered source versions must be plainly marked as such,
 
  19 //    and must not be misrepresented as being the original software.
 
  21 // 3. This notice may not be removed or altered from any source distribution.
 
  23 ////////////////////////////////////////////////////////////
 
  25 #ifndef SFML_CONVEXSHAPE_HPP
 
  26 #define SFML_CONVEXSHAPE_HPP
 
  28 ////////////////////////////////////////////////////////////
 
  30 ////////////////////////////////////////////////////////////
 
  31 #include <SFML/Graphics/Export.hpp>
 
  32 #include <SFML/Graphics/Shape.hpp>
 
  38 ////////////////////////////////////////////////////////////
 
  39 /// \brief Specialized shape representing a convex polygon
 
  41 ////////////////////////////////////////////////////////////
 
  42 class SFML_GRAPHICS_API ConvexShape : public Shape
 
  46     ////////////////////////////////////////////////////////////
 
  47     /// \brief Default constructor
 
  49     /// \param pointCount Number of points of the polygon
 
  51     ////////////////////////////////////////////////////////////
 
  52     explicit ConvexShape(unsigned int pointCount = 0);
 
  54     ////////////////////////////////////////////////////////////
 
  55     /// \brief Set the number of points of the polygon
 
  57     /// \a count must be greater than 2 to define a valid shape.
 
  59     /// \param count New number of points of the polygon
 
  61     /// \see getPointCount
 
  63     ////////////////////////////////////////////////////////////
 
  64     void setPointCount(unsigned int count);
 
  66     ////////////////////////////////////////////////////////////
 
  67     /// \brief Get the number of points of the polygon
 
  69     /// \return Number of points of the polygon
 
  71     /// \see setPointCount
 
  73     ////////////////////////////////////////////////////////////
 
  74     virtual unsigned int getPointCount() const;
 
  76     ////////////////////////////////////////////////////////////
 
  77     /// \brief Set the position of a point
 
  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.
 
  85     /// \param index Index of the point to change, in range [0 .. getPointCount() - 1]
 
  86     /// \param point New position of the point
 
  90     ////////////////////////////////////////////////////////////
 
  91     void setPoint(unsigned int index, const Vector2f& point);
 
  93     ////////////////////////////////////////////////////////////
 
  94     /// \brief Get the position of a point
 
  96     /// The result is undefined if \a index is out of the valid range.
 
  98     /// \param index Index of the point to get, in range [0 .. getPointCount() - 1]
 
 100     /// \return Position of the index-th point of the polygon
 
 104     ////////////////////////////////////////////////////////////
 
 105     virtual Vector2f getPoint(unsigned int index) const;
 
 109     ////////////////////////////////////////////////////////////
 
 111     ////////////////////////////////////////////////////////////
 
 112     std::vector<Vector2f> m_points; ///< Points composing the convex polygon
 
 118 #endif // SFML_CONVEXSHAPE_HPP
 
 121 ////////////////////////////////////////////////////////////
 
 122 /// \class sf::ConvexShape
 
 123 /// \ingroup graphics
 
 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, ...).
 
 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.
 
 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);
 
 145 /// window.draw(polygon);
 
 148 /// \see sf::Shape, sf::RectangleShape, sf::CircleShape
 
 150 ////////////////////////////////////////////////////////////