]> git.localhorst.tv Git - gworm.git/blob - src/graphics/Rect.h
added texture support
[gworm.git] / src / graphics / Rect.h
1 #ifndef GWORM_RECT_H_
2 #define GWORM_RECT_H_
3
4 #include "Vector.h"
5
6 #include <SDL.h>
7
8
9 namespace gworm {
10
11 template<class Scalar>
12 class Rect {
13
14 public:
15         constexpr Rect() : x(0), y(0), w(0), h(0) { }
16         constexpr Rect(Vector<Scalar> pos, Vector<Scalar> size)
17         : x(pos.x), y(pos.y), w(size.x), h(size.y) { }
18
19 public:
20         constexpr Vector<Scalar> Pos() const { return Vector<Scalar>(x, y); }
21         constexpr Vector<Scalar> Size() const { return Vector<Scalar>(w, h); }
22
23 public:
24         Scalar x;
25         Scalar y;
26         Scalar w;
27         Scalar h;
28
29 };
30
31
32 /// specialization with same layout as SDL_Rect
33 template<>
34 class Rect<int>
35 : public SDL_Rect {
36
37 public:
38         constexpr Rect() : SDL_Rect({0, 0, 0, 0}) { }
39         constexpr Rect(Vector<int> pos, Vector<int> size)
40         : SDL_Rect({pos.x, pos.y, size.x, size.y}) { }
41
42 public:
43         constexpr Vector<int> Pos() const { return Vector<int>(x, y); }
44         constexpr Vector<int> Size() const { return Vector<int>(w, h); }
45
46 };
47
48 }
49
50 #endif