SFGF
Plane.hpp
1 #ifndef PLANE_HPP
2 #define PLANE_HPP
3 
4 /* =========================================================== *
5  * SFGF (c) Kamil Koczurek | koczurekk@gmail.com *
6  * GNU GPL v3 License http://www.gnu.org/licenses/gpl-3.0.html *
7  * =========================================================== */
8 
9 #include <SFML/Graphics/Texture.hpp>
10 #include "Polygon.hpp"
11 
12 namespace sfgf {
13  class Plane
14  : public Polygon {
15  public:
16  Plane();
17 
18  void setTexture(const sf::Texture& tex);
19 
20  void setSize(sf::Vector2f size);
21  sf::Vector2f getSize() const;
22  void selfCenter();
23  };
24 
25  Plane::Plane()
26  : Polygon(4)
27  {}
28 
29  void Plane::setTexture(const sf::Texture& tex) {
30  Polygon::setTexture(tex, {
31  {0.f, 0.f},
32  {static_cast<float>(tex.getSize().x), 0.f},
33  static_cast<sf::Vector2f>(tex.getSize()),
34  {0.f, static_cast<float>(tex.getSize().y)}
35  });
36  }
37 
38  void Plane::setSize(sf::Vector2f size) {
39  setVertices({
40  {0, 0},
41  {size.x, 0},
42  size,
43  {0, size.y}
44  });
45  }
46  sf::Vector2f Plane::getSize() const {
47  return getVertices()[2].position;
48  }
49  void Plane::selfCenter() {
50  setOrigin(getSize() / 2.f);
51  }
52 }
53 
54 #endif // PLANE_HPP
Contains all SFGF classes.
Definition: Plane.hpp:13
Definition: Polygon.hpp:16