Back to home page

EIC code displayed by LXR

 
 

    


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

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_VERTEXARRAY_HPP
0026 #define SFML_VERTEXARRAY_HPP
0027 
0028 ////////////////////////////////////////////////////////////
0029 // Headers
0030 ////////////////////////////////////////////////////////////
0031 #include <SFML/Graphics/Export.hpp>
0032 #include <SFML/Graphics/Vertex.hpp>
0033 #include <SFML/Graphics/PrimitiveType.hpp>
0034 #include <SFML/Graphics/Rect.hpp>
0035 #include <SFML/Graphics/Drawable.hpp>
0036 #include <vector>
0037 
0038 
0039 namespace sf
0040 {
0041 ////////////////////////////////////////////////////////////
0042 /// \brief Define a set of one or more 2D primitives
0043 ///
0044 ////////////////////////////////////////////////////////////
0045 class SFML_GRAPHICS_API VertexArray : public Drawable
0046 {
0047 public:
0048 
0049     ////////////////////////////////////////////////////////////
0050     /// \brief Default constructor
0051     ///
0052     /// Creates an empty vertex array.
0053     ///
0054     ////////////////////////////////////////////////////////////
0055     VertexArray();
0056 
0057     ////////////////////////////////////////////////////////////
0058     /// \brief Construct the vertex array with a type and an initial number of vertices
0059     ///
0060     /// \param type        Type of primitives
0061     /// \param vertexCount Initial number of vertices in the array
0062     ///
0063     ////////////////////////////////////////////////////////////
0064     explicit VertexArray(PrimitiveType type, std::size_t vertexCount = 0);
0065 
0066     ////////////////////////////////////////////////////////////
0067     /// \brief Return the vertex count
0068     ///
0069     /// \return Number of vertices in the array
0070     ///
0071     ////////////////////////////////////////////////////////////
0072     std::size_t getVertexCount() const;
0073 
0074     ////////////////////////////////////////////////////////////
0075     /// \brief Get a read-write access to a vertex by its index
0076     ///
0077     /// This function doesn't check \a index, it must be in range
0078     /// [0, getVertexCount() - 1]. The behavior is undefined
0079     /// otherwise.
0080     ///
0081     /// \param index Index of the vertex to get
0082     ///
0083     /// \return Reference to the index-th vertex
0084     ///
0085     /// \see getVertexCount
0086     ///
0087     ////////////////////////////////////////////////////////////
0088     Vertex& operator [](std::size_t index);
0089 
0090     ////////////////////////////////////////////////////////////
0091     /// \brief Get a read-only access to a vertex by its index
0092     ///
0093     /// This function doesn't check \a index, it must be in range
0094     /// [0, getVertexCount() - 1]. The behavior is undefined
0095     /// otherwise.
0096     ///
0097     /// \param index Index of the vertex to get
0098     ///
0099     /// \return Const reference to the index-th vertex
0100     ///
0101     /// \see getVertexCount
0102     ///
0103     ////////////////////////////////////////////////////////////
0104     const Vertex& operator [](std::size_t index) const;
0105 
0106     ////////////////////////////////////////////////////////////
0107     /// \brief Clear the vertex array
0108     ///
0109     /// This function removes all the vertices from the array.
0110     /// It doesn't deallocate the corresponding memory, so that
0111     /// adding new vertices after clearing doesn't involve
0112     /// reallocating all the memory.
0113     ///
0114     ////////////////////////////////////////////////////////////
0115     void clear();
0116 
0117     ////////////////////////////////////////////////////////////
0118     /// \brief Resize the vertex array
0119     ///
0120     /// If \a vertexCount is greater than the current size, the previous
0121     /// vertices are kept and new (default-constructed) vertices are
0122     /// added.
0123     /// If \a vertexCount is less than the current size, existing vertices
0124     /// are removed from the array.
0125     ///
0126     /// \param vertexCount New size of the array (number of vertices)
0127     ///
0128     ////////////////////////////////////////////////////////////
0129     void resize(std::size_t vertexCount);
0130 
0131     ////////////////////////////////////////////////////////////
0132     /// \brief Add a vertex to the array
0133     ///
0134     /// \param vertex Vertex to add
0135     ///
0136     ////////////////////////////////////////////////////////////
0137     void append(const Vertex& vertex);
0138 
0139     ////////////////////////////////////////////////////////////
0140     /// \brief Set the type of primitives to draw
0141     ///
0142     /// This function defines how the vertices must be interpreted
0143     /// when it's time to draw them:
0144     /// \li As points
0145     /// \li As lines
0146     /// \li As triangles
0147     /// \li As quads
0148     /// The default primitive type is sf::Points.
0149     ///
0150     /// \param type Type of primitive
0151     ///
0152     ////////////////////////////////////////////////////////////
0153     void setPrimitiveType(PrimitiveType type);
0154 
0155     ////////////////////////////////////////////////////////////
0156     /// \brief Get the type of primitives drawn by the vertex array
0157     ///
0158     /// \return Primitive type
0159     ///
0160     ////////////////////////////////////////////////////////////
0161     PrimitiveType getPrimitiveType() const;
0162 
0163     ////////////////////////////////////////////////////////////
0164     /// \brief Compute the bounding rectangle of the vertex array
0165     ///
0166     /// This function returns the minimal axis-aligned rectangle
0167     /// that contains all the vertices of the array.
0168     ///
0169     /// \return Bounding rectangle of the vertex array
0170     ///
0171     ////////////////////////////////////////////////////////////
0172     FloatRect getBounds() const;
0173 
0174 private:
0175 
0176     ////////////////////////////////////////////////////////////
0177     /// \brief Draw the vertex array to a render target
0178     ///
0179     /// \param target Render target to draw to
0180     /// \param states Current render states
0181     ///
0182     ////////////////////////////////////////////////////////////
0183     virtual void draw(RenderTarget& target, RenderStates states) const;
0184 
0185 private:
0186 
0187     ////////////////////////////////////////////////////////////
0188     // Member data
0189     ////////////////////////////////////////////////////////////
0190     std::vector<Vertex> m_vertices;      //!< Vertices contained in the array
0191     PrimitiveType       m_primitiveType; //!< Type of primitives to draw
0192 };
0193 
0194 } // namespace sf
0195 
0196 
0197 #endif // SFML_VERTEXARRAY_HPP
0198 
0199 
0200 ////////////////////////////////////////////////////////////
0201 /// \class sf::VertexArray
0202 /// \ingroup graphics
0203 ///
0204 /// sf::VertexArray is a very simple wrapper around a dynamic
0205 /// array of vertices and a primitives type.
0206 ///
0207 /// It inherits sf::Drawable, but unlike other drawables it
0208 /// is not transformable.
0209 ///
0210 /// Example:
0211 /// \code
0212 /// sf::VertexArray lines(sf::LineStrip, 4);
0213 /// lines[0].position = sf::Vector2f(10, 0);
0214 /// lines[1].position = sf::Vector2f(20, 0);
0215 /// lines[2].position = sf::Vector2f(30, 5);
0216 /// lines[3].position = sf::Vector2f(40, 2);
0217 ///
0218 /// window.draw(lines);
0219 /// \endcode
0220 ///
0221 /// \see sf::Vertex
0222 ///
0223 ////////////////////////////////////////////////////////////