sf-svg
Base.hpp
Go to the documentation of this file.
1 /* =========================================================== *
2  * sf-svg (c) Kamil Koczurek | koczurekk@gmail.com *
3  * GNU GPL v3 License http://www.gnu.org/licenses/gpl-3.0.html *
4  * =========================================================== */
9 
10 #ifndef SFAS_BASE_HPP
11 #define SFAS_BASE_HPP
12 
13 #include <SFML/Graphics/RenderTarget.hpp>
14 #include <SFML/Graphics/RenderStates.hpp>
15 #include <SFML/Graphics/Drawable.hpp>
16 #include <SFML/Graphics/Vertex.hpp>
17 #include <SFML/System/Vector2.hpp>
18 
20 namespace sfc {
21 
23  enum class DrawMode {
25  NORMAL,
26 
28  DEBUG,
29 
31  NONE
32  };
33 
48  template<typename T>
49  struct Line2
50  : public sf::Drawable {
51 
53  sf::Vector2<T> point;
54 
58  sf::Vector2<T> vector;
59 
61  sf::Color color;
62 
66  Line2() {
67  point = {0, 0};
68  vector = {0, 0};
69  color = {255, 255, 255};
70  }
71 
79  Line2(const sf::Vector2<T> point, const sf::Vector2<T> vector, const sf::Color color = sf::Color::White) {
80  this->point = point;
81  this->vector = vector;
82  this->color = color;
83  }
84 
88  T length() {
89  return sqrt(vector.x * vector.x + vector.y * vector.y);
90  }
91 
92  private:
93  virtual void draw(sf::RenderTarget &target, sf::RenderStates states) const {
94  sf::Vertex tab[2] =
95  {{point, this->color},
96  {point + vector, this->color}};
97 
98  target.draw(tab, 2, sf::Lines, states);
99  }
100  };
101 }
102 
103 #endif // SYSTEM_HPP
sf::Color color
Color of the line.
Definition: Base.hpp:61
Namespace that contains all sf-svg method, classes, enums etc.
Definition: Base.hpp:20
T length()
Calculate length.
Definition: Base.hpp:88
DrawMode
Way to draw curves.
Definition: Base.hpp:23
Don&#39;t draw curve.
Line2()
Default constructor.
Definition: Base.hpp:66
Draw also helper lines etc.
Line2(const sf::Vector2< T > point, const sf::Vector2< T > vector, const sf::Color color=sf::Color::White)
Specialized constructor.
Definition: Base.hpp:79
Just draw the curve.
sf::Vector2< T > vector
Vector (offset)
Definition: Base.hpp:58
sf::Vector2< T > point
Beginning of the line.
Definition: Base.hpp:53
2D line
Definition: Base.hpp:49