]> git.localhorst.tv Git - gworm.git/blobdiff - src/graphics/Rect.h
added texture support
[gworm.git] / src / graphics / Rect.h
diff --git a/src/graphics/Rect.h b/src/graphics/Rect.h
new file mode 100644 (file)
index 0000000..7cef9d1
--- /dev/null
@@ -0,0 +1,50 @@
+#ifndef GWORM_RECT_H_
+#define GWORM_RECT_H_
+
+#include "Vector.h"
+
+#include <SDL.h>
+
+
+namespace gworm {
+
+template<class Scalar>
+class Rect {
+
+public:
+       constexpr Rect() : x(0), y(0), w(0), h(0) { }
+       constexpr Rect(Vector<Scalar> pos, Vector<Scalar> size)
+       : x(pos.x), y(pos.y), w(size.x), h(size.y) { }
+
+public:
+       constexpr Vector<Scalar> Pos() const { return Vector<Scalar>(x, y); }
+       constexpr Vector<Scalar> Size() const { return Vector<Scalar>(w, h); }
+
+public:
+       Scalar x;
+       Scalar y;
+       Scalar w;
+       Scalar h;
+
+};
+
+
+/// specialization with same layout as SDL_Rect
+template<>
+class Rect<int>
+: public SDL_Rect {
+
+public:
+       constexpr Rect() : SDL_Rect({0, 0, 0, 0}) { }
+       constexpr Rect(Vector<int> pos, Vector<int> size)
+       : SDL_Rect({pos.x, pos.y, size.x, size.y}) { }
+
+public:
+       constexpr Vector<int> Pos() const { return Vector<int>(x, y); }
+       constexpr Vector<int> Size() const { return Vector<int>(w, h); }
+
+};
+
+}
+
+#endif