Bromeon
Multimedia/ConcaveShape.hpp
Go to the documentation of this file.
00001 
00002 //
00003 // Thor C++ Library
00004 // Copyright (c) 2011-2012 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/Math/TriangulationFigures.hpp>
00033 #include <Thor/SmartPtr/CopiedPtr.hpp>
00034 #include <Thor/Detail/Swap.hpp>
00035 #include <Thor/Config.hpp>
00036 
00037 #include <SFML/Graphics/Drawable.hpp>
00038 #include <SFML/Graphics/Transformable.hpp>
00039 #include <SFML/Graphics/Color.hpp>
00040 
00041 #include <vector>
00042 
00043 
00044 namespace sf
00045 {
00046 
00047     class Shape;
00048 
00049 } // namespace sf
00050 
00051 
00052 namespace thor
00053 {
00054 
00057 
00061 class THOR_API ConcaveShape : public sf::Drawable, public sf::Transformable
00062 {
00063     // ---------------------------------------------------------------------------------------------------------------------------
00064     // Public member functions
00065     public:
00068                                     ConcaveShape();
00069                             
00072                                     ConcaveShape(const sf::Shape& shape);
00073 
00076         void                        Swap(ConcaveShape& other);
00077 
00078         
00081         void                        SetPointCount(unsigned int count);
00082 
00085         unsigned int                GetPointCount() const;
00086 
00090         void                        SetPoint(unsigned int index, sf::Vector2f position);
00091 
00094         sf::Vector2f                GetPoint(unsigned int index) const;
00095 
00098         void                        SetFillColor(const sf::Color& fillColor);
00099 
00102         void                        SetOutlineColor(const sf::Color& outlineColor);
00103 
00106         sf::Color                   GetFillColor() const;
00107 
00110         sf::Color                   GetOutlineColor() const;
00111 
00114         void                        SetOutlineThickness(float outlineThickness);
00115         
00118         float                       GetOutlineThickness() const;
00119         
00120 
00121     // ---------------------------------------------------------------------------------------------------------------------------
00122     // Private types
00123     private:            
00124         // Container typedefs
00125         typedef std::vector< CopiedPtr<sf::Shape> > ShapeContainer;
00126         typedef std::vector< Vertex >               PointContainer;
00127         typedef std::vector< Edge<Vertex> >         EdgeContainer;
00128 
00129         struct TriangleGenerator;
00130 
00131 
00132     // ---------------------------------------------------------------------------------------------------------------------------
00133     // Private member functions
00134     private:
00135         // Renders the shape to target.
00136         virtual void                Draw(sf::RenderTarget& target, sf::RenderStates states) const;
00137         
00138         // Computes how the shape can be split up into convex triangles.
00139         void                        Decompose() const;
00140                 
00141         // Forms the outline out of the given edges.
00142         void                        FormOutline() const;
00143 
00144 
00145     // ---------------------------------------------------------------------------------------------------------------------------
00146     // Private variables
00147     private:
00148         PointContainer              mPoints;
00149         sf::Color                   mFillColor;
00150         sf::Color                   mOutlineColor;
00151         float                       mOutlineThickness;
00152 
00153         mutable EdgeContainer       mEdges;
00154         mutable ShapeContainer      mTriangleShapes;
00155         mutable ShapeContainer      mEdgeShapes;
00156         mutable bool                mNeedsTriangleUpdate;
00157         mutable bool                mNeedsEdgeUpdate;
00158 };
00159 
00162 THOR_GLOBAL_SWAP(ConcaveShape)
00163 
00164 
00165 
00166 } // namespace thor
00167 
00168 #endif // THOR_CONCAVESHAPE_HPP