Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-06-02 08:58:13

0001 ////////////////////////////////////////////////////////////
0002 //
0003 // SFML - Simple and Fast Multimedia Library
0004 // Copyright (C) 2007-2023 Laurent Gomila (laurent@sfml-dev.org)
0005 //
0006 // This software is provided 'as-is', without any express or implied warranty.
0007 // In no event will the authors be held liable for any damages arising from the use of this software.
0008 //
0009 // Permission is granted to anyone to use this software for any purpose,
0010 // including commercial applications, and to alter it and redistribute it freely,
0011 // subject to the following restrictions:
0012 //
0013 // 1. The origin of this software must not be misrepresented;
0014 //    you must not claim that you wrote the original software.
0015 //    If you use this software in a product, an acknowledgment
0016 //    in the product documentation would be appreciated but is not required.
0017 //
0018 // 2. Altered source versions must be plainly marked as such,
0019 //    and must not be misrepresented as being the original software.
0020 //
0021 // 3. This notice may not be removed or altered from any source distribution.
0022 //
0023 ////////////////////////////////////////////////////////////
0024 
0025 #ifndef SFML_CONVEXSHAPE_HPP
0026 #define SFML_CONVEXSHAPE_HPP
0027 
0028 ////////////////////////////////////////////////////////////
0029 // Headers
0030 ////////////////////////////////////////////////////////////
0031 #include <SFML/Graphics/Export.hpp>
0032 #include <SFML/Graphics/Shape.hpp>
0033 #include <vector>
0034 
0035 
0036 namespace sf
0037 {
0038 ////////////////////////////////////////////////////////////
0039 /// \brief Specialized shape representing a convex polygon
0040 ///
0041 ////////////////////////////////////////////////////////////
0042 class SFML_GRAPHICS_API ConvexShape : public Shape
0043 {
0044 public:
0045 
0046     ////////////////////////////////////////////////////////////
0047     /// \brief Default constructor
0048     ///
0049     /// \param pointCount Number of points of the polygon
0050     ///
0051     ////////////////////////////////////////////////////////////
0052     explicit ConvexShape(std::size_t pointCount = 0);
0053 
0054     ////////////////////////////////////////////////////////////
0055     /// \brief Set the number of points of the polygon
0056     ///
0057     /// \a count must be greater than 2 to define a valid shape.
0058     ///
0059     /// \param count New number of points of the polygon
0060     ///
0061     /// \see getPointCount
0062     ///
0063     ////////////////////////////////////////////////////////////
0064     void setPointCount(std::size_t count);
0065 
0066     ////////////////////////////////////////////////////////////
0067     /// \brief Get the number of points of the polygon
0068     ///
0069     /// \return Number of points of the polygon
0070     ///
0071     /// \see setPointCount
0072     ///
0073     ////////////////////////////////////////////////////////////
0074     virtual std::size_t getPointCount() const;
0075 
0076     ////////////////////////////////////////////////////////////
0077     /// \brief Set the position of a point
0078     ///
0079     /// Don't forget that the polygon must remain convex, and
0080     /// the points need to stay ordered!
0081     /// setPointCount must be called first in order to set the total
0082     /// number of points. The result is undefined if \a index is out
0083     /// of the valid range.
0084     ///
0085     /// \param index Index of the point to change, in range [0 .. getPointCount() - 1]
0086     /// \param point New position of the point
0087     ///
0088     /// \see getPoint
0089     ///
0090     ////////////////////////////////////////////////////////////
0091     void setPoint(std::size_t index, const Vector2f& point);
0092 
0093     ////////////////////////////////////////////////////////////
0094     /// \brief Get the position of a point
0095     ///
0096     /// The returned point is in local coordinates, that is,
0097     /// the shape's transforms (position, rotation, scale) are
0098     /// not taken into account.
0099     /// The result is undefined if \a index is out of the valid range.
0100     ///
0101     /// \param index Index of the point to get, in range [0 .. getPointCount() - 1]
0102     ///
0103     /// \return Position of the index-th point of the polygon
0104     ///
0105     /// \see setPoint
0106     ///
0107     ////////////////////////////////////////////////////////////
0108     virtual Vector2f getPoint(std::size_t index) const;
0109 
0110 private:
0111 
0112     ////////////////////////////////////////////////////////////
0113     // Member data
0114     ////////////////////////////////////////////////////////////
0115     std::vector<Vector2f> m_points; //!< Points composing the convex polygon
0116 };
0117 
0118 } // namespace sf
0119 
0120 
0121 #endif // SFML_CONVEXSHAPE_HPP
0122 
0123 
0124 ////////////////////////////////////////////////////////////
0125 /// \class sf::ConvexShape
0126 /// \ingroup graphics
0127 ///
0128 /// This class inherits all the functions of sf::Transformable
0129 /// (position, rotation, scale, bounds, ...) as well as the
0130 /// functions of sf::Shape (outline, color, texture, ...).
0131 ///
0132 /// It is important to keep in mind that a convex shape must
0133 /// always be... convex, otherwise it may not be drawn correctly.
0134 /// Moreover, the points must be defined in order; using a random
0135 /// order would result in an incorrect shape.
0136 ///
0137 /// Usage example:
0138 /// \code
0139 /// sf::ConvexShape polygon;
0140 /// polygon.setPointCount(3);
0141 /// polygon.setPoint(0, sf::Vector2f(0, 0));
0142 /// polygon.setPoint(1, sf::Vector2f(0, 10));
0143 /// polygon.setPoint(2, sf::Vector2f(25, 5));
0144 /// polygon.setOutlineColor(sf::Color::Red);
0145 /// polygon.setOutlineThickness(5);
0146 /// polygon.setPosition(10, 20);
0147 /// ...
0148 /// window.draw(polygon);
0149 /// \endcode
0150 ///
0151 /// \see sf::Shape, sf::RectangleShape, sf::CircleShape
0152 ///
0153 ////////////////////////////////////////////////////////////