Bromeon
Multimedia/Arrow.hpp
Go to the documentation of this file.
00001 
00002 //
00003 // Thor C++ Library
00004 // Copyright (c) 2011 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_ARROW_HPP
00030 #define THOR_ARROW_HPP
00031 
00032 #include <Thor/Config.hpp>
00033 
00034 #include <SFML/Graphics/Drawable.hpp>
00035 #include <SFML/Graphics/Shape.hpp>
00036 
00037 
00038 namespace thor
00039 {
00040 
00043 
00046 class THOR_API Arrow : public sf::Drawable
00047 {
00048     // ---------------------------------------------------------------------------------------------------------------------------
00049     // Public static member functions
00050     public:
00054         static void                 SetZeroVectorTolerance(float tolerance);
00055         
00058         static float                GetZeroVectorTolerance();
00059 
00060 
00061     // ---------------------------------------------------------------------------------------------------------------------------
00062     // Public member functions
00063     public:
00069         explicit                    Arrow(sf::Vector2f position = sf::Vector2f(), sf::Vector2f direction = sf::Vector2f(),
00070                                         const sf::Color& color = sf::Color::White, float thickness = 3.f);
00071 
00074         void                        SetDirection(sf::Vector2f direction);
00075         
00078         void                        SetDirection(float dirX, float dirY);
00079         
00082         sf::Vector2f                GetDirection() const;
00083 
00086         void                        SetThickness(float thickness);
00087         
00090         float                       GetThickness() const;
00091         
00092 
00093     // ---------------------------------------------------------------------------------------------------------------------------
00094     // Private member functions
00095     private:
00096         float                       GetTriangleHeight() const;
00097         void                        AdaptLine() const;
00098         void                        AdaptTriangle() const;
00099         void                        Render(sf::RenderTarget& target, sf::Renderer& renderer) const;
00100 
00101 
00102     // ---------------------------------------------------------------------------------------------------------------------------
00103     // Private variables
00104     private:
00105         float                       mThickness;
00106         float                       mLength;
00107         sf::Vector2f                mDirection;
00108     
00109         mutable bool                mNeedsShapeUpdate;
00110         mutable sf::Shape           mLine;
00111         mutable sf::Shape           mTriangle;
00112         
00113         static float                zeroVectorTolerance;
00114         
00115 };
00116 
00118 
00119 } // namespace thor
00120 
00121 #endif // THOR_ARROW_HPP