Shapes/ConcaveShape.hpp
Go to the documentation of this file.
00001 
00002 //
00003 // Thor C++ Library
00004 // Copyright (c) 2011-2015 Jan Haller
00005 // 
00006 // This software is provided 'as-is', without any express or implied
00007 // warranty. In no event will the authors be held liable for any damages
00008 // arising from the use of this software.
00009 // 
00010 // Permission is granted to anyone to use this software for any purpose,
00011 // including commercial applications, and to alter it and redistribute it
00012 // freely, subject to the following restrictions:
00013 // 
00014 // 1. The origin of this software must not be misrepresented; you must not
00015 //    claim that you wrote the original software. If you use this software
00016 //    in a product, an acknowledgment in the product documentation would be
00017 //    appreciated but is not required.
00018 // 
00019 // 2. Altered source versions must be plainly marked as such, and must not be
00020 //    misrepresented as being the original software.
00021 // 
00022 // 3. This notice may not be removed or altered from any source distribution.
00023 //
00025 
00028 
00029 #ifndef THOR_CONCAVESHAPE_HPP
00030 #define THOR_CONCAVESHAPE_HPP
00031 
00032 #include <Thor/Config.hpp>
00033 
00034 #include <SFML/Graphics/Color.hpp>
00035 #include <SFML/Graphics/ConvexShape.hpp>
00036 #include <SFML/Graphics/Drawable.hpp>
00037 #include <SFML/Graphics/Transformable.hpp>
00038 #include <SFML/Graphics/VertexArray.hpp>
00039 
00040 #include <vector>
00041 
00042 
00043 namespace thor
00044 {
00045 
00048 
00052 class THOR_API ConcaveShape : public sf::Drawable, public sf::Transformable
00053 {
00054     // ---------------------------------------------------------------------------------------------------------------------------
00055     // Public member functions
00056     public:
00059                                     ConcaveShape();
00060 
00063                                     ConcaveShape(const sf::Shape& shape);
00064 
00067         void                        setPointCount(std::size_t count);
00068 
00071         std::size_t                 getPointCount() const;
00072 
00076         void                        setPoint(std::size_t index, sf::Vector2f position);
00077 
00080         sf::Vector2f                getPoint(std::size_t index) const;
00081 
00084         void                        setFillColor(const sf::Color& fillColor);
00085 
00088         void                        setOutlineColor(const sf::Color& outlineColor);
00089 
00092         sf::Color                   getFillColor() const;
00093 
00096         sf::Color                   getOutlineColor() const;
00097 
00100         void                        setOutlineThickness(float outlineThickness);
00101 
00104         float                       getOutlineThickness() const;
00105 
00108         sf::FloatRect               getLocalBounds() const;
00109 
00114         sf::FloatRect               getGlobalBounds() const;
00115 
00116 
00117     // ---------------------------------------------------------------------------------------------------------------------------
00118     // Private types
00119     private:
00120         struct TriangleGenerator;
00121 
00122 
00123     // ---------------------------------------------------------------------------------------------------------------------------
00124     // Private member functions
00125     private:
00126         // Renders the shape to target.
00127         virtual void                draw(sf::RenderTarget& target, sf::RenderStates states) const;
00128 
00129         // Computes how the shape can be split up into convex triangles.
00130         void                        ensureDecomposed() const;
00131 
00132         // Forms the outline out of the given edges.
00133         void                        ensureOutlineUpdated() const;
00134 
00135 
00136     // ---------------------------------------------------------------------------------------------------------------------------
00137     // Private variables
00138     private:
00139         std::vector<sf::Vector2f>               mPoints;
00140         sf::Color                               mFillColor;
00141         sf::Color                               mOutlineColor;
00142         float                                   mOutlineThickness;
00143 
00144         mutable sf::VertexArray                 mTriangleVertices;
00145         mutable std::vector<sf::ConvexShape>    mOutlineShapes;
00146         mutable sf::FloatRect                   mLocalBounds;
00147         mutable bool                            mNeedsDecomposition;
00148         mutable bool                            mNeedsOutlineUpdate;
00149 };
00150 
00152 
00153 } // namespace thor
00154 
00155 #endif // THOR_CONCAVESHAPE_HPP