Arrow.hpp
Go to the documentation of this file.
1 //
3 // Thor C++ Library
4 // Copyright (c) 2011-2016 Jan Haller
5 //
6 // This software is provided 'as-is', without any express or implied
7 // warranty. In no event will the authors be held liable for any damages
8 // arising from the use of this software.
9 //
10 // Permission is granted to anyone to use this software for any purpose,
11 // including commercial applications, and to alter it and redistribute it
12 // freely, subject to the following restrictions:
13 //
14 // 1. The origin of this software must not be misrepresented; you must not
15 // claim that you wrote the original software. If you use this software
16 // in a product, an acknowledgment in the product documentation would be
17 // appreciated but is not required.
18 //
19 // 2. Altered source versions must be plainly marked as such, and must not be
20 // misrepresented as being the original software.
21 //
22 // 3. This notice may not be removed or altered from any source distribution.
23 //
25 
28 
29 #ifndef THOR_ARROW_HPP
30 #define THOR_ARROW_HPP
31 
32 #include <Thor/Config.hpp>
33 
34 #include <SFML/Graphics/Drawable.hpp>
35 #include <SFML/Graphics/Transformable.hpp>
36 #include <SFML/Graphics/ConvexShape.hpp>
37 
38 
39 namespace thor
40 {
41 
44 
48 class THOR_API Arrow : public sf::Drawable, public sf::Transformable
49 {
50  // ---------------------------------------------------------------------------------------------------------------------------
51  // Public types
52  public:
55  enum Style
56  {
57  Line,
59  };
60 
61 
62  // ---------------------------------------------------------------------------------------------------------------------------
63  // Public static member functions
64  public:
68  static void setZeroVectorTolerance(float tolerance);
69 
72  static float getZeroVectorTolerance();
73 
74 
75  // ---------------------------------------------------------------------------------------------------------------------------
76  // Public member functions
77  public:
83  explicit Arrow(sf::Vector2f position = sf::Vector2f(), sf::Vector2f direction = sf::Vector2f(),
84  const sf::Color& color = sf::Color::White, float thickness = 3.f);
85 
88  void setDirection(sf::Vector2f direction);
89 
92  void setDirection(float dirX, float dirY);
93 
96  sf::Vector2f getDirection() const;
97 
100  void setThickness(float thickness);
101 
104  float getThickness() const;
105 
108  void setColor(const sf::Color& color);
109 
112  sf::Color getColor() const;
113 
116  void setStyle(Style style);
117 
120  Style getStyle() const;
121 
122 
123  // ---------------------------------------------------------------------------------------------------------------------------
124  // Private member functions
125  private:
126  float getTriangleHeight() const;
127  void adaptLine() const;
128  void adaptTriangle() const;
129  void draw(sf::RenderTarget& target, sf::RenderStates states) const;
130 
131 
132  // ---------------------------------------------------------------------------------------------------------------------------
133  // Private variables
134  private:
135  float mThickness;
136  float mLength;
137  sf::Vector2f mDirection;
138  sf::Color mColor;
139  Style mStyle;
140 
141  mutable bool mNeedsShapeUpdate;
142  mutable sf::ConvexShape mLine;
143  mutable sf::ConvexShape mTriangle;
144 
145  static float zeroVectorTolerance;
146 
147 };
148 
150 
151 } // namespace thor
152 
153 #endif // THOR_ARROW_HPP
void setColor(T &object, const sf::Color &color)
Sets the color of a graphical object.
Straight line without any triangles.
Definition: Arrow.hpp:57
Definition: AnimationMap.hpp:42
Drawable arrow class.
Definition: Arrow.hpp:48
Configuration header of the library.
Style
Determines whether the arrow has a triangle on his endpoint.
Definition: Arrow.hpp:55
Normal unidirectional arrow.
Definition: Arrow.hpp:58